cButton Texture Generate

This commit is contained in:
2018-08-30 09:16:39 -04:00
parent 30416b0334
commit 335166ea00
24 changed files with 163 additions and 174 deletions
@@ -19,11 +19,12 @@ namespace GUIHelpers {
typedef struct SDL_Rect Area;
static const RGBA WHITE = { 255, 255, 255, 255 };
static const RGBA GRAY = { 127, 127, 127, 255 };
static const RGBA BLACK = { 0, 0, 0, 255 };
static const RGBA RED = { 255, 0, 0, 255 };
static const RGBA ORANGE = { 255, 128, 0, 255 };
static const RGBA ORANGE = { 255, 127, 0, 255 };
static const RGBA YELLOW = { 255, 255, 0, 255 };
static const RGBA GREEN = { 0, 255, 0, 255 };
@@ -32,9 +33,9 @@ namespace GUIHelpers {
static const RGBA BLUE = { 0, 0, 255, 255 };
static const RGBA VIOLET = { 128, 0, 255, 255 };
static const RGBA VIOLET = { 127, 0, 255, 255 };
static const RGBA MAGENTA = { 255, 0, 255, 255 };
static const RGBA ROSE = { 255, 0, 128, 255 };
static const RGBA ROSE = { 255, 0, 127, 255 };
static const RGBA DEFAULT = WHITE;
@@ -4,7 +4,6 @@
#include "../../UtilityEngine/cUtility.hpp"
#include "../cGUI.hpp"
#include "../cLayout.hpp"
using GUIHelpers::cXMLoader;
@@ -66,6 +65,8 @@ void cXMLoader::GetElement( tinyxml2::XMLElement& element, GUIEngine::cWindow* p
tmp = LabelBuild(element, parent);
if (name == "sizer")
tmp = SizerBuild(element, parent);
if (name == "button")
tmp = ButtonBuild(element, parent);
tinyxml2::XMLElement* child = element.FirstChildElement();
if (child != nullptr)
@@ -93,7 +94,7 @@ const cString cXMLoader::GetAttribute( const tinyxml2::XMLElement& element, cons
return rtn;
}
void cXMLoader::Include(const tinyxml2::XMLElement& element, GUIEngine::cWindow* parent) const
void cXMLoader::Include( const tinyxml2::XMLElement& element, GUIEngine::cWindow* parent ) const
{
cString dir = getDir(element);
cString filename = getFileName(element);
@@ -133,7 +134,7 @@ void cXMLoader::Debug(const tinyxml2::XMLElement& element)
GUIEngine::cGUI::Inst().setDebugLevel(debug);
}
GUIEngine::cPanel* cXMLoader::PanelBuild(const tinyxml2::XMLElement& element, GUIEngine::cWindow* parent) const
GUIEngine::cPanel* cXMLoader::PanelBuild( const tinyxml2::XMLElement& element, GUIEngine::cWindow* parent ) const
{
signed long int id = getID(element);
GUIHelpers::eOrientation orientation = getOrientation(element);
@@ -193,7 +194,7 @@ GUIEngine::cLabel* cXMLoader::LabelBuild( const tinyxml2::XMLElement& element, G
return rtn;
}
GUIEngine::cSizer* cXMLoader::SizerBuild(const tinyxml2::XMLElement& element, GUIEngine::cWindow* parent) const
GUIEngine::cSizer* cXMLoader::SizerBuild( const tinyxml2::XMLElement& element, GUIEngine::cWindow* parent ) const
{
signed long int id = getID(element);
//GUIHelpers::eOrientation orientation = getOrientation(element);
@@ -210,12 +211,30 @@ GUIEngine::cSizer* cXMLoader::SizerBuild(const tinyxml2::XMLElement& element, GU
return rtn;
}
const cString cXMLoader::getDir(const tinyxml2::XMLElement& element) const
GUIEngine::cButton * cXMLoader::ButtonBuild( const tinyxml2::XMLElement & element, GUIEngine::cWindow* parent ) const
{
signed long int id = getID(element);
GUIHelpers::eOrientation orientation = getOrientation(element);
GUIHelpers::eAlign align = getAlign(element);
GUIHelpers::eLayout layout = getLayout(element);
GUIHelpers::Position pos = getPosition(element);
GUIHelpers::Size size = getSize(element);
GUIHelpers::Padding pad = getPadding(element);
GUIEngine::cButton* rtn = new GUIEngine::cButton(parent, id, align, layout, pos, size, pad);
if (parent == nullptr)
GUIEngine::cGUI::Inst().AddObject(rtn);
return rtn;
}
const cString cXMLoader::getDir( const tinyxml2::XMLElement& element ) const
{
return GetAttribute(element, "dir");
}
const cString cXMLoader::getFileName(const tinyxml2::XMLElement& element) const
const cString cXMLoader::getFileName( const tinyxml2::XMLElement& element ) const
{
return GetAttribute(element, "filename");
}
@@ -240,7 +259,7 @@ const unsigned long int cXMLoader::getDebug( const tinyxml2::XMLElement& element
return rtn;
}
const bool cXMLoader::getDebugXML(const tinyxml2::XMLElement& element) const
const bool cXMLoader::getDebugXML( const tinyxml2::XMLElement& element ) const
{
bool rtn = false;
cString str = GetAttribute(element, "xml").lower();
@@ -15,6 +15,7 @@
#include "../cLayout.hpp"
#include "../cLabel.hpp"
#include "../cSizer.hpp"
#include "../cButton.hpp"
#include "../../UtilityEngine/cString.hpp"
@@ -42,6 +43,7 @@ namespace GUIHelpers {
GUIEngine::cLayout* LayoutBuild( const tinyxml2::XMLElement& element, GUIEngine::cWindow* parent ) const;
GUIEngine::cLabel* LabelBuild( const tinyxml2::XMLElement& element, GUIEngine::cWindow* parent ) const;
GUIEngine::cSizer* SizerBuild( const tinyxml2::XMLElement& element, GUIEngine::cWindow* parent ) const;
GUIEngine::cButton* ButtonBuild( const tinyxml2::XMLElement& element, GUIEngine::cWindow* parent ) const;
const cString getDir( const tinyxml2::XMLElement& element ) const;
const cString getFileName( const tinyxml2::XMLElement& element ) const;
@@ -18,15 +18,14 @@ 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*/ )
: cWindow(parent, id, sORIENTATION, align, layout, pos, size, padding, name)
{
//Create(parent, id, align, layout, pos, size, padding, name, image);
mp_texture = nullptr;
mp_texturePress = nullptr;
mpp_image = image;
GenerateImage();
Create(parent, id, align, layout, pos, size, padding, name, image);
// mp_texture = nullptr;
// mp_texturePress = nullptr;
//
// mpp_image = image;
//
// GenerateImage();
}
/*virtual*/ cButton::~cButton()
@@ -44,13 +43,22 @@ void cButton::Create( cWindow* parent, const signed int id, const GUIHelpers::eA
const GUIHelpers::Position& pos /*= sPOSITION*/, const GUIHelpers::Size& size /*= sSIZE*/, const GUIHelpers::Padding& padding /*= sPADDING*/,
const cString& name /*= sNAME*/, VideoEngine::cImage** image /*= nullptr*/ )
{
cWindow::Create(parent, id, sORIENTATION, align, layout, pos, size, padding, name);
cLayout::Create(parent, id, sORIENTATION, align, layout, pos, size, padding, name);
mp_texture = nullptr;
mp_texturePress = nullptr;
mpp_image = image;
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()
@@ -58,113 +66,47 @@ void cButton::Create( cWindow* parent, const signed int id, const GUIHelpers::eA
mp_texture->SaveImage("hello.bmp");
}
// void cButton::setLabel( const cString& label )
// {
// if (label.size() > 0) {
// if (mp_label == nullptr)
// mp_label = new TextTypeEngine::cText(label);
// else
// mp_label->setText(label);
// }
// }
/*virtual*/ void cButton::OnLButtonUp()
{
}
/// Gets
// const cString cButton::getLabel() const
// {
// cString rtn = "";
// if (mp_label != nullptr)
// rtn = mp_label->getText();
// return rtn;
// }
/*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();
//GenerateTexture( mp_texturePress );
this->setImage((VideoEngine::cImage**)(&mp_texture));
m_sprite.setImage((VideoEngine::cImage**)(&mp_texture));
this->setImageArea(mp_texture->getWH());
m_sprite.setImageArea(mp_texture->getWH());
}
void cButton::GenerateTexture()
{
// SDL_Rect t = { 0, 0, 0, 0 };
// if (mp_label != nullptr)
// t = mp_label->getWH();
// SDL_Rect centerText = { 0, 0, 0, 0 };
// SDL_Rect centerButton = { 0, 0, 0, 0 };
// SDL_Rect dim = this->getImageArea();
//
// GUIHelpers::Padding TXTPADDING = PADDING;
// ///Find the min padding around the text.
// if (dim.w < (t.w + TXTPADDING.x + TXTPADDING.w) )
// dim.w += (t.w + TXTPADDING.x + TXTPADDING.w);
//
// if (dim.h < (t.h + TXTPADDING.y + TXTPADDING.z) )
// dim.h += (t.h + TXTPADDING.y + TXTPADDING.z);
//
// ///Find the center of the button
// centerButton.x = dim.w / 2;
// centerButton.y = dim.h / 2;
//
// ///Find the center of the text
// centerText.x = t.w / 2;
// centerText.y = t.h / 2;
//
// if (centerText.x < centerButton.x)
// t.x = centerButton.x - centerText.x;
//
// if (centerText.y < centerButton.y)
// t.y = centerButton.y - centerText.y;
//
// SDL_Texture* temptext = VideoEngine::cRenderer::Inst().NewTexture(dim.w, dim.h, SDL_TEXTUREACCESS_TARGET );
//
// GUIHelpers::RBGA colour = { 100, 100, 100, 255 };
//
// FXEngine::cGFX::Inst().RoundedRectangle(dim, 4, colour, temptext);
//
//
// if (mp_label != nullptr)
// VideoEngine::cRenderer::Inst().RenderToTexture(mp_label->getImage(), nullptr, temptext, &t);
GUIHelpers::RGBA colour = { 100, 100, 100, 255 };
//cRenderer::Inst().Render(temptext, nullptr, nullptr);
GUIHelpers::Size dim = this->getSize(false);
//cRenderer::Inst().RenderToTexture(temptext, nullptr, text->getImage(), nullptr);
SDL_Rect rect = { 0, 0, dim.x + 1, dim.y + 1 };
/*SDL_Surface* tempsurface = SDL_CreateRGBSurface(cVideo::Inst().getVideoSettings(), dimensions.w, dimensions.h, cVideo::Inst().getColour(),
0, 0, 0, 0);
SDL_Texture* tmptexture = VideoEngine::cRenderer::Inst().NewTexture(dim.x, dim.y);
SDL_Texture* tmptexture2 = VideoEngine::cRenderer::Inst().NewTexture(dim.x, dim.y);
SDL_FillRect(tempsurface, nullptr, SDL_MapRGB(tempsurface->format, 0, 255, 0));
FXEngine::cGFX::Inst().RoundedBox(rect, 20, GUIHelpers::GRAY, tmptexture);
FXEngine::cGFX::Inst().RoundedBox(rect, 20, colour, tmptexture2);
/*if (roundedBoxRGBA(tempsurface, dimensions.x, dimensions.y, dimensions.w, dimensions.h, 10, 255, 255, 0, 255) != 0)
cerr << "Unable to generate GUI Texture." << endl << SDL_GetError() << endl;*/
/*if (text != nullptr) {
SDL_Rect srcrect, dstrect = dimensions;
cVideo::Inst().Render(text->getImage(), &srcrect, temptext, &dstrect);
}
this->setImage(temptext);
this->setTransparent();*/
// delete mp_texture;
// mp_texture = nullptr;
//
// mp_texture = new VideoEngine::cImage(temptext);
//
// GUIHelpers::Size size = { 0, 0 };
// mp_texture->getWH((unsigned long&)size.x, (unsigned long&)size.y);
// cWindow::setSize(size);
// image->setImage(temptext);
//image->setImage(temptext);
mp_texture = new VideoEngine::cImage(tmptexture);
mp_texturePress = new VideoEngine::cImage(tmptexture2);
}
@@ -13,18 +13,18 @@
#include "../VideoEngine/cImage.hpp"
#include "../MathEngine/iVector/iVector2.hpp"
#include "cPanel.hpp"
/*** DLL Header File ***/
#include "dllExport.h"
/*** Custom Header Files ***/
#include "cLayout.hpp"
#include "../UtilityEngine/cString.hpp"
#include "../EventEngine/cEvent.hpp"
using UtilityEngine::cString;
namespace GUIEngine {
class EXPORT_FROM_MYDLL cButton : public cWindow, public VideoEngine::cSprite
class EXPORT_FROM_MYDLL cButton : public cLayout, public EventEngine::cEvent
{
public:
static const cString sNAME; /*= "button";*/
@@ -40,12 +40,17 @@ namespace GUIEngine {
const GUIHelpers::Position& pos = sPOSITION, const GUIHelpers::Size& size = sSIZE, const GUIHelpers::Padding& padding = sPADDING,
const cString& name = sNAME, VideoEngine::cImage** image = nullptr );
virtual void Display();
virtual void Press();
virtual void OnLButtonUp();
/// Sets
/// Gets
virtual const GUIHelpers::eType getType() const;
virtual const GUIHelpers::RGBA& getDebugColour() const;
private:
void CreateLabel();
@@ -54,10 +59,12 @@ namespace GUIEngine {
private:
/// Variables
VideoEngine::cSprite m_sprite;
VideoEngine::cImage* mp_texture;/// = nullptr
VideoEngine::cImage* mp_texturePress;/// = nullptr
//Pointer to the image that will be displayed on the button.
/// Pointer to the image that will be displayed on the button.
VideoEngine::cImage** mpp_image;/// = nullptr
};/// END CLASS DEFINITION cButton
}/// END NAMESPACE DEFINITION GUIEngine
@@ -35,7 +35,7 @@ cGUI::~cGUI()
m_children.clear();
}
//public:
///public:
///Functions
/*static*/ cGUI& cGUI::Inst()
{
@@ -104,7 +104,6 @@ std::vector<GUIEngine::cWindow*>& cGUI::GetObjects()
void cGUI::Display()
{
//m_obj->Display();
std::vector<GUIEngine::cWindow*>::iterator it;
for (it = m_children.begin(); it < m_children.end(); it++) {
@@ -27,9 +27,6 @@ void cLabel::Create( cWindow* parent, const signed int id, const cString& label
cWindow::Create(parent, id, sORIENTATION, align, layout, pos, size, padding, name);
if (layout == GUIHelpers::eLayout::DEFAULT_LAYOUT)
setLayout(sLAYOUT);
if (this->getParent() != nullptr) {
this->getParent()->AddChild(this);
}
setText(label);
}
@@ -48,11 +45,6 @@ void cLabel::GenerateTexture()
m_sprite.setImage((VideoEngine::cImage**)(&mp_text));
m_sprite.setImageArea(mp_text->getWH());
//this->setTransparent();
//this->setPosition()
}
/// Sets
@@ -24,9 +24,6 @@ cLayout::cLayout( cWindow* parent, const signed int id, const GUIHelpers::eOrien
if (ori == GUIHelpers::eOrientation::DEFAULT_ORIENTATION)
ori = sORIENTATION;
cWindow::Create(parent, id, ori, align, layout, pos, size, padding, name);
if (this->getParent() != nullptr) {
this->getParent()->AddChild(this);
}
}
/*virtual*/ void cLayout::Display()
@@ -24,9 +24,6 @@ void cSizer::Create( cWindow* parent, const signed int id, const GUIHelpers::eAl
if (size.x < 0)
sz = sSIZE;
cWindow::Create(parent, id, sORIENTATION, align, layout, pos, sz, padding, name);
if (this->getParent() != nullptr) {
this->getParent()->AddChild(this);
}
}
/*virtual*/ const GUIHelpers::eType cSizer::getType() const
@@ -50,6 +50,10 @@ cWindow::cWindow( cWindow* parent /*= nullptr*/, const signed int id /*= -1*/, c
setSize(size);
setPadding(padding);
m_name = name;
if (this->getParent() != nullptr) {
this->getParent()->AddChild(this);
}
}
/*virtual*/ void cWindow::Display() {
@@ -569,6 +573,9 @@ void cWindow::DebugDisplay() const
typePos = { -10, -10, 0, 0 };
type = "Label";
break;
case GUIHelpers::eType::CBUTTON:
type = "Button";
break;
default:
type = "";
}
@@ -91,9 +91,7 @@ namespace GUIEngine {
const unsigned long int getFillParentSize();
virtual const GUIHelpers::eType getType() const;
virtual const GUIHelpers::eType getType() const;
virtual void Resize();
virtual void RebuildLayout( const GUIHelpers::eLayout& layout );
@@ -13,16 +13,16 @@ cImage::cImage( const bool transparent /*= false*/, const unsigned char red /*=
m_transRed(red), m_transBlue(blue), m_transGreen(green), m_transLevel(translevel), m_isSurface(isSurface)
{}
cImage::cImage( SDL_Surface* surface )
cImage::cImage(SDL_Surface* surface)
: mp_texture(nullptr), mp_surface(nullptr), m_transparent(false),
m_transRed(0), m_transBlue(0), m_transGreen(255), m_transLevel(255)
m_transRed(0), m_transBlue(0), m_transGreen(255), m_transLevel(255), m_isSurface(true)
{
setImage(surface);
}
cImage::cImage( SDL_Texture* texture )
cImage::cImage(SDL_Texture* texture)
: mp_texture(nullptr), mp_surface(nullptr), m_transparent(false),
m_transRed(0), m_transBlue(0), m_transGreen(255), m_transLevel(255)
m_transRed(0), m_transBlue(0), m_transGreen(255), m_transLevel(255), m_isSurface(false)
{
setImage(texture);
}