- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window cursor_issues
authorunc0rr
Mon, 02 May 2011 18:37:57 +0400
branchcursor_issues
changeset 5191 c7000a6b397b
parent 5189 dc1fe432b293
child 5193 16eda3643fc3
child 5198 6533e5450a21
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window - Fixes pointing target near water when zooming
hedgewars/uCursor.pas
hedgewars/uWorld.pas
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hedgewars/uCursor.pas	Mon May 02 18:37:57 2011 +0400
@@ -0,0 +1,32 @@
+unit uCursor;
+
+interface
+
+procedure init;
+procedure updatePosition;
+
+implementation
+
+uses SDLh, uVariables;
+
+procedure init;
+begin
+    SDL_WarpMouse(cScreenWidth div 2, cScreenHeight div 2);
+end;
+
+procedure updatePosition;
+var x, y: LongInt;
+begin
+    SDL_GetMouseState(@x, @y);
+
+    if(x <> cScreenWidth div 2) or (y <> cScreenHeight div 2) then
+        begin
+writeln(x, ', ', y);
+        CursorPoint.X:= CursorPoint.X + x - cScreenWidth div 2;
+        CursorPoint.Y:= CursorPoint.Y - y + cScreenHeight div 2;
+
+        if cHasFocus then SDL_WarpMouse(cScreenWidth div 2, cScreenHeight div 2);
+        end
+end;
+
+end.
--- a/hedgewars/uWorld.pas	Fri Apr 29 13:56:38 2011 +0400
+++ b/hedgewars/uWorld.pas	Mon May 02 18:37:57 2011 +0400
@@ -50,7 +50,8 @@
     uUtils,
     uTextures,
     uRender,
-    uCaptions
+    uCaptions,
+    uCursor
     ;
 
 var cWaveWidth, cWaveHeight: LongInt;
@@ -173,7 +174,7 @@
 cWaveHeight:= 32;
 
 cGearScrEdgesDist:= Min(cScreenWidth div 2 - 100, cScreenHeight div 2 - 50);
-SDL_WarpMouse(cScreenWidth div 2, cScreenHeight div 2);
+uCursor.init();
 prevPoint.X:= 0;
 prevPoint.Y:= cScreenHeight div 2;
 WorldDx:=  - (LAND_WIDTH div 2) + cScreenWidth div 2;
@@ -211,7 +212,7 @@
        AMxShift:= 0
    else
        if AMxShift > MENUSPEED then
-      	   dec(AMxShift, MENUSPEED)
+           dec(AMxShift, MENUSPEED)
        else
            AMxShift:= 0;
    end else
@@ -221,7 +222,6 @@
       CursorPoint.X:= cScreenWidth shr 1;
       CursorPoint.Y:= cScreenHeight shr 1;
       prevPoint:= CursorPoint;
-      SDL_WarpMouse(CursorPoint.X  + cScreenWidth div 2, cScreenHeight - CursorPoint.Y)
       end;
    if (cReducedQuality and rqSlowMenu) <> 0 then
        AMxShift:= AMWidth
@@ -252,7 +252,7 @@
 dec(y, BORDERSIZE);
 DrawSprite(sprAMCorners, x - BORDERSIZE, y, 0);
 for i:= 0 to cMaxSlotAmmoIndex do
-	DrawSprite(sprAMBorderHorizontal, x + i * AMSlotSize, y, 0);
+    DrawSprite(sprAMBorderHorizontal, x + i * AMSlotSize, y, 0);
 DrawSprite(sprAMCorners, x + AMWidth - AMxOffset, y, 1);
 inc(y, BORDERSIZE);
 
@@ -303,12 +303,12 @@
 y:= cScreenHeight - AMyOffset;
 DrawSprite(sprAMCorners, x - BORDERSIZE, y, 2);
 for i:= 0 to cMaxSlotAmmoIndex + 1 do
-	DrawSprite(sprAMBorderHorizontal, x + i * AMSlotSize, y, 1);
+    DrawSprite(sprAMBorderHorizontal, x + i * AMSlotSize, y, 1);
 DrawSprite(sprAMCorners, x + AMWidth - AMxOffset, y, 3);
 dec(y, AMSlotSize);
 DrawSprite(sprAMBorderVertical, x - BORDERSIZE, y, 0);
 for i:= 0 to cMaxSlotAmmoIndex do
-	DrawSprite(sprAMSlot, x + i * AMSlotSize, y, 2);
+    DrawSprite(sprAMSlot, x + i * AMSlotSize, y, 2);
 DrawSprite(sprAMSlot, x + (cMaxSlotAmmoIndex + 1) * AMSlotSize, y, 1);
 DrawSprite(sprAMBorderVertical, x + AMWidth - AMxOffset, y, 1);
 
@@ -355,7 +355,7 @@
 dec(y, BORDERSIZE);
 DrawSprite(sprAMCorners, x - BORDERSIZE, y, 0);
 for i:= 0 to cMaxSlotAmmoIndex + 1 do
-	DrawSprite(sprAMBorderHorizontal, x + i * AMSlotSize, y, 0);
+    DrawSprite(sprAMBorderHorizontal, x + i * AMSlotSize, y, 0);
 DrawSprite(sprAMCorners, x + AMWidth - AMxOffset, y, 1);
 {$ENDIF}
 
@@ -1161,11 +1161,7 @@
 begin
 {$IFNDEF IPHONEOS}
 if (not (CurrentTeam^.ExtDriven and isCursorVisible and not bShowAmmoMenu)) and cHasFocus then
-begin
-    SDL_GetMouseState(@CursorPoint.X, @CursorPoint.Y);
-    CursorPoint.X:= CursorPoint.X - (cScreenWidth shr 1);
-    CursorPoint.Y:= cScreenHeight - CursorPoint.Y;
-end;
+    uCursor.updatePosition();
 {$ENDIF}
 
 if (not PlacingHogs) and (FollowGear <> nil) and (not isCursorVisible) and (not fastUntilLag) then
@@ -1200,7 +1196,7 @@
     if CursorPoint.Y < AMyOffset + AMSlotSize then CursorPoint.Y:= AMyOffset + AMSlotSize;
 {$ENDIF}
     prevPoint:= CursorPoint;
-    if cHasFocus then SDL_WarpMouse(CursorPoint.X + cScreenWidth div 2, cScreenHeight - CursorPoint.Y);
+    //if cHasFocus then SDL_WarpMouse(CursorPoint.X + cScreenWidth div 2, cScreenHeight - CursorPoint.Y);
     exit
 end;
 
@@ -1255,7 +1251,7 @@
 
 // this moves the camera according to CursorPoint X and Y
 prevPoint:= CursorPoint;
-if cHasFocus then SDL_WarpMouse(CursorPoint.X + (cScreenWidth shr 1), cScreenHeight - CursorPoint.Y);
+//if cHasFocus then SDL_WarpMouse(CursorPoint.X + (cScreenWidth shr 1), cScreenHeight - CursorPoint.Y);
 if WorldDy > LAND_HEIGHT + 1024 then WorldDy:= LAND_HEIGHT + 1024;
 if WorldDy < wdy then WorldDy:= wdy;
 if WorldDx < - LAND_WIDTH - 1024 then WorldDx:= - LAND_WIDTH - 1024;