diff options
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/gui/gui.cpp | 5 | ||||
-rw-r--r-- | src/gui/sdlinput.cpp | 30 | ||||
-rw-r--r-- | src/gui/sdlinput.h | 5 | ||||
-rw-r--r-- | src/guichan/include/guichan/mouseinput.hpp | 2 | ||||
-rw-r--r-- | src/touchactions.cpp | 13 | ||||
-rw-r--r-- | src/touchactions.h | 12 | ||||
-rw-r--r-- | src/touchmanager.cpp | 13 | ||||
-rw-r--r-- | src/touchmanager.h | 5 |
10 files changed, 63 insertions, 26 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d07d67dca..d312a9415 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -607,6 +607,8 @@ SET(SRCS mgl.h mobileopenglgraphics.cpp mobileopenglgraphics.h + mouseinput.cpp + mouseinput.h normalopenglgraphics.cpp normalopenglgraphics.h particle.cpp diff --git a/src/Makefile.am b/src/Makefile.am index d906b30ec..5523c0159 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -611,6 +611,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ mgl.h \ mobileopenglgraphics.cpp \ mobileopenglgraphics.h \ + mouseinput.cpp \ + mouseinput.h \ normalopenglgraphics.cpp \ normalopenglgraphics.h \ particle.cpp \ diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 8d26acea8..268f05fc1 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -36,6 +36,7 @@ #include "keydata.h" #include "keyevent.h" #include "keyinput.h" +#include "mouseinput.h" #include "touchmanager.h" #include "resources/image.h" @@ -272,7 +273,7 @@ void Gui::logic() handleModalFocus(); handleModalMouseInputFocus(); - if (mInput) + if (guiInput) handleMouseInput(); mTop->logic(); @@ -658,7 +659,7 @@ void Gui::handleMouseInput() BLOCK_START("Gui::handleMouseInput") while (!mInput->isMouseQueueEmpty()) { - const gcn::MouseInput mouseInput = mInput->dequeueMouseInput(); + const MouseInput mouseInput = guiInput->dequeueMouseInput2(); if (touchManager.processEvent(mouseInput)) { diff --git a/src/gui/sdlinput.cpp b/src/gui/sdlinput.cpp index a79752cba..32aff02c9 100644 --- a/src/gui/sdlinput.cpp +++ b/src/gui/sdlinput.cpp @@ -58,9 +58,9 @@ #include "gui/sdlinput.h" -#include "keydata.h" - #include "inputmanager.h" +#include "keydata.h" +#include "mouseinput.h" #include <guichan/exception.hpp> @@ -108,10 +108,25 @@ gcn::MouseInput SDLInput::dequeueMouseInput() return mouseInput; } +MouseInput SDLInput::dequeueMouseInput2() +{ + MouseInput mouseInput; + + if (mMouseInputQueue.empty()) + { + throw GCN_EXCEPTION("The queue is empty."); + } + + mouseInput = mMouseInputQueue.front(); + mMouseInputQueue.pop(); + + return mouseInput; +} + void SDLInput::pushInput(const SDL_Event &event) { KeyInput keyInput; - gcn::MouseInput mouseInput; + MouseInput mouseInput; switch (event.type) { @@ -153,6 +168,9 @@ void SDLInput::pushInput(const SDL_Event &event) mMouseDown = true; mouseInput.setX(event.button.x); mouseInput.setY(event.button.y); +#ifdef ANDROID + mouseInput.setReal(event.button.realx, event.button.realy); +#endif mouseInput.setButton(convertMouseButton(event.button.button)); if (event.button.button == SDL_BUTTON_WHEELDOWN) @@ -169,6 +187,9 @@ void SDLInput::pushInput(const SDL_Event &event) mMouseDown = false; mouseInput.setX(event.button.x); mouseInput.setY(event.button.y); +#ifdef ANDROID + mouseInput.setReal(event.button.realx, event.button.realy); +#endif mouseInput.setButton(convertMouseButton(event.button.button)); mouseInput.setType(gcn::MouseInput::RELEASED); mouseInput.setTimeStamp(SDL_GetTicks()); @@ -178,6 +199,9 @@ void SDLInput::pushInput(const SDL_Event &event) case SDL_MOUSEMOTION: mouseInput.setX(event.button.x); mouseInput.setY(event.button.y); +#ifdef ANDROID + mouseInput.setReal(event.button.realx, event.button.realy); +#endif mouseInput.setButton(gcn::MouseInput::EMPTY); mouseInput.setType(gcn::MouseInput::MOVED); mouseInput.setTimeStamp(SDL_GetTicks()); diff --git a/src/gui/sdlinput.h b/src/gui/sdlinput.h index c3b0d14e7..dc12789b2 100644 --- a/src/gui/sdlinput.h +++ b/src/gui/sdlinput.h @@ -70,6 +70,7 @@ #include <queue> class KeyInput; +class MouseInput; namespace Key { @@ -168,6 +169,8 @@ public: virtual gcn::MouseInput dequeueMouseInput() A_WARN_UNUSED; + virtual MouseInput dequeueMouseInput2() A_WARN_UNUSED; + protected: /** * Converts a mouse button from SDL to a Guichan mouse button @@ -188,7 +191,7 @@ protected: static int convertKeyCharacter(const SDL_Event &event) A_WARN_UNUSED; std::queue<KeyInput> mKeyInputQueue; - std::queue<gcn::MouseInput> mMouseInputQueue; + std::queue<MouseInput> mMouseInputQueue; bool mMouseDown; bool mMouseInWindow; diff --git a/src/guichan/include/guichan/mouseinput.hpp b/src/guichan/include/guichan/mouseinput.hpp index ab286cac1..a2911f1d4 100644 --- a/src/guichan/include/guichan/mouseinput.hpp +++ b/src/guichan/include/guichan/mouseinput.hpp @@ -61,7 +61,7 @@ namespace gcn * @author Per Larsson * @since 0.1.0 */ - class GCN_CORE_DECLSPEC MouseInput final + class GCN_CORE_DECLSPEC MouseInput { public: diff --git a/src/touchactions.cpp b/src/touchactions.cpp index 20d008eda..40f7e5641 100644 --- a/src/touchactions.cpp +++ b/src/touchactions.cpp @@ -24,6 +24,7 @@ #include "game.h" #include "keydata.h" #include "logger.h" +#include "mouseinput.h" #include "touchmanager.h" #ifdef ANDROID @@ -35,12 +36,12 @@ bool padClicked(false); #ifdef ANDROID -void showKeyboard(const gcn::MouseInput &mouseInput) +void showKeyboard(const MouseInput &mouseInput) { SDL_ANDROID_ToggleScreenKeyboardTextInput(nullptr); } #else -void showKeyboard(const gcn::MouseInput &mouseInput A_UNUSED) +void showKeyboard(const MouseInput &mouseInput A_UNUSED) { } #endif @@ -111,13 +112,13 @@ static void moveChar(int x, int y) } } -void padClick(const gcn::MouseInput &mouseInput) +void padClick(const MouseInput &mouseInput) { moveChar(mouseInput.getX(), mouseInput.getY()); padClicked = true; } -void padEvents(const gcn::MouseInput &mouseInput) +void padEvents(const MouseInput &mouseInput) { if (mouseInput.getType() == gcn::MouseInput::MOVED) { @@ -126,13 +127,13 @@ void padEvents(const gcn::MouseInput &mouseInput) } } -void padOut(const gcn::MouseInput &mouseInput A_UNUSED) +void padOut(const MouseInput &mouseInput A_UNUSED) { padClicked = false; moveChar(50, 50); } -void padUp(const gcn::MouseInput &mouseInput A_UNUSED) +void padUp(const MouseInput &mouseInput A_UNUSED) { padClicked = false; moveChar(50, 50); diff --git a/src/touchactions.h b/src/touchactions.h index b6d10dfc4..e76836a7f 100644 --- a/src/touchactions.h +++ b/src/touchactions.h @@ -25,14 +25,16 @@ #include "localconsts.h" -void showKeyboard(const gcn::MouseInput &mouseInput); +class MouseInput; -void padClick(const gcn::MouseInput &mouseInput); +void showKeyboard(const MouseInput &mouseInput); -void padEvents(const gcn::MouseInput &mouseInput); +void padClick(const MouseInput &mouseInput); -void padOut(const gcn::MouseInput &mouseInput); +void padEvents(const MouseInput &mouseInput); -void padUp(const gcn::MouseInput &mouseInput); +void padOut(const MouseInput &mouseInput); + +void padUp(const MouseInput &mouseInput); #endif diff --git a/src/touchmanager.cpp b/src/touchmanager.cpp index f2c91f867..8afc35119 100644 --- a/src/touchmanager.cpp +++ b/src/touchmanager.cpp @@ -23,6 +23,7 @@ #include "configuration.h" #include "graphics.h" #include "graphicsvertexes.h" +#include "mouseinput.h" #include "touchactions.h" #include "gui/theme.h" @@ -161,10 +162,10 @@ void TouchManager::draw() } } -bool TouchManager::processEvent(const gcn::MouseInput &mouseInput) +bool TouchManager::processEvent(const MouseInput &mouseInput) { - const int x = mouseInput.getX(); - const int y = mouseInput.getY(); + const int x = mouseInput.getTouchX(); + const int y = mouseInput.getTouchY(); for (TouchItemVectorCIter it = mObjects.begin(), it_end = mObjects.end(); it != it_end; ++ it) @@ -175,9 +176,9 @@ bool TouchManager::processEvent(const gcn::MouseInput &mouseInput) const gcn::Rectangle &rect = item->rect; if (rect.isPointInRect(x, y)) { - gcn::MouseInput event = mouseInput; - event.setX(event.getX() - item->x); - event.setY(event.getY() - item->y); + MouseInput event = mouseInput; + event.setX(event.getTouchX() - item->x); + event.setY(event.getTouchY() - item->y); if (item->funcAll) item->funcAll(event); diff --git a/src/touchmanager.h b/src/touchmanager.h index 43eaf65d1..8afd78c56 100644 --- a/src/touchmanager.h +++ b/src/touchmanager.h @@ -33,8 +33,9 @@ #include "localconsts.h" class ImageCollection; +class MouseInput; -typedef void (*TouchFuncPtr) (const gcn::MouseInput &mouseInput); +typedef void (*TouchFuncPtr) (const MouseInput &mouseInput); const int actionsSize = 10; @@ -90,7 +91,7 @@ class TouchManager final void draw(); - bool processEvent(const gcn::MouseInput &mouseInput); + bool processEvent(const MouseInput &mouseInput); bool isActionActive(const int index) const; |