summaryrefslogtreecommitdiff
path: root/game/client/dod/VGUI/dodcornercutpanel.cpp
blob: bc8dc684777d9d4e758c060991a9f8898ae64938 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
//=============================================================================//

#include "cbase.h"
#include <vgui_controls/EditablePanel.h>
#include <vgui_controls/ImagePanel.h>
#include <vgui/ISurface.h>
#include <KeyValues.h>
#include "dodcornercutpanel.h"

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
CDoDCutEditablePanel::CDoDCutEditablePanel( vgui::Panel *parent, const char *name ) : vgui::EditablePanel( parent, name )
{
	m_nCornerToCut = DOD_CORNERCUT_PANEL_BOTTOMRIGHT;
	m_nCornerCutSize = 1;

	memset( m_szBackgroundTexture, 0, sizeof( m_szBackgroundTexture ) );
	memset( m_szBackgroudColor, 0, sizeof( m_szBackgroudColor ) );
	memset( m_szBorderColor, 0, sizeof( m_szBorderColor ) );
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CDoDCutEditablePanel::SetBorder( vgui::IBorder *border )
{
	BaseClass::SetBorder( border );
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CDoDCutEditablePanel::ApplySettings( KeyValues *inResourceData )
{
	BaseClass::ApplySettings( inResourceData );

	// check to see if we have a new name assigned
	Q_strncpy( m_szBackgroundTexture, inResourceData->GetString( "BackgroundTexture", "vgui/white" ), sizeof( m_szBackgroundTexture ) );
	Q_strncpy( m_szBackgroudColor, inResourceData->GetString( "BackgroundColor", "HudPanelForeground" ), sizeof( m_szBackgroudColor ) );
	Q_strncpy( m_szBorderColor, inResourceData->GetString( "BackgroundBorder", "HudPanelBorder" ), sizeof( m_szBorderColor ) );

	m_iBackgroundTexture = vgui::surface()->DrawGetTextureId( m_szBackgroundTexture );
	if ( m_iBackgroundTexture == -1 )
	{
		m_iBackgroundTexture = vgui::surface()->CreateNewTextureID();
	}

	vgui::surface()->DrawSetTextureFile( m_iBackgroundTexture, m_szBackgroundTexture, true, true );

	m_nCornerCutSize = inResourceData->GetInt( "CornerCutSize", 1 );

	// scale the cut size to our screen co-ords
	if ( IsProportional() )
	{
		m_nCornerCutSize = vgui::scheme()->GetProportionalScaledValueEx( GetScheme(), m_nCornerCutSize );
	}
	
	const char *pszCorner = inResourceData->GetString( "CornerToCut", "" );
	if ( pszCorner )
	{
		if ( !Q_strcmp( pszCorner, "bottom_right" ) )
		{
			m_nCornerToCut = DOD_CORNERCUT_PANEL_BOTTOMRIGHT;
		}
		else if ( !Q_strcmp( pszCorner, "bottom_left" ) )
		{
			m_nCornerToCut = DOD_CORNERCUT_PANEL_BOTTOMLEFT;
		}
		else if ( !Q_strcmp( pszCorner, "top_right" ) )
		{
			m_nCornerToCut = DOD_CORNERCUT_PANEL_TOPRIGHT;

		}
		else if ( !Q_strcmp( pszCorner, "top_left" ) )
		{
			m_nCornerToCut = DOD_CORNERCUT_PANEL_TOPLEFT;
		}
	}
    
	InvalidateLayout( false, true );
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CDoDCutEditablePanel::GetSettings( KeyValues *outResourceData )
{
	BaseClass::GetSettings( outResourceData );

	outResourceData->SetString( "BackgroundTexture", m_szBackgroundTexture);
	outResourceData->SetString( "BackgroundColor", m_szBackgroudColor);
	outResourceData->SetString( "BackgroundBorder", m_szBorderColor);
	outResourceData->SetFloat( "CornerCutSize", m_nCornerCutSize );

	const char *pszCorner = NULL;
	switch( m_nCornerToCut )
	{
	case DOD_CORNERCUT_PANEL_TOPLEFT:
		pszCorner = "top_left";
		break;
	case DOD_CORNERCUT_PANEL_TOPRIGHT:
		pszCorner = "top_right";
		break;
	case DOD_CORNERCUT_PANEL_BOTTOMLEFT:
		pszCorner = "bottom_left";
		break;
	case DOD_CORNERCUT_PANEL_BOTTOMRIGHT:
	default:
		pszCorner = "bottom_right";
		break;
	}
	outResourceData->SetString( "CornerToCut", pszCorner );
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CDoDCutEditablePanel::ApplySchemeSettings( vgui::IScheme *pScheme )
{
	BaseClass::ApplySchemeSettings( pScheme );

	SetBorder( NULL );

	m_clrBackground = pScheme->GetColor( m_szBackgroudColor, GetFgColor() );
	m_clrBorder = pScheme->GetColor( m_szBorderColor, GetBgColor() );
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CDoDCutEditablePanel::PaintBackground()
{
	vgui::Vertex_t lineverts[5];
	vgui::Vertex_t verts[5];

	int nwide, ntall;
	GetSize( nwide, ntall );

	int wide = nwide - 1; // -1 because we can't draw all the way out to the width of our panel (it gets clipped), we can only draw to width - 1
	int tall = ntall - 1; // (same as above)

	switch ( m_nCornerToCut )
	{
	case DOD_CORNERCUT_PANEL_TOPLEFT:
		verts[0].Init( Vector2D( m_nCornerCutSize, 0 ) );
		verts[1].Init( Vector2D( wide, 0 ) );
		verts[2].Init( Vector2D( wide, tall ) );
		verts[3].Init( Vector2D( 0, tall ) );
		verts[4].Init( Vector2D( 0, m_nCornerCutSize ) );

		lineverts[0].Init( Vector2D( m_nCornerCutSize-1, 0 ) );
		lineverts[1].Init( Vector2D( wide, 0 ) );
		lineverts[2].Init( Vector2D( wide, tall ) );
		lineverts[3].Init( Vector2D( 0, tall ) );
		lineverts[4].Init( Vector2D( 0, m_nCornerCutSize-1 ) );

		break;

	case DOD_CORNERCUT_PANEL_TOPRIGHT:
		verts[0].Init( Vector2D( 0, 0 ) );
		verts[1].Init( Vector2D( wide - m_nCornerCutSize, 0 ) );
		verts[2].Init( Vector2D( wide, m_nCornerCutSize ) );
		verts[3].Init( Vector2D( wide, tall ) );
		verts[4].Init( Vector2D( 0, tall ) );

		lineverts[0].Init( Vector2D( 0, 0 ) );
		lineverts[1].Init( Vector2D( wide - m_nCornerCutSize, 0 ) );
		lineverts[2].Init( Vector2D( wide, m_nCornerCutSize ) );
		lineverts[3].Init( Vector2D( wide, tall ) );
		lineverts[4].Init( Vector2D( 0, tall ) );

		break;

	case DOD_CORNERCUT_PANEL_BOTTOMLEFT:
		verts[0].Init( Vector2D( 0, 0 ) );
		verts[1].Init( Vector2D( wide, 0 ) );
		verts[2].Init( Vector2D( wide, tall ) );
		verts[3].Init( Vector2D( m_nCornerCutSize, tall ) );
		verts[4].Init( Vector2D( 0, tall - m_nCornerCutSize ) );

		lineverts[0].Init( Vector2D( 0, 0 ) );
		lineverts[1].Init( Vector2D( wide, 0 ) );
		lineverts[2].Init( Vector2D( wide, tall ) );
		lineverts[3].Init( Vector2D( m_nCornerCutSize, tall ) );
		lineverts[4].Init( Vector2D( 0, tall - m_nCornerCutSize ) );

		break;

	case DOD_CORNERCUT_PANEL_BOTTOMRIGHT:
	default:
		verts[0].Init( Vector2D( 0, 0 ) );
		verts[1].Init( Vector2D( wide, 0 ) );
		verts[2].Init( Vector2D( wide, tall - m_nCornerCutSize + 1 ) );
		verts[3].Init( Vector2D( wide - m_nCornerCutSize + 1, tall ) );
		verts[4].Init( Vector2D( 0, tall ) );

		lineverts[0].Init( Vector2D( 0, 0 ) );
		lineverts[1].Init( Vector2D( wide, 0 ) );
		lineverts[2].Init( Vector2D( wide, tall - m_nCornerCutSize ) );
		lineverts[3].Init( Vector2D( wide - m_nCornerCutSize, tall ) );
		lineverts[4].Init( Vector2D( 0, tall ) );

		break;
	}

	vgui::surface()->DrawSetTexture( m_iBackgroundTexture );
	vgui::surface()->DrawSetColor( m_clrBackground );
	vgui::surface()->DrawTexturedPolygon( 5, verts );

	vgui::surface()->DrawSetColor( m_clrBorder );
	vgui::surface()->DrawTexturedPolyLine( lineverts, 5 );
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CDoDCutEditablePanel::SetBackGroundColor( const char *pszNewColor )
{
	if ( !pszNewColor )
	{
		return;
	}

	Q_strncpy( m_szBackgroudColor, pszNewColor, sizeof( m_szBackgroudColor ) );
	InvalidateLayout( false, true );
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CDoDCutEditablePanel::SetBorderColor( const char *pszNewColor )
{
	if ( !pszNewColor )
	{
		return;
	}

	Q_strncpy( m_szBorderColor, pszNewColor, sizeof( m_szBorderColor ) );
	InvalidateLayout( false, true );
}