Files
SDLPongCPP/TrooperEngineDLL/TrooperEngine/GUIEngine/cLabel.cpp
T
2018-08-13 22:22:10 -04:00

133 lines
3.1 KiB
C++

#include "cLabel.hpp"
using GUIEngine::cLabel;
/*static*/ const cString cLabel::sNAME = "label";
/*static*/ const GUIHelpers::eLayout cLabel::sLAYOUT = GUIHelpers::eLayout::WRAP_CONTENT;
cLabel::cLabel(cWindow* parent, const signed int id, const cString& label /*= ""*/, const GUIHelpers::eAlign& align /*= sALIGN*/,
const GUIHelpers::eLayout& layout /*= sLAYOUT*/, const GUIHelpers::Position& pos /*= sPOSITION*/, const GUIHelpers::Size& size /*= sSIZE*/,
const GUIHelpers::Padding& padding /*= sPADDING*/, const cString& name /*= sNAME*/)
{
mp_text = new TextTypeEngine::cText(label);
Create(parent, id, label, align, layout, pos, size, padding, name);
}
/*virtual*/ cLabel::~cLabel()
{
delete mp_text;
mp_text = nullptr;
}
/// Functions
void cLabel::Create(cWindow* parent, const signed int id, const cString& label /*= ""*/, const GUIHelpers::eAlign& align /*= sALIGN*/,
const GUIHelpers::eLayout& layout /*= sLAYOUT*/, const GUIHelpers::Position& pos /*= sPOSITION*/, const GUIHelpers::Size& size /*= sSIZE*/,
const GUIHelpers::Padding& padding /*= sPADDING*/, const cString& name /*= sNAME*/)
{
cWindow::Create(parent, id, sORIENTATION, align, layout, pos, size, padding, name);
if (this->getParent() != nullptr) {
this->getParent()->AddChild(this);
}
setText(label);
}
/*virtual*/ void cLabel::Display()
{
GenerateTexture();
m_sprite.setPosition(cWindow::getPosition());
m_sprite.Draw();
//cSprite::SaveImage("test.bmp", "xml/");
cWindow::Display();
}
void cLabel::GenerateTexture()
{
m_sprite.setImage((VideoEngine::cImage**)(&mp_text));
m_sprite.setImageArea(mp_text->getWH());
//this->setTransparent();
//this->setPosition()
}
/// Sets
void cLabel::setFontColour(const GUIHelpers::RGBA& colour)
{
mp_text->setColour(colour);
}
void cLabel::setFontSize(const unsigned long int size)
{
mp_text->setSize(size);
SetSize();
}
void cLabel::setText(const cString& text)
{
mp_text->setText(text);
SetSize();
}
void cLabel::setFont(const TextTypeEngine::cFont* font)
{
mp_text->setFont((TextTypeEngine::cFont**)(&font));
}
/// Gets
const GUIHelpers::RGBA& cLabel::getFontColour() const
{
return mp_text->getColour();
}
const unsigned long int cLabel::getFontSize() const
{
return mp_text->getSize();
}
const TextTypeEngine::cFont* cLabel::getFont() const
{
return mp_text->getFont();
}
const cString& cLabel::getText() const
{
return mp_text->getText();
}
/*virtual*/ const GUIHelpers::eType cLabel::getType() const
{
return GUIHelpers::eType::CLABEL;
}
/*virtual*/ const GUIHelpers::RGBA& cLabel::getDebugColour() const
{
return GUIHelpers::GREEN;
}
// /*virtual*/ void cLabel::Resize()
// {
// RebuildLayout(this->getLayout());
// cWindow::RePos();
// }
/*virtual*/ void cLabel::RebuildLayout(const GUIHelpers::eLayout& layout)
{
SetSize();
}
void cLabel::SetSize()
{
if (mp_text != nullptr) {
long int y = mp_text->getSize();
long int x = (mp_text->getText().length() * y);
GUIHelpers::Size size = { x, y };
// size.x += this->getPadding().x + this->getPadding().w;
// size.y += this->getPadding().y + this->getPadding().z;
this->setSize(size);
}
}