diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-12-18 22:42:34 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-12-18 22:43:53 +0300 |
commit | 4b2cbbeae4acc6b2c94f5455eb0c5d1134b32588 (patch) | |
tree | e29d33dd9b293093258b3e4238a00a7169c48e32 /src/touchmanager.cpp | |
parent | 26bf983ed44960508f318e804e8f2fa515f0df2c (diff) | |
download | plus-4b2cbbeae4acc6b2c94f5455eb0c5d1134b32588.tar.gz plus-4b2cbbeae4acc6b2c94f5455eb0c5d1134b32588.tar.bz2 plus-4b2cbbeae4acc6b2c94f5455eb0c5d1134b32588.tar.xz plus-4b2cbbeae4acc6b2c94f5455eb0c5d1134b32588.zip |
Add support for show images in on screen buttons center.
New theme files:
dbutton_image.xml
dpad_image.xml
Diffstat (limited to 'src/touchmanager.cpp')
-rw-r--r-- | src/touchmanager.cpp | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/src/touchmanager.cpp b/src/touchmanager.cpp index 38f9c3237..2bfe2c572 100644 --- a/src/touchmanager.cpp +++ b/src/touchmanager.cpp @@ -75,7 +75,7 @@ void TouchManager::init() setHalfJoyPad(getPadSize() / 2); #ifdef ANDROID - loadTouchItem(&mKeyboard, "keyboard_icon.xml", -1, -1, 28, 28, NORMAL, + loadTouchItem(&mKeyboard, "keyboard_icon.xml", "", -1, -1, 28, 28, NORMAL, nullptr, nullptr, &showKeyboard, nullptr); #endif @@ -86,6 +86,7 @@ void TouchManager::init() } void TouchManager::loadTouchItem(TouchItem **item, std::string name, + std::string imageName, int x, int y, int width, int height, int type, TouchFuncPtr fAll, TouchFuncPtr fPressed, TouchFuncPtr fReleased, TouchFuncPtr fOut) @@ -98,6 +99,12 @@ void TouchManager::loadTouchItem(TouchItem **item, std::string name, for (int f = 0; f < 9; f ++) images->grid[f] = nullptr; + Image *icon; + if (imageName.empty()) + icon = nullptr; + else + icon = Theme::getImageFromThemeXml(imageName, ""); + Skin *const skin = theme->loadSkinRect(*images, name, ""); if (skin) { @@ -125,7 +132,7 @@ void TouchManager::loadTouchItem(TouchItem **item, std::string name, } *item = new TouchItem(gcn::Rectangle(x, y, width + pad2, height + pad2), type, - images, x + pad, y + pad, width, height, + images, icon, x + pad, y + pad, width, height, fAll, fPressed, fReleased, fOut); mObjects.push_back(*item); } @@ -165,6 +172,13 @@ void TouchManager::draw() { mainGraphics->calcWindow(mVertexes, item->x, item->y, item->width, item->height, *item->images); + const Image *const icon = item->icon; + if (icon) + { + mainGraphics->calcTile(mVertexes, icon, + item->x + (item->width - icon->mBounds.w) / 2, + item->y + (item->height - icon->mBounds.h) / 2); + } } } } @@ -181,6 +195,13 @@ void TouchManager::draw() { mainGraphics->drawImageRect(item->x, item->y, item->width, item->height, *item->images); + const Image *const icon = item->icon; + if (icon) + { + mainGraphics->drawImage(icon, + item->x + (item->width - icon->mBounds.w) / 2, + item->y + (item->height - icon->mBounds.h) / 2); + } } } } @@ -284,6 +305,11 @@ void TouchManager::unload(TouchItem *item) theme->unloadRect(*item->images); delete item->images; item->images = nullptr; + if (item->icon) + { + item->icon->decRef(); + item->icon = nullptr; + } } delete item; } @@ -310,7 +336,7 @@ void TouchManager::unloadTouchItem(TouchItem **unloadItem) void TouchManager::loadPad() { const int sz = (mJoystickSize + 2) * 50; - loadTouchItem(&mPad, "dpad.xml", -1, -1, sz, sz, LEFT, + loadTouchItem(&mPad, "dpad.xml", "dpad_image.xml", -1, -1, sz, sz, LEFT, &padEvents, &padClick, &padUp, &padOut); } @@ -330,11 +356,12 @@ void TouchManager::loadButtons() 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(&mAttack, "dbutton.xml", "dbutton_image.xml", x, y, + sz, sz, RIGHT, nullptr, &attackClick, nullptr, nullptr); - loadTouchItem(&mCancel, "dbutton.xml", skipWidth, y, sz, sz, RIGHT, - nullptr, &cancelClick, nullptr, nullptr); + loadTouchItem(&mCancel, "dbutton.xml", "dbutton_image.xml", + skipWidth, y, sz, sz, RIGHT, nullptr, &cancelClick, + nullptr, nullptr); theme->unload(skin); } |