2004-05-29 06:06:50 +02:00
|
|
|
/*
|
|
|
|
IGUITextOwner
|
|
|
|
*/
|
|
|
|
|
2004-06-03 20:38:14 +02:00
|
|
|
#include "precompiled.h"
|
2004-05-29 06:06:50 +02:00
|
|
|
#include "GUI.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
// Constructor / Destructor
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
IGUITextOwner::IGUITextOwner()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
IGUITextOwner::~IGUITextOwner()
|
|
|
|
{
|
2005-04-07 11:13:10 +02:00
|
|
|
// Delete all generated texts.
|
2004-05-29 06:06:50 +02:00
|
|
|
vector<SGUIText*>::iterator it;
|
|
|
|
for (it=m_GeneratedTexts.begin(); it!=m_GeneratedTexts.end(); ++it)
|
|
|
|
{
|
|
|
|
delete *it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void IGUITextOwner::AddText(SGUIText * text)
|
|
|
|
{
|
|
|
|
m_GeneratedTexts.push_back(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IGUITextOwner::HandleMessage(const SGUIMessage &Message)
|
|
|
|
{
|
|
|
|
switch (Message.type)
|
|
|
|
{
|
|
|
|
case GUIM_SETTINGS_UPDATED:
|
|
|
|
// Everything that can change the visual appearance.
|
|
|
|
// it is assumed that the text of the object will be dependent on
|
2004-08-31 04:09:58 +02:00
|
|
|
// these. Although that is not certain, but one will have to manually
|
2004-05-29 06:06:50 +02:00
|
|
|
// change it and disregard this function.
|
2004-10-14 12:09:26 +02:00
|
|
|
// TODO Gee: (2004-09-07) Make sure this is all options that can affect the text.
|
2004-12-21 14:37:24 +01:00
|
|
|
if (Message.value == "size" || Message.value == "z" ||
|
|
|
|
Message.value == "absolute" || Message.value == "caption" ||
|
|
|
|
Message.value == "font" || Message.value == "textcolor" ||
|
2005-01-01 13:06:17 +01:00
|
|
|
Message.value == "buffer_zone")
|
2004-05-29 06:06:50 +02:00
|
|
|
{
|
|
|
|
SetupText();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GUIM_LOAD:
|
|
|
|
SetupText();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void IGUITextOwner::Draw(const int &index, const CColor &color, const CPos &pos,
|
2005-07-24 02:01:41 +02:00
|
|
|
const float &z, const CRect &clipping)
|
2004-05-29 06:06:50 +02:00
|
|
|
{
|
2004-05-29 13:59:59 +02:00
|
|
|
if (index < 0 || index >= (int)m_GeneratedTexts.size())
|
2004-05-29 06:06:50 +02:00
|
|
|
{
|
2004-08-31 04:09:58 +02:00
|
|
|
debug_warn("Trying to draw a Text Index within a IGUITextOwner that doesn't exist");
|
2004-05-29 06:06:50 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GetGUI())
|
|
|
|
{
|
2005-07-24 02:01:41 +02:00
|
|
|
GetGUI()->DrawText(*m_GeneratedTexts[index], color, pos, z, clipping);
|
2004-05-29 06:06:50 +02:00
|
|
|
}
|
|
|
|
}
|
2004-12-28 13:17:04 +01:00
|
|
|
|
|
|
|
void IGUITextOwner::CalculateTextPosition(CRect &ObjSize, CPos &TextPos, SGUIText &Text)
|
|
|
|
{
|
|
|
|
EAlign align;
|
|
|
|
EVAlign valign;
|
2005-01-01 13:06:17 +01:00
|
|
|
GUI<EAlign>::GetSetting(this, "text_align", align);
|
|
|
|
GUI<EVAlign>::GetSetting(this, "text_valign", valign);
|
2004-12-28 13:17:04 +01:00
|
|
|
|
|
|
|
switch (align)
|
|
|
|
{
|
|
|
|
case EAlign_Left:
|
2004-12-28 13:38:45 +01:00
|
|
|
TextPos.x = ObjSize.left;
|
2004-12-28 13:17:04 +01:00
|
|
|
break;
|
|
|
|
case EAlign_Center:
|
|
|
|
// Round to integer pixel values, else the fonts look awful
|
|
|
|
TextPos.x = floorf(ObjSize.CenterPoint().x - Text.m_Size.cx/2.f);
|
|
|
|
break;
|
|
|
|
case EAlign_Right:
|
2004-12-28 13:38:45 +01:00
|
|
|
TextPos.x = ObjSize.right - Text.m_Size.cx;
|
2004-12-28 13:17:04 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
debug_warn("Broken EAlign in CButton::SetupText()");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (valign)
|
|
|
|
{
|
|
|
|
case EVAlign_Top:
|
2004-12-28 13:38:45 +01:00
|
|
|
TextPos.y = ObjSize.top;
|
2004-12-28 13:17:04 +01:00
|
|
|
break;
|
|
|
|
case EVAlign_Center:
|
|
|
|
// Round to integer pixel values, else the fonts look awful
|
|
|
|
TextPos.y = floorf(ObjSize.CenterPoint().y - Text.m_Size.cy/2.f);
|
|
|
|
break;
|
|
|
|
case EVAlign_Bottom:
|
2004-12-28 13:38:45 +01:00
|
|
|
TextPos.y = ObjSize.bottom - Text.m_Size.cy;
|
2004-12-28 13:17:04 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
debug_warn("Broken EVAlign in CButton::SetupText()");
|
|
|
|
break;
|
|
|
|
}
|
2005-01-17 05:52:02 +01:00
|
|
|
}
|