author | Grigory Ustinov <grenka@altlinux.org> |
Wed, 28 Nov 2018 17:20:22 +0300 | |
changeset 14335 | 6b56a0a0afb4 |
parent 14289 | a3531b520efb |
child 14813 | 9443dc6663ba |
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 |
|
13499
424944a835a7
Fix cursor teleporting to center after leaving game with video recording
Wuzzy <Wuzzy2@mail.ru>
parents:
12836
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 |
|
13499
424944a835a7
Fix cursor teleporting to center after leaving game with video recording
Wuzzy <Wuzzy2@mail.ru>
parents:
12836
diff
changeset
|
21 |
if GameType = gmtRecord then |
424944a835a7
Fix cursor teleporting to center after leaving game with video recording
Wuzzy <Wuzzy2@mail.ru>
parents:
12836
diff
changeset
|
22 |
exit; |
12836 | 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 |
14289 | 36 |
x:= cScreenWidth div 2; |
37 |
y:= cScreenHeight div 2; |
|
13499
424944a835a7
Fix cursor teleporting to center after leaving game with video recording
Wuzzy <Wuzzy2@mail.ru>
parents:
12836
diff
changeset
|
38 |
if GameType <> gmtRecord then |
424944a835a7
Fix cursor teleporting to center after leaving game with video recording
Wuzzy <Wuzzy2@mail.ru>
parents:
12836
diff
changeset
|
39 |
SDL_GetMouseState(@x, @y); |
10017 | 40 |
|
12836 | 41 |
if(x <> cScreenWidth div 2) or (y <> cScreenHeight div 2) then |
42 |
begin |
|
43 |
handlePositionUpdate(x - cScreenWidth div 2, y - cScreenHeight div 2); |
|
44 |
||
13499
424944a835a7
Fix cursor teleporting to center after leaving game with video recording
Wuzzy <Wuzzy2@mail.ru>
parents:
12836
diff
changeset
|
45 |
if cHasFocus and (GameType <> gmtRecord) then |
12836 | 46 |
SDL_WarpMouse(cScreenWidth div 2, cScreenHeight div 2); |
47 |
end |
|
5191
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
48 |
end; |
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
49 |
|
8346 | 50 |
procedure handlePositionUpdate(x, y: LongInt); |
51 |
begin |
|
52 |
CursorPoint.X:= CursorPoint.X + x; |
|
53 |
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
|
54 |
end; |
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
55 |
|
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
56 |
end. |