2012-10-05 20:04:12 +00:00
|
|
|
#include "GuiBox.h"
|
2012-10-07 22:59:20 +00:00
|
|
|
#include <iostream>
|
2012-10-05 20:04:12 +00:00
|
|
|
|
|
|
|
GuiBox::GuiBox(int offsetX, int offsetY, unsigned int width, unsigned int height)
|
|
|
|
{
|
|
|
|
setOffsetX(offsetX);
|
|
|
|
setOffsetY(offsetY);
|
|
|
|
|
|
|
|
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.setResize(12, mHeight, true);
|
|
|
|
mHorizontalImage.setTiling(tiled);
|
|
|
|
mHorizontalImage.setOrigin(0, 0);
|
|
|
|
|
2012-10-05 20:04:12 +00:00
|
|
|
mHorizontalImage.setImage(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiBox::setVerticalImage(std::string path, bool tiled)
|
|
|
|
{
|
2012-10-07 21:56:33 +00:00
|
|
|
mVerticalImage.setResize(mWidth, 12, true);
|
|
|
|
mVerticalImage.setTiling(tiled);
|
|
|
|
mVerticalImage.setOrigin(0, 0);
|
|
|
|
|
2012-10-05 20:04:12 +00:00
|
|
|
mVerticalImage.setImage(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiBox::setBackgroundImage(std::string path, bool tiled)
|
|
|
|
{
|
2012-10-07 21:56:33 +00:00
|
|
|
mBackgroundImage.setResize(mWidth, mHeight, true);
|
2012-10-05 20:04:12 +00:00
|
|
|
mBackgroundImage.setTiling(tiled);
|
2012-10-07 21:56:33 +00:00
|
|
|
mBackgroundImage.setOffsetX(getOffsetX());
|
|
|
|
mBackgroundImage.setOffsetY(getOffsetY());
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void GuiBox::onRender()
|
|
|
|
{
|
|
|
|
//left border
|
2012-10-07 21:56:33 +00:00
|
|
|
mHorizontalImage.setOffsetX(getOffsetX() - getHorizontalBorderWidth());
|
2012-10-05 20:04:12 +00:00
|
|
|
mHorizontalImage.setOffsetY(getOffsetY());
|
2012-10-07 22:25:51 +00:00
|
|
|
mHorizontalImage.setFlipX(false);
|
2012-10-05 20:04:12 +00:00
|
|
|
mHorizontalImage.render();
|
2012-10-07 21:56:33 +00:00
|
|
|
//Renderer::drawRect(getOffsetX() - getHorizontalBorderWidth(), getOffsetY(), getHorizontalBorderWidth(), mHeight, 0xFF0000);
|
2012-10-05 20:04:12 +00:00
|
|
|
|
|
|
|
//right border
|
|
|
|
mHorizontalImage.setOffsetX(getOffsetX() + mWidth);
|
2012-10-07 21:56:33 +00:00
|
|
|
//same Y
|
2012-10-07 22:25:51 +00:00
|
|
|
mHorizontalImage.setFlipX(true);
|
2012-10-05 20:04:12 +00:00
|
|
|
mHorizontalImage.render();
|
2012-10-07 21:56:33 +00:00
|
|
|
//Renderer::drawRect(getOffsetX() + mWidth, getOffsetY(), getHorizontalBorderWidth(), mHeight, 0xFF0000);
|
|
|
|
|
|
|
|
//top border
|
|
|
|
mVerticalImage.setOffsetX(getOffsetX());
|
|
|
|
mVerticalImage.setOffsetY(getOffsetY() - getVerticalBorderWidth());
|
2012-10-07 22:25:51 +00:00
|
|
|
mVerticalImage.setFlipY(false);
|
2012-10-07 21:56:33 +00:00
|
|
|
mVerticalImage.render();
|
|
|
|
//Renderer::drawRect(getOffsetX(), getOffsetY() - getVerticalBorderWidth(), mWidth, getVerticalBorderWidth(), 0x00FF00);
|
|
|
|
|
|
|
|
//bottom border
|
|
|
|
//same X
|
|
|
|
mVerticalImage.setOffsetY(getOffsetY() + mHeight);
|
2012-10-07 22:25:51 +00:00
|
|
|
mVerticalImage.setFlipY(true);
|
2012-10-07 21:56:33 +00:00
|
|
|
mVerticalImage.render();
|
|
|
|
//Renderer::drawRect(getOffsetX(), getOffsetY() + mHeight, mWidth, getVerticalBorderWidth(), 0x00FF00);
|
|
|
|
|
2012-10-07 22:25:51 +00:00
|
|
|
|
|
|
|
//corner top left
|
|
|
|
mCornerImage.setOffsetX(getOffsetX() - getHorizontalBorderWidth());
|
|
|
|
mCornerImage.setOffsetY(getOffsetY() - getVerticalBorderWidth());
|
|
|
|
mCornerImage.setFlipX(false);
|
|
|
|
mCornerImage.setFlipY(false);
|
|
|
|
mCornerImage.render();
|
|
|
|
|
|
|
|
//top right
|
|
|
|
mCornerImage.setOffsetX(getOffsetX() + mWidth);
|
|
|
|
mCornerImage.setFlipX(true);
|
|
|
|
mCornerImage.render();
|
|
|
|
|
|
|
|
//bottom right
|
|
|
|
mCornerImage.setOffsetY(getOffsetY() + mHeight);
|
|
|
|
mCornerImage.setFlipY(true);
|
|
|
|
mCornerImage.render();
|
|
|
|
|
|
|
|
//bottom left
|
|
|
|
mCornerImage.setOffsetX(getOffsetX() - getHorizontalBorderWidth());
|
|
|
|
mCornerImage.setFlipX(false);
|
|
|
|
mCornerImage.render();
|
2012-10-05 20:04:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiBox::onInit()
|
|
|
|
{
|
|
|
|
mHorizontalImage.init();
|
|
|
|
mVerticalImage.init();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiBox::onDeinit()
|
|
|
|
{
|
|
|
|
mHorizontalImage.deinit();
|
|
|
|
mVerticalImage.deinit();
|
|
|
|
}
|
2012-10-07 21:56:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
int GuiBox::getHorizontalBorderWidth()
|
|
|
|
{
|
|
|
|
return 12;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GuiBox::getVerticalBorderWidth()
|
|
|
|
{
|
|
|
|
return 12;
|
|
|
|
}
|