hedgewars/uCursor.pas
author alfadur
Tue, 06 Aug 2019 23:28:14 +0300
changeset 15306 361e79c6c428
parent 14814 c2793ff4e887
permissions -rw-r--r--
add helper to find if a spite intersects gears
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14814
c2793ff4e887 Fix camera jumping around in touchscreen mode
Wuzzy <Wuzzy2@mail.ru>
parents: 14813
diff changeset
     1
{$INCLUDE "options.inc"}
c2793ff4e887 Fix camera jumping around in touchscreen mode
Wuzzy <Wuzzy2@mail.ru>
parents: 14813
diff changeset
     2
5191
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
     3
unit uCursor;
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
interface
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
     6
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
     7
procedure init;
8225
186229af4fc1 GCI2012: Remove Quit Prompt On Mouse Click
Drew Gottlieb
parents: 6580
diff changeset
     8
procedure resetPosition;
14813
9443dc6663ba Refactor mouse movement handling
Wuzzy <Wuzzy2@mail.ru>
parents: 14289
diff changeset
     9
procedure resetPositionDelta();
9443dc6663ba Refactor mouse movement handling
Wuzzy <Wuzzy2@mail.ru>
parents: 14289
diff changeset
    10
procedure updatePositionDelta(xrel, yrel: LongInt);
9443dc6663ba Refactor mouse movement handling
Wuzzy <Wuzzy2@mail.ru>
parents: 14289
diff changeset
    11
procedure updatePosition();
8346
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents: 8225
diff changeset
    12
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
    13
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    14
implementation
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    15
13499
424944a835a7 Fix cursor teleporting to center after leaving game with video recording
Wuzzy <Wuzzy2@mail.ru>
parents: 12836
diff changeset
    16
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
    17
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    18
procedure init;
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    19
begin
14813
9443dc6663ba Refactor mouse movement handling
Wuzzy <Wuzzy2@mail.ru>
parents: 14289
diff changeset
    20
    SDL_ShowCursor(SDL_DISABLE);
8225
186229af4fc1 GCI2012: Remove Quit Prompt On Mouse Click
Drew Gottlieb
parents: 6580
diff changeset
    21
    resetPosition();
14814
c2793ff4e887 Fix camera jumping around in touchscreen mode
Wuzzy <Wuzzy2@mail.ru>
parents: 14813
diff changeset
    22
{$IFNDEF USE_TOUCH_INTERFACE}
14813
9443dc6663ba Refactor mouse movement handling
Wuzzy <Wuzzy2@mail.ru>
parents: 14289
diff changeset
    23
    SDL_SetRelativeMouseMode(SDL_TRUE);
14814
c2793ff4e887 Fix camera jumping around in touchscreen mode
Wuzzy <Wuzzy2@mail.ru>
parents: 14813
diff changeset
    24
{$ENDIF}
8225
186229af4fc1 GCI2012: Remove Quit Prompt On Mouse Click
Drew Gottlieb
parents: 6580
diff changeset
    25
end;
186229af4fc1 GCI2012: Remove Quit Prompt On Mouse Click
Drew Gottlieb
parents: 6580
diff changeset
    26
186229af4fc1 GCI2012: Remove Quit Prompt On Mouse Click
Drew Gottlieb
parents: 6580
diff changeset
    27
procedure resetPosition;
186229af4fc1 GCI2012: Remove Quit Prompt On Mouse Click
Drew Gottlieb
parents: 6580
diff changeset
    28
begin
13499
424944a835a7 Fix cursor teleporting to center after leaving game with video recording
Wuzzy <Wuzzy2@mail.ru>
parents: 12836
diff changeset
    29
    if GameType = gmtRecord then
424944a835a7 Fix cursor teleporting to center after leaving game with video recording
Wuzzy <Wuzzy2@mail.ru>
parents: 12836
diff changeset
    30
        exit;
5191
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    31
    SDL_WarpMouse(cScreenWidth div 2, cScreenHeight div 2);
14813
9443dc6663ba Refactor mouse movement handling
Wuzzy <Wuzzy2@mail.ru>
parents: 14289
diff changeset
    32
    resetPositionDelta();
9443dc6663ba Refactor mouse movement handling
Wuzzy <Wuzzy2@mail.ru>
parents: 14289
diff changeset
    33
end;
9443dc6663ba Refactor mouse movement handling
Wuzzy <Wuzzy2@mail.ru>
parents: 14289
diff changeset
    34
9443dc6663ba Refactor mouse movement handling
Wuzzy <Wuzzy2@mail.ru>
parents: 14289
diff changeset
    35
procedure resetPositionDelta();
9443dc6663ba Refactor mouse movement handling
Wuzzy <Wuzzy2@mail.ru>
parents: 14289
diff changeset
    36
begin
9443dc6663ba Refactor mouse movement handling
Wuzzy <Wuzzy2@mail.ru>
parents: 14289
diff changeset
    37
    CursorPointDelta.X:= 0;
9443dc6663ba Refactor mouse movement handling
Wuzzy <Wuzzy2@mail.ru>
parents: 14289
diff changeset
    38
    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
    39
end;
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    40
14813
9443dc6663ba Refactor mouse movement handling
Wuzzy <Wuzzy2@mail.ru>
parents: 14289
diff changeset
    41
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
    42
begin
14813
9443dc6663ba Refactor mouse movement handling
Wuzzy <Wuzzy2@mail.ru>
parents: 14289
diff changeset
    43
    CursorPointDelta.X:= CursorPointDelta.X + xrel;
9443dc6663ba Refactor mouse movement handling
Wuzzy <Wuzzy2@mail.ru>
parents: 14289
diff changeset
    44
    CursorPointDelta.Y:= CursorPointDelta.Y + yrel;
9443dc6663ba Refactor mouse movement handling
Wuzzy <Wuzzy2@mail.ru>
parents: 14289
diff changeset
    45
end;
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    46
14813
9443dc6663ba Refactor mouse movement handling
Wuzzy <Wuzzy2@mail.ru>
parents: 14289
diff changeset
    47
procedure updatePosition();
9443dc6663ba Refactor mouse movement handling
Wuzzy <Wuzzy2@mail.ru>
parents: 14289
diff changeset
    48
begin
9443dc6663ba Refactor mouse movement handling
Wuzzy <Wuzzy2@mail.ru>
parents: 14289
diff changeset
    49
    handlePositionUpdate(CursorPointDelta.X, CursorPointDelta.Y);
9443dc6663ba Refactor mouse movement handling
Wuzzy <Wuzzy2@mail.ru>
parents: 14289
diff changeset
    50
    resetPositionDelta();
5191
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    51
end;
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    52
8346
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents: 8225
diff changeset
    53
procedure handlePositionUpdate(x, y: LongInt);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents: 8225
diff changeset
    54
begin
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents: 8225
diff changeset
    55
    CursorPoint.X:= CursorPoint.X + x;
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents: 8225
diff changeset
    56
    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
    57
end;
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    58
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    59
end.