Team Fortress 2 Source Code as on 22/4/2020
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.

326 lines
12 KiB

  1. //========= Copyright 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();
  72. virtual void PostMessage( 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 ClientLevelInitPreEntity();
  84. virtual void ClientLevelInitPostEntity();
  85. virtual void ClientLevelShutdownPreEntity();
  86. virtual void ClientLevelShutdownPostEntity();
  87. virtual void ClientPreRender();
  88. virtual void ClientPostRender();
  89. virtual void OnToolActivate();
  90. virtual void OnToolDeactivate();
  91. virtual bool TrapKey( ButtonCode_t key, bool down );
  92. virtual void AdjustEngineViewport( int& x, int& y, int& width, int& height );
  93. virtual bool SetupEngineView( Vector &origin, QAngle &angles, float &fov );
  94. virtual bool SetupAudioState( AudioState_t &audioState );
  95. virtual bool ShouldGameRenderView();
  96. virtual bool IsThirdPersonCamera();
  97. virtual bool IsToolRecording();
  98. virtual IMaterialProxy *LookupProxy( const char *proxyName );
  99. virtual bool GetSoundSpatialization( int iUserData, int guid, SpatializationInfo_t& info );
  100. virtual void HostRunFrameBegin();
  101. virtual void HostRunFrameEnd();
  102. virtual void RenderFrameBegin();
  103. virtual void RenderFrameEnd();
  104. virtual void VGui_PreRender( int paintMode );
  105. virtual void VGui_PostRender( int paintMode );
  106. virtual void VGui_PreSimulate();
  107. virtual void VGui_PostSimulate();
  108. // Inherited from vgui::Panel
  109. virtual void OnMousePressed( vgui::MouseCode code );
  110. virtual void OnThink();
  111. virtual void ApplySchemeSettings( vgui::IScheme *pScheme);
  112. // Inherited from IFileOpenStateMachineClient
  113. virtual void SetupFileOpenDialog( vgui::FileOpenDialog *pDialog, bool bOpenFile, const char *pFileFormat, KeyValues *pContextKeyValues ) { Assert(0); }
  114. virtual bool OnReadFileFromDisk( const char *pFileName, const char *pFileFormat, KeyValues *pContextKeyValues ) { Assert(0); return false; }
  115. virtual bool OnWriteFileToDisk( const char *pFileName, const char *pFileFormat, KeyValues *pContextKeyValues ) { Assert(0); return false; }
  116. MESSAGE_FUNC_INT( OnUnhandledMouseClick, "UnhandledMouseClick", code );
  117. public:
  118. // Other methods
  119. // NOTE: This name here is 'general' strictly so 'general' shows up in the keybinding dialog
  120. CBaseToolSystem( char const *toolName = "#ToolGeneral" );
  121. // Gets the action target to sent to panels so that the tool system's OnCommand is called
  122. vgui::Panel *GetActionTarget();
  123. // Gets at the action menu
  124. vgui::Menu *GetActionMenu();
  125. // Returns the client area
  126. vgui::Panel* GetClientArea();
  127. // Adds a menu button to the main menu bar
  128. void AddMenuButton( CToolMenuButton *pMenuButton );
  129. // Returns the current map name
  130. char const *MapName() const;
  131. // Derived classes implement this to create an action menu
  132. // that appears if you right-click in the tool workspace
  133. virtual vgui::Menu *CreateActionMenu( vgui::Panel *pParent ) { return NULL; }
  134. // Derived classes implement this to create a custom menubar
  135. virtual vgui::MenuBar *CreateMenuBar( CBaseToolSystem *pParent );
  136. // Derived classes implement this to create status bar, can return NULL for no status bar in tool...
  137. virtual vgui::Panel *CreateStatusBar( vgui::Panel *pParent );
  138. virtual CMiniViewport *CreateMiniViewport( vgui::Panel *parent );
  139. virtual void UpdateMenu( vgui::Menu *menu );
  140. virtual void ShowMiniViewport( bool state );
  141. void SetMiniViewportBounds( int x, int y, int width, int height );
  142. void SetMiniViewportText( const char *pText );
  143. void GetMiniViewportEngineBounds( int &x, int &y, int &width, int &height );
  144. vgui::Panel *GetMiniViewport( void );
  145. virtual void ComputeMenuBarTitle( char *buf, size_t buflen );
  146. // Usage mode
  147. void SetMode( bool bGameInputEnabled, bool bFullscreen );
  148. bool IsFullscreen() const;
  149. bool IsGameInputEnabled() const;
  150. void EnableFullscreenToolMode( bool bEnable );
  151. // Is this the active tool?
  152. bool IsActiveTool( ) const;
  153. // Returns the tool that had focus most recently
  154. Panel *GetMostRecentlyFocusedTool();
  155. void PostMessageToAllTools( KeyValues *message );
  156. protected:
  157. virtual void PaintBackground();
  158. // Derived classes must implement this to specify where in the
  159. // registry to store registry settings
  160. virtual const char *GetRegistryName() = 0;
  161. // Derived classes must return the key bindings context
  162. virtual const char *GetBindingsContextFile() = 0;
  163. // Derived classes implement this to do stuff when the tool is shown or hidden
  164. virtual void OnModeChanged() {}
  165. // Derived classes can implement this to get a new scheme to be applied to this tool
  166. virtual vgui::HScheme GetToolScheme() { return 0; }
  167. // Derived classes can implement this to get notified when files are saved/loaded
  168. virtual void OnFileOperationCompleted( const char *pFileType, bool bWroteFile, vgui::FileOpenStateMachine::CompletionState_t state, KeyValues *pContextKeyValues ) {}
  169. // Used to open a specified file, and deal with all the lovely dialogs
  170. void OpenFile( const char *pOpenFileType, const char *pSaveFileName = NULL, const char *pSaveFileType = NULL, int nFlags = 0, KeyValues *pKeyValues = NULL );
  171. void OpenFile( const char *pOpenFileName, const char *pOpenFileType, const char *pSaveFileName = NULL, const char *pSaveFileType = NULL, int nFlags = 0, KeyValues *pKeyValues = NULL );
  172. // Used to save a specified file, and deal with all the lovely dialogs
  173. // Pass in NULL to get a dialog to choose a filename to save
  174. // Posts the keyvalues
  175. void SaveFile( const char *pFileName, const char *pFileType, int nFlags, KeyValues *pKeyValues = NULL );
  176. KEYBINDING_FUNC_NODECLARE( editkeybindings, KEY_E, vgui::MODIFIER_SHIFT | vgui::MODIFIER_CONTROL | vgui::MODIFIER_ALT, OnEditKeyBindings, "#editkeybindings_help", 0 );
  177. KEYBINDING_FUNC( keybindinghelp, KEY_H, 0, OnKeyBindingHelp, "#keybindinghelp_help", 0 );
  178. virtual char const *GetBackgroundTextureName();
  179. virtual char const *GetLogoTextureName() = 0;
  180. virtual bool HasDocument();
  181. virtual void ToggleForceToolCamera();
  182. // Shows, hides the tool ui (menu, client area, status bar)
  183. void SetToolUIVisible( bool bVisible );
  184. // Deals with keybindings
  185. void LoadKeyBindings();
  186. void ShowKeyBindingsEditor( vgui::Panel *panel, vgui::KeyBindingContextHandle_t handle );
  187. void ShowKeyBindingsHelp( vgui::Panel *panel, vgui::KeyBindingContextHandle_t handle, vgui::KeyCode boundKey, int modifiers );
  188. vgui::KeyBindingContextHandle_t GetKeyBindingsHandle();
  189. // Registers tool window
  190. void RegisterToolWindow( vgui::PHandle hPanel );
  191. void UnregisterAllToolWindows();
  192. void PostMessageToActiveTool( char const *msg, float delay = 0.0f );
  193. void PostMessageToActiveTool( KeyValues *pKeyValues, float flDelay = 0.0f );
  194. protected:
  195. // Recent file list
  196. CRecentFileList m_RecentFiles;
  197. private:
  198. // Shows/hides the tool
  199. bool ShowUI( bool bVisible );
  200. // Updates UI visibility
  201. void UpdateUIVisibility();
  202. // Create, destroy action menu
  203. void InitActionMenu();
  204. void ShutdownActionMenu();
  205. // Positions the action menu when it's time to pop it up
  206. void PositionActionMenu();
  207. // Messages related to saving a file
  208. MESSAGE_FUNC_PARAMS( OnFileStateMachineFinished, "FileStateMachineFinished", kv );
  209. // Handlers for standard menus
  210. MESSAGE_FUNC( OnClearRecent, "OnClearRecent" );
  211. MESSAGE_FUNC( OnEditKeyBindings, "OnEditKeyBindings" );
  212. // The root toolsystem panel which should cover the entire screen
  213. // here to allow us to do action menus anywhere
  214. // The tool UI
  215. CToolUI *m_pToolUI;
  216. // The action menu
  217. vgui::DHANDLE<vgui::Menu> m_hActionMenu;
  218. bool m_bGameInputEnabled;
  219. bool m_bFullscreenMode;
  220. bool m_bIsActive;
  221. bool m_bFullscreenToolModeEnabled;
  222. vgui::DHANDLE< CMiniViewport > m_hMiniViewport;
  223. vgui::FileOpenStateMachine *m_pFileOpenStateMachine;
  224. IMaterial *m_pBackground;
  225. IMaterial *m_pLogo;
  226. // Keybindings
  227. vgui::KeyBindingContextHandle_t m_KeyBindingsHandle;
  228. vgui::DHANDLE< vgui::CKeyBoardEditorDialog > m_hKeyBindingsEditor;
  229. vgui::DHANDLE< vgui::CKeyBindingHelpDialog > m_hKeyBindingsHelp;
  230. CUtlVector< vgui::PHandle > m_Tools;
  231. vgui::PHandle m_MostRecentlyFocused;
  232. };
  233. //-----------------------------------------------------------------------------
  234. // Inline methods
  235. //-----------------------------------------------------------------------------
  236. //-----------------------------------------------------------------------------
  237. // Is this the active tool?
  238. //-----------------------------------------------------------------------------
  239. inline bool CBaseToolSystem::IsActiveTool( ) const
  240. {
  241. return m_bIsActive;
  242. }
  243. //-----------------------------------------------------------------------------
  244. // Mode query
  245. //-----------------------------------------------------------------------------
  246. inline bool CBaseToolSystem::IsFullscreen( ) const
  247. {
  248. return m_bFullscreenMode;
  249. }
  250. inline bool CBaseToolSystem::IsGameInputEnabled() const
  251. {
  252. // NOTE: IsActive check here is a little bogus.
  253. // It's necessary to get the IFM to play nice with other tools, though.
  254. // Is there a better way of doing it?
  255. return m_bGameInputEnabled || !m_bIsActive;
  256. }
  257. #endif // BASETOOLSYSTEM_H