summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client.cpp2
-rw-r--r--src/touchmanager.cpp61
-rw-r--r--src/touchmanager.h8
3 files changed, 45 insertions, 26 deletions
diff --git a/src/client.cpp b/src/client.cpp
index 1fd3793f1..fe7d8f987 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -2660,6 +2660,8 @@ void Client::resizeVideo(int width, int height, const bool always)
return;
}
+ touchManager.resize(width, height);
+
if (mainGraphics->resizeScreen(width, height))
{
if (gui)
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;
+ }
+ }
+}
diff --git a/src/touchmanager.h b/src/touchmanager.h
index ec4c46bb3..f54520cf7 100644
--- a/src/touchmanager.h
+++ b/src/touchmanager.h
@@ -45,11 +45,12 @@ const int actionsSize = Input::KEY_TOTAL;
struct TouchItem final
{
- TouchItem(const gcn::Rectangle rect0, ImageRect *const images0,
+ TouchItem(const gcn::Rectangle rect0, int type0, ImageRect *const images0,
int x0, int y0, int width0, int height0,
TouchFuncPtr ptrAll, TouchFuncPtr ptrPressed,
TouchFuncPtr ptrReleased, TouchFuncPtr ptrOut) :
rect(rect0),
+ type(type0),
images(images0),
x(x0),
y(y0),
@@ -65,6 +66,7 @@ struct TouchItem final
A_DELETE_COPY(TouchItem)
gcn::Rectangle rect;
+ int type;
ImageRect *images;
int x;
int y;
@@ -104,8 +106,6 @@ class TouchManager final
void clear();
-// void unloadTouchItem(TouchItem **item0);
-
void draw();
bool processEvent(const MouseInput &mouseInput);
@@ -118,6 +118,8 @@ class TouchManager final
mActions[index] = value;
}
+ void resize(int width, int height);
+
private:
TouchItem *mKeyboard;
TouchItem *mPad;