author | Wuzzy <Wuzzy2@mail.ru> |
Fri, 03 Nov 2017 05:46:36 +0100 | |
changeset 12822 | f062a31fc8f2 |
parent 12793 | 575c0de98505 |
child 12831 | 1fbc0d5a82d0 |
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); |
12793
575c0de98505
Use SDL_SetRelativeMouseMode to detect mouse movements, fixes xinput issues
Wuzzy <Wuzzy2@mail.ru>
parents:
12660
diff
changeset
|
9 |
procedure setSystemCursor(enabled: boolean); |
5191
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
10 |
|
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
11 |
implementation |
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
12 |
|
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
13 |
uses SDLh, uVariables; |
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
14 |
|
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
15 |
procedure init; |
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
16 |
begin |
8225 | 17 |
resetPosition(); |
18 |
end; |
|
19 |
||
20 |
procedure resetPosition; |
|
21 |
begin |
|
5191
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
22 |
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
|
23 |
end; |
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
24 |
|
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
25 |
procedure updatePosition; |
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
26 |
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
|
27 |
begin |
12793
575c0de98505
Use SDL_SetRelativeMouseMode to detect mouse movements, fixes xinput issues
Wuzzy <Wuzzy2@mail.ru>
parents:
12660
diff
changeset
|
28 |
SDL_GetRelativeMouseState(@x, @y); |
10017 | 29 |
|
12793
575c0de98505
Use SDL_SetRelativeMouseMode to detect mouse movements, fixes xinput issues
Wuzzy <Wuzzy2@mail.ru>
parents:
12660
diff
changeset
|
30 |
if(x <> 0) or (y <> 0) then |
575c0de98505
Use SDL_SetRelativeMouseMode to detect mouse movements, fixes xinput issues
Wuzzy <Wuzzy2@mail.ru>
parents:
12660
diff
changeset
|
31 |
handlePositionUpdate(x, y); |
5191
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
32 |
end; |
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
33 |
|
8346 | 34 |
procedure handlePositionUpdate(x, y: LongInt); |
35 |
begin |
|
36 |
CursorPoint.X:= CursorPoint.X + x; |
|
37 |
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
|
38 |
end; |
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
39 |
|
12793
575c0de98505
Use SDL_SetRelativeMouseMode to detect mouse movements, fixes xinput issues
Wuzzy <Wuzzy2@mail.ru>
parents:
12660
diff
changeset
|
40 |
procedure setSystemCursor(enabled: boolean); |
575c0de98505
Use SDL_SetRelativeMouseMode to detect mouse movements, fixes xinput issues
Wuzzy <Wuzzy2@mail.ru>
parents:
12660
diff
changeset
|
41 |
begin |
575c0de98505
Use SDL_SetRelativeMouseMode to detect mouse movements, fixes xinput issues
Wuzzy <Wuzzy2@mail.ru>
parents:
12660
diff
changeset
|
42 |
if enabled then |
575c0de98505
Use SDL_SetRelativeMouseMode to detect mouse movements, fixes xinput issues
Wuzzy <Wuzzy2@mail.ru>
parents:
12660
diff
changeset
|
43 |
begin |
575c0de98505
Use SDL_SetRelativeMouseMode to detect mouse movements, fixes xinput issues
Wuzzy <Wuzzy2@mail.ru>
parents:
12660
diff
changeset
|
44 |
SDL_SetRelativeMouseMode(false); |
575c0de98505
Use SDL_SetRelativeMouseMode to detect mouse movements, fixes xinput issues
Wuzzy <Wuzzy2@mail.ru>
parents:
12660
diff
changeset
|
45 |
if cHasFocus then |
575c0de98505
Use SDL_SetRelativeMouseMode to detect mouse movements, fixes xinput issues
Wuzzy <Wuzzy2@mail.ru>
parents:
12660
diff
changeset
|
46 |
resetPosition(); |
575c0de98505
Use SDL_SetRelativeMouseMode to detect mouse movements, fixes xinput issues
Wuzzy <Wuzzy2@mail.ru>
parents:
12660
diff
changeset
|
47 |
SDL_ShowCursor(1); |
575c0de98505
Use SDL_SetRelativeMouseMode to detect mouse movements, fixes xinput issues
Wuzzy <Wuzzy2@mail.ru>
parents:
12660
diff
changeset
|
48 |
end |
575c0de98505
Use SDL_SetRelativeMouseMode to detect mouse movements, fixes xinput issues
Wuzzy <Wuzzy2@mail.ru>
parents:
12660
diff
changeset
|
49 |
else |
575c0de98505
Use SDL_SetRelativeMouseMode to detect mouse movements, fixes xinput issues
Wuzzy <Wuzzy2@mail.ru>
parents:
12660
diff
changeset
|
50 |
begin |
575c0de98505
Use SDL_SetRelativeMouseMode to detect mouse movements, fixes xinput issues
Wuzzy <Wuzzy2@mail.ru>
parents:
12660
diff
changeset
|
51 |
SDL_ShowCursor(0); |
575c0de98505
Use SDL_SetRelativeMouseMode to detect mouse movements, fixes xinput issues
Wuzzy <Wuzzy2@mail.ru>
parents:
12660
diff
changeset
|
52 |
SDL_GetRelativeMouseState(nil, nil); |
575c0de98505
Use SDL_SetRelativeMouseMode to detect mouse movements, fixes xinput issues
Wuzzy <Wuzzy2@mail.ru>
parents:
12660
diff
changeset
|
53 |
SDL_SetRelativeMouseMode(true); |
575c0de98505
Use SDL_SetRelativeMouseMode to detect mouse movements, fixes xinput issues
Wuzzy <Wuzzy2@mail.ru>
parents:
12660
diff
changeset
|
54 |
end; |
575c0de98505
Use SDL_SetRelativeMouseMode to detect mouse movements, fixes xinput issues
Wuzzy <Wuzzy2@mail.ru>
parents:
12660
diff
changeset
|
55 |
end; |
575c0de98505
Use SDL_SetRelativeMouseMode to detect mouse movements, fixes xinput issues
Wuzzy <Wuzzy2@mail.ru>
parents:
12660
diff
changeset
|
56 |
|
5191
c7000a6b397b
- Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff
changeset
|
57 |
end. |