2012-10-05 20:04:12 +00:00
|
|
|
#include "GuiBox.h"
|
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
GuiBox::GuiBox(Window* window, int offsetX, int offsetY, unsigned int width, unsigned int height) : GuiComponent(window), mBackgroundImage(window),
|
2013-04-08 17:40:15 +00:00
|
|
|
mHorizontalImage(window), mVerticalImage(window), mCornerImage(window)
|
2012-10-05 20:04:12 +00:00
|
|
|
{
|
2013-06-02 15:08:32 +00:00
|
|
|
setOffset(Vector2i(offsetX, offsetY));
|
|
|
|
|
2012-10-05 20:04:12 +00:00
|
|
|
mWidth = width;
|
|
|
|
mHeight = height;
|
|
|
|
}
|
|
|
|
|
2012-10-07 22:59:20 +00:00
|
|
|
void GuiBox::setData(GuiBoxData data)
|
|
|
|
{
|
|
|
|
setBackgroundImage(data.backgroundPath, data.backgroundTiled);
|
|
|
|
setHorizontalImage(data.horizontalPath, data.horizontalTiled);
|
|
|
|
setVerticalImage(data.verticalPath, data.verticalTiled);
|
|
|
|
setCornerImage(data.cornerPath);
|
|
|
|
}
|
|
|
|
|
2012-10-05 20:04:12 +00:00
|
|
|
void GuiBox::setHorizontalImage(std::string path, bool tiled)
|
|
|
|
{
|
2012-10-07 21:56:33 +00:00
|
|
|
mHorizontalImage.setTiling(tiled);
|
|
|
|
mHorizontalImage.setOrigin(0, 0);
|
|
|
|
|
2012-10-05 20:04:12 +00:00
|
|
|
mHorizontalImage.setImage(path);
|
2012-10-10 13:51:48 +00:00
|
|
|
mHorizontalImage.setResize(mHorizontalImage.getHeight(), mHeight, true);
|
2012-10-05 20:04:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiBox::setVerticalImage(std::string path, bool tiled)
|
|
|
|
{
|
2012-10-07 21:56:33 +00:00
|
|
|
mVerticalImage.setTiling(tiled);
|
|
|
|
mVerticalImage.setOrigin(0, 0);
|
|
|
|
|
2012-10-05 20:04:12 +00:00
|
|
|
mVerticalImage.setImage(path);
|
2012-10-10 13:51:48 +00:00
|
|
|
mVerticalImage.setResize(mWidth, mVerticalImage.getHeight(), true);
|
2012-10-05 20:04:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiBox::setBackgroundImage(std::string path, bool tiled)
|
|
|
|
{
|
2012-10-10 13:54:39 +00:00
|
|
|
mBackgroundImage.setOrigin(0, 0);
|
2012-10-07 21:56:33 +00:00
|
|
|
mBackgroundImage.setResize(mWidth, mHeight, true);
|
2012-10-05 20:04:12 +00:00
|
|
|
mBackgroundImage.setTiling(tiled);
|
2013-06-02 15:08:32 +00:00
|
|
|
mBackgroundImage.setOffset(getOffset());
|
2012-10-07 21:56:33 +00:00
|
|
|
|
|
|
|
mBackgroundImage.setImage(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiBox::setCornerImage(std::string path)
|
|
|
|
{
|
2012-10-07 22:25:51 +00:00
|
|
|
mCornerImage.setOrigin(0, 0);
|
2012-10-07 21:56:33 +00:00
|
|
|
mCornerImage.setResize(getHorizontalBorderWidth(), getVerticalBorderWidth(), true);
|
2012-10-07 22:25:51 +00:00
|
|
|
|
|
|
|
mCornerImage.setImage(path);
|
2012-10-05 20:04:12 +00:00
|
|
|
}
|
|
|
|
|
2013-04-08 16:52:40 +00:00
|
|
|
void GuiBox::render()
|
2012-10-05 20:04:12 +00:00
|
|
|
{
|
2012-10-10 13:51:48 +00:00
|
|
|
mBackgroundImage.render();
|
|
|
|
|
2012-10-05 20:04:12 +00:00
|
|
|
//left border
|
2013-06-02 15:08:32 +00:00
|
|
|
mHorizontalImage.setOffset(getOffset().x - getHorizontalBorderWidth(), getOffset().y);
|
2012-10-07 22:25:51 +00:00
|
|
|
mHorizontalImage.setFlipX(false);
|
2012-10-05 20:04:12 +00:00
|
|
|
mHorizontalImage.render();
|
2013-06-02 15:08:32 +00:00
|
|
|
|
2012-10-05 20:04:12 +00:00
|
|
|
//right border
|
2013-06-02 15:08:32 +00:00
|
|
|
mHorizontalImage.setOffset(getOffset().x + mWidth, getOffset().y);
|
2012-10-07 22:25:51 +00:00
|
|
|
mHorizontalImage.setFlipX(true);
|
2012-10-05 20:04:12 +00:00
|
|
|
mHorizontalImage.render();
|
2013-06-02 15:08:32 +00:00
|
|
|
|
2012-10-07 21:56:33 +00:00
|
|
|
//top border
|
2013-06-02 15:08:32 +00:00
|
|
|
mVerticalImage.setOffset(getOffset().x, getOffset().y - getVerticalBorderWidth());
|
2012-10-07 22:25:51 +00:00
|
|
|
mVerticalImage.setFlipY(false);
|
2012-10-07 21:56:33 +00:00
|
|
|
mVerticalImage.render();
|
2013-06-02 15:08:32 +00:00
|
|
|
|
2012-10-07 21:56:33 +00:00
|
|
|
//bottom border
|
2013-06-02 15:08:32 +00:00
|
|
|
mVerticalImage.setOffset(getOffset().x, getOffset().y + mHeight);
|
2012-10-07 22:25:51 +00:00
|
|
|
mVerticalImage.setFlipY(true);
|
2012-10-07 21:56:33 +00:00
|
|
|
mVerticalImage.render();
|
|
|
|
|
2012-10-07 22:25:51 +00:00
|
|
|
|
|
|
|
//corner top left
|
2013-06-02 15:08:32 +00:00
|
|
|
mCornerImage.setOffset(getOffset().x - getHorizontalBorderWidth(), getOffset().y - getVerticalBorderWidth());
|
2012-10-07 22:25:51 +00:00
|
|
|
mCornerImage.setFlipX(false);
|
|
|
|
mCornerImage.setFlipY(false);
|
|
|
|
mCornerImage.render();
|
|
|
|
|
|
|
|
//top right
|
2013-06-02 15:08:32 +00:00
|
|
|
mCornerImage.setOffset(getOffset().x + mWidth, mCornerImage.getOffset().y);
|
2012-10-07 22:25:51 +00:00
|
|
|
mCornerImage.setFlipX(true);
|
|
|
|
mCornerImage.render();
|
|
|
|
|
|
|
|
//bottom right
|
2013-06-02 15:08:32 +00:00
|
|
|
mCornerImage.setOffset(mCornerImage.getOffset().x, getOffset().y + mHeight);
|
2012-10-07 22:25:51 +00:00
|
|
|
mCornerImage.setFlipY(true);
|
|
|
|
mCornerImage.render();
|
|
|
|
|
|
|
|
//bottom left
|
2013-06-02 15:08:32 +00:00
|
|
|
mCornerImage.setOffset(getOffset().x - getHorizontalBorderWidth(), mCornerImage.getOffset().y);
|
2012-10-07 22:25:51 +00:00
|
|
|
mCornerImage.setFlipX(false);
|
|
|
|
mCornerImage.render();
|
2012-10-05 20:04:12 +00:00
|
|
|
}
|
|
|
|
|
2013-04-10 17:29:07 +00:00
|
|
|
void GuiBox::init()
|
2012-10-05 20:04:12 +00:00
|
|
|
{
|
2013-04-10 17:29:07 +00:00
|
|
|
mVerticalImage.init();
|
|
|
|
mHorizontalImage.init();
|
|
|
|
mCornerImage.init();
|
2012-10-05 20:04:12 +00:00
|
|
|
}
|
|
|
|
|
2013-04-10 17:29:07 +00:00
|
|
|
void GuiBox::deinit()
|
2012-10-05 20:04:12 +00:00
|
|
|
{
|
2013-04-10 17:29:07 +00:00
|
|
|
mVerticalImage.deinit();
|
|
|
|
mHorizontalImage.deinit();
|
|
|
|
mCornerImage.deinit();
|
2012-10-05 20:04:12 +00:00
|
|
|
}
|
2012-10-07 21:56:33 +00:00
|
|
|
|
|
|
|
int GuiBox::getHorizontalBorderWidth()
|
|
|
|
{
|
2012-10-10 13:51:48 +00:00
|
|
|
return mHorizontalImage.getWidth();
|
2012-10-07 21:56:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int GuiBox::getVerticalBorderWidth()
|
|
|
|
{
|
2012-10-10 13:51:48 +00:00
|
|
|
return mVerticalImage.getHeight();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GuiBox::hasBackground()
|
|
|
|
{
|
|
|
|
return mBackgroundImage.hasImage();
|
2012-10-07 21:56:33 +00:00
|
|
|
}
|