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.

59 lines
1.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef TOOLWINDOWFACTORY_H
  7. #define TOOLWINDOWFACTORY_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "vgui_controls/ToolWindow.h"
  12. #include "vgui/IInput.h"
  13. #define TOOLWINDOW_DEFAULT_WIDTH 640
  14. #define TOOLWINDOW_DEFAULT_HEIGHT 480
  15. #define TOOLWINDOW_MIN_WIDTH 120
  16. #define TOOLWINDOW_MIN_HEIGHT 80
  17. template < class T >
  18. class CToolWindowFactory : public vgui::IToolWindowFactory
  19. {
  20. public:
  21. virtual vgui::ToolWindow *InstanceToolWindow
  22. (
  23. vgui::Panel *parent,
  24. bool contextLabel, // Tool window shows context button for pages with context menus?
  25. vgui::Panel *firstPage,
  26. char const *title,
  27. bool contextMenu // Page has context menu
  28. );
  29. };
  30. //-----------------------------------------------------------------------------
  31. // Methods related to CToolWindowFactory
  32. //-----------------------------------------------------------------------------
  33. template < class T >
  34. vgui::ToolWindow *CToolWindowFactory<T>::InstanceToolWindow( vgui::Panel *parent, bool contextLabel, vgui::Panel *firstPage, char const *title, bool contextMenu )
  35. {
  36. Assert( parent );
  37. if ( !parent )
  38. return NULL;
  39. int mx, my;
  40. vgui::input()->GetCursorPos( mx, my );
  41. parent->ScreenToLocal( mx, my );
  42. T *container = new T( parent, contextLabel, this, firstPage, title, contextMenu );
  43. Assert( container );
  44. if ( container )
  45. {
  46. container->SetBounds( mx, my, TOOLWINDOW_DEFAULT_WIDTH, TOOLWINDOW_DEFAULT_HEIGHT );
  47. container->SetMinimumSize( TOOLWINDOW_MIN_WIDTH, TOOLWINDOW_MIN_HEIGHT );
  48. }
  49. return container;
  50. }
  51. #endif // TOOLWINDOWFACTORY_H