Skip to content

Commit

Permalink
Added tracking of the still time on the mouse.
Browse files Browse the repository at this point in the history
"Still time" is recorded as the number of seconds (as a float) since the last movement of the mouse. This is in preparation for code to hide the targeting bars in-game when the mouse is still.

Signed-off-by: Alastair Lynn <[email protected]>
  • Loading branch information
prophile committed Jun 30, 2010
1 parent 32d3f95 commit 385bb86
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Engine/Input.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "Input.h"
#include "GameTime.h"

#include <SDL/SDL.h>
#include <SDL/SDL_OpenGL.h>
Expand All @@ -11,6 +12,8 @@ namespace Input
namespace Internal
{

static float mouseBase = 0.0f;

std::string MapKey ( SDLKey k )
{
switch (k)
Expand Down Expand Up @@ -145,6 +148,7 @@ void UpdateMouse ( Sint16 px, Sint16 py )
SDL_Surface* screen = SDL_GetVideoSurface();
mousePosition.X() = float(px) / float(screen->w);
mousePosition.Y() = 1.0f - (float(py) / float(screen->h));
mouseBase = GameTime();
}

std::string MouseButtonName ( Uint32 button )
Expand Down Expand Up @@ -227,4 +231,9 @@ vec2 MousePosition ()
return mousePosition;
}

float MouseStillTime ()
{
return GameTime() - mouseBase;
}

}
4 changes: 4 additions & 0 deletions Engine/Input.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ Event* Next ();
* Fetches the position of the mouse
*/
vec2 MousePosition ();
/**
* Time since the last movement of the mouse.
*/
float MouseStillTime ();

}

Expand Down

0 comments on commit 385bb86

Please sign in to comment.