From 23d29ec55093cd95c9084965a179ef70da2af150 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 6 Dec 2012 20:11:49 +0300 Subject: Add support for draw broders for on screen buttons. --- data/graphics/gui/dpad.xml | 19 ++++++++-- data/graphics/gui/dpad_attack.xml | 19 ++++++++-- data/graphics/gui/dpad_cancel.xml | 19 ++++++++-- data/graphics/gui/keyboard_icon.xml | 21 +++++++++-- data/graphics/gui/window.png | Bin 22500 -> 22519 bytes data/themes/jewelry/keyboard_icon.xml | 17 +++++++-- src/normalopenglgraphics.cpp | 2 ++ src/touchmanager.cpp | 66 ++++++++++++++++++++++------------ src/touchmanager.h | 18 +++++++--- 9 files changed, 140 insertions(+), 41 deletions(-) diff --git a/data/graphics/gui/dpad.xml b/data/graphics/gui/dpad.xml index 79ba00907..0cd91ef27 100644 --- a/data/graphics/gui/dpad.xml +++ b/data/graphics/gui/dpad.xml @@ -1,9 +1,22 @@ - + + + + + + + + + + + + + + + + diff --git a/data/graphics/gui/dpad_attack.xml b/data/graphics/gui/dpad_attack.xml index 675014eed..ebf312aca 100644 --- a/data/graphics/gui/dpad_attack.xml +++ b/data/graphics/gui/dpad_attack.xml @@ -1,9 +1,22 @@ - + + + + + + + + + + + + + + + + diff --git a/data/graphics/gui/dpad_cancel.xml b/data/graphics/gui/dpad_cancel.xml index 635d84721..34702c197 100644 --- a/data/graphics/gui/dpad_cancel.xml +++ b/data/graphics/gui/dpad_cancel.xml @@ -1,9 +1,22 @@ - + + + + + + + + + + + + + + + + diff --git a/data/graphics/gui/keyboard_icon.xml b/data/graphics/gui/keyboard_icon.xml index 4b157ef10..4cffb4502 100644 --- a/data/graphics/gui/keyboard_icon.xml +++ b/data/graphics/gui/keyboard_icon.xml @@ -1,9 +1,24 @@ - + + + + + + + + + + + + + + + + + + diff --git a/data/graphics/gui/window.png b/data/graphics/gui/window.png index 15f36d826..08b341ba3 100644 Binary files a/data/graphics/gui/window.png and b/data/graphics/gui/window.png differ diff --git a/data/themes/jewelry/keyboard_icon.xml b/data/themes/jewelry/keyboard_icon.xml index c31d38c8b..ed5773dda 100644 --- a/data/themes/jewelry/keyboard_icon.xml +++ b/data/themes/jewelry/keyboard_icon.xml @@ -1,9 +1,22 @@ - diff --git a/src/normalopenglgraphics.cpp b/src/normalopenglgraphics.cpp index f7ca7b802..d41229442 100644 --- a/src/normalopenglgraphics.cpp +++ b/src/normalopenglgraphics.cpp @@ -1150,6 +1150,8 @@ bool NormalOpenGLGraphics::calcWindow(ImageCollection *const vertCol, { ImageVertexes *vert = nullptr; Image *const image = imgRect.grid[4]; + if (!image) + return false; if (vertCol->currentGLImage != image->mGLImage) { vert = new ImageVertexes(); diff --git a/src/touchmanager.cpp b/src/touchmanager.cpp index 3a022afc3..4fc5c57e7 100644 --- a/src/touchmanager.cpp +++ b/src/touchmanager.cpp @@ -55,22 +55,23 @@ TouchManager::~TouchManager() void TouchManager::init() { #ifdef ANDROID - loadTouchItem(&mKeyboard, "keyboard_icon.xml", NORMAL, + loadTouchItem(&mKeyboard, "keyboard_icon.xml", 28, 28, NORMAL, nullptr, nullptr, &showKeyboard, nullptr); #endif if (config.getBoolValue("showScreenJoystick")) { - loadTouchItem(&mPad, "dpad.xml", LEFT, + loadTouchItem(&mPad, "dpad.xml", 100, 100, LEFT, &padEvents, &padClick, &padUp, &padOut); - loadTouchItem(&mAttack, "dpad_attack.xml", RIGHT, + loadTouchItem(&mAttack, "dpad_attack.xml", 60, 60, RIGHT, nullptr, &attackClick, &attackUp, &attackOut); - loadTouchItem(&mCancel, "dpad_cancel.xml", RIGHT, + loadTouchItem(&mCancel, "dpad_cancel.xml", 60, 60, RIGHT, nullptr, &cancelClick, &cancelUp, &cancelOut); } } -void TouchManager::loadTouchItem(TouchItem **item, std::string name, int type, +void TouchManager::loadTouchItem(TouchItem **item, std::string name, + int width, int height, int type, TouchFuncPtr fAll, TouchFuncPtr fPressed, TouchFuncPtr fReleased, TouchFuncPtr fOut) { @@ -78,14 +79,17 @@ void TouchManager::loadTouchItem(TouchItem **item, std::string name, int type, Theme *theme = Theme::instance(); if (!theme) return; - Skin *const skin = theme->load(name, ""); + ImageRect *images = new ImageRect; + for (int f = 0; f < 9; f ++) + images->grid[f] = nullptr; + + Skin *const skin = theme->loadSkinRect(*images, name, ""); if (skin) { - const ImageRect &images = skin->getBorder(); - Image *image = images.grid[0]; + Image *image = images->grid[0]; if (image) { - image->incRef(); +// image->incRef(); int x = skin->getOption("x", 10); int y = skin->getOption("y", 10); const int pad = skin->getPadding(); @@ -96,16 +100,17 @@ void TouchManager::loadTouchItem(TouchItem **item, std::string name, int type, y += (mainGraphics->mHeight - image->mBounds.h) / 2; break; case RIGHT: - x = mainGraphics->mWidth - image->mBounds.w - pad2 - x; - y = mainGraphics->mHeight - image->mBounds.h - pad2 - y; + x = mainGraphics->mWidth - width - pad2 - x; + y = mainGraphics->mHeight - height - pad2 - y; break; case NORMAL: default: break; } *item = new TouchItem(gcn::Rectangle(x, y, - image->getWidth() + pad2, image->getHeight() + pad2), - image, x + pad, y + pad, fAll, fPressed, fReleased, fOut); + width + pad2, height + pad2), + images, x + pad, y + pad, width, height, + fAll, fPressed, fReleased, fOut); mObjects.push_back(*item); } theme->unload(skin); @@ -118,14 +123,21 @@ void TouchManager::clear() // unloadTouchItem(&mPad); // unloadTouchItem(&mKeyboard); + Theme *theme = Theme::instance(); + if (!theme) + return; for (TouchItemVectorCIter it = mObjects.begin(), it_end = mObjects.end(); it != it_end; ++ it) { TouchItem *item = *it; if (item) { - if (item->image) - item->image->decRef(); + if (item->images) + { + theme->unloadRect(*item->images); + delete item->images; + item->images = nullptr; + } delete item; } } @@ -133,18 +145,25 @@ void TouchManager::clear() mRedraw = true; } +/* void TouchManager::unloadTouchItem(TouchItem **item0) { TouchItem *item = *item0; if (item) { - if (item->image) - item->image->decRef(); +// if (item->image) +// item->image->decRef(); + if (item->skin) + { + theme->unload(skin); + item->skin = nullptr; + } delete item; *item0 = nullptr; } mRedraw = true; } +*/ void TouchManager::draw() { @@ -159,10 +178,10 @@ void TouchManager::draw() it != it_end; ++ it) { const TouchItem *const item = *it; - if (item && item->image) + if (item && item->images) { - mainGraphics->calcTile(mVertexes, item->image, - item->x, item->y); + mainGraphics->calcWindow(mVertexes, item->x, item->y, + item->width, item->height, *item->images); } } } @@ -175,8 +194,11 @@ void TouchManager::draw() it != it_end; ++ it) { const TouchItem *const item = *it; - if (item && item->image) - mainGraphics->drawImage(item->image, item->x, item->y); + if (item && item->images) + { + mainGraphics->drawImageRect(item->x, item->y, + item->width, item->height, *item->images); + } } } } diff --git a/src/touchmanager.h b/src/touchmanager.h index 4c2339e15..ec4c46bb3 100644 --- a/src/touchmanager.h +++ b/src/touchmanager.h @@ -35,7 +35,9 @@ #include "localconsts.h" class ImageCollection; +class ImageRect; class MouseInput; +class Skin; typedef void (*TouchFuncPtr) (const MouseInput &mouseInput); @@ -43,13 +45,16 @@ const int actionsSize = Input::KEY_TOTAL; struct TouchItem final { - TouchItem(const gcn::Rectangle rect0, Image *const img, int x0, int y0, + TouchItem(const gcn::Rectangle rect0, ImageRect *const images0, + int x0, int y0, int width0, int height0, TouchFuncPtr ptrAll, TouchFuncPtr ptrPressed, TouchFuncPtr ptrReleased, TouchFuncPtr ptrOut) : rect(rect0), - image(img), + images(images0), x(x0), y(y0), + width(width0), + height(height0), funcAll(ptrAll), funcPressed(ptrPressed), funcReleased(ptrReleased), @@ -60,9 +65,11 @@ struct TouchItem final A_DELETE_COPY(TouchItem) gcn::Rectangle rect; - Image *image; + ImageRect *images; int x; int y; + int width; + int height; TouchFuncPtr funcAll; TouchFuncPtr funcPressed; TouchFuncPtr funcReleased; @@ -90,13 +97,14 @@ class TouchManager final void init(); - void loadTouchItem(TouchItem **item, std::string name, int type, + void loadTouchItem(TouchItem **item, std::string name, + int type, int width, int height, TouchFuncPtr fAll, TouchFuncPtr fPressed, TouchFuncPtr fReleased, TouchFuncPtr fOut); void clear(); - void unloadTouchItem(TouchItem **item0); +// void unloadTouchItem(TouchItem **item0); void draw(); -- cgit v1.2.3-70-g09d2