summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-11-09 01:53:40 +0300
committerAndrei Karas <akaras@inbox.ru>2012-11-12 18:54:58 +0300
commit363223352ee9c4c7c1d65e49cf48b38b538abaf2 (patch)
treefd43f37cdcbe02083ef66fdd54baca3f0c709f0b
parent9d66ae92ac714b4a4b21e588a3e2d481c352cd60 (diff)
downloadmanaverse-363223352ee9c4c7c1d65e49cf48b38b538abaf2.tar.gz
manaverse-363223352ee9c4c7c1d65e49cf48b38b538abaf2.tar.bz2
manaverse-363223352ee9c4c7c1d65e49cf48b38b538abaf2.tar.xz
manaverse-363223352ee9c4c7c1d65e49cf48b38b538abaf2.zip
Moving Android on screen keyboard button from SDL to ManaPlus.
Also add basic functions for handling other on screen buttons.
-rw-r--r--data/graphics/gui/CMakeLists.txt1
-rw-r--r--data/graphics/gui/Makefile.am1
-rw-r--r--data/graphics/gui/keyboard_icon.xml5
-rw-r--r--data/graphics/gui/window.pngbin18125 -> 20056 bytes
-rw-r--r--data/themes/blacknblack/window.pngbin13442 -> 15274 bytes
-rw-r--r--data/themes/blackwood/window.pngbin30664 -> 32527 bytes
-rw-r--r--data/themes/enchilado/window.pngbin24287 -> 26309 bytes
-rw-r--r--data/themes/pink/window.pngbin14518 -> 16515 bytes
-rw-r--r--data/themes/unity/window.pngbin23385 -> 25451 bytes
-rw-r--r--data/themes/wood/window.pngbin51481 -> 53518 bytes
-rw-r--r--src/CMakeLists.txt4
-rw-r--r--src/Makefile.am4
-rw-r--r--src/client.cpp3
-rw-r--r--src/gui/gui.cpp42
-rw-r--r--src/gui/gui.h3
-rw-r--r--src/gui/theme.cpp6
-rw-r--r--src/gui/theme.h9
-rw-r--r--src/guichan/gui.cpp33
-rw-r--r--src/mobileopenglgraphics.cpp2
-rw-r--r--src/touchactions.cpp36
-rw-r--r--src/touchactions.h30
-rw-r--r--src/touchmanager.cpp114
-rw-r--r--src/touchmanager.h90
23 files changed, 350 insertions, 33 deletions
diff --git a/data/graphics/gui/CMakeLists.txt b/data/graphics/gui/CMakeLists.txt
index 4cb568721..ea3312600 100644
--- a/data/graphics/gui/CMakeLists.txt
+++ b/data/graphics/gui/CMakeLists.txt
@@ -27,6 +27,7 @@ SET (FILES
item_selection.xml
item_shortcut_background.xml
itemcontainer.xml
+ keyboard_icon.xml
label.xml
listbox.xml
mouse.png
diff --git a/data/graphics/gui/Makefile.am b/data/graphics/gui/Makefile.am
index f6d9eb9df..cd3f80397 100644
--- a/data/graphics/gui/Makefile.am
+++ b/data/graphics/gui/Makefile.am
@@ -30,6 +30,7 @@ gui_DATA = \
item_selection.xml \
item_shortcut_background.xml \
itemcontainer.xml \
+ keyboard_icon.xml \
label.xml \
listbox.xml \
mouse.png \
diff --git a/data/graphics/gui/keyboard_icon.xml b/data/graphics/gui/keyboard_icon.xml
new file mode 100644
index 000000000..5b84f50b2
--- /dev/null
+++ b/data/graphics/gui/keyboard_icon.xml
@@ -0,0 +1,5 @@
+<skinset name="Default" image="window.png">
+ <widget type="Window">
+ <part type="standart" xpos="168" ypos="220" width="28" height="28" />
+ </widget>
+</skinset>
diff --git a/data/graphics/gui/window.png b/data/graphics/gui/window.png
index 20f5bf829..54455fa9d 100644
--- a/data/graphics/gui/window.png
+++ b/data/graphics/gui/window.png
Binary files differ
diff --git a/data/themes/blacknblack/window.png b/data/themes/blacknblack/window.png
index fbf71eb1d..3e11d9aab 100644
--- a/data/themes/blacknblack/window.png
+++ b/data/themes/blacknblack/window.png
Binary files differ
diff --git a/data/themes/blackwood/window.png b/data/themes/blackwood/window.png
index b9bc61935..920037f3b 100644
--- a/data/themes/blackwood/window.png
+++ b/data/themes/blackwood/window.png
Binary files differ
diff --git a/data/themes/enchilado/window.png b/data/themes/enchilado/window.png
index 58d8faf17..6aaa5d567 100644
--- a/data/themes/enchilado/window.png
+++ b/data/themes/enchilado/window.png
Binary files differ
diff --git a/data/themes/pink/window.png b/data/themes/pink/window.png
index c6b648b15..b19aa1655 100644
--- a/data/themes/pink/window.png
+++ b/data/themes/pink/window.png
Binary files differ
diff --git a/data/themes/unity/window.png b/data/themes/unity/window.png
index faf09695d..2ff7578a1 100644
--- a/data/themes/unity/window.png
+++ b/data/themes/unity/window.png
Binary files differ
diff --git a/data/themes/wood/window.png b/data/themes/wood/window.png
index f6d03c7d9..8a7bc51db 100644
--- a/data/themes/wood/window.png
+++ b/data/themes/wood/window.png
Binary files differ
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index f25ae995d..0610d23b3 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -644,6 +644,10 @@ SET(SRCS
textparticle.h
textrenderer.h
tileset.h
+ touchactions.cpp
+ touchactions.h
+ touchmanager.cpp
+ touchmanager.h
units.cpp
units.h
variabledata.h
diff --git a/src/Makefile.am b/src/Makefile.am
index 2140f85cc..124fb4c86 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -648,6 +648,10 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \
textparticle.h \
textrenderer.h \
tileset.h \
+ touchactions.cpp \
+ touchactions.h \
+ touchmanager.cpp \
+ touchmanager.h \
units.cpp \
units.h \
variabledata.h \
diff --git a/src/client.cpp b/src/client.cpp
index e71ae370b..338a474c1 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -44,6 +44,7 @@
#include "sound.h"
#include "statuseffect.h"
#include "units.h"
+#include "touchmanager.h"
#include "gui/buydialog.h"
#include "gui/buyselldialog.h"
@@ -557,6 +558,7 @@ void Client::gameInit()
mainGraphics->_beginDraw();
Theme::selectSkin();
+ touchManager.init();
// Theme::prepareThemePath();
// Initialize the item and emote shortcuts.
@@ -775,6 +777,7 @@ void Client::gameClear()
ActorSprite::unload();
+ touchManager.clear();
ResourceManager::deleteInstance();
if (logger)
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 956b9e8b3..f0171ede4 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 "touchmanager.h"
#include "resources/image.h"
#include "resources/imageset.h"
@@ -395,6 +396,7 @@ void Gui::draw()
BLOCK_START("Gui::draw 1")
mGraphics->pushClipArea(getTop()->getDimension());
getTop()->draw(mGraphics);
+ touchManager.draw();
int mouseX, mouseY;
const uint8_t button = SDL_GetMouseState(&mouseX, &mouseY);
@@ -650,3 +652,43 @@ void Gui::getAbsolutePosition(gcn::Widget *widget, int &x, int &y)
widget = widget->getParent();
}
}
+
+void Gui::handleMouseInput()
+{
+ BLOCK_START("Gui::handleMouseInput")
+ while (!mInput->isMouseQueueEmpty())
+ {
+ const gcn::MouseInput mouseInput = mInput->dequeueMouseInput();
+
+ if (touchManager.processEvent(mouseInput))
+ continue;
+
+ // Save the current mouse state. It will be needed if modal focus
+ // changes or modal mouse input focus changes.
+ mLastMouseX = mouseInput.getX();
+ mLastMouseY = mouseInput.getY();
+
+ switch (mouseInput.getType())
+ {
+ case gcn::MouseInput::PRESSED:
+ handleMousePressed(mouseInput);
+ break;
+ case gcn::MouseInput::RELEASED:
+ handleMouseReleased(mouseInput);
+ break;
+ case gcn::MouseInput::MOVED:
+ handleMouseMoved(mouseInput);
+ break;
+ case gcn::MouseInput::WHEEL_MOVED_DOWN:
+ handleMouseWheelMovedDown(mouseInput);
+ break;
+ case gcn::MouseInput::WHEEL_MOVED_UP:
+ handleMouseWheelMovedUp(mouseInput);
+ break;
+ default:
+ throw GCN_EXCEPTION("Unknown mouse input type.");
+ break;
+ }
+ }
+ BLOCK_END("Gui::handleMouseInput")
+}
diff --git a/src/gui/gui.h b/src/gui/gui.h
index 74c5404aa..db373193a 100644
--- a/src/gui/gui.h
+++ b/src/gui/gui.h
@@ -24,6 +24,7 @@
#define GUI_H
#include "resources/cursor.h"
+#include "resources/image.h"
#include <guichan/gui.hpp>
@@ -144,6 +145,8 @@ class Gui final : public gcn::Gui
protected:
void handleMouseMoved(const gcn::MouseInput &mouseInput);
+ void handleMouseInput();
+
void distributeMouseEvent(gcn::Widget* source, int type, int button,
int x, int y, bool force = false,
bool toSourceOnly = false);
diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp
index 7331724d1..46506ecb4 100644
--- a/src/gui/theme.cpp
+++ b/src/gui/theme.cpp
@@ -46,6 +46,9 @@ static std::string defaultThemePath;
std::string Theme::mThemePath;
std::string Theme::mThemeName;
Theme *Theme::mInstance = nullptr;
+#ifdef ANDROID
+SDL_Rect *Theme::mKeybRect = nullptr;
+#endif
// Set the theme path...
static void initDefaultThemePath()
@@ -634,6 +637,9 @@ void Theme::fillSoundsList(StringVect &list)
void Theme::selectSkin()
{
prepareThemePath();
+#ifdef ANDROID
+ mKeybRect = SDL_GetScreenKeyboardBlock();
+#endif
}
void Theme::prepareThemePath()
diff --git a/src/gui/theme.h b/src/gui/theme.h
index a19e93812..bd5e27708 100644
--- a/src/gui/theme.h
+++ b/src/gui/theme.h
@@ -361,6 +361,12 @@ class Theme final : public Palette, public ConfigListener
static ThemeInfo *loadInfo(const std::string &themeName) A_WARN_UNUSED;
+ static SDL_Rect *getKeybRect()
+#ifdef ANDROID
+ { return mKeybRect; }
+#else
+ { return nullptr; }
+#endif
private:
Theme();
@@ -391,6 +397,9 @@ class Theme final : public Palette, public ConfigListener
typedef std::vector<DyePalette*> ProgressColors;
ProgressColors mProgressColors;
+#ifdef ANDROID
+ static SDL_Rect *mKeybRect;
+#endif
};
#endif
diff --git a/src/guichan/gui.cpp b/src/guichan/gui.cpp
index ed4417650..f77a121d3 100644
--- a/src/guichan/gui.cpp
+++ b/src/guichan/gui.cpp
@@ -161,39 +161,6 @@ namespace gcn
void Gui::handleMouseInput()
{
- BLOCK_START("Gui::handleMouseInput")
- while (!mInput->isMouseQueueEmpty())
- {
- const MouseInput mouseInput = mInput->dequeueMouseInput();
-
- // Save the current mouse state. It will be needed if modal focus
- // changes or modal mouse input focus changes.
- mLastMouseX = mouseInput.getX();
- mLastMouseY = mouseInput.getY();
-
- switch (mouseInput.getType())
- {
- case MouseInput::PRESSED:
- handleMousePressed(mouseInput);
- break;
- case MouseInput::RELEASED:
- handleMouseReleased(mouseInput);
- break;
- case MouseInput::MOVED:
- handleMouseMoved(mouseInput);
- break;
- case MouseInput::WHEEL_MOVED_DOWN:
- handleMouseWheelMovedDown(mouseInput);
- break;
- case MouseInput::WHEEL_MOVED_UP:
- handleMouseWheelMovedUp(mouseInput);
- break;
- default:
- throw GCN_EXCEPTION("Unknown mouse input type.");
- break;
- }
- }
- BLOCK_END("Gui::handleMouseInput")
}
void Gui::handleKeyInput()
diff --git a/src/mobileopenglgraphics.cpp b/src/mobileopenglgraphics.cpp
index 7cb445342..504df6897 100644
--- a/src/mobileopenglgraphics.cpp
+++ b/src/mobileopenglgraphics.cpp
@@ -745,7 +745,9 @@ void MobileOpenGLGraphics::updateScreen()
BLOCK_START("Graphics::updateScreen")
// glFlush();
// glFinish();
+// setTexturingAndBlending(true);
SDL_GL_SwapBuffers();
+// mLastImage = 0;
// may be need clear?
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
BLOCK_END("Graphics::updateScreen")
diff --git a/src/touchactions.cpp b/src/touchactions.cpp
new file mode 100644
index 000000000..5fcaa1802
--- /dev/null
+++ b/src/touchactions.cpp
@@ -0,0 +1,36 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2012 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "touchactions.h"
+
+#include "logger.h"
+
+#ifdef ANDROID
+#include <SDL_screenkeyboard.h>
+#endif
+
+#include "debug.h"
+
+void showKeyboard(const gcn::MouseInput &mouseInput)
+{
+#ifdef ANDROID
+ SDL_ANDROID_ToggleScreenKeyboardTextInput(nullptr);
+#endif
+}
diff --git a/src/touchactions.h b/src/touchactions.h
new file mode 100644
index 000000000..0c9cdd23a
--- /dev/null
+++ b/src/touchactions.h
@@ -0,0 +1,30 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2012 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef TOUCHACTIONS_H
+#define TOUCHACTIONS_H
+
+#include <guichan/mouseinput.hpp>
+
+#include "localconsts.h"
+
+void showKeyboard(const gcn::MouseInput &mouseInput);
+
+#endif
diff --git a/src/touchmanager.cpp b/src/touchmanager.cpp
new file mode 100644
index 000000000..0278b9ddb
--- /dev/null
+++ b/src/touchmanager.cpp
@@ -0,0 +1,114 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2012 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "touchmanager.h"
+
+#include "graphics.h"
+#include "touchactions.h"
+
+#include "gui/theme.h"
+
+#include "debug.h"
+
+TouchManager touchManager;
+
+TouchManager::TouchManager()
+{
+}
+
+TouchManager::~TouchManager()
+{
+ clear();
+}
+
+void TouchManager::init()
+{
+#ifdef ANDROID
+ Image *image = Theme::getImageFromThemeXml("keyboard_icon.xml", "");
+ TouchItem *keyboard = new TouchItem(gcn::Rectangle(10, 10,
+ image->getWidth(), image->getHeight()), image, 10, 10,
+ nullptr, nullptr, &showKeyboard);
+ mObjects.push_back(keyboard);
+#endif
+}
+
+void TouchManager::clear()
+{
+ for (TouchItemVectorCIter it = mObjects.begin(), it_end = mObjects.end();
+ it != it_end; ++ it)
+ {
+ const TouchItem *const item = *it;
+ if (item)
+ {
+ if (item->image)
+ item->image->decRef();
+ delete *it;
+ }
+ }
+ mObjects.clear();
+}
+
+void TouchManager::draw()
+{
+ for (TouchItemVectorCIter it = mObjects.begin(), it_end = mObjects.end();
+ it != it_end; ++ it)
+ {
+ const TouchItem *const item = *it;
+ if (item && item->image)
+ mainGraphics->drawImage(item->image, item->x, item->y);
+ }
+}
+
+bool TouchManager::processEvent(const gcn::MouseInput &mouseInput)
+{
+ const int x = mouseInput.getX();
+ const int y = mouseInput.getY();
+
+ for (TouchItemVectorCIter it = mObjects.begin(), it_end = mObjects.end();
+ it != it_end; ++ it)
+ {
+ const TouchItem *const item = *it;
+ if (item && item->rect.isPointInRect(x, y))
+ {
+ if (item->funcAll)
+ {
+ item->funcAll(mouseInput);
+ }
+ else
+ {
+ switch (mouseInput.getType())
+ {
+ case gcn::MouseInput::PRESSED:
+ if (item->funcPressed)
+ item->funcPressed(mouseInput);
+ break;
+ case gcn::MouseInput::RELEASED:
+ if (item->funcReleased)
+ item->funcReleased(mouseInput);
+ break;
+ default:
+ break;
+ }
+ }
+ return true;
+ }
+ }
+ return false;
+}
diff --git a/src/touchmanager.h b/src/touchmanager.h
new file mode 100644
index 000000000..c37a1aeae
--- /dev/null
+++ b/src/touchmanager.h
@@ -0,0 +1,90 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2012 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef TOUCHMANAGER_H
+#define TOUCHMANAGER_H
+
+#include "resources/image.h"
+
+#include <guichan/mouseinput.hpp>
+#include <guichan/rectangle.hpp>
+
+#include <map>
+#include <string>
+#include <vector>
+
+#include "localconsts.h"
+
+typedef void (*TouchFuncPtr) (const gcn::MouseInput &mouseInput);
+
+struct TouchItem final
+{
+ TouchItem(const gcn::Rectangle rect0, Image *const img, int x0, int y0,
+ TouchFuncPtr ptrAll, TouchFuncPtr ptrPressed,
+ TouchFuncPtr ptrReleased) :
+ rect(rect0),
+ image(img),
+ x(x0),
+ y(y0),
+ funcAll(ptrAll),
+ funcPressed(ptrPressed),
+ funcReleased(ptrReleased)
+ {
+ }
+
+ A_DELETE_COPY(TouchItem)
+
+ gcn::Rectangle rect;
+ Image *image;
+ int x;
+ int y;
+ TouchFuncPtr funcAll;
+ TouchFuncPtr funcPressed;
+ TouchFuncPtr funcReleased;
+};
+
+typedef std::vector<TouchItem*> TouchItemVector;
+typedef TouchItemVector::const_iterator TouchItemVectorCIter;
+
+class TouchManager final
+{
+ public:
+ TouchManager();
+
+ ~TouchManager();
+
+ A_DELETE_COPY(TouchManager)
+
+ void init();
+
+ void clear();
+
+ void draw();
+
+ bool processEvent(const gcn::MouseInput &mouseInput);
+
+ private:
+ TouchItemVector mObjects;
+
+// std::map <std::string, int> mNameToRect;
+};
+
+extern TouchManager touchManager;
+#endif