aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/android/events.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'backends/platform/android/events.cpp')
-rw-r--r--backends/platform/android/events.cpp181
1 files changed, 53 insertions, 128 deletions
diff --git a/backends/platform/android/events.cpp b/backends/platform/android/events.cpp
index 634a84002f..465c6a1531 100644
--- a/backends/platform/android/events.cpp
+++ b/backends/platform/android/events.cpp
@@ -40,6 +40,7 @@
#define FORBIDDEN_SYMBOL_EXCEPTION_printf
#include "backends/platform/android/android.h"
+#include "backends/platform/android/graphics.h"
#include "backends/platform/android/events.h"
#include "backends/platform/android/jni.h"
@@ -76,69 +77,6 @@ void OSystem_Android::setupKeymapper() {
#endif
}
-void OSystem_Android::warpMouse(int x, int y) {
- ENTER("%d, %d", x, y);
-
- Common::Event e;
-
- e.type = Common::EVENT_MOUSEMOVE;
- e.mouse.x = x;
- e.mouse.y = y;
-
- clipMouse(e.mouse);
-
- pushEvent(e);
-}
-
-void OSystem_Android::clipMouse(Common::Point &p) {
- const GLESBaseTexture *tex;
-
- if (_show_overlay)
- tex = _overlay_texture;
- else
- tex = _game_texture;
-
- p.x = CLIP(p.x, int16(0), int16(tex->width() - 1));
- p.y = CLIP(p.y, int16(0), int16(tex->height() - 1));
-}
-
-void OSystem_Android::scaleMouse(Common::Point &p, int x, int y,
- bool deductDrawRect, bool touchpadMode) {
- const GLESBaseTexture *tex;
-
- if (_show_overlay)
- tex = _overlay_texture;
- else
- tex = _game_texture;
-
- const Common::Rect &r = tex->getDrawRect();
-
- if (touchpadMode) {
- x = x * 100 / _touchpad_scale;
- y = y * 100 / _touchpad_scale;
- }
-
- if (deductDrawRect) {
- x -= r.left;
- y -= r.top;
- }
-
- p.x = scalef(x, tex->width(), r.width());
- p.y = scalef(y, tex->height(), r.height());
-}
-
-void OSystem_Android::updateEventScale() {
- const GLESBaseTexture *tex;
-
- if (_show_overlay)
- tex = _overlay_texture;
- else
- tex = _game_texture;
-
- _eventScaleY = 100 * 480 / tex->height();
- _eventScaleX = 100 * 640 / tex->width();
-}
-
void OSystem_Android::pushEvent(int type, int arg1, int arg2, int arg3,
int arg4, int arg5, int arg6) {
Common::Event e;
@@ -199,7 +137,7 @@ void OSystem_Android::pushEvent(int type, int arg1, int arg2, int arg3,
else
e.type = Common::EVENT_RBUTTONUP;
- e.mouse = getEventManager()->getMousePos();
+ e.mouse = dynamic_cast<AndroidGraphicsManager *>(_graphicsManager)->getMousePosition();
pushEvent(e);
@@ -324,7 +262,7 @@ void OSystem_Android::pushEvent(int type, int arg1, int arg2, int arg3,
e.type = Common::EVENT_MOUSEMOVE;
- e.mouse = getEventManager()->getMousePos();
+ e.mouse = dynamic_cast<AndroidGraphicsManager *>(_graphicsManager)->getMousePosition();
{
int16 *c;
@@ -348,8 +286,6 @@ void OSystem_Android::pushEvent(int type, int arg1, int arg2, int arg3,
*c += f;
}
- clipMouse(e.mouse);
-
pushEvent(e);
return;
@@ -367,7 +303,7 @@ void OSystem_Android::pushEvent(int type, int arg1, int arg2, int arg3,
return;
}
- e.mouse = getEventManager()->getMousePos();
+ e.mouse = dynamic_cast<AndroidGraphicsManager *>(_graphicsManager)->getMousePosition();
pushEvent(e);
@@ -375,7 +311,7 @@ void OSystem_Android::pushEvent(int type, int arg1, int arg2, int arg3,
}
case JE_DOWN:
- _touch_pt_down = getEventManager()->getMousePos();
+ _touch_pt_down = dynamic_cast<AndroidGraphicsManager *>(_graphicsManager)->getMousePosition();
_touch_pt_scroll.x = -1;
_touch_pt_scroll.y = -1;
break;
@@ -390,13 +326,13 @@ void OSystem_Android::pushEvent(int type, int arg1, int arg2, int arg3,
return;
}
- scaleMouse(e.mouse, arg3 - _touch_pt_scroll.x,
- arg4 - _touch_pt_scroll.y, false, true);
+ e.mouse.x = (arg3 - _touch_pt_scroll.x) * 100 / _touchpad_scale;
+ e.mouse.y = (arg4 - _touch_pt_scroll.y) * 100 / _touchpad_scale;
e.mouse += _touch_pt_down;
- clipMouse(e.mouse);
+
} else {
- scaleMouse(e.mouse, arg3, arg4);
- clipMouse(e.mouse);
+ e.mouse.x = arg3;
+ e.mouse.y = arg4;
}
pushEvent(e);
@@ -412,10 +348,10 @@ void OSystem_Android::pushEvent(int type, int arg1, int arg2, int arg3,
e.type = Common::EVENT_MOUSEMOVE;
if (_touchpad_mode) {
- e.mouse = getEventManager()->getMousePos();
+ e.mouse = dynamic_cast<AndroidGraphicsManager *>(_graphicsManager)->getMousePosition();
} else {
- scaleMouse(e.mouse, arg1, arg2);
- clipMouse(e.mouse);
+ e.mouse.x = arg1;
+ e.mouse.y = arg2;
}
{
@@ -457,10 +393,10 @@ void OSystem_Android::pushEvent(int type, int arg1, int arg2, int arg3,
e.type = Common::EVENT_MOUSEMOVE;
if (_touchpad_mode) {
- e.mouse = getEventManager()->getMousePos();
+ e.mouse = dynamic_cast<AndroidGraphicsManager *>(_graphicsManager)->getMousePosition();
} else {
- scaleMouse(e.mouse, arg1, arg2);
- clipMouse(e.mouse);
+ e.mouse.x = arg1;
+ e.mouse.y = arg2;
}
{
@@ -486,11 +422,9 @@ void OSystem_Android::pushEvent(int type, int arg1, int arg2, int arg3,
dptype = Common::EVENT_MOUSEMOVE;
if (_touchpad_mode) {
- scaleMouse(e.mouse, arg1 - _touch_pt_dt.x,
- arg2 - _touch_pt_dt.y, false, true);
+ e.mouse.x = (arg1 - _touch_pt_dt.x) * 100 / _touchpad_scale;
+ e.mouse.y = (arg2 - _touch_pt_dt.y) * 100 / _touchpad_scale;
e.mouse += _touch_pt_down;
-
- clipMouse(e.mouse);
}
break;
@@ -537,7 +471,7 @@ void OSystem_Android::pushEvent(int type, int arg1, int arg2, int arg3,
return;
}
- e.mouse = getEventManager()->getMousePos();
+ e.mouse = dynamic_cast<AndroidGraphicsManager *>(_graphicsManager)->getMousePosition();
lockMutex(_event_queue_lock);
@@ -562,7 +496,7 @@ void OSystem_Android::pushEvent(int type, int arg1, int arg2, int arg3,
return;
case JE_BALL:
- e.mouse = getEventManager()->getMousePos();
+ e.mouse = dynamic_cast<AndroidGraphicsManager *>(_graphicsManager)->getMousePosition();
switch (arg1) {
case JACTION_DOWN:
@@ -578,8 +512,6 @@ void OSystem_Android::pushEvent(int type, int arg1, int arg2, int arg3,
e.mouse.x += arg2 * _trackball_scale / _eventScaleX;
e.mouse.y += arg3 * _trackball_scale / _eventScaleY;
- clipMouse(e.mouse);
-
break;
default:
LOGE("unhandled jaction on system key: %d", arg1);
@@ -592,9 +524,8 @@ void OSystem_Android::pushEvent(int type, int arg1, int arg2, int arg3,
case JE_MOUSE_MOVE:
e.type = Common::EVENT_MOUSEMOVE;
-
- scaleMouse(e.mouse, arg1, arg2);
- clipMouse(e.mouse);
+ e.mouse.x = arg1;
+ e.mouse.y = arg2;
pushEvent(e);
@@ -602,9 +533,8 @@ void OSystem_Android::pushEvent(int type, int arg1, int arg2, int arg3,
case JE_LMB_DOWN:
e.type = Common::EVENT_LBUTTONDOWN;
-
- scaleMouse(e.mouse, arg1, arg2);
- clipMouse(e.mouse);
+ e.mouse.x = arg1;
+ e.mouse.y = arg2;
pushEvent(e);
@@ -612,9 +542,8 @@ void OSystem_Android::pushEvent(int type, int arg1, int arg2, int arg3,
case JE_LMB_UP:
e.type = Common::EVENT_LBUTTONUP;
-
- scaleMouse(e.mouse, arg1, arg2);
- clipMouse(e.mouse);
+ e.mouse.x = arg1;
+ e.mouse.y = arg2;
pushEvent(e);
@@ -622,9 +551,8 @@ void OSystem_Android::pushEvent(int type, int arg1, int arg2, int arg3,
case JE_RMB_DOWN:
e.type = Common::EVENT_RBUTTONDOWN;
-
- scaleMouse(e.mouse, arg1, arg2);
- clipMouse(e.mouse);
+ e.mouse.x = arg1;
+ e.mouse.y = arg2;
pushEvent(e);
@@ -632,9 +560,8 @@ void OSystem_Android::pushEvent(int type, int arg1, int arg2, int arg3,
case JE_RMB_UP:
e.type = Common::EVENT_RBUTTONUP;
-
- scaleMouse(e.mouse, arg1, arg2);
- clipMouse(e.mouse);
+ e.mouse.x = arg1;
+ e.mouse.y = arg2;
pushEvent(e);
@@ -669,7 +596,7 @@ void OSystem_Android::pushEvent(int type, int arg1, int arg2, int arg3,
break;
}
- e.mouse = getEventManager()->getMousePos();
+ e.mouse = dynamic_cast<AndroidGraphicsManager *>(_graphicsManager)->getMousePosition();
break;
@@ -692,7 +619,7 @@ void OSystem_Android::pushEvent(int type, int arg1, int arg2, int arg3,
break;
case JE_JOYSTICK:
- e.mouse = getEventManager()->getMousePos();
+ e.mouse = dynamic_cast<AndroidGraphicsManager *>(_graphicsManager)->getMousePosition();
switch (arg1) {
case JACTION_MULTIPLE:
@@ -702,8 +629,6 @@ void OSystem_Android::pushEvent(int type, int arg1, int arg2, int arg3,
e.mouse.x += arg2 * _joystick_scale / _eventScaleX;
e.mouse.y += arg3 * _joystick_scale / _eventScaleY;
- clipMouse(e.mouse);
-
break;
default:
LOGE("unhandled jaction on joystick: %d", arg1);
@@ -745,23 +670,19 @@ bool OSystem_Android::pollEvent(Common::Event &event) {
if (pthread_self() == _main_thread) {
if (_screen_changeid != JNI::surface_changeid) {
+ _screen_changeid = JNI::surface_changeid;
+
if (JNI::egl_surface_width > 0 && JNI::egl_surface_height > 0) {
// surface changed
- JNI::deinitSurface();
- initSurface();
- initViewport();
- updateScreenRect();
- updateEventScale();
-
- // double buffered, flip twice
- clearScreen(kClearUpdate, 2);
+ dynamic_cast<AndroidGraphicsManager *>(_graphicsManager)->deinitSurface();
+ dynamic_cast<AndroidGraphicsManager *>(_graphicsManager)->initSurface();
event.type = Common::EVENT_SCREEN_CHANGED;
return true;
} else {
// surface lost
- deinitSurface();
+ dynamic_cast<AndroidGraphicsManager *>(_graphicsManager)->deinitSurface();
}
}
@@ -777,24 +698,28 @@ bool OSystem_Android::pollEvent(Common::Event &event) {
if (_queuedEventTime && (getMillis() > _queuedEventTime)) {
event = _queuedEvent;
_queuedEventTime = 0;
- unlockMutex(_event_queue_lock);
- return true;
- }
-
- if (_event_queue.empty()) {
+ // unlockMutex(_event_queue_lock);
+ // return true;
+ } else if (_event_queue.empty()) {
unlockMutex(_event_queue_lock);
return false;
+ } else {
+ event = _event_queue.pop();
}
- event = _event_queue.pop();
-
unlockMutex(_event_queue_lock);
- if (event.type == Common::EVENT_MOUSEMOVE) {
- const Common::Point &m = getEventManager()->getMousePos();
-
- if (m != event.mouse)
- _force_redraw = true;
+ switch (event.type) {
+ case Common::EVENT_MOUSEMOVE:
+ case Common::EVENT_LBUTTONDOWN:
+ case Common::EVENT_LBUTTONUP:
+ case Common::EVENT_RBUTTONDOWN:
+ case Common::EVENT_RBUTTONUP:
+ if (_graphicsManager)
+ return dynamic_cast<AndroidGraphicsManager *>(_graphicsManager)->notifyMousePosition(event.mouse);
+ break;
+ default:
+ break;
}
return true;