Changeset View
Changeset View
Standalone View
Standalone View
source/gui/ObjectBases/IGUITextOwner.cpp
Show All 22 Lines | |||||
#include "gui/SGUIMessage.h" | #include "gui/SGUIMessage.h" | ||||
#include "gui/ObjectBases/IGUIObject.h" | #include "gui/ObjectBases/IGUIObject.h" | ||||
#include "gui/SettingTypes/CGUIString.h" | #include "gui/SettingTypes/CGUIString.h" | ||||
#include "maths/Vector2D.h" | #include "maths/Vector2D.h" | ||||
#include <math.h> | #include <math.h> | ||||
IGUITextOwner::IGUITextOwner(IGUIObject& pObject) | IGUITextOwner::IGUITextOwner(IGUIObject& pObject) | ||||
: m_pObject(pObject), | : m_pObject(pObject), | ||||
m_GeneratedTextsValid() | m_GeneratedTextsValid(), | ||||
m_TextAlign(&pObject, "text_align", EAlign::LEFT), | |||||
m_TextVAlign(&pObject, "text_valign", EVAlign::TOP) | |||||
{ | { | ||||
} | } | ||||
IGUITextOwner::~IGUITextOwner() | IGUITextOwner::~IGUITextOwner() | ||||
{ | { | ||||
} | } | ||||
CGUIText& IGUITextOwner::AddText() | CGUIText& IGUITextOwner::AddText() | ||||
{ | { | ||||
m_GeneratedTexts.emplace_back(); | m_GeneratedTexts.emplace_back(); | ||||
return m_GeneratedTexts.back(); | return m_GeneratedTexts.back(); | ||||
} | } | ||||
CGUIText& IGUITextOwner::AddText(const CGUIString& Text, const CStrW& Font, const float& Width, const float& BufferZone) | CGUIText& IGUITextOwner::AddText(const CGUIString& Text, const CStrW& Font, const float& Width, const float& BufferZone) | ||||
{ | { | ||||
// Avoids a move constructor | // Avoids a move constructor | ||||
m_GeneratedTexts.emplace_back(m_pObject.GetGUI(), Text, Font, Width, BufferZone, &m_pObject); | m_GeneratedTexts.emplace_back(m_pObject.GetGUI(), Text, Font, Width, BufferZone, m_TextAlign, &m_pObject); | ||||
return m_GeneratedTexts.back(); | return m_GeneratedTexts.back(); | ||||
} | } | ||||
void IGUITextOwner::HandleMessage(SGUIMessage& Message) | void IGUITextOwner::HandleMessage(SGUIMessage& Message) | ||||
{ | { | ||||
switch (Message.type) | switch (Message.type) | ||||
{ | { | ||||
case GUIM_SETTINGS_UPDATED: | case GUIM_SETTINGS_UPDATED: | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
void IGUITextOwner::CalculateTextPosition(CRect& ObjSize, CVector2D& TextPos, CGUIText& Text) | void IGUITextOwner::CalculateTextPosition(CRect& ObjSize, CVector2D& TextPos, CGUIText& Text) | ||||
{ | { | ||||
// The horizontal Alignment is now computed in GenerateText in order to not have to | // The horizontal Alignment is now computed in GenerateText in order to not have to | ||||
// loop through all of the TextCall objects again. | // loop through all of the TextCall objects again. | ||||
TextPos.X = ObjSize.left; | TextPos.X = ObjSize.left; | ||||
switch (m_pObject.GetSetting<EVAlign>("text_valign")) | switch (m_TextVAlign) | ||||
{ | { | ||||
case EVAlign::TOP: | case EVAlign::TOP: | ||||
TextPos.Y = ObjSize.top; | TextPos.Y = ObjSize.top; | ||||
break; | break; | ||||
case EVAlign::CENTER: | case EVAlign::CENTER: | ||||
// Round to integer pixel values, else the fonts look awful | // Round to integer pixel values, else the fonts look awful | ||||
TextPos.Y = floorf(ObjSize.CenterPoint().Y - Text.GetSize().Height / 2.f); | TextPos.Y = floorf(ObjSize.CenterPoint().Y - Text.GetSize().Height / 2.f); | ||||
break; | break; | ||||
Show All 13 Lines |
Wildfire Games · Phabricator