hedgewars/uCursor.pas
author Wuzzy <Wuzzy2@mail.ru>
Sat, 28 Oct 2017 17:48:54 +0200
changeset 12793 575c0de98505
parent 12660 d3fb69e31165
child 12831 1fbc0d5a82d0
permissions -rw-r--r--
Use SDL_SetRelativeMouseMode to detect mouse movements, fixes xinput issues
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
186229af4fc1 GCI2012: Remove Quit Prompt On Mouse Click
Drew Gottlieb
parents: 6580
diff changeset
     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
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents: 8225
diff changeset
     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
186229af4fc1 GCI2012: Remove Quit Prompt On Mouse Click
Drew Gottlieb
parents: 6580
diff changeset
    17
    resetPosition();
186229af4fc1 GCI2012: Remove Quit Prompt On Mouse Click
Drew Gottlieb
parents: 6580
diff changeset
    18
end;
186229af4fc1 GCI2012: Remove Quit Prompt On Mouse Click
Drew Gottlieb
parents: 6580
diff changeset
    19
186229af4fc1 GCI2012: Remove Quit Prompt On Mouse Click
Drew Gottlieb
parents: 6580
diff changeset
    20
procedure resetPosition;
186229af4fc1 GCI2012: Remove Quit Prompt On Mouse Click
Drew Gottlieb
parents: 6580
diff changeset
    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
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    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
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents: 8225
diff changeset
    34
procedure handlePositionUpdate(x, y: LongInt);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents: 8225
diff changeset
    35
begin
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents: 8225
diff changeset
    36
    CursorPoint.X:= CursorPoint.X + x;
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents: 8225
diff changeset
    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.