More work on Android touch events. Fixed the issues I was having with busted float coords, and added some logic for a different way to deal with selection. Doubleclicking is no longer required; instead, if you generate a finger up event within 50 pixels of where you fingered down, this will be treated as an JGE_BTN_OK event. I think this feels more natural, as you can drag around in a menu or to various cards; then when you find your selection, simply touching it again once triggers the selection.

This commit is contained in:
wrenczes@gmail.com
2011-06-11 06:59:32 +00:00
parent 97dfc9f4bc
commit 56a8bed0e3
3 changed files with 37 additions and 19 deletions

View File

@@ -40,6 +40,8 @@ enum eDisplayMode
unsigned int gDisplayMode = DisplayMode_lowRes;
const int kHitzonePliancy = 50;
class SdlApp
{
public: /* For easy interfacing with JGE static functions */
@@ -53,8 +55,11 @@ public: /* For easy interfacing with JGE static functions */
int windowed_pos_x;
int windowed_pos_y;
int mMouseDownX;
int mMouseDownY;
public:
SdlApp() : Surf_Display(NULL), window(NULL), lastMouseUpTime(0), Running(true)
SdlApp() : Surf_Display(NULL), window(NULL), lastMouseUpTime(0), Running(true), mMouseDownX(0), mMouseDownY(0)
{
}
@@ -503,11 +508,21 @@ void SdlApp::OnTouchEvent(const SDL_TouchFingerEvent& event)
g_engine->LeftClicked(
((event.x - viewPort.x) * SCREEN_WIDTH) / actualWidth,
((event.y - viewPort.y) * SCREEN_HEIGHT) / actualHeight);
if (event.type == SDL_FINGERDOWN)
{
mMouseDownX = event.x;
mMouseDownY = event.y;
}
#if (defined ANDROID) || (defined IOS)
if (event.type == SDL_FINGERUP)
{
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
}