forked from hitmen047/Source-PlusPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVsVGuiWindow.h
195 lines (151 loc) · 5.38 KB
/
VsVGuiWindow.h
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
//===== Copyright © 1996-2006, Valve Corporation, All rights reserved. ======//
//
// Base class for windows that draw vgui in Maya
//
//===========================================================================//
#ifndef VSVGUIWINDOW_H
#define VSVGUIWINDOW_H
#ifdef _WIN32
#pragma once
#endif
#include "imayavgui.h"
#include "vgui_controls/Frame.h"
#include "tier1/utlmap.h"
#include "valveMaya.h"
//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
class IMayaVGui;
//-----------------------------------------------------------------------------
// The singleton is defined here twice just so we don't have to include valvemaya.h also
//-----------------------------------------------------------------------------
extern IMayaVGui *g_pMayaVGui;
//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
namespace vgui
{
class EditablePanel;
}
class CVsVGuiWindowBase
{
public:
virtual void SetPeriod( float flPeriod ) = 0;
virtual void StartTick() = 0;
virtual void StartTick( float flPeriod ) = 0;
virtual void StopTick() = 0;
virtual void Tick( float flElapsedTime ) = 0;
virtual void NonTimerTick() = 0;
};
//-----------------------------------------------------------------------------
// Creates, destroys a maya vgui window
//-----------------------------------------------------------------------------
CVsVGuiWindowBase *CreateMayaVGuiWindow( vgui::EditablePanel *pRootPanel, const char *pPanelName );
void DestroyMayaVGuiWindow( const char *pPanelName );
//-----------------------------------------------------------------------------
// Factory used to install vgui windows easily
//-----------------------------------------------------------------------------
class CVsVguiWindowFactoryBase : public IMayaVguiWindowFactory
{
public:
CVsVguiWindowFactoryBase( const char *pWindowTypeName, const char *pDccStartupCommand );
// Returns the DCC command
const char *GetDccStartupCommand() const;
// Registers/deregisters all vgui windows
static void RegisterAllVguiWindows( );
static void UnregisterAllVguiWindows( );
protected:
const char *m_pWindowTypeName;
const char *m_pDccStartupCommand;
private:
CVsVguiWindowFactoryBase *m_pNext;
static CVsVguiWindowFactoryBase *s_pFirstCommandFactory;
};
template< class T >
class CVsVguiWindowFactory : public CVsVguiWindowFactoryBase
{
typedef CVsVguiWindowFactoryBase BaseClass;
static bool StringLessFunc( const CUtlString &a, const CUtlString &b )
{
return StringLessThan( a.Get(), b.Get() );
}
public:
CVsVguiWindowFactory( const char *pWindowTypeName, const char *pDccCommand )
: BaseClass( pWindowTypeName, pDccCommand )
, m_panelMap( StringLessFunc )
{
}
struct PanelMapElem_s
{
CVsVGuiWindowBase *m_pVGuiWindow;
T *m_pPanel;
};
typedef CUtlMap< CUtlString, PanelMapElem_s > PanelMap_t;
virtual void CreateVguiWindow( const char *pPanelName )
{
T *pVGuiPanel = new T( NULL, pPanelName );
vgui::Frame *pFrame = dynamic_cast< vgui::Frame * >( pVGuiPanel );
if ( pFrame )
{
pFrame->SetSizeable( false );
pFrame->SetCloseButtonVisible( false );
pFrame->SetMoveable( false );
CVsVGuiWindowBase *pVGuiWindow = CreateMayaVGuiWindow( pVGuiPanel, pPanelName );
const CUtlString panelName( pPanelName );
PanelMap_t::IndexType_t nIndex = m_panelMap.Find( panelName );
if ( m_panelMap.IsValidIndex( nIndex ) )
{
merr << "[vsVguiWindow]: Panel \"" << pPanelName << "\" of Type: \"" << m_pWindowTypeName << "\" Already Exists!!!" << std::endl;
}
else
{
PanelMap_t::ElemType_t &element = m_panelMap.Element( m_panelMap.Insert( panelName ) );
element.m_pVGuiWindow = pVGuiWindow;
element.m_pPanel = pVGuiPanel;
}
}
}
virtual void DestroyVguiWindow( const char *pPanelName )
{
PanelMap_t::IndexType_t nIndex = m_panelMap.Find( pPanelName );
if ( !m_panelMap.IsValidIndex( nIndex ) )
return;
PanelMap_t::ElemType_t &element = m_panelMap.Element( nIndex );
delete element.m_pPanel;
m_panelMap.Remove( CUtlString( pPanelName ) );
DestroyMayaVGuiWindow( pPanelName );
}
virtual vgui::Frame *GetVGuiPanel( const char *pPanelName = NULL )
{
if ( pPanelName )
{
PanelMap_t::IndexType_t nPanelIndex = m_panelMap.Find( CUtlString( pPanelName ) );
if ( m_panelMap.IsValidIndex( nPanelIndex ) )
return dynamic_cast< vgui::Frame * >( m_panelMap.Element( nPanelIndex ).m_pPanel );
}
else if ( m_panelMap.Count() > 0 )
{
return dynamic_cast< vgui::Frame * >( m_panelMap.Element( m_panelMap.FirstInorder() ).m_pPanel );
}
return NULL;
}
virtual CVsVGuiWindowBase *GetVGuiWindow( const char *pPanelName = NULL )
{
if ( pPanelName )
{
PanelMap_t::IndexType_t nPanelIndex = m_panelMap.Find( CUtlString( pPanelName ) );
if ( m_panelMap.IsValidIndex( nPanelIndex ) )
return m_panelMap.Element( nPanelIndex ).m_pVGuiWindow;
}
else if ( m_panelMap.Count() > 0 )
{
return m_panelMap.Element( m_panelMap.FirstInorder() ).m_pVGuiWindow;
}
return NULL;
}
private:
PanelMap_t m_panelMap;
};
#define INSTALL_MAYA_VGUI_WINDOW( _className, _windowTypeName, _dccCommand ) \
static CVsVguiWindowFactory< _className > s_VsVguiWindowFactory##_className##( _windowTypeName, _dccCommand )
#endif // VSVGUIWINDOW_H