summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-12-09 19:51:15 +0300
committerAndrei Karas <akaras@inbox.ru>2012-12-09 21:03:32 +0300
commit351b7cf1ff682026485b0e7a8f7623fe356cdf84 (patch)
tree69e4863afbcf3bddf19affecb53ad0205e3f45a3 /src
parentb43ed947efd36471a0608d103faed95e61f7b124 (diff)
downloadplus-351b7cf1ff682026485b0e7a8f7623fe356cdf84.tar.gz
plus-351b7cf1ff682026485b0e7a8f7623fe356cdf84.tar.bz2
plus-351b7cf1ff682026485b0e7a8f7623fe356cdf84.tar.xz
plus-351b7cf1ff682026485b0e7a8f7623fe356cdf84.zip
Add resize options for on screen joystick and buttons.
Diffstat (limited to 'src')
-rw-r--r--src/defaults.cpp2
-rw-r--r--src/gui/setup_touch.cpp15
-rw-r--r--src/gui/setup_touch.h1
-rw-r--r--src/touchactions.cpp15
-rw-r--r--src/touchactions.h2
-rw-r--r--src/touchmanager.cpp76
-rw-r--r--src/touchmanager.h7
7 files changed, 102 insertions, 16 deletions
diff --git a/src/defaults.cpp b/src/defaults.cpp
index 37bfab0c1..bd51110ce 100644
--- a/src/defaults.cpp
+++ b/src/defaults.cpp
@@ -282,6 +282,8 @@ DefaultsData* getConfigDefaults()
AddDEF("allowscreensaver", false);
AddDEF("debugOpenGL", 0);
AddDEF("protectChatFocus", true);
+ AddDEF("screenButtonsSize", 1);
+ AddDEF("screenJoystickSize", 1);
return configData;
}
diff --git a/src/gui/setup_touch.cpp b/src/gui/setup_touch.cpp
index e46ff0d73..e311195b8 100644
--- a/src/gui/setup_touch.cpp
+++ b/src/gui/setup_touch.cpp
@@ -30,7 +30,8 @@
#include "debug.h"
Setup_Touch::Setup_Touch(const Widget2 *const widget) :
- SetupTabScroll(widget)
+ SetupTabScroll(widget),
+ mSizeList(new SetupItemNames)
{
setName(_("Touch"));
@@ -41,12 +42,24 @@ Setup_Touch::Setup_Touch(const Widget2 *const widget) :
new SetupItemCheckBox(_("Show on screen buttons"), "",
"showScreenButtons", this, "showScreenButtonsEvent");
+ mSizeList->push_back(_("Small"));
+ mSizeList->push_back(_("Normal"));
+ mSizeList->push_back(_("Medium"));
+ mSizeList->push_back(_("Large"));
+ new SetupItemSlider2(_("Buttons size"), "", "screenButtonsSize", this,
+ "screenButtonsSizeEvent", 0, 3, mSizeList);
+
new SetupItemCheckBox(_("Show on screen joystick"), "",
"showScreenJoystick", this, "showScreenJoystickEvent");
+ new SetupItemSlider2(_("Joystick size"), "", "screenJoystickSize", this,
+ "screenJoystickEvent", 0, 3, mSizeList);
+
setDimension(gcn::Rectangle(0, 0, 550, 350));
}
Setup_Touch::~Setup_Touch()
{
+ delete mSizeList;
+ mSizeList = nullptr;
}
diff --git a/src/gui/setup_touch.h b/src/gui/setup_touch.h
index ef677f214..f0d574bdd 100644
--- a/src/gui/setup_touch.h
+++ b/src/gui/setup_touch.h
@@ -38,6 +38,7 @@ class Setup_Touch final : public SetupTabScroll
~Setup_Touch();
protected:
+ SetupItemNames *mSizeList;
};
#endif
diff --git a/src/touchactions.cpp b/src/touchactions.cpp
index c88a25cf8..84b6e0942 100644
--- a/src/touchactions.cpp
+++ b/src/touchactions.cpp
@@ -37,6 +37,7 @@
InputEvent tempEvent(0, 0);
bool padClicked(false);
+int haldJoyPad = 50;
#define impHandler(name) void name(const MouseInput &mouseInput)
#define impHandler0(name) void name(const MouseInput &mouseInput A_UNUSED)
@@ -48,6 +49,12 @@ impHandler0(showKeyboard)
#endif
}
+void setHalfJoyPad(int s)
+{
+ logger->log("set size: %d", s);
+ haldJoyPad = s;
+}
+
static void moveChar(int x, int y)
{
Game *const game = Game::instance();
@@ -58,8 +65,8 @@ static void moveChar(int x, int y)
static const int diff = 20;
// set center at (0,0)
- x -= 50;
- y -= 50;
+ x -= haldJoyPad;
+ y -= haldJoyPad;
// some magic for checking at what sector was click
if (abs(x) < lim1)
@@ -132,13 +139,13 @@ impHandler(padEvents)
impHandler0(padOut)
{
padClicked = false;
- moveChar(50, 50);
+ moveChar(haldJoyPad, haldJoyPad);
}
impHandler0(padUp)
{
padClicked = false;
- moveChar(50, 50);
+ moveChar(haldJoyPad, haldJoyPad);
}
impHandler0(attackClick)
diff --git a/src/touchactions.h b/src/touchactions.h
index 0f55d46a8..70400acb4 100644
--- a/src/touchactions.h
+++ b/src/touchactions.h
@@ -37,6 +37,8 @@ decHandler(padUp);
decHandler(attackClick);
decHandler(cancelClick);
+void setHalfJoyPad(int s);
+
#undef decHandler
#endif
diff --git a/src/touchmanager.cpp b/src/touchmanager.cpp
index 359eebbf9..2780f186f 100644
--- a/src/touchmanager.cpp
+++ b/src/touchmanager.cpp
@@ -39,7 +39,11 @@ TouchManager::TouchManager() :
mPad(nullptr),
mAttack(nullptr),
mVertexes(new ImageCollection),
- mRedraw(true)
+ mRedraw(true),
+ mShowJoystick(false),
+ mShowButtons(false),
+ mButtonsSize(1),
+ mJoystickSize(1)
{
for (int f = 0; f < actionsSize; f ++)
mActions[f] = false;
@@ -57,12 +61,18 @@ void TouchManager::init()
{
config.addListener("showScreenJoystick", this);
config.addListener("showScreenButtons", this);
+ config.addListener("screenButtonsSize", this);
+ config.addListener("screenJoystickSize", this);
mShowJoystick = config.getBoolValue("showScreenJoystick");
mShowButtons = config.getBoolValue("showScreenButtons");
+ mButtonsSize = config.getIntValue("screenButtonsSize");
+ mJoystickSize = config.getIntValue("screenJoystickSize");
+
+ setHalfJoyPad(getPadSize() / 2);
#ifdef ANDROID
- loadTouchItem(&mKeyboard, "keyboard_icon.xml", 28, 28, NORMAL,
+ loadTouchItem(&mKeyboard, "keyboard_icon.xml", -1, -1, 28, 28, NORMAL,
nullptr, nullptr, &showKeyboard, nullptr);
#endif
@@ -73,7 +83,7 @@ void TouchManager::init()
}
void TouchManager::loadTouchItem(TouchItem **item, std::string name,
- int width, int height, int type,
+ int x, int y, int width, int height, int type,
TouchFuncPtr fAll, TouchFuncPtr fPressed,
TouchFuncPtr fReleased, TouchFuncPtr fOut)
{
@@ -91,8 +101,10 @@ void TouchManager::loadTouchItem(TouchItem **item, std::string name,
Image *image = images->grid[0];
if (image)
{
- int x = skin->getOption("x", 10);
- int y = skin->getOption("y", 10);
+ if (x == -1)
+ x = skin->getOption("x", 10);
+ if (y == -1)
+ y = skin->getOption("y", 10);
const int pad = skin->getPadding();
const int pad2 = 2 * pad;
switch (type)
@@ -294,16 +306,36 @@ void TouchManager::unloadTouchItem(TouchItem **unloadItem)
void TouchManager::loadPad()
{
- loadTouchItem(&mPad, "dpad.xml", 100, 100, LEFT,
+ const int sz = (mJoystickSize + 2) * 50;
+ loadTouchItem(&mPad, "dpad.xml", -1, -1, sz, sz, LEFT,
&padEvents, &padClick, &padUp, &padOut);
}
void TouchManager::loadButtons()
{
- loadTouchItem(&mAttack, "dpad_attack.xml", 60, 60, RIGHT,
- nullptr, &attackClick, nullptr, nullptr);
- loadTouchItem(&mCancel, "dpad_cancel.xml", 60, 60, RIGHT,
- nullptr, &cancelClick, nullptr, nullptr);
+ const int sz = (mButtonsSize + 1) * 50;
+ Theme *theme = Theme::instance();
+ if (!theme)
+ return;
+ Skin *const skin = theme->load("dbutton.xml", "");
+
+ if (skin)
+ {
+ const int x = skin->getOption("x", 10);
+ const int y = skin->getOption("y", 10);
+ const int pad = skin->getPadding();
+ const int pad2 = 2 * pad;
+ const int skipWidth = pad2 + sz + x;
+
+ loadTouchItem(&mAttack, "dbutton.xml", x, y, sz, sz, RIGHT,
+ nullptr, &attackClick, nullptr, nullptr);
+
+ loadTouchItem(&mCancel, "dbutton.xml", skipWidth, y, sz, sz, RIGHT,
+ nullptr, &cancelClick, nullptr, nullptr);
+
+ theme->unload(skin);
+ }
+
}
void TouchManager::optionChanged(const std::string &value)
@@ -336,4 +368,28 @@ void TouchManager::optionChanged(const std::string &value)
}
mRedraw = true;
}
+ else if (value == "screenButtonsSize")
+ {
+ if (mButtonsSize == config.getIntValue("screenButtonsSize"))
+ return;
+ mButtonsSize = config.getIntValue("screenButtonsSize");
+ if (mShowButtons)
+ {
+ unloadTouchItem(&mAttack);
+ unloadTouchItem(&mCancel);
+ loadButtons();
+ }
+ }
+ else if (value == "screenJoystickSize")
+ {
+ if (mJoystickSize == config.getIntValue("screenJoystickSize"))
+ return;
+ mJoystickSize = config.getIntValue("screenJoystickSize");
+ setHalfJoyPad(getPadSize() / 2);
+ if (mShowJoystick)
+ {
+ unloadTouchItem(&mPad);
+ loadPad();
+ }
+ }
}
diff --git a/src/touchmanager.h b/src/touchmanager.h
index e3d76d910..e93618fc8 100644
--- a/src/touchmanager.h
+++ b/src/touchmanager.h
@@ -102,7 +102,7 @@ class TouchManager final : public ConfigListener
void init();
void loadTouchItem(TouchItem **item, std::string name,
- int type, int width, int height,
+ int type, int x, int y, int width, int height,
TouchFuncPtr fAll, TouchFuncPtr fPressed,
TouchFuncPtr fReleased, TouchFuncPtr fOut);
@@ -132,6 +132,9 @@ class TouchManager final : public ConfigListener
void loadButtons();
+ int getPadSize()
+ { return (mJoystickSize + 2) * 50; }
+
private:
TouchItem *mKeyboard;
TouchItem *mPad;
@@ -143,6 +146,8 @@ class TouchManager final : public ConfigListener
bool mRedraw;
bool mShowJoystick;
bool mShowButtons;
+ int mButtonsSize;
+ int mJoystickSize;
};
extern TouchManager touchManager;