hedgewars/uCursor.pas
author Bryan Dunsmore <dunsmoreb@gmail.com>
Fri, 30 Nov 2012 21:28:40 -0600
branchwebgl
changeset 8111 4307de8780fa
parent 8026 4a4f21070479
child 8330 aaefa587e277
permissions -rw-r--r--
Move version check of Clang to CMakeLists.

unit uCursor;

interface

procedure init;
procedure updatePosition;

implementation

uses SDLh, uVariables;

{$IFDEF WEBGL}
var offsetx, offsety : Integer;
{$ENDIF}

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

procedure updatePosition;
var x, y: LongInt;
{$IFDEF WEBGL}
    tx, ty : LongInt;
{$ENDIF}
begin
    SDL_GetMouseState(@x, @y);

{$IFDEF WEBGL}
    tx := x;
    ty := y;
    x := x + offsetx;
    y := y + offsety;
{$ENDIF}

    if(x <> cScreenWidth div 2) or (y <> cScreenHeight div 2) then
        begin
        CursorPoint.X:= CursorPoint.X + x - cScreenWidth div 2;
        CursorPoint.Y:= CursorPoint.Y - y + cScreenHeight div 2;

        if cHasFocus then
            begin
            {$IFNDEF WEBGL}
            SDL_WarpMouse(cScreenWidth div 2, cScreenHeight div 2);
            {$ELSE}
            offsetx := cScreenWidth div 2 - tx;
            offsety := cScreenHeight div 2 - ty;
            {$ENDIF}
            end;
        end
end;

end.