author | Wuzzy <Wuzzy2@mail.ru> |
Mon, 30 Jul 2018 19:23:28 +0200 | |
changeset 13574 | 9c83afd65e8c |
parent 13498 | 424944a835a7 |
child 14305 | a3531b520efb |
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 |
|
13498
424944a835a7
Fix cursor teleporting to center after leaving game with video recording
Wuzzy <Wuzzy2@mail.ru>
parents:
12831
diff
changeset
|
12 |
uses SDLh, uVariables, uTypes; |
5191
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 |
|
13498
424944a835a7
Fix cursor teleporting to center after leaving game with video recording
Wuzzy <Wuzzy2@mail.ru>
parents:
12831
diff
changeset
|
21 |
if GameType = gmtRecord then |
424944a835a7
Fix cursor teleporting to center after leaving game with video recording
Wuzzy <Wuzzy2@mail.ru>
parents:
12831
diff
changeset
|
22 |
exit; |
12831 | 23 |
// Move curser by 1px in case it's already centered. |
24 |
// The game camera in the Alpha for 0.9.23 screwed up if |
|
25 |
// the game started with the mouse already being centered. |
|
26 |
// This fixes it, but we might have overlooked a related |
|
27 |
// bug somewhere else. |
|
28 |
// No big deal since this function is (so far) only called once. |
|
29 |
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
|
30 |
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
|
31 |
end; |
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
32 |
|
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
33 |
procedure updatePosition; |
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
34 |
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
|
35 |
begin |
13498
424944a835a7
Fix cursor teleporting to center after leaving game with video recording
Wuzzy <Wuzzy2@mail.ru>
parents:
12831
diff
changeset
|
36 |
if GameType <> gmtRecord then |
424944a835a7
Fix cursor teleporting to center after leaving game with video recording
Wuzzy <Wuzzy2@mail.ru>
parents:
12831
diff
changeset
|
37 |
SDL_GetMouseState(@x, @y); |
10017 | 38 |
|
12831 | 39 |
if(x <> cScreenWidth div 2) or (y <> cScreenHeight div 2) then |
40 |
begin |
|
41 |
handlePositionUpdate(x - cScreenWidth div 2, y - cScreenHeight div 2); |
|
42 |
||
13498
424944a835a7
Fix cursor teleporting to center after leaving game with video recording
Wuzzy <Wuzzy2@mail.ru>
parents:
12831
diff
changeset
|
43 |
if cHasFocus and (GameType <> gmtRecord) then |
12831 | 44 |
SDL_WarpMouse(cScreenWidth div 2, cScreenHeight div 2); |
45 |
end |
|
5191
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
46 |
end; |
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
47 |
|
8346 | 48 |
procedure handlePositionUpdate(x, y: LongInt); |
49 |
begin |
|
50 |
CursorPoint.X:= CursorPoint.X + x; |
|
51 |
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
|
52 |
end; |
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
53 |
|
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
54 |
end. |