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.

118 lines
3.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // The tool UI has 4 purposes:
  4. // 1) Create the menu bar and client area (lies under the menu bar)
  5. // 2) Forward all mouse messages to the tool workspace so action menus work
  6. // 3) Forward all commands to the tool system so all smarts can reside there
  7. // 4) Control the size of the menu bar + the working area
  8. //=============================================================================
  9. #include "ToolUI.h"
  10. #include "toolutils/toolmenubar.h"
  11. #include "toolutils/basetoolsystem.h"
  12. #include "vgui/Cursor.h"
  13. #include "vgui/ISurface.h"
  14. #include "tier1/KeyValues.h"
  15. #include "toolutils/toolmenubar.h"
  16. // memdbgon must be the last include file in a .cpp file!!!
  17. #include "tier0/memdbgon.h"
  18. #define MENU_HEIGHT 28
  19. // Height of the status bar, if the tool installs one
  20. #define STATUS_HEIGHT 24
  21. //-----------------------------------------------------------------------------
  22. // Constructor
  23. //-----------------------------------------------------------------------------
  24. CToolUI::CToolUI( vgui::Panel *pParent, const char *panelName, CBaseToolSystem *pBaseToolSystem ) :
  25. BaseClass( pParent, panelName ), m_pClientArea( 0 ), m_pBaseToolSystem( pBaseToolSystem )
  26. {
  27. SetPaintEnabled(false);
  28. SetPaintBackgroundEnabled(false);
  29. SetPaintBorderEnabled(false);
  30. int w, h;
  31. pParent->GetSize( w, h );
  32. SetBounds( 0, 0, w, h );
  33. m_pMenuBar = m_pBaseToolSystem->CreateMenuBar( m_pBaseToolSystem );
  34. m_pMenuBar->SetParent( this );
  35. m_pMenuBar->SetSize( w, MENU_HEIGHT );
  36. // This can be NULL if no status bar should be included
  37. m_pStatusBar = m_pBaseToolSystem->CreateStatusBar( this );
  38. m_pStatusBar->SetParent( this );
  39. m_pClientArea = new vgui::Panel( this, "ClientArea" );
  40. m_pClientArea->SetMouseInputEnabled( false );
  41. m_pClientArea->SetCursor( vgui::dc_none );
  42. m_pClientArea->SetBounds( 0, MENU_HEIGHT, w, h - MENU_HEIGHT );
  43. }
  44. vgui::Panel *CToolUI::GetClientArea()
  45. {
  46. return m_pClientArea;
  47. }
  48. //-----------------------------------------------------------------------------
  49. // The tool UI panel should always fill the space...
  50. //-----------------------------------------------------------------------------
  51. void CToolUI::PerformLayout()
  52. {
  53. BaseClass::PerformLayout();
  54. // Make the editor panel fill the space
  55. int iWidth, iHeight;
  56. vgui::VPANEL parent = GetParent() ? GetParent()->GetVPanel() : vgui::surface()->GetEmbeddedPanel();
  57. vgui::ipanel()->GetSize( parent, iWidth, iHeight );
  58. SetSize( iWidth, iHeight );
  59. int insettop = MENU_HEIGHT;
  60. int insetbottom = 0;
  61. m_pMenuBar->SetSize( iWidth, insettop );
  62. if ( m_pStatusBar )
  63. {
  64. insetbottom = STATUS_HEIGHT;
  65. m_pStatusBar->SetBounds( 0, iHeight - insetbottom, iWidth, insetbottom );
  66. }
  67. m_pClientArea->SetBounds( 0, insettop, iWidth, iHeight - insettop - insetbottom );
  68. }
  69. //-----------------------------------------------------------------------------
  70. // Returns the menu bar
  71. //-----------------------------------------------------------------------------
  72. vgui::MenuBar *CToolUI::GetMenuBar()
  73. {
  74. return m_pMenuBar;
  75. }
  76. vgui::Panel *CToolUI::GetStatusBar()
  77. {
  78. return m_pStatusBar;
  79. }
  80. //-----------------------------------------------------------------------------
  81. // Forward commands to systems that have more smarts than I do!
  82. //-----------------------------------------------------------------------------
  83. void CToolUI::OnMousePressed( vgui::MouseCode code )
  84. {
  85. // Chain mouse pressed calls to the parent tool workspace
  86. CallParentFunction( new KeyValues( "MousePressed", "code", code ) );
  87. }
  88. void CToolUI::OnCommand( const char *cmd )
  89. {
  90. m_pBaseToolSystem->OnCommand( cmd );
  91. }
  92. void CToolUI::UpdateMenuBarTitle()
  93. {
  94. CToolFileMenuBar *mb = dynamic_cast< CToolFileMenuBar * >( GetMenuBar() );
  95. if ( mb )
  96. {
  97. char title[ 64 ];
  98. m_pBaseToolSystem->ComputeMenuBarTitle( title, sizeof( title ) );
  99. mb->SetInfo( title );
  100. }
  101. }