ES-DE/src/components/GuiBox.cpp

136 lines
3.1 KiB
C++
Raw Normal View History

#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)
{
2013-06-02 15:08:32 +00:00
setOffset(Vector2i(offsetX, offsetY));
mSize = Vector2u(width, height);
}
void GuiBox::setData(GuiBoxData data)
{
setBackgroundImage(data.backgroundPath, data.backgroundTiled);
setHorizontalImage(data.horizontalPath, data.horizontalTiled);
setVerticalImage(data.verticalPath, data.verticalTiled);
setCornerImage(data.cornerPath);
}
void GuiBox::setHorizontalImage(std::string path, bool tiled)
{
2012-10-07 21:56:33 +00:00
mHorizontalImage.setTiling(tiled);
mHorizontalImage.setOrigin(0, 0);
mHorizontalImage.setImage(path);
mHorizontalImage.setResize(getHorizontalBorderWidth(), mSize.y, true);
}
void GuiBox::setVerticalImage(std::string path, bool tiled)
{
2012-10-07 21:56:33 +00:00
mVerticalImage.setTiling(tiled);
mVerticalImage.setOrigin(0, 0);
mVerticalImage.setImage(path);
mVerticalImage.setResize(mSize.x, getVerticalBorderWidth(), true);
}
void GuiBox::setBackgroundImage(std::string path, bool tiled)
{
mBackgroundImage.setOrigin(0, 0);
mBackgroundImage.setResize(mSize.x, mSize.y, true);
mBackgroundImage.setTiling(tiled);
mBackgroundImage.setOffset(0, 0);
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);
}
void GuiBox::onRender()
{
mBackgroundImage.render();
//left border
mHorizontalImage.setOffset(-getHorizontalBorderWidth(), 0);
2012-10-07 22:25:51 +00:00
mHorizontalImage.setFlipX(false);
mHorizontalImage.render();
2013-06-02 15:08:32 +00:00
//right border
mHorizontalImage.setOffset(mSize.x, 0);
2012-10-07 22:25:51 +00:00
mHorizontalImage.setFlipX(true);
mHorizontalImage.render();
2013-06-02 15:08:32 +00:00
2012-10-07 21:56:33 +00:00
//top border
mVerticalImage.setOffset(0, -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
mVerticalImage.setOffset(0, mSize.y);
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
mCornerImage.setOffset(-getHorizontalBorderWidth(), -getVerticalBorderWidth());
2012-10-07 22:25:51 +00:00
mCornerImage.setFlipX(false);
mCornerImage.setFlipY(false);
mCornerImage.render();
//top right
mCornerImage.setOffset(mSize.x, mCornerImage.getOffset().y);
2012-10-07 22:25:51 +00:00
mCornerImage.setFlipX(true);
mCornerImage.render();
//bottom right
mCornerImage.setOffset(mCornerImage.getOffset().x, mSize.y);
2012-10-07 22:25:51 +00:00
mCornerImage.setFlipY(true);
mCornerImage.render();
//bottom left
mCornerImage.setOffset(-getHorizontalBorderWidth(), mCornerImage.getOffset().y);
2012-10-07 22:25:51 +00:00
mCornerImage.setFlipX(false);
mCornerImage.render();
GuiComponent::onRender();
}
void GuiBox::init()
{
mVerticalImage.init();
mHorizontalImage.init();
mCornerImage.init();
GuiComponent::init();
}
void GuiBox::deinit()
{
mVerticalImage.deinit();
mHorizontalImage.deinit();
mCornerImage.deinit();
GuiComponent::deinit();
}
2012-10-07 21:56:33 +00:00
int GuiBox::getHorizontalBorderWidth()
{
return mHorizontalImage.getTextureSize().x;
2012-10-07 21:56:33 +00:00
}
int GuiBox::getVerticalBorderWidth()
{
return mVerticalImage.getTextureSize().y;
}
bool GuiBox::hasBackground()
{
return mBackgroundImage.hasImage();
2012-10-07 21:56:33 +00:00
}