Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

195 lines
5.6 KiB

  1. //===== Copyright � 1996-2006, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Base class for windows that draw vgui in Maya
  4. //
  5. //===========================================================================//
  6. #ifndef VSVGUIWINDOW_H
  7. #define VSVGUIWINDOW_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "imayavgui.h"
  12. #include "vgui_controls/Frame.h"
  13. #include "tier1/UtlMap.h"
  14. #include "valveMaya.h"
  15. //-----------------------------------------------------------------------------
  16. // Forward declarations
  17. //-----------------------------------------------------------------------------
  18. class IMayaVGui;
  19. //-----------------------------------------------------------------------------
  20. // The singleton is defined here twice just so we don't have to include valvemaya.h also
  21. //-----------------------------------------------------------------------------
  22. extern IMayaVGui *g_pMayaVGui;
  23. //-----------------------------------------------------------------------------
  24. // Forward declarations
  25. //-----------------------------------------------------------------------------
  26. namespace vgui
  27. {
  28. class EditablePanel;
  29. }
  30. class CVsVGuiWindowBase
  31. {
  32. public:
  33. virtual void SetPeriod( float flPeriod ) = 0;
  34. virtual void StartTick() = 0;
  35. virtual void StartTick( float flPeriod ) = 0;
  36. virtual void StopTick() = 0;
  37. virtual void Tick( float flElapsedTime ) = 0;
  38. virtual void NonTimerTick() = 0;
  39. };
  40. //-----------------------------------------------------------------------------
  41. // Creates, destroys a maya vgui window
  42. //-----------------------------------------------------------------------------
  43. CVsVGuiWindowBase *CreateMayaVGuiWindow( vgui::EditablePanel *pRootPanel, const char *pPanelName );
  44. void DestroyMayaVGuiWindow( const char *pPanelName );
  45. //-----------------------------------------------------------------------------
  46. // Factory used to install vgui windows easily
  47. //-----------------------------------------------------------------------------
  48. class CVsVguiWindowFactoryBase : public IMayaVguiWindowFactory
  49. {
  50. public:
  51. CVsVguiWindowFactoryBase( const char *pWindowTypeName, const char *pDccStartupCommand );
  52. // Returns the DCC command
  53. const char *GetDccStartupCommand() const;
  54. // Registers/deregisters all vgui windows
  55. static void RegisterAllVguiWindows( );
  56. static void UnregisterAllVguiWindows( );
  57. protected:
  58. const char *m_pWindowTypeName;
  59. const char *m_pDccStartupCommand;
  60. private:
  61. CVsVguiWindowFactoryBase *m_pNext;
  62. static CVsVguiWindowFactoryBase *s_pFirstCommandFactory;
  63. };
  64. template< class T >
  65. class CVsVguiWindowFactory : public CVsVguiWindowFactoryBase
  66. {
  67. typedef CVsVguiWindowFactoryBase BaseClass;
  68. static bool StringLessFunc( const CUtlString &a, const CUtlString &b )
  69. {
  70. return StringLessThan( a.Get(), b.Get() );
  71. }
  72. public:
  73. CVsVguiWindowFactory( const char *pWindowTypeName, const char *pDccCommand )
  74. : BaseClass( pWindowTypeName, pDccCommand )
  75. , m_panelMap( StringLessFunc )
  76. {
  77. }
  78. struct PanelMapElem_s
  79. {
  80. CVsVGuiWindowBase *m_pVGuiWindow;
  81. T *m_pPanel;
  82. };
  83. typedef CUtlMap< CUtlString, PanelMapElem_s > PanelMap_t;
  84. virtual void CreateVguiWindow( const char *pPanelName )
  85. {
  86. T *pVGuiPanel = new T( NULL, pPanelName );
  87. vgui::Frame *pFrame = dynamic_cast< vgui::Frame * >( pVGuiPanel );
  88. if ( pFrame )
  89. {
  90. pFrame->SetSizeable( false );
  91. pFrame->SetCloseButtonVisible( false );
  92. pFrame->SetMoveable( false );
  93. CVsVGuiWindowBase *pVGuiWindow = CreateMayaVGuiWindow( pVGuiPanel, pPanelName );
  94. const CUtlString panelName( pPanelName );
  95. PanelMap_t::IndexType_t nIndex = m_panelMap.Find( panelName );
  96. if ( m_panelMap.IsValidIndex( nIndex ) )
  97. {
  98. merr << "[vsVguiWindow]: Panel \"" << pPanelName << "\" of Type: \"" << m_pWindowTypeName << "\" Already Exists!!!" << std::endl;
  99. }
  100. else
  101. {
  102. PanelMap_t::ElemType_t &element = m_panelMap.Element( m_panelMap.Insert( panelName ) );
  103. element.m_pVGuiWindow = pVGuiWindow;
  104. element.m_pPanel = pVGuiPanel;
  105. }
  106. }
  107. }
  108. virtual void DestroyVguiWindow( const char *pPanelName )
  109. {
  110. PanelMap_t::IndexType_t nIndex = m_panelMap.Find( pPanelName );
  111. if ( !m_panelMap.IsValidIndex( nIndex ) )
  112. return;
  113. PanelMap_t::ElemType_t &element = m_panelMap.Element( nIndex );
  114. delete element.m_pPanel;
  115. m_panelMap.Remove( CUtlString( pPanelName ) );
  116. DestroyMayaVGuiWindow( pPanelName );
  117. }
  118. virtual vgui::Frame *GetVGuiPanel( const char *pPanelName = NULL )
  119. {
  120. if ( pPanelName )
  121. {
  122. PanelMap_t::IndexType_t nPanelIndex = m_panelMap.Find( CUtlString( pPanelName ) );
  123. if ( m_panelMap.IsValidIndex( nPanelIndex ) )
  124. return dynamic_cast< vgui::Frame * >( m_panelMap.Element( nPanelIndex ).m_pPanel );
  125. }
  126. else if ( m_panelMap.Count() > 0 )
  127. {
  128. return dynamic_cast< vgui::Frame * >( m_panelMap.Element( m_panelMap.FirstInorder() ).m_pPanel );
  129. }
  130. return NULL;
  131. }
  132. virtual CVsVGuiWindowBase *GetVGuiWindow( const char *pPanelName = NULL )
  133. {
  134. if ( pPanelName )
  135. {
  136. PanelMap_t::IndexType_t nPanelIndex = m_panelMap.Find( CUtlString( pPanelName ) );
  137. if ( m_panelMap.IsValidIndex( nPanelIndex ) )
  138. return m_panelMap.Element( nPanelIndex ).m_pVGuiWindow;
  139. }
  140. else if ( m_panelMap.Count() > 0 )
  141. {
  142. return m_panelMap.Element( m_panelMap.FirstInorder() ).m_pVGuiWindow;
  143. }
  144. return NULL;
  145. }
  146. private:
  147. PanelMap_t m_panelMap;
  148. };
  149. #define INSTALL_MAYA_VGUI_WINDOW( _className, _windowTypeName, _dccCommand ) \
  150. static CVsVguiWindowFactory< _className > s_VsVguiWindowFactory##_className##( _windowTypeName, _dccCommand )
  151. #endif // VSVGUIWINDOW_H