summaryrefslogtreecommitdiff
path: root/src/touchmanager.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-12-07 01:46:36 +0300
committerAndrei Karas <akaras@inbox.ru>2012-12-07 01:46:36 +0300
commit524679ca67f977ebadb143205d5c45f798827e67 (patch)
treee4c8f453a78fef13b3a3932c2fcfdef83a663847 /src/touchmanager.cpp
parent3a9398d853caf39778771d4916b0781a8597db42 (diff)
downloadplus-524679ca67f977ebadb143205d5c45f798827e67.tar.gz
plus-524679ca67f977ebadb143205d5c45f798827e67.tar.bz2
plus-524679ca67f977ebadb143205d5c45f798827e67.tar.xz
plus-524679ca67f977ebadb143205d5c45f798827e67.zip
Resize screen buttons with window resizing.
Diffstat (limited to 'src/touchmanager.cpp')
-rw-r--r--src/touchmanager.cpp61
1 files changed, 38 insertions, 23 deletions
diff --git a/src/touchmanager.cpp b/src/touchmanager.cpp
index 2382e13b4..96a083872 100644
--- a/src/touchmanager.cpp
+++ b/src/touchmanager.cpp
@@ -89,7 +89,6 @@ void TouchManager::loadTouchItem(TouchItem **item, std::string name,
Image *image = images->grid[0];
if (image)
{
-// image->incRef();
int x = skin->getOption("x", 10);
int y = skin->getOption("y", 10);
const int pad = skin->getPadding();
@@ -97,7 +96,7 @@ void TouchManager::loadTouchItem(TouchItem **item, std::string name,
switch (type)
{
case LEFT:
- y += (mainGraphics->mHeight - image->mBounds.h) / 2;
+ y += (mainGraphics->mHeight - height) / 2;
break;
case RIGHT:
x = mainGraphics->mWidth - width - pad2 - x;
@@ -108,7 +107,7 @@ void TouchManager::loadTouchItem(TouchItem **item, std::string name,
break;
}
*item = new TouchItem(gcn::Rectangle(x, y,
- width + pad2, height + pad2),
+ width + pad2, height + pad2), type,
images, x + pad, y + pad, width, height,
fAll, fPressed, fReleased, fOut);
mObjects.push_back(*item);
@@ -145,26 +144,6 @@ void TouchManager::clear()
mRedraw = true;
}
-/*
-void TouchManager::unloadTouchItem(TouchItem **item0)
-{
- TouchItem *item = *item0;
- if (item)
- {
-// if (item->image)
-// item->image->decRef();
- if (item->skin)
- {
- theme->unload(skin);
- item->skin = nullptr;
- }
- delete item;
- *item0 = nullptr;
- }
- mRedraw = true;
-}
-*/
-
void TouchManager::draw()
{
if (openGLMode != 2)
@@ -252,3 +231,39 @@ bool TouchManager::isActionActive(const int index) const
return false;
return mActions[index];
}
+
+void TouchManager::resize(int width, int height)
+{
+ mRedraw = true;
+ for (TouchItemVectorCIter it = mObjects.begin(),
+ it_end = mObjects.end(); it != it_end; ++ it)
+ {
+ TouchItem *const item = *it;
+ if (!item)
+ continue;
+
+ switch (item->type)
+ {
+ case LEFT:
+ if (height != mainGraphics->mHeight)
+ {
+ item->y += (height - item->height) / 2;
+ item->rect.y += (height - item->rect.y) / 2;
+ }
+ 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;
+ item->rect.y += diffH;
+ break;
+ }
+ case NORMAL:
+ default:
+ break;
+ }
+ }
+}