OpenBarnyard
 
Loading...
Searching...
No Matches
AGUI2Button.cpp
Go to the documentation of this file.
1#include "pch.h"
2#include "AGUI2Button.h"
4
5//-----------------------------------------------------------------------------
6// Enables memory debugging.
7// Note: Should be the last include!
8//-----------------------------------------------------------------------------
10
12{
13 m_bScaleOnFocus = TTRUE;
14 m_bFocused = TFALSE;
15 m_fRectangle1Width = 0.0f;
16 m_fRectangle1Height = 0.0f;
17 m_bUseRectangle1 = TFALSE;
18 m_Unk3 = 0;
19 m_uiFocusedColour = 0xffffff80;
20 m_uiEnabledColour = 0xffffffff;
21 m_uiDisabledColour = 0xffc0c0c0;
22 m_fFocusedScale = 1.25f;
23 m_fScale = 1.0f;
24 m_pFont = TNULL;
25 m_fGap = 0.0f;
26 m_wszButtonText = TNULL;
27}
28
30{
31 m_oBackgroundRect.Unlink();
32}
33
34void AGUI2Button::Create( AGUI2Font* a_pFont, TFLOAT a_fWidth, const TWCHAR* a_wszText, TFLOAT a_fGap )
35{
36 TVALIDPTR( a_pFont );
37 TVALIDPTR( a_wszText );
38
39 m_fGap = a_fGap;
40 m_pFont = a_pFont;
41
42 m_oText.Create( a_pFont, a_fWidth );
43 SetButtonColour( m_uiEnabledColour );
44
45 if ( m_bScaleOnFocus )
46 m_oTransform.SetScale( m_fScale, m_fScale );
47
48 m_oText.SetText( a_wszText );
49 AddChildTail( m_oText );
50
52 m_oText.SetTextAlign( AGUI2Font::TextAlign_Center );
53}
54
55void AGUI2Button::SetImage( const TCHAR* a_szTexSec, TFLOAT a_fScaleX, TFLOAT a_fScaleY )
56{
57 TVALIDPTR( a_szTexSec );
58
60 TVALIDPTR( pTexSec );
61
62 TFLOAT fHeight = m_oText.GetHeight() * a_fScaleY;
63 TFLOAT fWidth = m_oText.GetWidth() * a_fScaleX;
64 m_oBackgroundRect.SetDimensions( fWidth, fHeight );
65 m_oBackgroundRect.SetTextureSection( pTexSec );
66 m_oBackgroundRect.SetAttachment( AGUI2ATTACHMENT_MIDDLECENTER, AGUI2ATTACHMENT_MIDDLECENTER );
67 LinkChildBefore( m_oBackgroundRect, m_oText );
68}
69
70void AGUI2Button::GetDimensions( TFLOAT& a_rWidth, TFLOAT& a_rHeight )
71{
72 m_oText.GetDimensions( a_rWidth, a_rHeight );
73}
74
76{
77 m_oText.SetAlpha( a_fAlpha );
78 m_Rectangle1.SetAlpha( a_fAlpha );
79 m_oBackgroundRect.SetAlpha( a_fAlpha );
80
81 for ( auto it = m_oText.ChildRBegin(); it != TNULL; it = m_oText.GetPrevChild( it ) )
82 {
83 it->SetAlpha( a_fAlpha );
84 }
85
86 AGUI2MenuItem::SetAlpha( a_fAlpha );
87}
88
90{
91 m_oText.SetShadowAlpha( a_fAlpha );
92
93 for ( auto it = m_oText.ChildRBegin(); it != TNULL; it = m_oText.GetPrevChild( it ) )
94 {
95 it->SetShadowAlpha( a_fAlpha );
96 }
97
99}
100
102{
103 m_bFocused = TTRUE;
104
105 if ( m_bScaleOnFocus )
106 m_oTransform.SetScale( m_fFocusedScale, m_fFocusedScale );
107
108 SetButtonColour( m_uiFocusedColour );
109
110 if ( m_bUseRectangle1 )
111 {
112 TFLOAT fWidth, fHeight;
113 GetDimensions( fWidth, fHeight );
114
115 m_Rectangle1.SetDimensions( fWidth + m_fRectangle1Width, fHeight + m_fRectangle1Height );
116 LinkChildBefore( m_Rectangle1, m_oText );
117 }
118}
119
121{
122 m_bFocused = TFALSE;
123
124 if ( m_bScaleOnFocus )
125 m_oTransform.SetScale( m_fScale, m_fScale );
126
127 SetButtonColour( IsEnabled() ? m_uiEnabledColour : m_uiDisabledColour );
128
129 if ( m_bUseRectangle1 )
130 m_Rectangle1.RemoveSelf();
131}
132
134{
135 if ( IsEnabled() != a_bEnabled )
136 {
137 AGUI2MenuItem::SetEnabled( a_bEnabled );
138
139 SetButtonColour( IsEnabled() ? m_uiEnabledColour : m_uiDisabledColour );
140 }
141}
142
144{
145 TVALIDPTR( m_pFont );
146 return m_pFont->GetLinesMargin() * 0.5f + m_fGap;
147}
148
150{
151 TVALIDPTR( m_pFont );
152 return m_pFont->GetLinesMargin() * 0.5f + m_fGap;
153}
154
155void AGUI2Button::SetButtonColour( TUINT a_uiColour )
156{
157 m_oText.SetColour( a_uiColour );
158
159 for ( auto it = m_oText.ChildRBegin(); it != TNULL; it = m_oText.GetPrevChild( it ) )
160 {
161 it->SetColour( a_uiColour );
162 }
163}
#define TVALIDPTR(PTR)
Definition Defines.h:139
wchar_t TWCHAR
Definition Typedefs.h:21
unsigned int TUINT
Definition Typedefs.h:8
char TCHAR
Definition Typedefs.h:20
float TFLOAT
Definition Typedefs.h:4
#define TNULL
Definition Typedefs.h:23
#define TFALSE
Definition Typedefs.h:24
#define TTRUE
Definition Typedefs.h:25
bool TBOOL
Definition Typedefs.h:6
@ AGUI2ATTACHMENT_MIDDLECENTER
virtual void SetAlpha(TFLOAT a_fAlpha) override
virtual TFLOAT GetFlowVisualOffset() override
virtual void OnFocusLost() override
virtual void SetShadowAlpha(TFLOAT a_fAlpha) override
virtual void GetDimensions(TFLOAT &a_rWidth, TFLOAT &a_rHeight) override
void SetImage(const TCHAR *a_szTexSec, TFLOAT a_fScaleX, TFLOAT a_fScaleY)
virtual void OnFocus() override
virtual TFLOAT GetFlowOffset() override
void Create(AGUI2Font *a_pFont, TFLOAT a_fWidth, const TWCHAR *a_wszText, TFLOAT a_fGap)
virtual void SetEnabled(TBOOL a_bEnabled) override
void AddChildTail(AGUI2Element &a_rElement)
AGUI2Transform m_oTransform
AGUI2Element * GetPrevChild(AGUI2Element *a_pCurrentChild)
virtual void SetColour(TUINT32 a_uiColour)
virtual void SetShadowAlpha(TFLOAT a_fAlpha)
void LinkChildBefore(AGUI2Element &a_rNewChildren, AGUI2Element &a_rInsertAfter)
AGUI2Element * ChildRBegin() const
TBOOL Create(AGUI2FontDef *a_pFontDef)
Definition AGUI2Font.cpp:13
@ TextAlign_Center
Definition AGUI2Font.h:40
virtual void SetEnabled(TBOOL a_bEnabled)
TBOOL IsEnabled() const
Definition AGUI2Menu.h:105
virtual void SetAlpha(TFLOAT a_fAlpha) override
static AGUI2TextureSection * GetTextureSection(const TCHAR *a_szSectionName)