More incremental work on getting touch commands on Android. I've pinpointed a nasty problem that looks possibly like a compiler bug - the float values that are passed into SDL_SendFingerDown() are coming out junk on the other end. Probably an extra push of something on the stack, as when I tried using pointers to floats instead, the y value showed up in the x position.
This commit is contained in:
@@ -20,6 +20,8 @@
|
|||||||
*/
|
*/
|
||||||
#include "SDL_config.h"
|
#include "SDL_config.h"
|
||||||
|
|
||||||
|
#include <android/log.h>
|
||||||
|
|
||||||
/* General touch handling code for SDL */
|
/* General touch handling code for SDL */
|
||||||
|
|
||||||
#include "SDL_events.h"
|
#include "SDL_events.h"
|
||||||
@@ -324,11 +326,14 @@ SDL_SendFingerDown(SDL_TouchID id, SDL_FingerID fingerid, SDL_bool down,
|
|||||||
return SDL_TouchNotFoundError(id);
|
return SDL_TouchNotFoundError(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//scale to Integer coordinates
|
//scale to Integer coordinates
|
||||||
x = (Uint16)((xin+touch->x_min)*(touch->xres)/(touch->native_xres));
|
x = (Uint16)((xin+touch->x_min)*(touch->xres)/(touch->native_xres));
|
||||||
y = (Uint16)((yin+touch->y_min)*(touch->yres)/(touch->native_yres));
|
y = (Uint16)((yin+touch->y_min)*(touch->yres)/(touch->native_yres));
|
||||||
pressure = (Uint16)((yin+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) {
|
||||||
|
|||||||
@@ -44,10 +44,11 @@ SDL_Touch* CreateTouchInstance()
|
|||||||
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.x_max - touch.x_min;
|
touch.native_xres = 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.y_max - touch.y_min;
|
touch.native_yres = touch.yres = 1;
|
||||||
touch.pressure_min = 0;
|
touch.pressure_min = 0;
|
||||||
touch.pressure_max = 1;
|
touch.pressure_max = 1;
|
||||||
touch.native_pressureres = touch.pressure_max - touch.pressure_min;
|
touch.native_pressureres = touch.pressure_max - touch.pressure_min;
|
||||||
@@ -74,19 +75,23 @@ void Android_OnTouch(int action, float x, float y, float p)
|
|||||||
touch = CreateTouchInstance();
|
touch = CreateTouchInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char buffer[64];
|
||||||
|
sprintf(buffer, "Touch action: %d x: %f y: %f", action, x, y);
|
||||||
|
__android_log_write(ANDROID_LOG_DEBUG, "Wagic", buffer);
|
||||||
|
|
||||||
switch(action)
|
switch(action)
|
||||||
{
|
{
|
||||||
case ACTION_DOWN:
|
case ACTION_DOWN:
|
||||||
SDL_SendFingerDown(touch->id, 1, 1, x, y, p);
|
SDL_SendFingerDown(touch->id, 1, 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, 0, x, y, 1);
|
SDL_SendTouchMotion(touch->id, 1, SDL_FALSE, x, y, 1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ACTION_UP:
|
case ACTION_UP:
|
||||||
SDL_SendFingerDown(touch->id, 1, 0, x, y, p);
|
SDL_SendFingerDown(touch->id, 1, 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;
|
||||||
}
|
}
|
||||||
|
|||||||
+35
-21
@@ -132,6 +132,8 @@ public:
|
|||||||
void OnMouseClicked(const SDL_MouseButtonEvent& event);
|
void OnMouseClicked(const SDL_MouseButtonEvent& event);
|
||||||
void OnMouseMoved(const SDL_MouseMotionEvent& event);
|
void OnMouseMoved(const SDL_MouseMotionEvent& event);
|
||||||
|
|
||||||
|
void OnTouchEvent(const SDL_TouchFingerEvent& event);
|
||||||
|
|
||||||
void OnEvent(SDL_Event* Event)
|
void OnEvent(SDL_Event* Event)
|
||||||
{
|
{
|
||||||
/* if(Event->type < SDL_USEREVENT)
|
/* if(Event->type < SDL_USEREVENT)
|
||||||
@@ -180,28 +182,17 @@ public:
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_FINGERMOTION:
|
case SDL_FINGERMOTION:
|
||||||
DebugTrace("FingerMotion : touchId " << Event->tfinger.touchId
|
case SDL_FINGERDOWN:
|
||||||
<< ", fingerId " << Event->tfinger.fingerId
|
case SDL_FINGERUP:
|
||||||
<< ", state " << Event->tfinger.state
|
DebugTrace("Touch Event triggered");
|
||||||
<< ", x " << Event->tfinger.x
|
DebugTrace("touchId " << Event->tfinger.touchId);
|
||||||
<< ", y " << Event->tfinger.y
|
DebugTrace("fingerId " << Event->tfinger.fingerId);
|
||||||
<< ", dy " << Event->tfinger.dx
|
DebugTrace("state " << Event->tfinger.state);
|
||||||
<< ", dy " << Event->tfinger.dy
|
DebugTrace("x " << Event->tfinger.x << ", y " << Event->tfinger.y);
|
||||||
<< ", pressure " << Event->tfinger.pressure
|
DebugTrace("dx " << Event->tfinger.dx << ", dy " << Event->tfinger.dy);
|
||||||
);
|
DebugTrace("pressure " << Event->tfinger.pressure);
|
||||||
|
|
||||||
OnMouseMoved(Event->motion);
|
OnTouchEvent(Event->tfinger);
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_FINGERDOWN:
|
|
||||||
DebugTrace("FingerDown msg");
|
|
||||||
OnMouseClicked(Event->button);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_FINGERUP:
|
|
||||||
DebugTrace("FingerUp msg");
|
|
||||||
DebugTrace("X: " << Event->button.x << ", Y: " << Event->button.y);
|
|
||||||
OnMouseDoubleClicked(Event->button);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_MULTIGESTURE:
|
case SDL_MULTIGESTURE:
|
||||||
@@ -499,6 +490,29 @@ void SdlApp::OnMouseClicked(const SDL_MouseButtonEvent& event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SdlApp::OnTouchEvent(const SDL_TouchFingerEvent& event)
|
||||||
|
{
|
||||||
|
if (event.y >= viewPort.y &&
|
||||||
|
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(
|
||||||
|
((event.x - viewPort.x) * SCREEN_WIDTH) / actualWidth,
|
||||||
|
((event.y - viewPort.y) * SCREEN_HEIGHT) / actualHeight);
|
||||||
|
|
||||||
|
#if (defined ANDROID) || (defined IOS)
|
||||||
|
if (event.type == SDL_FINGERUP)
|
||||||
|
{
|
||||||
|
g_engine->HoldKey_NoRepeat(JGE_BTN_OK);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool SdlApp::OnInit()
|
bool SdlApp::OnInit()
|
||||||
{
|
{
|
||||||
int window_w, window_h;
|
int window_w, window_h;
|
||||||
|
|||||||
Reference in New Issue
Block a user