hedgewars/uCursor.pas
author koda
Sun, 27 Jan 2013 00:28:57 +0100
branchwebgl
changeset 8444 75db7bb8dce8
parent 8330 aaefa587e277
parent 8346 3443e0de2c9d
child 10015 4feced261c68
permissions -rw-r--r--
update branch
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
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
    14
{$IFDEF WEBGL}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
    15
var offsetx, offsety : Integer;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
    16
{$ENDIF}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
    17
5191
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
8225
186229af4fc1 GCI2012: Remove Quit Prompt On Mouse Click
Drew Gottlieb
parents: 6580
diff changeset
    20
    resetPosition();
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
5191
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    25
    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
    26
end;
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    27
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    28
procedure updatePosition;
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    29
var x, y: LongInt;
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
    30
{$IFDEF WEBGL}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
    31
    tx, ty : LongInt;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
    32
{$ENDIF}
5191
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    33
begin
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    34
    SDL_GetMouseState(@x, @y);
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    35
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
    36
{$IFDEF WEBGL}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
    37
    tx := x;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
    38
    ty := y;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
    39
    x := x + offsetx;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
    40
    y := y + offsety;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
    41
{$ENDIF}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
    42
5191
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    43
    if(x <> cScreenWidth div 2) or (y <> cScreenHeight div 2) then
8346
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents: 8225
diff changeset
    44
    begin
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents: 8225
diff changeset
    45
        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
    46
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 5199
diff changeset
    47
        if cHasFocus then
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
    48
            begin
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
    49
            {$IFNDEF WEBGL}
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 5199
diff changeset
    50
            SDL_WarpMouse(cScreenWidth div 2, cScreenHeight div 2);
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
    51
            {$ELSE}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
    52
            offsetx := cScreenWidth div 2 - tx;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
    53
            offsety := cScreenHeight div 2 - ty;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
    54
            {$ENDIF}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 6580
diff changeset
    55
            end;
5191
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    56
        end
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
8346
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents: 8225
diff changeset
    59
procedure handlePositionUpdate(x, y: LongInt);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents: 8225
diff changeset
    60
begin
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents: 8225
diff changeset
    61
    CursorPoint.X:= CursorPoint.X + x;
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents: 8225
diff changeset
    62
    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
    63
end;
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    64
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    65
end.