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
|
//========= 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();
}
|