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.

117 lines
3.7 KiB

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