hedgewars/uCursor.pas
author Wuzzy <Wuzzy2@mail.ru>
Sun, 29 Oct 2017 16:21:24 +0100
changeset 12796 d97fa936778e
parent 12793 575c0de98505
child 12831 1fbc0d5a82d0
permissions -rw-r--r--
ACF2: Fix Lua error spam when Leaks A Lot died in same turn as weaklings, also do other minor tweaks - Grant skip to Dense Cloud and Leaks A Lot again, after refusing the cyborg's offer - Fix flow chart - String freeze is maintained, the new string is already in stub.lua.

unit uCursor;

interface

procedure init;
procedure resetPosition;
procedure updatePosition;
procedure handlePositionUpdate(x, y: LongInt);
procedure setSystemCursor(enabled: boolean);

implementation

uses SDLh, uVariables;

procedure init;
begin
    resetPosition();
end;

procedure resetPosition;
begin
    SDL_WarpMouse(cScreenWidth div 2, cScreenHeight div 2);
end;

procedure updatePosition;
var x, y: LongInt;
begin
    SDL_GetRelativeMouseState(@x, @y);

    if(x <> 0) or (y <> 0) then
        handlePositionUpdate(x, y);
end;

procedure handlePositionUpdate(x, y: LongInt);
begin
    CursorPoint.X:= CursorPoint.X + x;
    CursorPoint.Y:= CursorPoint.Y - y;
end;

procedure setSystemCursor(enabled: boolean);
begin
    if enabled then
        begin
        SDL_SetRelativeMouseMode(false);
        if cHasFocus then
            resetPosition();
        SDL_ShowCursor(1);
        end
    else
        begin
        SDL_ShowCursor(0);
        SDL_GetRelativeMouseState(nil, nil);
        SDL_SetRelativeMouseMode(true);
        end;
end;

end.