From 524679ca67f977ebadb143205d5c45f798827e67 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 7 Dec 2012 01:46:36 +0300 Subject: Resize screen buttons with window resizing. --- src/touchmanager.cpp | 61 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 23 deletions(-) (limited to 'src/touchmanager.cpp') 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; + } + } +} -- cgit v1.2.3-70-g09d2