hedgewars/uCursor.pas
author Periklis Ntanasis <pntanasis@gmail.com>
Sun, 22 Sep 2013 18:34:53 +0300
branchspacecampaign
changeset 9645 da7b4d8c181e
parent 8346 3443e0de2c9d
child 8444 75db7bb8dce8
permissions -rw-r--r--
autoselect weapon in time challenges
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);
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
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    12
uses SDLh, uVariables;
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
186229af4fc1 GCI2012: Remove Quit Prompt On Mouse Click
Drew Gottlieb
parents: 6580
diff changeset
    16
    resetPosition();
186229af4fc1 GCI2012: Remove Quit Prompt On Mouse Click
Drew Gottlieb
parents: 6580
diff changeset
    17
end;
186229af4fc1 GCI2012: Remove Quit Prompt On Mouse Click
Drew Gottlieb
parents: 6580
diff changeset
    18
186229af4fc1 GCI2012: Remove Quit Prompt On Mouse Click
Drew Gottlieb
parents: 6580
diff changeset
    19
procedure resetPosition;
186229af4fc1 GCI2012: Remove Quit Prompt On Mouse Click
Drew Gottlieb
parents: 6580
diff changeset
    20
begin
5191
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    21
    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
    22
end;
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    23
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    24
procedure updatePosition;
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    25
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
    26
begin
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    27
    SDL_GetMouseState(@x, @y);
8346
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents: 8225
diff changeset
    28
    
5191
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    29
    if(x <> cScreenWidth div 2) or (y <> cScreenHeight div 2) then
8346
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents: 8225
diff changeset
    30
    begin
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents: 8225
diff changeset
    31
        handlePositionUpdate(x - cScreenWidth div 2, y - 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
    32
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 5199
diff changeset
    33
        if cHasFocus then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 5199
diff changeset
    34
            SDL_WarpMouse(cScreenWidth div 2, cScreenHeight div 2);
8346
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents: 8225
diff changeset
    35
    end
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents: 8225
diff changeset
    36
end;
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents: 8225
diff changeset
    37
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents: 8225
diff changeset
    38
procedure handlePositionUpdate(x, y: LongInt);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents: 8225
diff changeset
    39
begin
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents: 8225
diff changeset
    40
    CursorPoint.X:= CursorPoint.X + x;
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents: 8225
diff changeset
    41
    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
    42
end;
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    43
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    44
end.