summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-03-24 15:13:34 +0300
committerAndrei Karas <akaras@inbox.ru>2013-03-24 15:13:34 +0300
commitf71b05916f639b230ed7f484fdbeaee15599d7e0 (patch)
tree4f18ff68c3ec203d698cf649bbe6fdc68bd72959
parent39d19da4f4e882e561c080ed443ddf596008649f (diff)
downloadmanaverse-f71b05916f639b230ed7f484fdbeaee15599d7e0.tar.gz
manaverse-f71b05916f639b230ed7f484fdbeaee15599d7e0.tar.bz2
manaverse-f71b05916f639b230ed7f484fdbeaee15599d7e0.tar.xz
manaverse-f71b05916f639b230ed7f484fdbeaee15599d7e0.zip
improve touchmanager class.
-rw-r--r--src/touchmanager.cpp41
-rw-r--r--src/touchmanager.h30
2 files changed, 35 insertions, 36 deletions
diff --git a/src/touchmanager.cpp b/src/touchmanager.cpp
index 8f9f20964..4dbffdf06 100644
--- a/src/touchmanager.cpp
+++ b/src/touchmanager.cpp
@@ -94,16 +94,20 @@ void TouchManager::init()
loadButtons();
}
-void TouchManager::loadTouchItem(TouchItem **item, std::string name,
- std::string imageName,
- int x, int y, int width, int height, int type,
+void TouchManager::loadTouchItem(TouchItem **item, const std::string &name,
+ const std::string &imageName,
+ int x, int y,
+ const int width, const int height,
+ const int type,
const std::string &eventPressed,
const std::string &eventReleased,
- TouchFuncPtr fAll, TouchFuncPtr fPressed,
- TouchFuncPtr fReleased, TouchFuncPtr fOut)
+ const TouchFuncPtr fAll,
+ const TouchFuncPtr fPressed,
+ const TouchFuncPtr fReleased,
+ const TouchFuncPtr fOut)
{
*item = nullptr;
- Theme *theme = Theme::instance();
+ Theme *const theme = Theme::instance();
if (!theme)
return;
ImageRect *images = new ImageRect;
@@ -119,7 +123,7 @@ void TouchManager::loadTouchItem(TouchItem **item, std::string name,
Skin *const skin = theme->loadSkinRect(*images, name, "");
if (skin)
{
- Image *image = images->grid[0];
+ Image *const image = images->grid[0];
if (image)
{
if (x == -1)
@@ -166,9 +170,6 @@ void TouchManager::loadTouchItem(TouchItem **item, std::string name,
void TouchManager::clear()
{
- Theme *theme = Theme::instance();
- if (!theme)
- return;
FOR_EACH (TouchItemVectorCIter, it, mObjects)
unload(*it);
mObjects.clear();
@@ -278,9 +279,12 @@ bool TouchManager::isActionActive(const int index) const
return mActions[index];
}
-void TouchManager::resize(int width, int height)
+void TouchManager::resize(const int width, const int height)
{
mRedraw = true;
+ const int maxHeight = mainGraphics->mHeight;
+ const int diffW = width - mainGraphics->mWidth;
+ const int diffH = height - maxHeight;
FOR_EACH (TouchItemVectorCIter, it, mObjects)
{
TouchItem *const item = *it;
@@ -290,7 +294,7 @@ void TouchManager::resize(int width, int height)
switch (item->type)
{
case LEFT:
- if (height != mainGraphics->mHeight)
+ if (height != maxHeight)
{
item->y += (height - item->height) / 2;
item->rect.y += (height - item->rect.y) / 2;
@@ -298,8 +302,6 @@ void TouchManager::resize(int width, int height)
break;
case RIGHT:
{
- const int diffW = width - mainGraphics->mWidth;
- const int diffH = height - mainGraphics->mHeight;
item->x += diffW;
item->rect.x += diffW;
item->y += diffH;
@@ -313,7 +315,7 @@ void TouchManager::resize(int width, int height)
}
}
-void TouchManager::unload(TouchItem *item)
+void TouchManager::unload(TouchItem *const item)
{
if (item)
{
@@ -337,9 +339,6 @@ void TouchManager::unload(TouchItem *item)
void TouchManager::unloadTouchItem(TouchItem **unloadItem)
{
- Theme *theme = Theme::instance();
- if (!theme)
- return;
FOR_EACH (TouchItemVectorIter, it, mObjects)
{
TouchItem *item = *it;
@@ -362,7 +361,7 @@ void TouchManager::loadPad()
void TouchManager::loadButtons()
{
const int sz = (mButtonsSize + 1) * 50;
- Theme *theme = Theme::instance();
+ Theme *const theme = Theme::instance();
if (!theme)
return;
Skin *const skin = theme->load("dbutton.xml", "");
@@ -489,14 +488,14 @@ void TouchManager::optionChanged(const std::string &value)
}
}
-void TouchManager::setInGame(bool b)
+void TouchManager::setInGame(const bool b)
{
mInGame = b;
mShow = mInGame && !mTempHideButtons;
mRedraw = true;
}
-void TouchManager::setTempHide(bool b)
+void TouchManager::setTempHide(const bool b)
{
mTempHideButtons = b;
mShow = mInGame && !mTempHideButtons;
diff --git a/src/touchmanager.h b/src/touchmanager.h
index fc8a2923f..3dc1eda29 100644
--- a/src/touchmanager.h
+++ b/src/touchmanager.h
@@ -47,13 +47,13 @@ const int buttonsCount = 4;
struct TouchItem final
{
- TouchItem(const gcn::Rectangle rect0, int type0,
+ TouchItem(const gcn::Rectangle rect0, const int type0,
const std::string &eventPressed0,
const std::string &eventReleased0,
ImageRect *const images0, Image *const icon0,
- int x0, int y0, int width0, int height0,
- TouchFuncPtr ptrAll, TouchFuncPtr ptrPressed,
- TouchFuncPtr ptrReleased, TouchFuncPtr ptrOut) :
+ const int x0, const int y0, const int width0, const int height0,
+ const TouchFuncPtr ptrAll, const TouchFuncPtr ptrPressed,
+ const TouchFuncPtr ptrReleased, const TouchFuncPtr ptrOut) :
rect(rect0),
type(type0),
eventPressed(eventPressed0),
@@ -111,15 +111,15 @@ class TouchManager final : public ConfigListener
void init();
- void loadTouchItem(TouchItem **item, std::string name,
- std::string imageName,
- int x, int y, int width, int height,
+ void loadTouchItem(TouchItem **item, const std::string &name,
+ const std::string &imageName,
+ int x, int y, const int width, const int height,
int type, const std::string &eventPressed,
const std::string &eventReleased,
- TouchFuncPtr fAll = nullptr,
- TouchFuncPtr fPressed = nullptr,
- TouchFuncPtr fReleased = nullptr,
- TouchFuncPtr fOut = nullptr);
+ const TouchFuncPtr fAll = nullptr,
+ const TouchFuncPtr fPressed = nullptr,
+ const TouchFuncPtr fReleased = nullptr,
+ const TouchFuncPtr fOut = nullptr);
void clear();
@@ -135,9 +135,9 @@ class TouchManager final : public ConfigListener
mActions[index] = value;
}
- void resize(int width, int height);
+ void resize(const int width, const int height);
- void unload(TouchItem *item);
+ static void unload(TouchItem *const item);
void unloadTouchItem(TouchItem **unloadItem);
@@ -152,9 +152,9 @@ class TouchManager final : public ConfigListener
int getPadSize()
{ return (mJoystickSize + 2) * 50; }
- void setInGame(bool b);
+ void setInGame(const bool b);
- void setTempHide(bool b);
+ void setTempHide(const bool b);
void shutdown();