summaryrefslogtreecommitdiff
path: root/vgui2/dme_controls/AttributeTextPanel.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/AttributeTextPanel.cpp
downloadarchived-source-engine-2018-hl2-src-master.tar.xz
archived-source-engine-2018-hl2-src-master.zip
Diffstat (limited to 'vgui2/dme_controls/AttributeTextPanel.cpp')
-rw-r--r--vgui2/dme_controls/AttributeTextPanel.cpp119
1 files changed, 119 insertions, 0 deletions
diff --git a/vgui2/dme_controls/AttributeTextPanel.cpp b/vgui2/dme_controls/AttributeTextPanel.cpp
new file mode 100644
index 0000000..c956f06
--- /dev/null
+++ b/vgui2/dme_controls/AttributeTextPanel.cpp
@@ -0,0 +1,119 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//
+//=============================================================================//
+
+#include "dme_controls/AttributeTextPanel.h"
+#include "dme_controls/AttributeTextEntry.h"
+#include "dme_controls/AttributeWidgetFactory.h"
+#include "tier1/KeyValues.h"
+#include "datamodel/dmelement.h"
+#include "movieobjects/dmeeditortypedictionary.h"
+#include "dme_controls/inotifyui.h"
+
+// memdbgon must be the last include file in a .cpp file!!!
+#include "tier0/memdbgon.h"
+
+
+using namespace vgui;
+
+
+//-----------------------------------------------------------------------------
+// CAttributeTextPanel constructor
+//-----------------------------------------------------------------------------
+CAttributeTextPanel::CAttributeTextPanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) :
+ BaseClass( parent, info ), m_pData( 0 ), m_bShowMemoryUsage( info.m_bShowMemoryUsage )
+{
+ m_pData = new CAttributeTextEntry( this, "AttributeValue" );
+ m_pData->SetEnabled( !HasFlag( READONLY ) );
+
+ m_pData->AddActionSignalTarget(this);
+ SetAllowKeyBindingChainToParent( false );
+}
+
+void CAttributeTextPanel::SetFont( HFont font )
+{
+ BaseClass::SetFont( font );
+ m_pData->SetFont( font );
+}
+
+//-----------------------------------------------------------------------------
+// Returns the text type
+//-----------------------------------------------------------------------------
+const char *CAttributeTextPanel::GetTextType()
+{
+ // If a specific text type is specified, then filter if it doesn't match
+ CDmeEditorAttributeInfo *pInfo = GetEditorInfo();
+ const char *pTextType = pInfo ? pInfo->GetValueString( "texttype" ) : NULL;
+ return pTextType ? pTextType : "";
+}
+
+
+void CAttributeTextPanel::Apply()
+{
+ char txt[ 256 ];
+ m_pData->GetText( txt, sizeof( txt ) );
+
+ // Apply means we no longer look blue
+ SetDirty( false );
+
+ if ( GetAttributeType( ) == AT_UNKNOWN )
+ {
+ CElementTreeUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG, GetNotify(), "Set Attribute Value", "Set Attribute Value" );
+ SetAttributeValue( "" );
+ return;
+ }
+
+ char curvalue[ 256 ];
+ GetAttributeValueAsString( curvalue, sizeof( curvalue ) );
+
+ // Only if differnt
+ if ( Q_strcmp( curvalue, txt ) )
+ {
+ CElementTreeUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG, GetNotify(), "Set Attribute Value", "Set Attribute Value" );
+ SetAttributeValueFromString( txt );
+ }
+}
+
+vgui::Panel *CAttributeTextPanel::GetDataPanel()
+{
+ return static_cast< vgui::Panel * >( m_pData );
+}
+
+void CAttributeTextPanel::Refresh()
+{
+ char buf[ 512 ];
+ if ( IsArrayType( GetAttributeType() ) )
+ {
+ int count = GetAttributeArrayCount();
+ if ( m_bShowMemoryUsage )
+ {
+ CDmAttribute *pAttr = GetPanelElement()->GetAttribute( GetAttributeName() );
+ Q_snprintf( buf, sizeof( buf ), "%d items %.3fMB", count, pAttr->EstimateMemoryUsage( TD_DEEP ) / float( 1 << 20 ) );
+ }
+ else
+ {
+ Q_snprintf( buf, sizeof( buf ), "%d items", count );
+ }
+ m_pData->SetText( buf );
+ m_pData->SetEnabled(false);
+ }
+ else if ( GetAttributeType() == AT_ELEMENT )
+ {
+ m_pData->SetText( "" );
+ }
+ else
+ {
+ GetAttributeValueAsString( buf, sizeof( buf ) );
+ m_pData->SetText( buf );
+ }
+}
+
+void CAttributeTextPanel::PostConstructor()
+{
+ Refresh();
+}
+