hedgewars/uTouch.pas
changeset 6684 112a0eb8782b
parent 6683 75a1d84ac606
child 6685 ef706fccfb0a
equal deleted inserted replaced
6683:75a1d84ac606 6684:112a0eb8782b
    20 
    20 
    21 unit uTouch;
    21 unit uTouch;
    22 
    22 
    23 interface
    23 interface
    24 
    24 
    25 uses sysutils, math, uConsole, uVariables, SDLh, uFloat, uConsts, uIO, GLUnit;
    25 uses sysutils, math, uConsole, uVariables, SDLh, uFloat, uConsts, uIO, GLUnit, uTypes;
    26 
    26 
    27 // TODO: this type should be Int64
    27 // TODO: this type should be Int64
    28 // TODO: this type should be named TSDL_FingerId
    28 // TODO: this type should be named TSDL_FingerId
    29 type SDL_FingerId = LongInt;
    29 type SDL_FingerId = LongInt;
    30 
    30 
   551 end;
   551 end;
   552 
   552 
   553 function isOnRect(rect: TSDL_Rect; finger: Touch_Finger): boolean;
   553 function isOnRect(rect: TSDL_Rect; finger: Touch_Finger): boolean;
   554 var widget: TOnScreenWidget;
   554 var widget: TOnScreenWidget;
   555 begin
   555 begin
   556 	widget.x:= rect.x;
   556     widget.x:= rect.x;
   557 	widget.y:= rect.y;
   557     widget.y:= rect.y;
   558 	widget.width:= rect.width;
   558     widget.width:= rect.w;
   559 	widget.height:= rect.height;
   559     widget.height:= rect.h;
   560 	widget.hOffset:= 0;
   560     widget.hOffset:= 0;
   561 	widget.vOffset:= 0;
   561     widget.vOffset:= 0;
   562 	exit(isOnRect(widget, finger));
   562     exit(isOnRect(widget, finger));
   563 end;
   563 end;
   564 
   564 
   565 function isOnRect(widget: TOnScreenWidget; finger: Touch_Finger): boolean;
   565 function isOnRect(widget: TOnScreenWidget; finger: Touch_Finger): boolean;
   566 begin
   566 begin
   567 with widget do
   567 with widget do
   568 	isOnRect:= (finger.x > x + hOffset)   and
   568     isOnRect:= (finger.x > x + hOffset)   and
   569                (finger.x < x + w + hOffset) and
   569                (finger.x < x + width + hOffset) and
   570                (cScreenHeight - finger.y > y + vOffset)   and
   570                (cScreenHeight - finger.y > y + vOffset)   and
   571                (cScreenHeight - finger.y < y + h + vOffset));
   571                (cScreenHeight - finger.y < y + height + vOffset);
   572 end;
   572 end;
   573 
   573 
   574 procedure printFinger(finger: Touch_Finger);
   574 procedure printFinger(finger: Touch_Finger);
   575 begin
   575 begin
   576     WriteToConsole(Format('id:%d, (%d,%d), (%d,%d), time: %d', [finger.id, finger.x, finger.y, finger.historicalX, finger.historicalY, finger.timeSinceDown]));
   576     WriteToConsole(Format('id:%d, (%d,%d), (%d,%d), time: %d', [finger.id, finger.x, finger.y, finger.historicalX, finger.historicalY, finger.timeSinceDown]));