It looks like you're new here. If you want to get involved, click one of these buttons!
#ifndef __ENGINE_OBJETOS_BOTON_H__
#define __ENGINE_OBJETOS_BOTON_H__
#include "../GameObject.h"
#include "../Eventos.h"
namespace Engine
{
namespace Objetos
{
namespace Var
{
static orxOBJECT* highlighted_button_ = orxNULL;
}
class Boton : public Engine::GameObject
{
private:
orxFONT* pstFont;
orxTEXT* pstText;
void FreeFont();
void UpdateFont();
protected:
std::string eventName;
std::string fontName;
std::string text;
public:
Boton(const orxSTRING conf) : Engine::GameObject()
{
text = "none";
pstFont = orxNULL;
pstText = orxNULL;
myObject = orxObject_CreateFromConfig(conf);
eventName = "ButtonLeft";
SetFont("ButtonFont");
if(orxConfig_PushSection(orxObject_GetName(myObject)))
{
orxObject_SetTargetAnim(myObject, orxConfig_GetString("AnimationInactive"));
orxConfig_PopSection();
}
}
~Boton();
void OnUpdate();
virtual void OnButtonClick() {}
void SetFont(const std::string& fontName);
void SetText(const std::string& text);
std::string GetText();
};
};
};
#endif
#include "Boton.h"
#include <orx.h>
namespace Engine
{
namespace Objetos
{
Boton::~Boton()
{
FreeFont();
}
void Boton::FreeFont()
{
if(pstFont != orxNULL)
{
orxFont_Delete(pstFont);
pstFont = orxNULL;
}
if(pstText != orxNULL)
{
orxText_Delete(pstText);
pstText = orxNULL;
}
}
void Boton::SetFont(const std::string& fontName)
{
FreeFont();
this->fontName = fontName;
pstFont = orxFont_CreateFromConfig(fontName.c_str());
pstText = orxText_Create();
orxText_SetFont(pstText, pstFont);
orxText_SetString(pstText, this->text.c_str());
}
void Boton::UpdateFont()
{
SetFont(fontName);
}
void Boton::OnUpdate()
{
// ...
}
void Boton::SetText(const std::string& text)
{
this->text = text;
UpdateFont();
}
std::string Boton::GetText()
{
return text;
}
};
};
Comments
Well, I think you can go with something simpler.
You don't need to create your own font or text directly, everything can be done from config.
In config:
In code:
If you want to change the font dynamically, I'd recommend to either delete that button and recreate one with the new font or to use the localization module that can associate localized texts with fonts (see the tutorial #10).
Thanks! it's working!! i'm using "MyButton" like a text object, and i move it over the button