hedgewars/uCursor.pas
changeset 14808 9443dc6663ba
parent 14284 a3531b520efb
child 14809 c2793ff4e887
equal deleted inserted replaced
14807:b2beb784e4b5 14808:9443dc6663ba
     2 
     2 
     3 interface
     3 interface
     4 
     4 
     5 procedure init;
     5 procedure init;
     6 procedure resetPosition;
     6 procedure resetPosition;
     7 procedure updatePosition;
     7 procedure resetPositionDelta();
       
     8 procedure updatePositionDelta(xrel, yrel: LongInt);
       
     9 procedure updatePosition();
     8 procedure handlePositionUpdate(x, y: LongInt);
    10 procedure handlePositionUpdate(x, y: LongInt);
     9 
    11 
    10 implementation
    12 implementation
    11 
    13 
    12 uses SDLh, uVariables, uTypes;
    14 uses SDLh, uVariables, uTypes;
    13 
    15 
    14 procedure init;
    16 procedure init;
    15 begin
    17 begin
       
    18     SDL_ShowCursor(SDL_DISABLE);
    16     resetPosition();
    19     resetPosition();
       
    20     SDL_SetRelativeMouseMode(SDL_TRUE);
    17 end;
    21 end;
    18 
    22 
    19 procedure resetPosition;
    23 procedure resetPosition;
    20 begin
    24 begin
    21     if GameType = gmtRecord then
    25     if GameType = gmtRecord then
    22         exit;
    26         exit;
    23     // Move curser by 1px in case it's already centered.
       
    24     // The game camera in the Alpha for 0.9.23 screwed up if
       
    25     // the game started with the mouse already being centered.
       
    26     // This fixes it, but we might have overlooked a related
       
    27     // bug somewhere else.
       
    28     // No big deal since this function is (so far) only called once.
       
    29     SDL_WarpMouse((cScreenWidth div 2) + 1, cScreenHeight div 2);
       
    30     SDL_WarpMouse(cScreenWidth div 2, cScreenHeight div 2);
    27     SDL_WarpMouse(cScreenWidth div 2, cScreenHeight div 2);
       
    28     resetPositionDelta();
    31 end;
    29 end;
    32 
    30 
    33 procedure updatePosition;
    31 procedure resetPositionDelta();
    34 var x, y: LongInt;
       
    35 begin
    32 begin
    36 	x:= cScreenWidth div 2;
    33     CursorPointDelta.X:= 0;
    37 	y:= cScreenHeight div 2;
    34     CursorPointDelta.Y:= 0;
    38     if GameType <> gmtRecord then
    35 end;
    39         SDL_GetMouseState(@x, @y);
       
    40 
    36 
    41     if(x <> cScreenWidth div 2) or (y <> cScreenHeight div 2) then
    37 procedure updatePositionDelta(xrel, yrel: LongInt);
    42     begin
    38 begin
    43         handlePositionUpdate(x - cScreenWidth div 2, y - cScreenHeight div 2);
    39     CursorPointDelta.X:= CursorPointDelta.X + xrel;
       
    40     CursorPointDelta.Y:= CursorPointDelta.Y + yrel;
       
    41 end;
    44 
    42 
    45         if cHasFocus and (GameType <> gmtRecord) then
    43 procedure updatePosition();
    46             SDL_WarpMouse(cScreenWidth div 2, cScreenHeight div 2);
    44 begin
    47     end
    45     handlePositionUpdate(CursorPointDelta.X, CursorPointDelta.Y);
       
    46     resetPositionDelta();
    48 end;
    47 end;
    49 
    48 
    50 procedure handlePositionUpdate(x, y: LongInt);
    49 procedure handlePositionUpdate(x, y: LongInt);
    51 begin
    50 begin
    52     CursorPoint.X:= CursorPoint.X + x;
    51     CursorPoint.X:= CursorPoint.X + x;