refactored a few types involved in the touch interface and corrected a few invisible mistakes
--- a/hedgewars/options.inc Fri Feb 17 09:33:03 2012 +0100
+++ b/hedgewars/options.inc Fri Feb 17 12:08:01 2012 +0100
@@ -51,6 +51,7 @@
{$IFDEF WIN32}
{$DEFINE USE_CONTEXT_RESTORE}
+ {$DEFINE USE_TOUCH_INTERFACE}
{$ENDIF}
{$IFNDEF IPHONEOS}
--- a/hedgewars/uMisc.pas Fri Feb 17 09:33:03 2012 +0100
+++ b/hedgewars/uMisc.pas Fri Feb 17 12:08:01 2012 +0100
@@ -27,7 +27,11 @@
function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;
function MakeScreenshot(filename: shortstring): boolean;
function GetTeamStatString(p: PTeam): shortstring;
-
+{$IFDEF SDL13}
+function SDL_RectMake(x, y, width, height: LongInt): TSDL_Rect;
+{$ELSE}
+function SDL_RectMake(x, y: SmallInt; width, height: Word): TSDL_Rect;
+{$ENDIF}
procedure initModule;
procedure freeModule;
@@ -144,6 +148,19 @@
exit(tmpsurf);
end;
+{$IFDEF SDL13}
+function SDL_RectMake(x, y, width, height: LongInt): TSDL_Rect;
+{$ELSE}
+function SDL_RectMake(x, y: SmallInt; width, height: Word): TSDL_Rect;
+{$ENDIF}
+var rect: TSDL_Rect;
+begin
+ rect.x:= x;
+ rect.y:= y;
+ rect.w:= width;
+ rect.h:= height;
+ exit(rect);
+end;
function GetTeamStatString(p: PTeam): shortstring;
var s: ansistring;
--- a/hedgewars/uRender.pas Fri Feb 17 09:33:03 2012 +0100
+++ b/hedgewars/uRender.pas Fri Feb 17 12:08:01 2012 +0100
@@ -470,19 +470,19 @@
if RealTicks > (startTime + MOVE_ANIM_TIME) then
begin
startTime:= 0;
- x:= targetToX;
- y:= targetToY;
+ frame.x:= target.x;
+ frame.y:= target.y;
end
else
begin
- x:= targetFromX + Round((targetToX - targetFromX) * ((RealTicks - startTime) / MOVE_ANIM_TIME));
- y:= targetFromY + Round((targetToY - targetFromY) * ((RealTicks - startTime) / MOVE_ANIM_TIME));
+ frame.x:= source.x + Round((target.x - source.x) * ((RealTicks - startTime) / MOVE_ANIM_TIME));
+ frame.y:= source.y + Round((target.y - source.y) * ((RealTicks - startTime) / MOVE_ANIM_TIME));
end;
if show or (fadeAnimStart <> 0) then
begin
Tint($FF, $FF, $FF, alpha);
- DrawTexture(x, y, spritesData[sprite].Texture, buttonScale);
+ DrawTexture(frame.x, frame.y, spritesData[sprite].Texture, buttonScale);
Tint($FF, $FF, $FF, $FF);
end;
end;
--- a/hedgewars/uTouch.pas Fri Feb 17 09:33:03 2012 +0100
+++ b/hedgewars/uTouch.pas Fri Feb 17 12:08:01 2012 +0100
@@ -50,7 +50,6 @@
function fingerHasMoved(finger: TTouch_Data): boolean;
function calculateDelta(finger1, finger2: TTouch_Data): hwFloat;
function getSecondFinger(finger: TTouch_Data): PTouch_Data;
-function isOnRect(widget: TOnScreenWidget; finger: TTouch_Data): boolean;
function isOnRect(rect: TSDL_Rect; finger: TTouch_Data): boolean;
procedure printFinger(finger: TTouch_Data);
implementation
@@ -99,48 +98,48 @@
exit;
end;
- if isOnRect(fireButton, finger^) then
+ if isOnRect(fireButton.active, finger^) then
begin
stopFiring:= false;
spaceKey:= true;
exit;
end;
- if isOnRect(arrowLeft, finger^) then
+ if isOnRect(arrowLeft.active, finger^) then
begin
leftKey:= true;
walkingLeft := true;
exit;
end;
- if isOnRect(arrowRight, finger^) then
+ if isOnRect(arrowRight.active, finger^) then
begin
rightKey:= true;
walkingRight:= true;
exit;
end;
- if isOnRect(arrowUp, finger^) then
+ if isOnRect(arrowUp.active, finger^) then
begin
upKey:= true;
aimingUp:= true;
exit;
end;
- if isOnRect(arrowDown, finger^) then
+ if isOnRect(arrowDown.active, finger^) then
begin
downKey:= true;
aimingDown:= true;
exit;
end;
- if isOnRect(backjump, finger^) then
+ if isOnRect(backjump.active, finger^) then
begin
enterKey:= true;
exit;
end;
- if isOnRect(forwardjump, finger^) then
+ if isOnRect(forwardjump.active, finger^) then
begin
backspaceKey:= true;
exit;
end;
- if isOnRect(pauseButton, finger^) then
+ if isOnRect(pauseButton.active, finger^) then
begin
isPaused:= not isPaused;
exit;
@@ -543,24 +542,10 @@
end;
function isOnRect(rect: TSDL_Rect; finger: TTouch_Data): boolean;
-var widget: TOnScreenWidget;
-begin
- widget.x:= rect.x;
- widget.y:= rect.y;
- widget.width:= rect.w;
- widget.height:= rect.h;
- widget.hOffset:= 0;
- widget.vOffset:= 0;
- exit(isOnRect(widget, finger));
-end;
-
-function isOnRect(widget: TOnScreenWidget; finger: TTouch_Data): boolean;
-begin
-with widget do
- isOnRect:= (finger.x > x + hOffset) and
- (finger.x < x + width + hOffset) and
- (cScreenHeight - finger.y > y + vOffset) and
- (cScreenHeight - finger.y < y + height + vOffset);
+ isOnRect:= (finger.x > rect.x) and
+ (finger.x < rect.x + rect.w) and
+ (cScreenHeight - finger.y > rect.y) and
+ (cScreenHeight - finger.y < rect.y + rect.h);
end;
procedure printFinger(finger: TTouch_Data);
--- a/hedgewars/uTypes.pas Fri Feb 17 09:33:03 2012 +0100
+++ b/hedgewars/uTypes.pas Fri Feb 17 12:08:01 2012 +0100
@@ -426,20 +426,19 @@
PWidgetMovement = ^TWidgetMovement;
TWidgetMovement = record
animate: Boolean;
- targetFromX, targetFromY: LongInt;
- targetToX, targetToY: LongInt;
+ source: TPoint;
+ target: TPoint;
startTime: Longword;
end;
POnScreenWidget = ^TOnScreenWidget;
TOnScreenWidget = record
- show: boolean;
- sprite: TSprite;
- x, y: LongInt; // graphical coordinates
- hOffset, width: LongInt; // horizontal active region
- vOffset, height: LongInt; // vertical active region
- fadeAnimStart: Longword; //time the fade started, 0 means don't fade
- moveAnim: TWidgetMovement;
+ show: boolean; // if false widget will not be drawn
+ sprite: TSprite; // a convenience type
+ frame: TSDL_Rect; // graphical coordinates
+ active: TSDL_Rect; // active touch region
+ fadeAnimStart: Longword; // time the fade started, 0 means don't fade
+ moveAnim: TWidgetMovement; // the animation associated to the widget
end;
{$IFDEF SDL13}
--- a/hedgewars/uWorld.pas Fri Feb 17 09:33:03 2012 +0100
+++ b/hedgewars/uWorld.pas Fri Feb 17 12:08:01 2012 +0100
@@ -213,73 +213,76 @@
//positioning of the buttons
buttonScale:= 1.5/cDefaultZoomLevel;
-//TODO: add sensible hOffset and vOffset values
-firebutton.x:= (cScreenWidth shr 1) - Round(spritesData[sprFireButton].Texture^.h * buttonScale);
-firebutton.y:= -Round(spritesData[sprFireButton].Texture^.h* buttonScale) + cScreenHeight;
-firebutton.width:= Round(spritesData[sprFireButton].Texture^.w * buttonScale);
-firebutton.height:= Round(spritesData[sprFireButton].Texture^.h * buttonScale);
-firebutton.hOffset:= 0;
-firebutton.vOffset:= 0;
-firebutton.sprite:= sprFireButton;
-firebutton.show:= true;
+with firebutton do
+ begin
+ show:= true;
+ sprite:= sprFireButton;
+ frame.w:= Round(spritesData[sprite].Texture^.w * buttonScale);
+ frame.h:= Round(spritesData[sprite].Texture^.h * buttonScale);
+ frame.x:= (cScreenWidth shr 1) - frame.w;
+ frame.y:= cScreenHeight - frame.h;
+ active:= frame;
+ end;
-backjump.x:= (cScreenWidth shr 1) - Round(spritesData[sprbackjump].Texture^.h * 2 * buttonScale);
-backjump.y:= -Round(spritesData[sprbackjump].Texture^.h * 1.2 * buttonScale) + cScreenHeight;
-backjump.width:= Round(spritesData[sprbackjump].Texture^.w * buttonScale);
-backjump.height:= Round(spritesData[sprbackjump].Texture^.h * buttonScale);
-backjump.hOffset:= 0;
-backjump.vOffset:= 0;
-backjump.sprite:= sprbackjump;
-backjump.show:= true;
+with backjump do
+ begin
+ show:= true;
+ sprite:= sprbackjump;
+ frame.w:= Round(spritesData[sprite].Texture^.w * buttonScale);
+ frame.h:= Round(spritesData[sprite].Texture^.h * buttonScale);
+ frame.x:= (cScreenWidth shr 1) - frame.w * 2;
+ frame.y:= cScreenHeight - Round(frame.h * 1.2);
+ active:= frame;
+ end;
-forwardjump.x:= (cScreenWidth shr 1) - Round(spritesData[sprforwardjump].Texture^.h * 1.2 * buttonScale);
-forwardjump.y:= -Round(spritesData[sprforwardjump].Texture^.h * 2 * buttonScale) + cScreenHeight;
-forwardjump.width:= Round(spritesData[sprforwardjump].Texture^.w * buttonScale);
-forwardjump.height:= Round(spritesData[sprforwardjump].Texture^.h * buttonScale);
-forwardjump.hOffset:= 0;
-forwardjump.vOffset:= 0;
-forwardjump.sprite:= sprforwardjump;
-forwardjump.show:= true;
+with forwardjump do
+ begin
+ show:= true;
+ sprite:= sprforwardjump;
+ frame.w:= Round(spritesData[sprite].Texture^.w * buttonScale);
+ frame.h:= Round(spritesData[sprite].Texture^.h * buttonScale);
+ frame.x:= (cScreenWidth shr 1) - Round(frame.w * 1.2);
+ frame.y:= cScreenHeight - frame.h * 2;
+ active:= frame;
+ end;
with arrowLeft do
begin
show:= true;
sprite:= sprArrowLeft;
- x:= -(cScreenWidth shr 1) + Round(spritesData[sprite].Texture^.h*buttonScale * 0.25);
- y:= -Round(spritesData[sprite].Texture^.h*buttonScale) + cScreenHeight - Round(spritesData[sprite].Texture^.h*buttonScale *0.5);
- width:= Round(spritesData[sprite].Texture^.h * buttonScale);
- height:= Round(spritesData[sprite].Texture^.h * buttonScale);
- hOffset:= 0;
- vOffset:= 0;
+ frame.w:= Round(spritesData[sprite].Texture^.w * buttonScale);
+ frame.h:= Round(spritesData[sprite].Texture^.h * buttonScale);
+ frame.x:= -(cScreenWidth shr 1) + Round(frame.w * 0.25);
+ frame.y:= cScreenHeight - Round(frame.h * 1.5);
+ active:= frame;
end;
+
with arrowRight do
begin
show:= true;
sprite:= sprArrowRight;
- x:= -(cScreenWidth shr 1) + Round(spritesData[sprite].Texture^.h * buttonScale *1.5);
- y:= -Round(spritesData[sprite].Texture^.h*buttonScale) + cScreenHeight - Round(spritesData[sprite].Texture^.h*buttonScale * 0.5);
- width:= Round(spritesData[sprite].Texture^.w * buttonScale);
- height:= Round(spritesData[sprite].Texture^.h * buttonScale);
- hOffset:= 0;
- vOffset:= 0;
+ frame.w:= Round(spritesData[sprite].Texture^.w * buttonScale);
+ frame.h:= Round(spritesData[sprite].Texture^.h * buttonScale);
+ frame.x:= -(cScreenWidth shr 1) + Round(frame.w * 1.5);
+ frame.y:= cScreenHeight - Round(frame.h * 1.5);
+ active:= frame;
end;
with arrowUp do
begin
show:= false;
sprite:= sprArrowUp;
- x:= (cScreenWidth shr 1) - Round(spritesData[sprite].Texture^.w * buttonScale *2);
- y:= backjump.y -Round(spritesData[sprite].Texture^.h * buttonScale*2.25);
- width:= Round(spritesData[sprite].Texture^.w * buttonScale);
- height:= Round(spritesData[sprite].Texture^.h * buttonScale);
- hOffset:= 0;
- vOffset:= 0;
+ frame.w:= Round(spritesData[sprite].Texture^.w * buttonScale);
+ frame.h:= Round(spritesData[sprite].Texture^.h * buttonScale);
+ frame.x:= (cScreenWidth shr 1) - frame.w * 2;
+ frame.y:= backjump.frame.y - Round(frame.h * 2.25);
+ active:= frame;
with moveAnim do
begin
- targetToX:= arrowUp.x;
- targetToY:= arrowUp.y;
- targetFromX:= arrowUp.x - Round(spritesData[sprite].Texture^.w * buttonScale *0.75);
- targetFromY:= arrowUp.y;
+ target.x:= frame.x;
+ target.y:= frame.y;
+ source.x:= frame.x - Round(frame.w * 0.75);
+ source.y:= frame.y;
end;
end;
@@ -287,29 +290,30 @@
begin
show:= false;
sprite:= sprArrowDown;
- x:= (cScreenWidth shr 1) - Round(spritesData[sprite].Texture^.w * buttonScale * 2);
- y:= backjump.y -Round(spritesData[sprite].Texture^.h * buttonScale *2.25);
- width:= Round(spritesData[sprite].Texture^.w * buttonScale);
- height:= Round(spritesData[sprite].Texture^.h * buttonScale);
- hOffset:= 0;
- vOffset:= 0;
+ frame.w:= Round(spritesData[sprite].Texture^.w * buttonScale);
+ frame.h:= Round(spritesData[sprite].Texture^.h * buttonScale);
+ frame.x:= (cScreenWidth shr 1) - frame.w * 2;
+ frame.y:= backjump.frame.y - Round(frame.h * 2.25);
+ active:= frame;
with moveAnim do
begin
- targetToX:= arrowDown.x;
- targetToY:= arrowDown.y;
- targetFromX:= arrowDown.x + Round(spritesData[sprite].Texture^.w * buttonScale *0.75);
- targetFromY:= arrowDown.y;
+ target.x:= frame.x;
+ target.y:= frame.y;
+ source.x:= frame.x + Round(frame.w * 0.75);
+ source.y:= frame.y;
end;
end;
-pauseButton.x:= cScreenWidth div 2 - Round(spritesData[sprPauseButton].Texture^.w * buttonscale);
-pauseButton.y:= 0; //-Round(spritesData[sprPauseButton].Texture^.h * buttonscale);
-pauseButton.width:= Round(spritesData[sprPauseButton].Texture^.w * buttonScale);;
-pauseButton.height:= Round(spritesData[sprPauseButton].Texture^.h * buttonScale);;
-pauseButton.hOffset:= 0;
-pauseButton.vOffset:= 0;
-pauseButton.sprite:= sprPauseButton;
-pauseButton.show:= true;
+with pauseButton do
+ begin
+ show:= true;
+ sprite:= sprPauseButton;
+ frame.w:= Round(spritesData[sprPauseButton].Texture^.w * buttonScale);
+ frame.h:= Round(spritesData[sprPauseButton].Texture^.h * buttonScale);
+ frame.x:= cScreenWidth div 2 - frame.w;
+ frame.y:= 0;
+ active:= frame;
+ end;
{$ENDIF}
end;
@@ -1187,17 +1191,7 @@
DrawScreenWidget(@backjump);
DrawScreenWidget(@forwardjump);
DrawScreenWidget(@pauseButton);
-{
-DrawTexture(arrowLeft.x, arrowLeft.y, spritesData[sprArrowLeft].Texture, buttonScale);
-DrawTexture(arrowRight.x, arrowRight.y, spritesData[sprArrowRight].Texture, buttonScale);
-DrawTexture(arrowUp.x, arrowUp.y, spritesData[sprArrowUp].Texture, buttonScale);
-DrawTexture(arrowDown.x, arrowDown.y, spritesData[sprArrowDown].Texture, buttonScale);
-
-DrawTexture(fireButton.x, firebutton.y, spritesData[sprFireButton].Texture, buttonScale);
-DrawTexture(backjump.x, backjump.y, spritesData[sprBackjump].Texture, buttonScale);
-DrawTexture(forwardjump.x, forwardjump.y, spritesData[sprForwardjump].Texture, buttonScale);
-DrawTexture(pauseButton.x, pauseButton.y, spritesData[sprPauseButton].Texture, buttonScale);
-}{$ENDIF}
+{$ENDIF}
// Teams Healths
if TeamsCount * 20 > Longword(cScreenHeight) div 7 then // take up less screen on small displays
@@ -1343,7 +1337,7 @@
// fps
{$IFDEF USE_TOUCH_INTERFACE}
-offsetX:= pauseButton.y + pauseButton.height + 12;
+offsetX:= pauseButton.frame.y + pauseButton.frame.h + 12;
{$ELSE}
offsetX:= 10;
{$ENDIF}
@@ -1649,12 +1643,12 @@
begin
animate:= true;
startTime:= RealTicks;
- targetFromX:= targetFromX xor targetToX;//swap From <-> To
- targetToX:= targetFromX xor targetToX;
- targetFromX:= targetFromX xor targetToX;
- targetFromY:= targetFromY xor targetToY;
- targetToY:= targetFromY xor targetToY;
- targetFromY:= targetFromY xor targetToY;
+ source.x:= source.x xor target.x; //swap source <-> target
+ target.x:= source.x xor target.x;
+ source.x:= source.x xor target.x;
+ source.y:= source.y xor target.y;
+ target.y:= source.y xor target.y;
+ source.y:= source.y xor target.y;
end;
end;
end;