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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#include "dme_controls/AttributeColorPickerPanel.h"
#include "datamodel/dmelement.h"
#include "vgui_controls/Button.h"
#include "dme_controls/AttributeTextEntry.h"
#include "matsys_controls/colorpickerpanel.h"
#include "tier1/KeyValues.h"
#include "dme_controls/inotifyui.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CAttributeColorPickerPanel::CAttributeColorPickerPanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) :
BaseClass( parent, info )
{
m_pOpen = new vgui::Button( this, "Open", "", this, "open" );
}
void CAttributeColorPickerPanel::OnCommand( char const *cmd )
{
if ( !Q_stricmp( cmd, "open" ) )
{
m_InitialColor = GetAttributeValue<Color>();
CColorPickerFrame *pColorPickerDialog = new CColorPickerFrame( this, "Select Color" );
pColorPickerDialog->AddActionSignalTarget( this );
pColorPickerDialog->DoModal( m_InitialColor );
}
else
{
BaseClass::OnCommand( cmd );
}
}
//-----------------------------------------------------------------------------
// Update button color
//-----------------------------------------------------------------------------
void CAttributeColorPickerPanel::UpdateButtonColor()
{
Color clr = GetAttributeValue<Color>();
m_pOpen->SetDefaultColor( clr, clr );
m_pOpen->SetArmedColor( clr, clr );
m_pOpen->SetDepressedColor( clr, clr );
}
//-----------------------------------------------------------------------------
// Used to set the current color on the picker button
//-----------------------------------------------------------------------------
void CAttributeColorPickerPanel::Refresh()
{
BaseClass::Refresh();
UpdateButtonColor();
}
void CAttributeColorPickerPanel::ApplySchemeSettings(IScheme *pScheme)
{
// Need to override the scheme settings for this button
BaseClass::ApplySchemeSettings( pScheme );
UpdateButtonColor();
}
//-----------------------------------------------------------------------------
// Called when the picker gets a new color but apply hasn't happened yet
//-----------------------------------------------------------------------------
void CAttributeColorPickerPanel::OnPreview( KeyValues *data )
{
{
CDisableUndoScopeGuard guard;
Color c = data->GetColor( "color" );
SetAttributeValue( c );
}
Refresh( );
if ( IsAutoApply() )
{
// NOTE: Don't call Apply since that generates an undo record
CElementTreeNotifyScopeGuard guard( "CAttributeColorPickerPanel::OnPreview", NOTIFY_CHANGE_ATTRIBUTE_VALUE, GetNotify() );
}
else
{
SetDirty( true );
}
}
//-----------------------------------------------------------------------------
// Called when cancel is hit in the picker
//-----------------------------------------------------------------------------
void CAttributeColorPickerPanel::OnCancelled( )
{
// Restore the initial color
CDisableUndoScopeGuard guard;
SetAttributeValue( m_InitialColor );
Refresh( );
CElementTreeNotifyScopeGuard notify( "CAttributeColorPickerPanel::OnCancelled", NOTIFY_CHANGE_ATTRIBUTE_VALUE, GetNotify() );
SetDirty( false );
}
//-----------------------------------------------------------------------------
// Called when the picker gets a new color
//-----------------------------------------------------------------------------
void CAttributeColorPickerPanel::OnPicked( KeyValues *data )
{
Color c = data->GetColor( "color" );
if ( c == m_InitialColor )
{
SetDirty( false );
return;
}
// Kind of an evil hack, but "undo" copies the "old value" off for doing undo, and that value is the new value because
// we haven't been tracking undo while manipulating this. So we'll turn off undo and set the value to the original value.
// In effect, all of the wheeling will drop out and it'll look just like we started at the original value and ended up at the
// final value...
{
CDisableUndoScopeGuard guard;
SetAttributeValue( m_InitialColor );
}
{
CElementTreeUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG, GetNotify(), "Set Attribute Value", "Set Attribute Value" );
SetAttributeValue( c );
}
if ( IsAutoApply() )
{
Refresh();
SetDirty( false );
}
}
//-----------------------------------------------------------------------------
// Lays out the button position
//-----------------------------------------------------------------------------
void CAttributeColorPickerPanel::PerformLayout()
{
BaseClass::PerformLayout();
int x, y, w, h;
m_pType->GetBounds( x, y, w, h );
int inset = 25;
m_pType->SetWide( w - inset );
x += w;
x -= inset;
h -= 2;
m_pOpen->SetBounds( x, y, inset, h );
}
|