Suppose I have a Font
class that looks like this:
const unsigned int MAX_CHAR = 256; //better than dynamic I think?
struct BMchar
{
int x_ofs, y_ofs;
_uint32 x, y;
_uint32 width, height;
_uint32 x_advance;
};
struct BMkerninfo
{
_ushort first, second;
_ushort kerning;
};
class BM_FONT_CALL BMfont
{
public:
BMfont();
~BMfont(); //what will I free?
BMfont_Status Load(const char* fontName);
public:
float scale;
_uint32 tabSize;
_uint32 backTexture;
_uint32 frontTexture;
_uint32 textureSheet;
bool enableMasking;
bool hasBackground;
_uint32 base;
_uint32 lineHeight;
_uint32 pages;
_uint32 scaleW, scaleH;
_uint32 kerninfo_count;
BMkerninfo *kerninfo; //unused
BMchar chars[MAX_CHAR];
float texCoordBuff[MAX_CHAR * 8];
};
And I have a class Label
:
class SWC_DLL SWC_Label
{
public:
SWC_Label ();
public:
void ShowText (const Point& basePoint, int baseW, int baseH);
public:
std::string text;
Point textCoord;
BMfont font;
T_Alignment textAlignment;
};
Then for all of this I worry about, as you see, the BMfont
class uses lot of resources. I will inherit the class SWC_Label
to a class SWC_Button
(Yes a button, with a label/text on it).
Now, I want this SWC_Button
to have a feature of having a different font. What is the better and memory-efficient way to do things like this, should I make a limitations like: make a defined number of available font only (making static fonts in class label)?
Note: I am making a UI using OpenGL