summaryrefslogtreecommitdiff
path: root/vgui2/dme_controls/AttributeColorPickerPanel.cpp
diff options
context:
space:
mode:
authorFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
committerFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
commit3bf9df6b2785fa6d951086978a3e66f49427166a (patch)
tree2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /vgui2/dme_controls/AttributeColorPickerPanel.cpp
downloadarchived-source-engine-2018-hl2-src-master.tar.xz
archived-source-engine-2018-hl2-src-master.zip
Diffstat (limited to 'vgui2/dme_controls/AttributeColorPickerPanel.cpp')
-rw-r--r--vgui2/dme_controls/AttributeColorPickerPanel.cpp170
1 files changed, 170 insertions, 0 deletions
diff --git a/vgui2/dme_controls/AttributeColorPickerPanel.cpp b/vgui2/dme_controls/AttributeColorPickerPanel.cpp
new file mode 100644
index 0000000..11e5e3c
--- /dev/null
+++ b/vgui2/dme_controls/AttributeColorPickerPanel.cpp
@@ -0,0 +1,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 );
+}