OpenBarnyard
 
Loading...
Searching...
No Matches
AGUI2Element.cpp
Go to the documentation of this file.
1#include "pch.h"
2#include "AGUI2.h"
3#include "AGUI2Element.h"
4
6
7//-----------------------------------------------------------------------------
8// Enables memory debugging.
9// Note: Should be the last include!
10//-----------------------------------------------------------------------------
11#include <Core/TMemoryDebugOn.h>
12
25
26void AGUI2Element::Tick( TFLOAT a_fDeltaTime )
27{
28 for ( AGUI2Element* it = ChildRBegin(); it != TNULL; it = GetPrevChild( it ) )
29 {
30 it->Tick( a_fDeltaTime );
31 }
32}
33
35{
36 Toshi::TVector2 vecAnchorPos = { 0.0f, 0.0f };
37 Toshi::TVector2 vecPivotPos = { 0.0f, 0.0f };
38
39 if ( m_pParent != TNULL )
40 {
41 TFLOAT fParentWidth, fParentHeight;
42 m_pParent->GetDimensions( fParentWidth, fParentHeight );
43 AnchorPos( vecAnchorPos.x, vecAnchorPos.y, fParentWidth, fParentHeight );
44 }
45
46 TFLOAT fWidth, fHeight;
47 GetDimensions( fWidth, fHeight );
48 PivotPos( vecPivotPos.x, vecPivotPos.y, fWidth, fHeight );
49
50 AGUI2::GetRenderer()->PushTransform( m_oTransform, vecAnchorPos, vecPivotPos );
51}
52
54{
55#if 0
56 {
57 TFLOAT fWidth;
58 TFLOAT fHeight;
59 GetDimensions(fWidth, fHeight);
60 Toshi::TVector2 pos1 = { -fWidth / 2, -fHeight / 2 };
61 Toshi::TVector2 pos2 = { pos1.x + fWidth - 1, pos1.y + fHeight - 1 };
62
64 }
65#endif
66
67 for ( AGUI2Element* it = ChildRBegin(); it != TNULL && it != &m_Children; it = GetPrevChild( it ) )
68 {
69 if ( it->IsVisible() )
70 {
71 it->PreRender();
72 it->Render();
73 it->PostRender();
74 }
75 }
76
77 if ( m_cbPostRender )
78 {
80 }
81}
82
87
88void AGUI2Element::GetDimensions( TFLOAT& a_rWidth, TFLOAT& a_rHeight )
89{
90 a_rWidth = m_fWidth;
91 a_rHeight = m_fHeight;
92}
93
98
103
105{
106 m_fWidth = a_fWidth;
107}
108
110{
111 m_fHeight = a_fHeight;
112}
113
114void AGUI2Element::SetDimensions( TFLOAT a_fWidth, TFLOAT a_fHeight )
115{
116 m_fWidth = a_fWidth;
117 m_fHeight = a_fHeight;
118}
119
121{
122 TFLOAT fWidth, fHeight;
123 GetDimensions( fWidth, fHeight );
124 a_fX = fWidth * -0.5f;
125 a_fY = fHeight * -0.5f;
126}
127
129{
130 TFLOAT fWidth, fHeight;
131 GetDimensions( fWidth, fHeight );
132 a_fX = fWidth * 0.5f;
133 a_fY = fHeight * 0.5f;
134}
135
137{
138 m_uiColour = a_uiColour;
139}
140
142{
143 TUINT8 alpha8 = (TUINT8)( a_fAlpha * 255.0f );
144 m_uiColour = ( m_uiColour & 0x00FFFFFF ) | alpha8 << 24;
145}
146
148{
149}
150
152{
153 if ( a_bFocused )
154 {
155 m_eFlags |= 2;
156 }
157 else
158 {
159 m_eFlags &= ~2;
160 }
161}
162
164{
165 TFLOAT minX, minY;
166 TFLOAT maxX, maxY;
167
168 GetMins( minX, minY );
169 GetMaxs( maxX, maxY );
170
171 return ( minX <= a_fX && a_fX <= maxX ) && ( minY <= a_fY && a_fY <= maxY );
172}
173
174void AGUI2Element::AnchorPos( TFLOAT& a_rX, TFLOAT& a_rY, TFLOAT a_fWidth, TFLOAT a_fHeight )
175{
176 switch ( m_eAnchor )
177 {
179 a_rX -= a_fWidth * 0.5f;
180 a_rY -= a_fHeight * 0.5f;
181 break;
183 a_rY -= a_fHeight * 0.5f;
184 break;
186 a_rX += a_fWidth * 0.5f;
187 a_rY -= a_fHeight * 0.5f;
188 break;
190 a_rX -= a_fWidth * 0.5f;
191 break;
193 a_rX += a_fWidth * 0.5f;
194 break;
196 a_rX -= a_fWidth * 0.5f;
197 a_rY += a_fHeight * 0.5f;
198 break;
200 a_rY += a_fHeight * 0.5f;
201 break;
203 a_rX += a_fWidth * 0.5f;
204 a_rY += a_fHeight * 0.5f;
205 break;
206 }
207}
208
209void AGUI2Element::PivotPos( TFLOAT& a_rX, TFLOAT& a_rY, TFLOAT a_fWidth, TFLOAT a_fHeight )
210{
211 switch ( m_ePivot )
212 {
214 a_rX += a_fWidth * 0.5f;
215 a_rY += a_fHeight * 0.5f;
216 break;
218 a_rY += a_fHeight * 0.5f;
219 break;
221 a_rX -= a_fWidth * 0.5f;
222 a_rY += a_fHeight * 0.5f;
223 break;
225 a_rX += a_fWidth * 0.5f;
226 break;
228 a_rX -= a_fWidth * 0.5f;
229 break;
231 a_rX += a_fWidth * 0.5f;
232 a_rY -= a_fHeight * 0.5f;
233 break;
235 a_rY -= a_fHeight * 0.5f;
236 break;
238 a_rX -= a_fWidth * 0.5f;
239 a_rY -= a_fHeight * 0.5f;
240 break;
241 }
242}
243
245{
246 Toshi::TVector2 vecAnchorPos = { 0.0f, 0.0f };
247 Toshi::TVector2 vecPivotPos = { 0.0f, 0.0f };
248
249 if ( m_pParent != TNULL )
250 {
251 TFLOAT fParentWidth, fParentHeight;
252 m_pParent->GetDimensions( fParentWidth, fParentHeight );
253 AnchorPos( vecAnchorPos.x, vecAnchorPos.y, fParentWidth, fParentHeight );
254 }
255
256 TFLOAT fWidth, fHeight;
257 GetDimensions( fWidth, fHeight );
258 PivotPos( vecPivotPos.x, vecPivotPos.y, fWidth, fHeight );
259
260 AGUI2Transform transform1;
261 AGUI2Transform transform2;
262
263 if ( m_pParent )
264 {
265 m_pParent->GetScreenTransform( transform1 );
266 transform2 = GetTransform();
267 }
268 else
269 {
270 auto pDisplayParams = Toshi::TRenderInterface::GetSingleton()->GetCurrentDisplayParams();
271
272 transform1.m_aMatrixRows[ 0 ] = { 1.0f, 0.0f };
273 transform1.m_aMatrixRows[ 1 ] = { 0.0f, 1.0f };
274 transform1.m_vecTranslation = { pDisplayParams->uiWidth / 2.0f, pDisplayParams->uiHeight / 2.0f };
275
276 transform1.Scale( pDisplayParams->uiWidth / fWidth, pDisplayParams->uiHeight / fHeight );
277 transform2 = GetTransform();
278 }
279
280 Toshi::TVector2 vec;
281 transform1.Transform( vec, vecAnchorPos );
282 transform1.m_vecTranslation = { vec.x, vec.y };
283
284 transform2.Transform( vec, vecPivotPos );
285 transform2.m_vecTranslation = { vec.x, vec.y };
286
287 AGUI2Transform::Multiply( a_rOutTransform, transform1, transform2 );
288}
289
291{
292 AGUI2Transform transform;
293 GetScreenTransform( transform );
294 transform.GetInverse( a_rOutTransform );
295}
Rendering system interface for the Toshi engine.
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
bool TBOOL
Definition Typedefs.h:6
@ AGUI2ATTACHMENT_TOPLEFT
@ AGUI2ATTACHMENT_MIDDLELEFT
@ AGUI2ATTACHMENT_MIDDLECENTER
@ AGUI2ATTACHMENT_BOTTOMLEFT
@ AGUI2ATTACHMENT_MIDDLERIGHT
@ AGUI2ATTACHMENT_BOTTOMRIGHT
@ AGUI2ATTACHMENT_TOPRIGHT
@ AGUI2ATTACHMENT_BOTTOMCENTER
@ AGUI2ATTACHMENT_TOPCENTER
static AGUI2Renderer * GetRenderer()
Definition AGUI2.cpp:239
AGUI2Transform & GetTransform()
TUINT32 m_uiVisibilityMask
virtual void Render()
void AnchorPos(TFLOAT &a_rX, TFLOAT &a_rY, TFLOAT a_fWidth, TFLOAT a_fHeight)
TUINT32 m_eFlags
TUINT32 m_uiColour
virtual void GetMaxs(TFLOAT &a_fX, TFLOAT &a_fY)
virtual void SetWidth(TFLOAT a_fWidth)
AGUI2ATTACHMENT m_eAnchor
AGUI2Transform m_oTransform
AGUI2ElementNode m_Children
void PivotPos(TFLOAT &a_rX, TFLOAT &a_rY, TFLOAT a_fWidth, TFLOAT a_fHeight)
virtual void GetMins(TFLOAT &a_fX, TFLOAT &a_fY)
virtual TFLOAT GetHeight()
virtual TFLOAT GetWidth()
virtual void PreRender()
virtual void GetDimensions(TFLOAT &a_rWidth, TFLOAT &a_rHeight)
void GetScreenTransform(AGUI2Transform &a_rOutTransform)
AGUI2Element * GetPrevChild(AGUI2Element *a_pCurrentChild)
virtual void PostRender()
virtual void SetColour(TUINT32 a_uiColour)
virtual void Tick(TFLOAT a_fDeltaTime)
virtual void SetShadowAlpha(TFLOAT a_fAlpha)
t_PostRender m_cbPostRender
AGUI2Element * m_pParent
void GetInvScreenTransform(AGUI2Transform &a_rOutTransform)
AGUI2ATTACHMENT m_ePivot
AGUI2Element * ChildRBegin() const
virtual TBOOL IsPointInside(TFLOAT a_fX, TFLOAT a_fY)
virtual void SetDimensions(TFLOAT a_fWidth, TFLOAT a_fHeight)
virtual void SetHeight(TFLOAT a_fHeight)
virtual void SetFocus(TBOOL a_bFocused)
virtual void SetAlpha(TFLOAT a_fAlpha)
virtual void PopTransform()=0
virtual void PushTransform(const AGUI2Transform &a_rTransform, const Toshi::TVector2 &a_rVec1, const Toshi::TVector2 &a_rVec2)=0
virtual void RenderOutlineRectangle(const Toshi::TVector2 &a, const Toshi::TVector2 &b)=0
void Transform(Toshi::TVector2 &a_rOutVec, const Toshi::TVector2 &a_rTransformVec) const
Toshi::TVector2 m_vecTranslation
Toshi::TVector2 m_aMatrixRows[2]
static void Multiply(AGUI2Transform &a_rOutTransform, const AGUI2Transform &a_rA, const AGUI2Transform &a_rB)
void Scale(TFLOAT a_fScaleX, TFLOAT a_fScaleY)
void GetInverse(AGUI2Transform &a_rInverse) const