Multiple finger events now translate correctly into an SDL_MULTIGESTURE. I still haven't mapped this into anything meaningful, but all least the wiring is now present.
This commit is contained in:
@@ -123,9 +123,9 @@ extern "C" void Java_org_libsdl_app_SDLActivity_onNativeKeyUp(
|
|||||||
// Touch
|
// Touch
|
||||||
extern "C" void Java_org_libsdl_app_SDLActivity_onNativeTouch(
|
extern "C" void Java_org_libsdl_app_SDLActivity_onNativeTouch(
|
||||||
JNIEnv* env, jclass jcls,
|
JNIEnv* env, jclass jcls,
|
||||||
jint action, jfloat x, jfloat y, jfloat p)
|
jint index, jint action, jfloat x, jfloat y, jfloat p)
|
||||||
{
|
{
|
||||||
Android_OnTouch(action, x, y, p);
|
Android_OnTouch(index, action, x, y, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Accelerometer
|
// Accelerometer
|
||||||
|
|||||||
@@ -20,7 +20,10 @@
|
|||||||
*/
|
*/
|
||||||
#include "SDL_config.h"
|
#include "SDL_config.h"
|
||||||
|
|
||||||
|
#if defined(ANDROID)
|
||||||
#include <android/log.h>
|
#include <android/log.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* General touch handling code for SDL */
|
/* General touch handling code for SDL */
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,8 @@
|
|||||||
#define ACTION_MOVE 2
|
#define ACTION_MOVE 2
|
||||||
#define ACTION_CANCEL 3
|
#define ACTION_CANCEL 3
|
||||||
#define ACTION_OUTSIDE 4
|
#define ACTION_OUTSIDE 4
|
||||||
|
#define ACTION_POINTER_DOWN 5
|
||||||
|
#define ACTION_POINTER_UP 6
|
||||||
|
|
||||||
|
|
||||||
static SDL_TouchID gTouchID = 0;
|
static SDL_TouchID gTouchID = 0;
|
||||||
@@ -64,7 +66,7 @@ SDL_Touch* CreateTouchInstance()
|
|||||||
return SDL_GetTouch(touch.id);
|
return SDL_GetTouch(touch.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Android_OnTouch(int action, float x, float y, float p)
|
void Android_OnTouch(int index, int action, float x, float y, float p)
|
||||||
{
|
{
|
||||||
if (!Android_Window)
|
if (!Android_Window)
|
||||||
{
|
{
|
||||||
@@ -81,23 +83,32 @@ void Android_OnTouch(int action, float x, float y, float p)
|
|||||||
touch = CreateTouchInstance();
|
touch = CreateTouchInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
char buffer[64];
|
//char buffer[64];
|
||||||
sprintf(buffer, "Touch action: %d x: %f y: %f", action, x, y);
|
//sprintf(buffer, "Touch action: %d x: %f y: %f, index: %d", action, x, y, index);
|
||||||
__android_log_write(ANDROID_LOG_DEBUG, "Wagic", buffer);
|
//__android_log_write(ANDROID_LOG_DEBUG, "Wagic", buffer);
|
||||||
|
|
||||||
switch(action)
|
switch(action)
|
||||||
{
|
{
|
||||||
case ACTION_DOWN:
|
case ACTION_DOWN:
|
||||||
SDL_SendFingerDown(touch->id, 1, SDL_TRUE, x, y, p);
|
case ACTION_POINTER_DOWN:
|
||||||
|
SDL_SendFingerDown(touch->id, index, SDL_TRUE, x, y, p);
|
||||||
//SDL_SendMouseButton(Android_Window, SDL_PRESSED, SDL_BUTTON_LEFT);
|
//SDL_SendMouseButton(Android_Window, SDL_PRESSED, SDL_BUTTON_LEFT);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ACTION_MOVE:
|
case ACTION_MOVE:
|
||||||
SDL_SendTouchMotion(touch->id, 1, SDL_FALSE, x, y, 1);
|
SDL_SendTouchMotion(touch->id, index, SDL_FALSE, x, y, 1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ACTION_UP:
|
case ACTION_UP:
|
||||||
SDL_SendFingerDown(touch->id, 1, SDL_FALSE, x, y, p);
|
// this means a completed gesture
|
||||||
|
SDL_SendFingerDown(touch->id, index, SDL_FALSE, x, y, p);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ACTION_POINTER_UP:
|
||||||
|
// this is an individual finger up - due to some false hits on finger 0 lifting, only honor this event
|
||||||
|
// if the finger up is anything BUT finger 0, this prevents false action triggers
|
||||||
|
if (index > 0)
|
||||||
|
SDL_SendFingerDown(touch->id, index, SDL_FALSE, x, y, p);
|
||||||
//SDL_SendMouseButton(Android_Window, SDL_RELEASED, SDL_BUTTON_LEFT);
|
//SDL_SendMouseButton(Android_Window, SDL_RELEASED, SDL_BUTTON_LEFT);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,6 @@
|
|||||||
|
|
||||||
#include "SDL_androidvideo.h"
|
#include "SDL_androidvideo.h"
|
||||||
|
|
||||||
extern void Android_OnTouch(int action, float x, float y, float p);
|
extern void Android_OnTouch(int index, int action, float x, float y, float p);
|
||||||
|
|
||||||
/* vi: set ts=4 sw=4 expandtab: */
|
/* vi: set ts=4 sw=4 expandtab: */
|
||||||
|
|||||||
+33
-28
@@ -189,13 +189,13 @@ public:
|
|||||||
case SDL_FINGERMOTION:
|
case SDL_FINGERMOTION:
|
||||||
case SDL_FINGERDOWN:
|
case SDL_FINGERDOWN:
|
||||||
case SDL_FINGERUP:
|
case SDL_FINGERUP:
|
||||||
DebugTrace("Touch Event triggered");
|
//DebugTrace("Touch Event triggered");
|
||||||
DebugTrace("touchId " << Event->tfinger.touchId);
|
//DebugTrace("touchId " << Event->tfinger.touchId);
|
||||||
DebugTrace("fingerId " << Event->tfinger.fingerId);
|
//DebugTrace("fingerId " << Event->tfinger.fingerId);
|
||||||
DebugTrace("state " << Event->tfinger.state);
|
//DebugTrace("state " << Event->tfinger.state);
|
||||||
DebugTrace("x " << Event->tfinger.x << ", y " << Event->tfinger.y);
|
//DebugTrace("x " << Event->tfinger.x << ", y " << Event->tfinger.y);
|
||||||
DebugTrace("dx " << Event->tfinger.dx << ", dy " << Event->tfinger.dy);
|
//DebugTrace("dx " << Event->tfinger.dx << ", dy " << Event->tfinger.dy);
|
||||||
DebugTrace("pressure " << Event->tfinger.pressure);
|
//DebugTrace("pressure " << Event->tfinger.pressure);
|
||||||
|
|
||||||
OnTouchEvent(Event->tfinger);
|
OnTouchEvent(Event->tfinger);
|
||||||
break;
|
break;
|
||||||
@@ -206,7 +206,7 @@ public:
|
|||||||
<< ", y " << Event->mgesture.y
|
<< ", y " << Event->mgesture.y
|
||||||
<< ", dTheta " << Event->mgesture.dTheta
|
<< ", dTheta " << Event->mgesture.dTheta
|
||||||
<< ", dDist " << Event->mgesture.dDist
|
<< ", dDist " << Event->mgesture.dDist
|
||||||
<< ", numFinder " << Event->mgesture.numFingers);
|
<< ", numFingers " << Event->mgesture.numFingers);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -497,34 +497,39 @@ void SdlApp::OnMouseClicked(const SDL_MouseButtonEvent& event)
|
|||||||
|
|
||||||
void SdlApp::OnTouchEvent(const SDL_TouchFingerEvent& event)
|
void SdlApp::OnTouchEvent(const SDL_TouchFingerEvent& event)
|
||||||
{
|
{
|
||||||
if (event.y >= viewPort.y &&
|
// only respond to the first finger for mouse type movements - any additional finger
|
||||||
event.y <= viewPort.y + viewPort.h &&
|
// should be ignored, and will come through instead as a multigesture event
|
||||||
event.x >= viewPort.x &&
|
if (event.fingerId == 0)
|
||||||
event.x <= viewPort.x + viewPort.w)
|
|
||||||
{
|
{
|
||||||
int actualWidth = (int) JRenderer::GetInstance()->GetActualWidth();
|
if (event.y >= viewPort.y &&
|
||||||
int actualHeight = (int) JRenderer::GetInstance()->GetActualHeight();
|
event.y <= viewPort.y + viewPort.h &&
|
||||||
|
event.x >= viewPort.x &&
|
||||||
|
event.x <= viewPort.x + viewPort.w)
|
||||||
|
{
|
||||||
|
int actualWidth = (int) JRenderer::GetInstance()->GetActualWidth();
|
||||||
|
int actualHeight = (int) JRenderer::GetInstance()->GetActualHeight();
|
||||||
|
|
||||||
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)
|
if (event.type == SDL_FINGERDOWN)
|
||||||
{
|
{
|
||||||
mMouseDownX = event.x;
|
mMouseDownX = event.x;
|
||||||
mMouseDownY = event.y;
|
mMouseDownY = event.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
#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 (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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ public class SDLActivity extends Activity {
|
|||||||
public static native void onNativeResize(int x, int y, int format);
|
public static native void onNativeResize(int x, int y, int format);
|
||||||
public static native void onNativeKeyDown(int keycode);
|
public static native void onNativeKeyDown(int keycode);
|
||||||
public static native void onNativeKeyUp(int keycode);
|
public static native void onNativeKeyUp(int keycode);
|
||||||
public static native void onNativeTouch(int action, float x,
|
public static native void onNativeTouch(int index, int action, float x,
|
||||||
float y, float p);
|
float y, float p);
|
||||||
public static native void onNativeAccel(float x, float y, float z);
|
public static native void onNativeAccel(float x, float y, float z);
|
||||||
public static native void nativeRunAudioThread();
|
public static native void nativeRunAudioThread();
|
||||||
@@ -456,14 +456,18 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
|
|||||||
// Touch events
|
// Touch events
|
||||||
public boolean onTouch(View v, MotionEvent event) {
|
public boolean onTouch(View v, MotionEvent event) {
|
||||||
|
|
||||||
int action = event.getAction();
|
for (int index = 0; index < event.getPointerCount(); ++index)
|
||||||
float x = event.getX();
|
{
|
||||||
float y = event.getY();
|
int action = event.getActionMasked();
|
||||||
float p = event.getPressure();
|
float x = event.getX(index);
|
||||||
|
float y = event.getY(index);
|
||||||
|
float p = event.getPressure(index);
|
||||||
|
|
||||||
// TODO: Anything else we need to pass?
|
// TODO: Anything else we need to pass?
|
||||||
SDLActivity.onNativeTouch(action, x, y, p);
|
SDLActivity.onNativeTouch(index, action, x, y, p);
|
||||||
return true;
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sensor events
|
// Sensor events
|
||||||
|
|||||||
Reference in New Issue
Block a user