hedgewars/uCursor.pas
author unc0rr
Wed, 10 Jan 2018 23:49:47 +0100
branchqmlfrontend
changeset 12895 9c259fb4d405
parent 12836 1fbc0d5a82d0
permissions -rw-r--r--
Pass mouse movements to engine, warp cursor in frontend
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;
8346
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents: 8225
diff changeset
     7
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
     8
12895
9c259fb4d405 Pass mouse movements to engine, warp cursor in frontend
unc0rr
parents: 12836
diff changeset
     9
function updateMousePosition(cx, cy, x, y: LongInt): boolean; cdecl; export;
9c259fb4d405 Pass mouse movements to engine, warp cursor in frontend
unc0rr
parents: 12836
diff changeset
    10
5191
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
12895
9c259fb4d405 Pass mouse movements to engine, warp cursor in frontend
unc0rr
parents: 12836
diff changeset
    13
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
    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
12895
9c259fb4d405 Pass mouse movements to engine, warp cursor in frontend
unc0rr
parents: 12836
diff changeset
    17
    //resetPosition();
8225
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
12836
1fbc0d5a82d0 Backed out changeset 575c0de98505
Wuzzy <Wuzzy2@mail.ru>
parents: 12798
diff changeset
    22
    // Move curser by 1px in case it's already centered.
1fbc0d5a82d0 Backed out changeset 575c0de98505
Wuzzy <Wuzzy2@mail.ru>
parents: 12798
diff changeset
    23
    // The game camera in the Alpha for 0.9.23 screwed up if
1fbc0d5a82d0 Backed out changeset 575c0de98505
Wuzzy <Wuzzy2@mail.ru>
parents: 12798
diff changeset
    24
    // the game started with the mouse already being centered.
1fbc0d5a82d0 Backed out changeset 575c0de98505
Wuzzy <Wuzzy2@mail.ru>
parents: 12798
diff changeset
    25
    // This fixes it, but we might have overlooked a related
1fbc0d5a82d0 Backed out changeset 575c0de98505
Wuzzy <Wuzzy2@mail.ru>
parents: 12798
diff changeset
    26
    // bug somewhere else.
1fbc0d5a82d0 Backed out changeset 575c0de98505
Wuzzy <Wuzzy2@mail.ru>
parents: 12798
diff changeset
    27
    // No big deal since this function is (so far) only called once.
12895
9c259fb4d405 Pass mouse movements to engine, warp cursor in frontend
unc0rr
parents: 12836
diff changeset
    28
    //SDL_WarpMouse((cScreenWidth div 2) + 1, cScreenHeight div 2);
9c259fb4d405 Pass mouse movements to engine, warp cursor in frontend
unc0rr
parents: 12836
diff changeset
    29
    //SDL_WarpMouse(cScreenWidth div 2, 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
    30
end;
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    31
12895
9c259fb4d405 Pass mouse movements to engine, warp cursor in frontend
unc0rr
parents: 12836
diff changeset
    32
function updateMousePosition(cx, cy, x, y: LongInt): boolean; cdecl; export;
5191
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    33
begin
12895
9c259fb4d405 Pass mouse movements to engine, warp cursor in frontend
unc0rr
parents: 12836
diff changeset
    34
    if (GameState <> gsConfirm)
9c259fb4d405 Pass mouse movements to engine, warp cursor in frontend
unc0rr
parents: 12836
diff changeset
    35
            and (GameState <> gsSuspend)
9c259fb4d405 Pass mouse movements to engine, warp cursor in frontend
unc0rr
parents: 12836
diff changeset
    36
            and (GameState <> gsExit)
9c259fb4d405 Pass mouse movements to engine, warp cursor in frontend
unc0rr
parents: 12836
diff changeset
    37
            and (GameState <> gsLandgen)
9c259fb4d405 Pass mouse movements to engine, warp cursor in frontend
unc0rr
parents: 12836
diff changeset
    38
            and (GameState <> gsStart)
9c259fb4d405 Pass mouse movements to engine, warp cursor in frontend
unc0rr
parents: 12836
diff changeset
    39
            and cHasFocus
9c259fb4d405 Pass mouse movements to engine, warp cursor in frontend
unc0rr
parents: 12836
diff changeset
    40
            and (not (CurrentTeam^.ExtDriven and isCursorVisible and (not bShowAmmoMenu) and autoCameraOn)) 
9c259fb4d405 Pass mouse movements to engine, warp cursor in frontend
unc0rr
parents: 12836
diff changeset
    41
            and ((x <> cx) or (y <> cy)) then
9c259fb4d405 Pass mouse movements to engine, warp cursor in frontend
unc0rr
parents: 12836
diff changeset
    42
    begin
9c259fb4d405 Pass mouse movements to engine, warp cursor in frontend
unc0rr
parents: 12836
diff changeset
    43
        handlePositionUpdate(x - cx, y - cy);
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    44
12895
9c259fb4d405 Pass mouse movements to engine, warp cursor in frontend
unc0rr
parents: 12836
diff changeset
    45
        updateMousePosition:= true
9c259fb4d405 Pass mouse movements to engine, warp cursor in frontend
unc0rr
parents: 12836
diff changeset
    46
    end else
9c259fb4d405 Pass mouse movements to engine, warp cursor in frontend
unc0rr
parents: 12836
diff changeset
    47
        updateMousePosition:= false
5191
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    48
end;
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    49
8346
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents: 8225
diff changeset
    50
procedure handlePositionUpdate(x, y: LongInt);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents: 8225
diff changeset
    51
begin
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents: 8225
diff changeset
    52
    CursorPoint.X:= CursorPoint.X + x;
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents: 8225
diff changeset
    53
    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
    54
end;
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    55
c7000a6b397b - Implement a thin wrapper over real cursor, which eliminates need in SDL_WarpMouse outside game window
unc0rr
parents:
diff changeset
    56
end.