author | Wuzzy <almikes@aol.com> |
Sun, 08 Oct 2017 04:57:28 +0200 | |
changeset 12671 | 87b3009f51c3 |
parent 12660 | d3fb69e31165 |
child 12793 | 575c0de98505 |
permissions | -rw-r--r-- |
5191
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
1 |
unit uCursor; |
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
2 |
|
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
3 |
interface |
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
4 |
|
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
5 |
procedure init; |
8225 | 6 |
procedure resetPosition; |
5191
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
7 |
procedure updatePosition; |
8346 | 8 |
procedure handlePositionUpdate(x, y: LongInt); |
5191
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
9 |
|
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
10 |
implementation |
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
11 |
|
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
12 |
uses SDLh, uVariables; |
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
13 |
|
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
14 |
procedure init; |
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
15 |
begin |
8225 | 16 |
resetPosition(); |
17 |
end; |
|
18 |
||
19 |
procedure resetPosition; |
|
20 |
begin |
|
12659
545e1198e8b9
Fix camera going crazy when starting game with mouse centered
Wuzzy <almikes@aol.com>
parents:
10017
diff
changeset
|
21 |
// Move curser by 1px in case it's already centered. |
12660
d3fb69e31165
Less stupid resetPosition comment in uCursor.pas
Wuzzy <almikes@aol.com>
parents:
12659
diff
changeset
|
22 |
// The game camera in the Alpha for 0.9.23 screwed up if |
d3fb69e31165
Less stupid resetPosition comment in uCursor.pas
Wuzzy <almikes@aol.com>
parents:
12659
diff
changeset
|
23 |
// the game started with the mouse already being centered. |
d3fb69e31165
Less stupid resetPosition comment in uCursor.pas
Wuzzy <almikes@aol.com>
parents:
12659
diff
changeset
|
24 |
// This fixes it, but we might have overlooked a related |
d3fb69e31165
Less stupid resetPosition comment in uCursor.pas
Wuzzy <almikes@aol.com>
parents:
12659
diff
changeset
|
25 |
// bug somewhere else. |
12659
545e1198e8b9
Fix camera going crazy when starting game with mouse centered
Wuzzy <almikes@aol.com>
parents:
10017
diff
changeset
|
26 |
// No big deal since this function is (so far) only called once. |
545e1198e8b9
Fix camera going crazy when starting game with mouse centered
Wuzzy <almikes@aol.com>
parents:
10017
diff
changeset
|
27 |
SDL_WarpMouse((cScreenWidth div 2) + 1, cScreenHeight div 2); |
5191
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
28 |
SDL_WarpMouse(cScreenWidth div 2, cScreenHeight div 2); |
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
29 |
end; |
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
30 |
|
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
31 |
procedure updatePosition; |
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
32 |
var x, y: LongInt; |
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
33 |
begin |
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
34 |
SDL_GetMouseState(@x, @y); |
10017 | 35 |
|
5191
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
36 |
if(x <> cScreenWidth div 2) or (y <> cScreenHeight div 2) then |
8346 | 37 |
begin |
38 |
handlePositionUpdate(x - cScreenWidth div 2, y - cScreenHeight div 2); |
|
5191
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
39 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
5199
diff
changeset
|
40 |
if cHasFocus then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
5199
diff
changeset
|
41 |
SDL_WarpMouse(cScreenWidth div 2, cScreenHeight div 2); |
10015 | 42 |
end |
5191
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
43 |
end; |
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
44 |
|
8346 | 45 |
procedure handlePositionUpdate(x, y: LongInt); |
46 |
begin |
|
47 |
CursorPoint.X:= CursorPoint.X + x; |
|
48 |
CursorPoint.Y:= CursorPoint.Y - y; |
|
5191
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
49 |
end; |
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
50 |
|
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
51 |
end. |