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.

345 lines
12 KiB

  1. //====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose: Core Movie Maker UI API
  4. //
  5. //=============================================================================
  6. #ifndef BASETOOLSYSTEM_H
  7. #define BASETOOLSYSTEM_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "tier1/interface.h"
  12. #include "toolframework/itoolsystem.h"
  13. #include "vgui/ischeme.h"
  14. #include "vgui_controls/editablepanel.h"
  15. #include "vgui_controls/phandle.h"
  16. #include "toolutils/recentfilelist.h"
  17. #include "vgui/keycode.h"
  18. #include "vgui_controls/fileopenstatemachine.h"
  19. // #defines
  20. #define TOGGLE_WINDOWED_KEY_CODE KEY_F11
  21. #define TOGGLE_WINDOWED_KEY_NAME "F11"
  22. #define TOGGLE_INPUT_KEY_CODE KEY_F10
  23. #define TOGGLE_INPUT_KEY_NAME "F10"
  24. //-----------------------------------------------------------------------------
  25. // Forward declarations
  26. //-----------------------------------------------------------------------------
  27. class KeyValues;
  28. class CToolUI;
  29. class CToolMenuButton;
  30. class CMiniViewport;
  31. class IGlobalFlexController;
  32. namespace vgui
  33. {
  34. class Panel;
  35. class Menu;
  36. class CKeyBoardEditorDialog;
  37. class CKeyBindingHelpDialog;
  38. enum KeyBindingContextHandle_t;
  39. class IScheme;
  40. }
  41. //-----------------------------------------------------------------------------
  42. // Save document types
  43. //-----------------------------------------------------------------------------
  44. enum SaveDocumentCloseType_t
  45. {
  46. SAVEDOC_QUIT_AFTER_SAVE = 0,
  47. SAVEDOC_CLOSE_AFTER_SAVE,
  48. SAVEDOC_LEAVEOPEN_AFTER_SAVE,
  49. SAVEDOC_POSTCOMMAND_AFTER_SAVE, // Closes, then posts a command
  50. SAVEDOC_LEAVEOPEN_POSTCOMMAND_AFTER_SAVE, // Leaves open, then posts a command
  51. };
  52. //-----------------------------------------------------------------------------
  53. // The toolsystem panel is the main panel in which the tool "ui" lives.
  54. // The tool "ui" encapsulates the main menu and a client area in which the
  55. // tools are drawn.
  56. // Usually, the workspace is the size of the entire screen
  57. // and the ui can be smaller than the toolsystem panel. The reason these are decoupled
  58. // is so that you can get the 'action' menu no matter where you click on the screen
  59. //-----------------------------------------------------------------------------
  60. class CBaseToolSystem : public vgui::EditablePanel, public IToolSystem, public vgui::IFileOpenStateMachineClient
  61. {
  62. DECLARE_CLASS_SIMPLE( CBaseToolSystem, vgui::EditablePanel );
  63. public:
  64. // Methods inherited from IToolSystem
  65. virtual bool Init( );
  66. virtual void Shutdown();
  67. virtual bool ServerInit( CreateInterfaceFn serverFactory );
  68. virtual bool ClientInit( CreateInterfaceFn clientFactory );
  69. virtual void ServerShutdown();
  70. virtual void ClientShutdown();
  71. virtual bool CanQuit( const char *pExitMsg );
  72. virtual void PostToolMessage( HTOOLHANDLE hEntity, KeyValues *message );
  73. virtual void Think( bool finalTick );
  74. virtual void ServerLevelInitPreEntity();
  75. virtual void ServerLevelInitPostEntity();
  76. virtual void ServerLevelShutdownPreEntity();
  77. virtual void ServerLevelShutdownPostEntity();
  78. virtual void ServerFrameUpdatePreEntityThink();
  79. virtual void ServerFrameUpdatePostEntityThink();
  80. virtual void ServerPreClientUpdate();
  81. virtual void ServerPreSetupVisibility();
  82. virtual const char* GetEntityData( const char *pActualEntityData );
  83. virtual void* QueryInterface( const char *pInterfaceName );
  84. virtual void ClientLevelInitPreEntity();
  85. virtual void ClientLevelInitPostEntity();
  86. virtual void ClientLevelShutdownPreEntity();
  87. virtual void ClientLevelShutdownPostEntity();
  88. virtual void ClientPreRender();
  89. virtual void ClientPostRender();
  90. virtual void OnToolActivate();
  91. virtual void OnToolDeactivate();
  92. virtual bool TrapKey( ButtonCode_t key, bool down );
  93. virtual void AdjustEngineViewport( int& x, int& y, int& width, int& height );
  94. virtual bool SetupEngineView( Vector &origin, QAngle &angles, float &fov );
  95. virtual bool SetupAudioState( AudioState_t &audioState );
  96. virtual bool ShouldGameRenderView();
  97. virtual bool ShouldGamePlaySounds();
  98. virtual bool IsThirdPersonCamera();
  99. virtual bool IsToolRecording();
  100. virtual IMaterialProxy *LookupProxy( const char *proxyName );
  101. virtual bool GetSoundSpatialization( int iUserData, int guid, SpatializationInfo_t& info );
  102. virtual void HostRunFrameBegin();
  103. virtual void HostRunFrameEnd();
  104. virtual void RenderFrameBegin();
  105. virtual void RenderFrameEnd();
  106. virtual void VGui_PreRender( int paintMode );
  107. virtual void VGui_PostRender( int paintMode );
  108. virtual void VGui_PreSimulate();
  109. virtual void VGui_PostSimulate();
  110. virtual vgui::VPANEL GetClientWorkspaceArea();
  111. // Inherited from vgui::Panel
  112. virtual void OnMousePressed( vgui::MouseCode code );
  113. virtual void OnThink();
  114. virtual void ApplySchemeSettings( vgui::IScheme *pScheme);
  115. // Inherited from IFileOpenStateMachineClient
  116. virtual void SetupFileOpenDialog( vgui::FileOpenDialog *pDialog, bool bOpenFile, const char *pFileFormat, KeyValues *pContextKeyValues ) { Assert(0); }
  117. virtual bool OnReadFileFromDisk( const char *pFileName, const char *pFileFormat, KeyValues *pContextKeyValues ) { Assert(0); return false; }
  118. virtual bool OnWriteFileToDisk( const char *pFileName, const char *pFileFormat, KeyValues *pContextKeyValues ) { Assert(0); return false; }
  119. MESSAGE_FUNC_INT( OnUnhandledMouseClick, "UnhandledMouseClick", code );
  120. public:
  121. // Other methods
  122. // NOTE: This name here is 'general' strictly so 'general' shows up in the keybinding dialog
  123. CBaseToolSystem( char const *toolName = "#ToolGeneral" );
  124. // Gets the action target to sent to panels so that the tool system's OnCommand is called
  125. vgui::Panel *GetActionTarget();
  126. // Gets at the action menu
  127. vgui::Menu *GetActionMenu();
  128. // Returns the client area
  129. vgui::Panel* GetClientArea();
  130. // Returns the menu bar
  131. vgui::MenuBar* GetMenuBar();
  132. // Returns the status bar
  133. vgui::Panel* GetStatusBar();
  134. // Adds a menu button to the main menu bar
  135. void AddMenuButton( CToolMenuButton *pMenuButton );
  136. // Returns the current map name
  137. char const *MapName() const;
  138. // Derived classes implement this to create an action menu
  139. // that appears if you right-click in the tool workspace
  140. virtual vgui::Menu *CreateActionMenu( vgui::Panel *pParent ) { return NULL; }
  141. // Derived classes implement this to create a custom menubar
  142. virtual vgui::MenuBar *CreateMenuBar( CBaseToolSystem *pParent );
  143. // Derived classes implement this to create status bar, can return NULL for no status bar in tool...
  144. virtual vgui::Panel *CreateStatusBar( vgui::Panel *pParent );
  145. virtual CMiniViewport *CreateMiniViewport( vgui::Panel *parent );
  146. virtual void UpdateMenu( vgui::Menu *menu );
  147. virtual void ShowMiniViewport( bool state );
  148. void SetMiniViewportBounds( int x, int y, int width, int height );
  149. void SetMiniViewportText( const char *pText );
  150. void GetMiniViewportEngineBounds( int &x, int &y, int &width, int &height );
  151. vgui::Panel *GetMiniViewport( void );
  152. virtual void ComputeMenuBarTitle( char *buf, size_t buflen );
  153. // Usage mode
  154. void SetMode( bool bGameInputEnabled, bool bFullscreen );
  155. bool IsFullscreen() const;
  156. bool IsGameInputEnabled() const;
  157. void EnableFullscreenToolMode( bool bEnable );
  158. // Is this the active tool?
  159. bool IsActiveTool( ) const;
  160. // Returns the tool that had focus most recently
  161. Panel *GetMostRecentlyFocusedTool();
  162. void PostMessageToAllTools( KeyValues *message );
  163. protected:
  164. virtual void PaintBackground();
  165. // Derived classes must implement this to specify where in the
  166. // registry to store registry settings
  167. virtual const char *GetRegistryName() = 0;
  168. // Derived classes must return the key bindings context
  169. virtual const char *GetBindingsContextFile() = 0;
  170. // Derived classes implement this to do stuff when the tool is shown or hidden
  171. virtual void OnModeChanged() {}
  172. // Derived classes can implement this to get a new scheme to be applied to this tool
  173. virtual vgui::HScheme GetToolScheme();
  174. // Derived classes can implement this to get notified when files are saved/loaded
  175. virtual void OnFileOperationCompleted( const char *pFileType, bool bWroteFile, vgui::FileOpenStateMachine::CompletionState_t state, KeyValues *pContextKeyValues ) {}
  176. // Used to open a specified file, and deal with all the lovely dialogs
  177. void OpenFile( const char *pOpenFileType, const char *pSaveFileName = NULL, const char *pSaveFileType = NULL, int nFlags = 0, KeyValues *pKeyValues = NULL );
  178. void OpenFile( const char *pOpenFileName, const char *pOpenFileType, const char *pSaveFileName = NULL, const char *pSaveFileType = NULL, int nFlags = 0, KeyValues *pKeyValues = NULL );
  179. // Used to save a specified file, and deal with all the lovely dialogs
  180. // Pass in NULL to get a dialog to choose a filename to save
  181. // Posts the keyvalues
  182. void SaveFile( const char *pFileName, const char *pFileType, int nFlags, KeyValues *pKeyValues = NULL );
  183. KEYBINDING_FUNC_NODECLARE( editkeybindings, KEY_E, vgui::MODIFIER_SHIFT | vgui::MODIFIER_CONTROL | vgui::MODIFIER_ALT, OnEditKeyBindings, "#editkeybindings_help", 0 );
  184. KEYBINDING_FUNC( keybindinghelp, KEY_H, 0, OnKeyBindingHelp, "#keybindinghelp_help", 0 );
  185. virtual char const *GetBackgroundTextureName();
  186. virtual char const *GetLogoTextureName() = 0;
  187. virtual bool HasDocument();
  188. virtual void ToggleForceToolCamera();
  189. // Shows, hides the tool ui (menu, client area, status bar)
  190. void SetToolUIVisible( bool bVisible );
  191. // Deals with keybindings
  192. void LoadKeyBindings();
  193. void ShowKeyBindingsEditor( vgui::Panel *panel, vgui::KeyBindingContextHandle_t handle );
  194. void ShowKeyBindingsHelp( vgui::Panel *panel, vgui::KeyBindingContextHandle_t handle, vgui::KeyCode boundKey, int modifiers );
  195. vgui::KeyBindingContextHandle_t GetKeyBindingsHandle();
  196. // Registers tool window
  197. void RegisterToolWindow( vgui::PHandle hPanel );
  198. void UnregisterAllToolWindows();
  199. void PostMessageToActiveTool( char const *msg, float delay = 0.0f );
  200. void PostMessageToActiveTool( KeyValues *pKeyValues, float flDelay = 0.0f );
  201. // Destroys all tool windows containers
  202. virtual void DestroyToolContainers();
  203. protected:
  204. // Recent file list
  205. CToolsRecentFileList m_RecentFiles;
  206. private:
  207. // Shows/hides the tool
  208. bool ShowUI( bool bVisible );
  209. // Updates UI visibility
  210. void UpdateUIVisibility();
  211. // Create, destroy action menu
  212. void InitActionMenu();
  213. void ShutdownActionMenu();
  214. // Positions the action menu when it's time to pop it up
  215. void PositionActionMenu();
  216. // Messages related to saving a file
  217. MESSAGE_FUNC_PARAMS( OnFileStateMachineFinished, "FileStateMachineFinished", kv );
  218. // Handlers for standard menus
  219. MESSAGE_FUNC( OnClearRecent, "OnClearRecent" );
  220. MESSAGE_FUNC( OnEditKeyBindings, "OnEditKeyBindings" );
  221. // The root toolsystem panel which should cover the entire screen
  222. // here to allow us to do action menus anywhere
  223. // The tool UI
  224. CToolUI *m_pToolUI;
  225. // The action menu
  226. vgui::DHANDLE<vgui::Menu> m_hActionMenu;
  227. bool m_bGameInputEnabled;
  228. bool m_bFullscreenMode;
  229. bool m_bIsActive;
  230. bool m_bFullscreenToolModeEnabled;
  231. vgui::DHANDLE< CMiniViewport > m_hMiniViewport;
  232. vgui::FileOpenStateMachine *m_pFileOpenStateMachine;
  233. IMaterial *m_pBackground;
  234. IMaterial *m_pLogo;
  235. // Keybindings
  236. vgui::KeyBindingContextHandle_t m_KeyBindingsHandle;
  237. vgui::DHANDLE< vgui::CKeyBoardEditorDialog > m_hKeyBindingsEditor;
  238. vgui::DHANDLE< vgui::CKeyBindingHelpDialog > m_hKeyBindingsHelp;
  239. CUtlVector< vgui::PHandle > m_Tools;
  240. vgui::PHandle m_MostRecentlyFocused;
  241. };
  242. //-----------------------------------------------------------------------------
  243. // Inline methods
  244. //-----------------------------------------------------------------------------
  245. //-----------------------------------------------------------------------------
  246. // Is this the active tool?
  247. //-----------------------------------------------------------------------------
  248. inline bool CBaseToolSystem::IsActiveTool( ) const
  249. {
  250. return m_bIsActive;
  251. }
  252. //-----------------------------------------------------------------------------
  253. // Mode query
  254. //-----------------------------------------------------------------------------
  255. inline bool CBaseToolSystem::IsFullscreen( ) const
  256. {
  257. return m_bFullscreenMode;
  258. }
  259. inline bool CBaseToolSystem::IsGameInputEnabled() const
  260. {
  261. // NOTE: IsActive check here is a little bogus.
  262. // It's necessary to get the IFM to play nice with other tools, though.
  263. // Is there a better way of doing it?
  264. return m_bGameInputEnabled || !m_bIsActive;
  265. }
  266. inline vgui::VPANEL CBaseToolSystem::GetClientWorkspaceArea()
  267. {
  268. if ( GetClientArea() )
  269. {
  270. return (vgui::VPANEL)GetClientArea()->GetVPanel();
  271. }
  272. return (vgui::VPANEL)0;
  273. }
  274. #endif // BASETOOLSYSTEM_H