diff options
| author | Joe Ludwig <[email protected]> | 2013-06-26 15:22:04 -0700 |
|---|---|---|
| committer | Joe Ludwig <[email protected]> | 2013-06-26 15:22:04 -0700 |
| commit | 39ed87570bdb2f86969d4be821c94b722dc71179 (patch) | |
| tree | abc53757f75f40c80278e87650ea92808274aa59 /sp/src/vgui2/vgui_controls/BuildFactoryHelper.cpp | |
| download | source-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.tar.xz source-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.zip | |
First version of the SOurce SDK 2013
Diffstat (limited to 'sp/src/vgui2/vgui_controls/BuildFactoryHelper.cpp')
| -rw-r--r-- | sp/src/vgui2/vgui_controls/BuildFactoryHelper.cpp | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/sp/src/vgui2/vgui_controls/BuildFactoryHelper.cpp b/sp/src/vgui2/vgui_controls/BuildFactoryHelper.cpp new file mode 100644 index 00000000..6d3743d3 --- /dev/null +++ b/sp/src/vgui2/vgui_controls/BuildFactoryHelper.cpp @@ -0,0 +1,104 @@ +//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose: Helper for the CHudElement class to add themselves to the list of hud elements
+//
+// $NoKeywords: $
+//=============================================================================//
+#include "vgui/IVGui.h"
+#include "vgui_controls/MessageMap.h"
+
+// memdbgon must be the last include file in a .cpp file!!!
+#include "tier0/memdbgon.h"
+
+using namespace vgui;
+
+// Start with empty list
+CBuildFactoryHelper *CBuildFactoryHelper::m_sHelpers = NULL;
+
+//-----------------------------------------------------------------------------
+// Purpose: Constructs a panel factory
+// Input : pfnCreate - fn Ptr to a function which generates a panel
+//-----------------------------------------------------------------------------
+CBuildFactoryHelper::CBuildFactoryHelper( char const *className, PANELCREATEFUNC func )
+{
+ // Make this fatal
+ if ( HasFactory( className ) )
+ {
+ Error( "CBuildFactoryHelper: Factory for '%s' already exists!!!!\n", className );
+ }
+
+ //List is empty, or element belongs at front, insert here
+ m_pNext = m_sHelpers;
+ m_sHelpers = this;
+
+ Assert( func );
+ m_CreateFunc = func;
+ Assert( className );
+ m_pClassName = className;
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Returns next object in list
+// Output : CBuildFactoryHelper
+//-----------------------------------------------------------------------------
+CBuildFactoryHelper *CBuildFactoryHelper::GetNext( void )
+{
+ return m_pNext;
+}
+
+char const *CBuildFactoryHelper::GetClassName() const
+{
+ return m_pClassName;
+}
+
+vgui::Panel *CBuildFactoryHelper::CreatePanel()
+{
+ if ( !m_CreateFunc )
+ return NULL;
+
+ return ( *m_CreateFunc )();
+}
+
+// private static meethod
+bool CBuildFactoryHelper::HasFactory( char const *className )
+{
+ CBuildFactoryHelper *p = m_sHelpers;
+ while ( p )
+ {
+ if ( !Q_stricmp( className, p->GetClassName() ) )
+ return true;
+
+ p = p->GetNext();
+ }
+ return false;
+}
+
+// static method
+vgui::Panel *CBuildFactoryHelper::InstancePanel( char const *className )
+{
+ CBuildFactoryHelper *p = m_sHelpers;
+ while ( p )
+ {
+ if ( !Q_stricmp( className, p->GetClassName() ) )
+ return p->CreatePanel();
+
+ p = p->GetNext();
+ }
+ return NULL;
+}
+
+// static method
+void CBuildFactoryHelper::GetFactoryNames( CUtlVector< char const * >& list )
+{
+ list.RemoveAll();
+
+ CBuildFactoryHelper *p = m_sHelpers;
+ while ( p )
+ {
+ list.AddToTail( p->GetClassName() );
+ p = p->GetNext();
+ }
+}
+
+
+
|