summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-12-06 20:11:49 +0300
committerAndrei Karas <akaras@inbox.ru>2012-12-06 20:21:25 +0300
commit23d29ec55093cd95c9084965a179ef70da2af150 (patch)
treebc579bc2dcc30fb588926a64d4ef1415e281492c /src
parent17bb7a5de4b9406f1a02d092ae590ab71b7265ba (diff)
downloadmanaplus-23d29ec55093cd95c9084965a179ef70da2af150.tar.gz
manaplus-23d29ec55093cd95c9084965a179ef70da2af150.tar.bz2
manaplus-23d29ec55093cd95c9084965a179ef70da2af150.tar.xz
manaplus-23d29ec55093cd95c9084965a179ef70da2af150.zip
Add support for draw broders for on screen buttons.
Diffstat (limited to 'src')
-rw-r--r--src/normalopenglgraphics.cpp2
-rw-r--r--src/touchmanager.cpp66
-rw-r--r--src/touchmanager.h18
3 files changed, 59 insertions, 27 deletions
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();