Another usability improvement to the touch interface: added a timer for the delta between finger down/up. A 'tap' has to be under a 1/4 second for it to act as a double-click.
This commit is contained in:
@@ -42,6 +42,9 @@ unsigned int gDisplayMode = DisplayMode_lowRes;
|
|||||||
|
|
||||||
const int kHitzonePliancy = 50;
|
const int kHitzonePliancy = 50;
|
||||||
|
|
||||||
|
// tick value equates to ms
|
||||||
|
const int kTapEventTimeout = 250;
|
||||||
|
|
||||||
class SdlApp
|
class SdlApp
|
||||||
{
|
{
|
||||||
public: /* For easy interfacing with JGE static functions */
|
public: /* For easy interfacing with JGE static functions */
|
||||||
@@ -50,6 +53,7 @@ public: /* For easy interfacing with JGE static functions */
|
|||||||
SDL_Surface* Surf_Display;
|
SDL_Surface* Surf_Display;
|
||||||
SDL_Rect viewPort;
|
SDL_Rect viewPort;
|
||||||
Uint32 lastMouseUpTime;
|
Uint32 lastMouseUpTime;
|
||||||
|
Uint32 lastFingerDownTime;
|
||||||
int windowed_w;
|
int windowed_w;
|
||||||
int windowed_h;
|
int windowed_h;
|
||||||
int windowed_pos_x;
|
int windowed_pos_x;
|
||||||
@@ -59,7 +63,7 @@ public: /* For easy interfacing with JGE static functions */
|
|||||||
int mMouseDownY;
|
int mMouseDownY;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SdlApp() : Surf_Display(NULL), window(NULL), lastMouseUpTime(0), Running(true), mMouseDownX(0), mMouseDownY(0)
|
SdlApp() : Surf_Display(NULL), window(NULL), lastMouseUpTime(0), lastFingerDownTime(0), Running(true), mMouseDownX(0), mMouseDownY(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,7 +214,7 @@ public:
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_JOYBALLMOTION:
|
case SDL_JOYBALLMOTION:
|
||||||
DebugTrace("Flick gesture detected");
|
DebugTrace("Flick gesture detected, x: " << Event->jball.xrel << ", y: " << Event->jball.yrel);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -517,19 +521,26 @@ void SdlApp::OnTouchEvent(const SDL_TouchFingerEvent& event)
|
|||||||
((event.x - viewPort.x) * SCREEN_WIDTH) / actualWidth,
|
((event.x - viewPort.x) * SCREEN_WIDTH) / actualWidth,
|
||||||
((event.y - viewPort.y) * SCREEN_HEIGHT) / actualHeight);
|
((event.y - viewPort.y) * SCREEN_HEIGHT) / actualHeight);
|
||||||
|
|
||||||
|
|
||||||
|
Uint32 eventTime = SDL_GetTicks();
|
||||||
if (event.type == SDL_FINGERDOWN)
|
if (event.type == SDL_FINGERDOWN)
|
||||||
{
|
{
|
||||||
mMouseDownX = event.x;
|
mMouseDownX = event.x;
|
||||||
mMouseDownY = event.y;
|
mMouseDownY = event.y;
|
||||||
|
|
||||||
|
lastFingerDownTime = eventTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (defined ANDROID) || (defined IOS)
|
#if (defined ANDROID) || (defined IOS)
|
||||||
if (event.type == SDL_FINGERUP)
|
if (event.type == SDL_FINGERUP)
|
||||||
{
|
{
|
||||||
// treat an up finger within 50 pixels of the down finger coords as a double click event
|
if (eventTime - lastFingerDownTime <= kTapEventTimeout)
|
||||||
if (abs(mMouseDownX - event.x) < kHitzonePliancy && abs(mMouseDownY - event.y) < kHitzonePliancy)
|
|
||||||
{
|
{
|
||||||
g_engine->HoldKey_NoRepeat(JGE_BTN_OK);
|
// treat an up finger within 50 pixels of the down finger coords as a double click event
|
||||||
|
if (abs(mMouseDownX - event.x) < kHitzonePliancy && abs(mMouseDownY - event.y) < kHitzonePliancy)
|
||||||
|
{
|
||||||
|
g_engine->HoldKey_NoRepeat(JGE_BTN_OK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user