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:
@@ -141,8 +141,10 @@ SDL_AddTouch(const SDL_Touch * touch, char *name)
|
|||||||
SDL_touchPads[index]->relative_mode = SDL_FALSE;
|
SDL_touchPads[index]->relative_mode = SDL_FALSE;
|
||||||
SDL_touchPads[index]->flush_motion = SDL_FALSE;
|
SDL_touchPads[index]->flush_motion = SDL_FALSE;
|
||||||
|
|
||||||
SDL_touchPads[index]->xres = (1<<(16-1));
|
// Wil 06/10/11: WTF is this for? It's stomping over what's been passed in!
|
||||||
SDL_touchPads[index]->yres = (1<<(16-1));
|
//SDL_touchPads[index]->xres = (1<<(16-1));
|
||||||
|
//SDL_touchPads[index]->yres = (1<<(16-1));
|
||||||
|
|
||||||
//Do I want this here? Probably
|
//Do I want this here? Probably
|
||||||
SDL_GestureAddTouch(SDL_touchPads[index]);
|
SDL_GestureAddTouch(SDL_touchPads[index]);
|
||||||
|
|
||||||
@@ -309,16 +311,15 @@ SDL_DelFinger(SDL_Touch* touch,SDL_FingerID fingerid)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
SDL_SendFingerDown(SDL_TouchID id, SDL_FingerID fingerid, SDL_bool down,
|
SDL_SendFingerDown(SDL_TouchID id, SDL_FingerID fingerid, SDL_bool down,
|
||||||
float xin, float yin, float pressurein)
|
float xin, float yin, float pressurein)
|
||||||
{
|
{
|
||||||
int posted;
|
int posted;
|
||||||
Uint16 x;
|
Uint16 x;
|
||||||
Uint16 y;
|
Uint16 y;
|
||||||
Uint16 pressure;
|
Uint16 pressure;
|
||||||
SDL_Finger *finger;
|
SDL_Finger *finger;
|
||||||
|
|
||||||
SDL_Touch* touch = SDL_GetTouch(id);
|
SDL_Touch* touch = SDL_GetTouch(id);
|
||||||
|
|
||||||
@@ -331,10 +332,6 @@ SDL_SendFingerDown(SDL_TouchID id, SDL_FingerID fingerid, SDL_bool down,
|
|||||||
y = (Uint16)((yin+touch->y_min)*(touch->yres)/(touch->native_yres));
|
y = (Uint16)((yin+touch->y_min)*(touch->yres)/(touch->native_yres));
|
||||||
pressure = (Uint16)((pressurein+touch->pressure_min)*(touch->pressureres)/(touch->native_pressureres));
|
pressure = (Uint16)((pressurein+touch->pressure_min)*(touch->pressureres)/(touch->native_pressureres));
|
||||||
|
|
||||||
char buffer[64];
|
|
||||||
sprintf(buffer, "Finger Down: xin: %g yin: %g x: %d y: %d", xin, yin, x, y);
|
|
||||||
__android_log_write(ANDROID_LOG_DEBUG, "Wagic", buffer);
|
|
||||||
|
|
||||||
finger = SDL_GetFinger(touch,fingerid);
|
finger = SDL_GetFinger(touch,fingerid);
|
||||||
if(down) {
|
if(down) {
|
||||||
if(finger == NULL) {
|
if(finger == NULL) {
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include "SDL_events.h"
|
#include "SDL_events.h"
|
||||||
#include "SDL_touch.h"
|
#include "SDL_touch.h"
|
||||||
#include "../../events/SDL_mouse_c.h"
|
#include "../../events/SDL_mouse_c.h"
|
||||||
|
#include "../../events/SDL_touch_c.h"
|
||||||
|
|
||||||
#include "SDL_androidtouch.h"
|
#include "SDL_androidtouch.h"
|
||||||
|
|
||||||
@@ -42,16 +43,21 @@ SDL_Touch* CreateTouchInstance()
|
|||||||
{
|
{
|
||||||
SDL_Touch touch;
|
SDL_Touch touch;
|
||||||
touch.id = gTouchID;
|
touch.id = gTouchID;
|
||||||
|
|
||||||
touch.x_min = 0;
|
touch.x_min = 0;
|
||||||
touch.x_max = 1;
|
touch.x_max = 1;
|
||||||
touch.native_xres = touch.xres = 1;
|
touch.native_xres = 1;
|
||||||
touch.xres = 1;
|
touch.xres = 1;
|
||||||
touch.y_min = 0;
|
|
||||||
|
touch.y_min = 0;
|
||||||
touch.y_max = 1;
|
touch.y_max = 1;
|
||||||
touch.native_yres = touch.yres = 1;
|
touch.native_yres = 1;
|
||||||
touch.pressure_min = 0;
|
touch.yres = 1;
|
||||||
|
|
||||||
|
touch.pressure_min = 0;
|
||||||
touch.pressure_max = 1;
|
touch.pressure_max = 1;
|
||||||
touch.native_pressureres = touch.pressure_max - touch.pressure_min;
|
touch.native_pressureres = 1;
|
||||||
|
touch.pressureres = 1;
|
||||||
|
|
||||||
SDL_AddTouch(&touch, "");
|
SDL_AddTouch(&touch, "");
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ enum eDisplayMode
|
|||||||
|
|
||||||
unsigned int gDisplayMode = DisplayMode_lowRes;
|
unsigned int gDisplayMode = DisplayMode_lowRes;
|
||||||
|
|
||||||
|
const int kHitzonePliancy = 50;
|
||||||
|
|
||||||
class SdlApp
|
class SdlApp
|
||||||
{
|
{
|
||||||
public: /* For easy interfacing with JGE static functions */
|
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_x;
|
||||||
int windowed_pos_y;
|
int windowed_pos_y;
|
||||||
|
|
||||||
|
int mMouseDownX;
|
||||||
|
int mMouseDownY;
|
||||||
|
|
||||||
public:
|
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(
|
g_engine->LeftClicked(
|
||||||
((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);
|
||||||
|
|
||||||
|
if (event.type == SDL_FINGERDOWN)
|
||||||
|
{
|
||||||
|
mMouseDownX = event.x;
|
||||||
|
mMouseDownY = event.y;
|
||||||
|
}
|
||||||
|
|
||||||
#if (defined ANDROID) || (defined IOS)
|
#if (defined ANDROID) || (defined IOS)
|
||||||
if (event.type == SDL_FINGERUP)
|
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
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user