hedgewars/uTouch.pas
changeset 7194 d8e68cbca7ee
parent 7185 92a045156255
child 7237 1bbe31e0d707
equal deleted inserted replaced
7180:53ffc8853008 7194:d8e68cbca7ee
    60 implementation
    60 implementation
    61 
    61 
    62 const
    62 const
    63     clickTime = 200;
    63     clickTime = 200;
    64     nilFingerId = High(TSDL_FingerId);
    64     nilFingerId = High(TSDL_FingerId);
    65 
    65     baseRectSize = 96;
    66 var
    66 
       
    67 var
       
    68     rectSize, halfRectSize: LongInt;
       
    69 
    67     pointerCount : Longword;
    70     pointerCount : Longword;
    68     fingers: array of TTouch_Data;
    71     fingers: array of TTouch_Data;
    69     moveCursor : boolean;
    72     moveCursor : boolean;
    70     invertCursor : boolean;
    73     invertCursor : boolean;
    71 
    74 
   549     x,y : LongInt;
   552     x,y : LongInt;
   550 begin
   553 begin
   551     x := 0;//avoid compiler hint
   554     x := 0;//avoid compiler hint
   552     y := 0;
   555     y := 0;
   553     convertToFingerCoord(x, y, CrosshairX, CrosshairY);
   556     convertToFingerCoord(x, y, CrosshairX, CrosshairY);
   554   isOnCrosshair:= sqrt(sqr(finger.x-x) + sqr(finger.y-y)) < 50;
   557     isOnCrosshair:= isOnRect((x-HalfRectSize), (y-HalfRectSize), RectSize, RectSize, finger);
   555 //    isOnCrosshair:= isOnRect(x-24, y-24, 48, 48, finger);
   558     printFinger(finger);
       
   559     WriteLnToConsole(inttostr(finger.x) + '   ' + inttostr(x));
       
   560     WriteLnToConsole(inttostr(x) + '  ' + inttostr(y) + '   ' + inttostr(round(Android_JNI_getDensity() * 10)));
   556 end;
   561 end;
   557 
   562 
   558 function isOnCurrentHog(finger: TTouch_Data): boolean;
   563 function isOnCurrentHog(finger: TTouch_Data): boolean;
   559 var
   564 var
   560     x,y : LongInt;
   565     x,y : LongInt;
   561 begin
   566 begin
   562     x := 0;
   567     x := 0;
   563     y := 0;
   568     y := 0;
   564     convertToFingerCoord(x,y, hwRound(CurrentHedgehog^.Gear^.X), hwRound(CurrentHedgehog^.Gear^.Y));
   569     convertToFingerCoord(x,y, hwRound(CurrentHedgehog^.Gear^.X), hwRound(CurrentHedgehog^.Gear^.Y));
   565     isOnCurrentHog := sqrt(sqr(finger.X-x) + sqr(finger.Y-y)) < 50;
   570     isOnCurrentHog:= isOnRect((x-HalfRectSize), (y-HalfRectSize), RectSize, RectSize, finger);
   566 end;
   571 end;
   567 
   572 
   568 procedure convertToFingerCoord(var x,y : LongInt; oldX, oldY: LongInt);
   573 procedure convertToFingerCoord(var x,y : LongInt; oldX, oldY: LongInt);
   569 begin
   574 begin
   570     x := oldX + WorldDx;
   575     x := oldX + WorldDx;
   625 
   630 
   626 procedure initModule;
   631 procedure initModule;
   627 var
   632 var
   628     index: Longword;
   633     index: Longword;
   629     //uRenderCoordScaleX, uRenderCoordScaleY: Longword;
   634     //uRenderCoordScaleX, uRenderCoordScaleY: Longword;
       
   635     density: Single;
   630 begin
   636 begin
   631     buttonsDown:= 0;
   637     buttonsDown:= 0;
   632 
   638 
   633     setLength(fingers, 4);
   639     setLength(fingers, 4);
   634     for index := 0 to High(fingers) do 
   640     for index := 0 to High(fingers) do 
   635         fingers[index].id := nilFingerId;
   641         fingers[index].id := nilFingerId;
       
   642 
       
   643 {$IFDEF ANDROID}
       
   644     density:= Android_JNI_getDensity();
       
   645 {$ELSE}
       
   646     density:= 1.0;
       
   647 {$ENDIF}
       
   648 
       
   649     rectSize:= round(baseRectSize * density);
       
   650     halfRectSize:= rectSize shl 1;
   636 end;
   651 end;
   637 
   652 
   638 begin
   653 begin
   639 end.
   654 end.