Files
PlanetFleet/button.cpp
T
2021-10-27 21:37:09 +03:00

59 lines
1.8 KiB
C++
Executable File

#include "button.h"
#include "defConfigs.h"
using namespace irr::core;
using namespace irr::video;
using namespace irr::gui;
using namespace game::core;
using namespace game::core;
namespace game{
namespace gui{
Button::Button() {}
Button::Button(GameManager *gM, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) {
gameManager = gM;
color = new SColor(255, 200, 200, 200);
this->name = name;
this->pos = pos;
this->size = size;
this->separate = separate;
}
Button::~Button() {
delete color;
color = nullptr;
}
void Button::update() {
IVideoDriver *driver = gameManager->getDevice()->getVideoDriver();
if (!imageButton) {
driver->draw2DRectangle(*color, rect<s32>(pos.X, pos.Y, pos.X + size.X, pos.Y + size.Y), nullptr);
if (separate) {
IGUIFont *font = gameManager->getDevice()->getGUIEnvironment()->getFont(PATH + "Fonts/fontcourier.bmp");
font->draw(name, rect<s32>(pos.X + size.X / 4 + textXOffset, pos.Y + size.Y / 4 + textYOffset, size.X, size.Y), SColor(255, 250, 250, 250));
}
} else
driver->draw2DImage(image->getImage(), pos);
}
void Button::moveButton(int x, int y) {
pos.X += x;
pos.Y += y;
moveText(x, y);
}
void Button::moveText(int x, int y) {
textXOffset += x;
textYOffset += y;
}
void Button::setImageButton(Image *i) {
imageButton = true;
image = i;
image->setPos(pos);
size = image->getSize();
}
}
}