4 |
4 |
5 procedure init; |
5 procedure init; |
6 procedure resetPosition; |
6 procedure resetPosition; |
7 procedure updatePosition; |
7 procedure updatePosition; |
8 procedure handlePositionUpdate(x, y: LongInt); |
8 procedure handlePositionUpdate(x, y: LongInt); |
9 procedure setSystemCursor(enabled: boolean); |
|
10 |
9 |
11 implementation |
10 implementation |
12 |
11 |
13 uses SDLh, uVariables; |
12 uses SDLh, uVariables; |
14 |
13 |
17 resetPosition(); |
16 resetPosition(); |
18 end; |
17 end; |
19 |
18 |
20 procedure resetPosition; |
19 procedure resetPosition; |
21 begin |
20 begin |
|
21 // Move curser by 1px in case it's already centered. |
|
22 // The game camera in the Alpha for 0.9.23 screwed up if |
|
23 // the game started with the mouse already being centered. |
|
24 // This fixes it, but we might have overlooked a related |
|
25 // bug somewhere else. |
|
26 // No big deal since this function is (so far) only called once. |
|
27 SDL_WarpMouse((cScreenWidth div 2) + 1, cScreenHeight div 2); |
22 SDL_WarpMouse(cScreenWidth div 2, cScreenHeight div 2); |
28 SDL_WarpMouse(cScreenWidth div 2, cScreenHeight div 2); |
23 end; |
29 end; |
24 |
30 |
25 procedure updatePosition; |
31 procedure updatePosition; |
26 var x, y: LongInt; |
32 var x, y: LongInt; |
27 begin |
33 begin |
28 SDL_GetRelativeMouseState(@x, @y); |
34 SDL_GetMouseState(@x, @y); |
29 |
35 |
30 if(x <> 0) or (y <> 0) then |
36 if(x <> cScreenWidth div 2) or (y <> cScreenHeight div 2) then |
31 handlePositionUpdate(x, y); |
37 begin |
|
38 handlePositionUpdate(x - cScreenWidth div 2, y - cScreenHeight div 2); |
|
39 |
|
40 if cHasFocus then |
|
41 SDL_WarpMouse(cScreenWidth div 2, cScreenHeight div 2); |
|
42 end |
32 end; |
43 end; |
33 |
44 |
34 procedure handlePositionUpdate(x, y: LongInt); |
45 procedure handlePositionUpdate(x, y: LongInt); |
35 begin |
46 begin |
36 CursorPoint.X:= CursorPoint.X + x; |
47 CursorPoint.X:= CursorPoint.X + x; |
37 CursorPoint.Y:= CursorPoint.Y - y; |
48 CursorPoint.Y:= CursorPoint.Y - y; |
38 end; |
49 end; |
39 |
50 |
40 procedure setSystemCursor(enabled: boolean); |
|
41 begin |
|
42 if enabled then |
|
43 begin |
|
44 SDL_SetRelativeMouseMode(false); |
|
45 if cHasFocus then |
|
46 resetPosition(); |
|
47 SDL_ShowCursor(1); |
|
48 end |
|
49 else |
|
50 begin |
|
51 SDL_ShowCursor(0); |
|
52 SDL_GetRelativeMouseState(nil, nil); |
|
53 SDL_SetRelativeMouseMode(true); |
|
54 end; |
|
55 end; |
|
56 |
|
57 end. |
51 end. |