113 lines
2.8 KiB
C++
113 lines
2.8 KiB
C++
#include "cButton.hpp"
|
|
|
|
/*** Custom Header Files ***/
|
|
#include "GUIHelpers/Enums.hpp"
|
|
#include "../VideoEngine/cRenderer.hpp"
|
|
#include "../FXEngine/cGFX.hpp"
|
|
|
|
using GUIEngine::cButton;
|
|
|
|
using MathEngine::iVector2;
|
|
using MathEngine::iVector4;
|
|
|
|
/*static*/ const cString cButton::sNAME = "button";
|
|
|
|
cButton::cButton()
|
|
{}
|
|
|
|
cButton::cButton( cWindow* parent, const signed int id, 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*/, VideoEngine::cImage** image /*= nullptr*/ )
|
|
{
|
|
Create(parent, id, align, layout, pos, size, padding, name, image);
|
|
// mp_texture = nullptr;
|
|
// mp_texturePress = nullptr;
|
|
//
|
|
// mpp_image = image;
|
|
//
|
|
// GenerateImage();
|
|
}
|
|
|
|
/*virtual*/ cButton::~cButton()
|
|
{
|
|
delete mp_texture;
|
|
mp_texture = nullptr;
|
|
|
|
delete mp_texturePress;
|
|
mp_texturePress = nullptr;
|
|
|
|
}
|
|
|
|
/// Functions
|
|
void cButton::Create( cWindow* parent, const signed int id, 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*/, VideoEngine::cImage** image /*= nullptr*/ )
|
|
{
|
|
cLayout::Create(parent, id, sORIENTATION, align, layout, pos, size, padding, name);
|
|
|
|
mp_texture = nullptr;
|
|
mp_texturePress = nullptr;
|
|
|
|
mpp_image = image;
|
|
}
|
|
|
|
void cButton::Display()
|
|
{
|
|
GenerateImage();
|
|
|
|
m_sprite.setPosition(cWindow::getPosition());
|
|
m_sprite.Draw();
|
|
m_sprite.SaveImage("test.bmp", "xml/");
|
|
cWindow::Display();
|
|
}
|
|
|
|
/*virtual*/ void cButton::Press()
|
|
{
|
|
mp_texture->SaveImage("hello.bmp");
|
|
}
|
|
|
|
/*virtual*/ void cButton::OnLButtonUp()
|
|
{
|
|
|
|
}
|
|
|
|
/// Gets
|
|
/*virtual*/ const GUIHelpers::eType cButton::getType() const
|
|
{
|
|
return GUIHelpers::eType::CBUTTON;
|
|
}
|
|
|
|
const GUIHelpers::RGBA& cButton::getDebugColour() const
|
|
{
|
|
return GUIHelpers::ORANGE;
|
|
}
|
|
|
|
/// private
|
|
void cButton::GenerateImage()
|
|
{
|
|
m_sprite.setImageArea(this->getSize(false));
|
|
GenerateTexture();
|
|
|
|
m_sprite.setImage((VideoEngine::cImage**)(&mp_texture));
|
|
|
|
m_sprite.setImageArea(mp_texture->getWH());
|
|
}
|
|
|
|
void cButton::GenerateTexture()
|
|
{
|
|
GUIHelpers::RGBA colour = { 100, 100, 100, 255 };
|
|
|
|
GUIHelpers::Size dim = this->getSize(false);
|
|
|
|
SDL_Rect rect = { 0, 0, dim.x + 1, dim.y + 1 };
|
|
|
|
SDL_Texture* tmptexture = VideoEngine::cRenderer::Inst().NewTexture(dim.x, dim.y);
|
|
SDL_Texture* tmptexture2 = VideoEngine::cRenderer::Inst().NewTexture(dim.x, dim.y);
|
|
|
|
FXEngine::cGFX::Inst().RoundedBox(rect, 20, GUIHelpers::GRAY, tmptexture);
|
|
FXEngine::cGFX::Inst().RoundedBox(rect, 20, colour, tmptexture2);
|
|
|
|
mp_texture = new VideoEngine::cImage(tmptexture);
|
|
mp_texturePress = new VideoEngine::cImage(tmptexture2);
|
|
}
|