hedgewars/uCursor.pas
author Wuzzy <Wuzzy2@mail.ru>
Thu, 18 Apr 2019 19:44:25 +0200
changeset 14813 9443dc6663ba
parent 14289 a3531b520efb
child 14814 c2793ff4e887
permissions -rw-r--r--
Refactor mouse movement handling
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;
14813
9443dc6663ba Refactor mouse movement handling
Wuzzy <Wuzzy2@mail.ru>
parents: 14289
diff changeset
     7
procedure resetPositionDelta();
9443dc6663ba Refactor mouse movement handling
Wuzzy <Wuzzy2@mail.ru>
parents: 14289
diff changeset
     8
procedure updatePositionDelta(xrel, yrel: LongInt);
9443dc6663ba Refactor mouse movement handling
Wuzzy <Wuzzy2@mail.ru>
parents: 14289
diff changeset
     9
procedure updatePosition();
8346
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents: 8225
diff changeset
    10
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
    11
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    12
implementation
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    13
13499
424944a835a7 Fix cursor teleporting to center after leaving game with video recording
Wuzzy <Wuzzy2@mail.ru>
parents: 12836
diff changeset
    14
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
    15
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    16
procedure init;
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    17
begin
14813
9443dc6663ba Refactor mouse movement handling
Wuzzy <Wuzzy2@mail.ru>
parents: 14289
diff changeset
    18
    SDL_ShowCursor(SDL_DISABLE);
8225
186229af4fc1 GCI2012: Remove Quit Prompt On Mouse Click
Drew Gottlieb
parents: 6580
diff changeset
    19
    resetPosition();
14813
9443dc6663ba Refactor mouse movement handling
Wuzzy <Wuzzy2@mail.ru>
parents: 14289
diff changeset
    20
    SDL_SetRelativeMouseMode(SDL_TRUE);
8225
186229af4fc1 GCI2012: Remove Quit Prompt On Mouse Click
Drew Gottlieb
parents: 6580
diff changeset
    21
end;
186229af4fc1 GCI2012: Remove Quit Prompt On Mouse Click
Drew Gottlieb
parents: 6580
diff changeset
    22
186229af4fc1 GCI2012: Remove Quit Prompt On Mouse Click
Drew Gottlieb
parents: 6580
diff changeset
    23
procedure resetPosition;
186229af4fc1 GCI2012: Remove Quit Prompt On Mouse Click
Drew Gottlieb
parents: 6580
diff changeset
    24
begin
13499
424944a835a7 Fix cursor teleporting to center after leaving game with video recording
Wuzzy <Wuzzy2@mail.ru>
parents: 12836
diff changeset
    25
    if GameType = gmtRecord then
424944a835a7 Fix cursor teleporting to center after leaving game with video recording
Wuzzy <Wuzzy2@mail.ru>
parents: 12836
diff changeset
    26
        exit;
5191
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    27
    SDL_WarpMouse(cScreenWidth div 2, cScreenHeight div 2);
14813
9443dc6663ba Refactor mouse movement handling
Wuzzy <Wuzzy2@mail.ru>
parents: 14289
diff changeset
    28
    resetPositionDelta();
9443dc6663ba Refactor mouse movement handling
Wuzzy <Wuzzy2@mail.ru>
parents: 14289
diff changeset
    29
end;
9443dc6663ba Refactor mouse movement handling
Wuzzy <Wuzzy2@mail.ru>
parents: 14289
diff changeset
    30
9443dc6663ba Refactor mouse movement handling
Wuzzy <Wuzzy2@mail.ru>
parents: 14289
diff changeset
    31
procedure resetPositionDelta();
9443dc6663ba Refactor mouse movement handling
Wuzzy <Wuzzy2@mail.ru>
parents: 14289
diff changeset
    32
begin
9443dc6663ba Refactor mouse movement handling
Wuzzy <Wuzzy2@mail.ru>
parents: 14289
diff changeset
    33
    CursorPointDelta.X:= 0;
9443dc6663ba Refactor mouse movement handling
Wuzzy <Wuzzy2@mail.ru>
parents: 14289
diff changeset
    34
    CursorPointDelta.Y:= 0;
5191
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    35
end;
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    36
14813
9443dc6663ba Refactor mouse movement handling
Wuzzy <Wuzzy2@mail.ru>
parents: 14289
diff changeset
    37
procedure updatePositionDelta(xrel, yrel: LongInt);
5191
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    38
begin
14813
9443dc6663ba Refactor mouse movement handling
Wuzzy <Wuzzy2@mail.ru>
parents: 14289
diff changeset
    39
    CursorPointDelta.X:= CursorPointDelta.X + xrel;
9443dc6663ba Refactor mouse movement handling
Wuzzy <Wuzzy2@mail.ru>
parents: 14289
diff changeset
    40
    CursorPointDelta.Y:= CursorPointDelta.Y + yrel;
9443dc6663ba Refactor mouse movement handling
Wuzzy <Wuzzy2@mail.ru>
parents: 14289
diff changeset
    41
end;
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    42
14813
9443dc6663ba Refactor mouse movement handling
Wuzzy <Wuzzy2@mail.ru>
parents: 14289
diff changeset
    43
procedure updatePosition();
9443dc6663ba Refactor mouse movement handling
Wuzzy <Wuzzy2@mail.ru>
parents: 14289
diff changeset
    44
begin
9443dc6663ba Refactor mouse movement handling
Wuzzy <Wuzzy2@mail.ru>
parents: 14289
diff changeset
    45
    handlePositionUpdate(CursorPointDelta.X, CursorPointDelta.Y);
9443dc6663ba Refactor mouse movement handling
Wuzzy <Wuzzy2@mail.ru>
parents: 14289
diff changeset
    46
    resetPositionDelta();
5191
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    47
end;
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    48
8346
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents: 8225
diff changeset
    49
procedure handlePositionUpdate(x, y: LongInt);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents: 8225
diff changeset
    50
begin
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents: 8225
diff changeset
    51
    CursorPoint.X:= CursorPoint.X + x;
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents: 8225
diff changeset
    52
    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
    53
end;
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    54
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    55
end.