summaryrefslogtreecommitdiff
path: root/vgui2/dme_controls/DmeSourceSkinPanel.cpp
blob: 294fe05977c172ad2c5dec4af258db7fa98bbfe7 (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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
//=============================================================================

#include "dme_controls/DmeSourceSkinPanel.h"
#include "dme_controls/DmePanel.h"
#include "movieobjects/dmemdlmakefile.h"
#include "vgui_controls/TextEntry.h"
#include "vgui_controls/CheckButton.h"
#include "tier1/KeyValues.h"

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"


using namespace vgui;


//-----------------------------------------------------------------------------
//
// Hook into the dme panel editor system
//
//-----------------------------------------------------------------------------
IMPLEMENT_DMEPANEL_FACTORY( CDmeSourceSkinPanel, DmeSourceSkin, "DmeSourceSkinDefault", "MDL Skin Editor", true );



//-----------------------------------------------------------------------------
// Purpose: Constructor, destructor
//-----------------------------------------------------------------------------
CDmeSourceSkinPanel::CDmeSourceSkinPanel( vgui::Panel *pParent, const char *pPanelName ) : 
	BaseClass( pParent, pPanelName )
{	
	m_pSkinName = new vgui::TextEntry( this, "SkinName" );
	m_pSkinName->AddActionSignalTarget( this );

	m_pScale = new vgui::TextEntry( this, "Scale" );
	m_pScale->AddActionSignalTarget( this );

	m_pFlipTriangles = new vgui::CheckButton( this, "FlipTriangles", "" );
	m_pFlipTriangles->AddActionSignalTarget( this );

	// Load layout settings; has to happen before pinning occurs in code
	LoadControlSettings( "resource/DmeSourceSkinPanel.res" );
}

CDmeSourceSkinPanel::~CDmeSourceSkinPanel()
{
}


//-----------------------------------------------------------------------------
// Marks the file as dirty (or not)
//-----------------------------------------------------------------------------
void CDmeSourceSkinPanel::SetDirty()
{
	PostActionSignal( new KeyValues( "DmeElementChanged" ) );
}


//-----------------------------------------------------------------------------
// Resets the state
//-----------------------------------------------------------------------------
void CDmeSourceSkinPanel::SetDmeElement( CDmeSourceSkin *pSourceSkin )
{
	m_hSourceSkin = pSourceSkin;

	bool bEnabled = (pSourceSkin != NULL);
	m_pSkinName->SetEnabled( bEnabled );
	m_pScale->SetEnabled( bEnabled );
	m_pFlipTriangles->SetEnabled( bEnabled );
	if ( !bEnabled )
	{
		m_pSkinName->SetText( "" );
		m_pScale->SetText( "" );
		m_pFlipTriangles->SetSelected( false );
		return;
	}

	char pBuf[32];
	Q_snprintf( pBuf, sizeof(pBuf), "%.3f", pSourceSkin->m_flScale.Get() );
	m_pSkinName->SetText( pSourceSkin->m_SkinName );
	m_pScale->SetText( pBuf );
	m_pFlipTriangles->SetSelected( pSourceSkin->m_bFlipTriangles );
}


//-----------------------------------------------------------------------------
// Command handler
//-----------------------------------------------------------------------------
void CDmeSourceSkinPanel::OnCheckButtonChecked( int nChecked )
{
	if ( !m_hSourceSkin.Get() )
		return;

	bool bFlipTriangles = ( nChecked != 0 );
	if ( bFlipTriangles != m_hSourceSkin->m_bFlipTriangles )
	{
		m_hSourceSkin->m_bFlipTriangles = bFlipTriangles;
		SetDirty();
	}
}


//-----------------------------------------------------------------------------
// Called when something is typed in a text entry field
//-----------------------------------------------------------------------------
void CDmeSourceSkinPanel::OnTextChanged( KeyValues *kv )
{
	if ( !m_hSourceSkin.Get() )
		return;

	Panel *pPanel = (Panel *)kv->GetPtr( "panel", NULL );
	if ( pPanel == m_pSkinName )
	{
		char pTextBuf[256];
		m_pSkinName->GetText( pTextBuf, sizeof( pTextBuf) );
		if ( Q_stricmp( pTextBuf, m_hSourceSkin->m_SkinName ) )
		{
			m_hSourceSkin->m_SkinName = pTextBuf;
			SetDirty();
		}
		return;
	}

	if ( pPanel == m_pScale )
	{
		char pTextBuf[256];
		m_pScale->GetText( pTextBuf, sizeof( pTextBuf) );
		float flScale = atoi( pTextBuf );
		if ( flScale != m_hSourceSkin->m_flScale )
		{
			m_hSourceSkin->m_flScale = flScale;
			SetDirty();
		}
		return;
	}
}