OpenBarnyard
 
Loading...
Searching...
No Matches
AGUI2TextBox.cpp
Go to the documentation of this file.
1#include "pch.h"
2#include "AGUI2TextBox.h"
3
4//-----------------------------------------------------------------------------
5// Enables memory debugging.
6// Note: Should be the last include!
7//-----------------------------------------------------------------------------
9
11{
12 m_bRenderShadow = TFALSE;
13 m_wszText = TNULL;
14 m_pFont = TNULL;
15 m_bUnkFlag2 = TFALSE;
16 m_fShadowOffsetX = 5.0f;
17 m_fShadowOffsetY = 5.0f;
18 m_uiShadowColour = 0x80000000;
19 m_fScale = 1.0f;
20 m_eTextAlign = AGUI2Font::TextAlign_Center;
21}
22
26
27void AGUI2TextBox::Create( AGUI2Font* a_pFont, TFLOAT a_fWidth )
28{
29 m_pFont = a_pFont;
30 AGUI2Element::m_fWidth = a_fWidth;
31 m_bDimensionsDirty = TTRUE;
32 m_bUnkFlag2 = TFALSE;
33}
34
35void AGUI2TextBox::SetText( const TWCHAR* a_wszText )
36{
37 m_wszText = a_wszText;
38 m_bDimensionsDirty = TTRUE;
39}
40
41void AGUI2TextBox::RenderText( void* a_fnCallback )
42{
43 if ( m_pFont && m_wszText )
44 {
45 TFLOAT fWidth;
46 TFLOAT fHeight;
47 GetDimensions( fWidth, fHeight );
48
49 TFLOAT fPosX = -fWidth * 0.5f;
50 TFLOAT fPosY = -fHeight * 0.5f;
51
52 if ( m_bRenderShadow )
53 {
54 m_pFont->DrawTextWrapped(
55 m_wszText,
56 fPosX + m_fShadowOffsetX,
57 fPosY + m_fShadowOffsetY,
58 fWidth,
59 fHeight,
60 m_uiShadowColour,
61 m_fScale,
62 m_eTextAlign,
63 a_fnCallback
64 );
65 }
66
67 m_pFont->DrawTextWrapped(
68 m_wszText,
69 fPosX,
70 fPosY,
71 fWidth,
72 fHeight,
74 m_fScale,
75 m_eTextAlign,
76 a_fnCallback
77 );
78 }
79}
80
82{
83 m_fScale = a_fScale;
84 m_bDimensionsDirty = TTRUE;
85}
86
87void AGUI2TextBox::SetShadow( TBOOL a_bEnabled, TUINT32 a_uiColour )
88{
89 m_bRenderShadow = a_bEnabled;
90 m_uiShadowColour = a_uiColour;
91}
92
94{
95 m_bRenderShadow = a_bEnabled;
96}
97
99{
100 m_uiShadowColour = a_uiColour;
101}
102
103void AGUI2TextBox::SetShadowColour( const Toshi::TColor& a_rColour )
104{
105 m_uiShadowColour = a_rColour.Value32;
106}
107
108void AGUI2TextBox::SetShadowOffset( TFLOAT a_fOffsetX, TFLOAT a_fOffsetY )
109{
110 m_fShadowOffsetX = m_fScale * a_fOffsetX;
111 m_fShadowOffsetY = m_fScale * a_fOffsetY;
112}
113
115{
116 m_eTextAlign = a_eTextAlign;
117}
118
120{
121 TASSERT( m_pFont != TNULL );
122
123 if ( AGUI2Element::HasFlags( 8 ) )
124 {
125 // Render children before text
127 }
128
129 RenderText( TNULL );
130
131 if ( !AGUI2Element::HasFlags( 8 ) )
132 {
133 // Render children after text
135 }
136}
137
138void AGUI2TextBox::GetDimensions( TFLOAT& a_rWidth, TFLOAT& a_rHeight )
139{
140 if ( !m_bUnkFlag2 && m_bDimensionsDirty )
141 {
142 if ( !m_wszText || !m_pFont )
143 {
145 }
146 else
147 {
148 AGUI2Element::m_fHeight = m_pFont->GetTextHeightWrapped( m_wszText, AGUI2Element::m_fWidth, m_fScale );
149 }
150
151 m_bDimensionsDirty = TFALSE;
152 }
153
154 a_rWidth = AGUI2Element::m_fWidth;
155 a_rHeight = AGUI2Element::m_fHeight;
156}
157
159{
160 TFLOAT fWidth;
161 TFLOAT fHeight;
162 GetDimensions( fWidth, fHeight );
163
164 return fWidth;
165}
166
168{
169 TFLOAT fWidth;
170 TFLOAT fHeight;
171 GetDimensions( fWidth, fHeight );
172
173 return fHeight;
174}
175
177{
178 AGUI2Element::m_fWidth = a_fWidth;
179 m_bDimensionsDirty = TTRUE;
180}
181
183{
184 TUINT8 ui8Alpha = TUINT8( a_fAlpha * 255.0f );
185 m_uiShadowColour = ( m_uiShadowColour & 0x00FFFFFF ) | ui8Alpha << 24;
186}
#define TASSERT(X,...)
Definition Defines.h:138
wchar_t TWCHAR
Definition Typedefs.h:21
uint8_t TUINT8
Definition Typedefs.h:17
float TFLOAT
Definition Typedefs.h:4
#define TNULL
Definition Typedefs.h:23
uint32_t TUINT32
Definition Typedefs.h:13
#define TFALSE
Definition Typedefs.h:24
#define TTRUE
Definition Typedefs.h:25
bool TBOOL
Definition Typedefs.h:6
virtual void Render()
TBOOL HasFlags(TUINT32 a_uiFlags) const
TUINT32 m_uiColour
void DrawTextWrapped(const TWCHAR *a_wszText, TFLOAT a_fX, TFLOAT a_fY, TFLOAT a_fWidth, TFLOAT a_fHeight, TUINT32 a_uiColour, TFLOAT a_fScale, TextAlign a_eAlign, void *a_fnCallback=nullptr)
Definition AGUI2Font.cpp:34
@ TextAlign_Center
Definition AGUI2Font.h:40
virtual TFLOAT GetWidth() OVERRIDE
void SetTextAlign(AGUI2Font::TextAlign a_eTextAlign)
void SetShadow(TBOOL a_bEnabled, TUINT32 a_uiColour)
void SetShadowColour(const Toshi::TColor &a_rColour)
virtual void SetWidth(TFLOAT a_fWidth) OVERRIDE
virtual void SetShadowAlpha(TFLOAT a_fAlpha) OVERRIDE
virtual void GetDimensions(TFLOAT &a_rWidth, TFLOAT &a_rHeight) OVERRIDE
void SetShadowEnabled(TBOOL a_bEnabled)
virtual void Render() OVERRIDE
void SetShadowOffset(TFLOAT a_fOffsetX, TFLOAT a_fOffsetY)
void SetText(const TWCHAR *a_wszText)
void SetScale(TFLOAT a_fScale)
virtual TFLOAT GetHeight() OVERRIDE
void Create(AGUI2Font *a_pFont, TFLOAT a_fWidth)