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
@@ -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);
}