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.

77 lines
2.6 KiB

  1. //=========== Copyright Valve Corporation, All rights reserved. ===============//
  2. //
  3. // Purpose:
  4. //=============================================================================//
  5. #ifndef CONTEXTMENU_H
  6. #define CONTEXTMENU_H
  7. #ifdef _WIN32
  8. #pragma once
  9. #endif
  10. #include "panorama/controls/panel2d.h"
  11. DECLARE_PANEL_EVENT1( ContextMenuEvent, const char * )
  12. DECLARE_PANEL_EVENT1( ContextMenuEventDirect, panorama::IUIEvent * );
  13. namespace panorama
  14. {
  15. //-----------------------------------------------------------------------------
  16. // Purpose: Helper class to derive from for creating context menus
  17. //-----------------------------------------------------------------------------
  18. class CContextMenu : public panorama::CPanel2D
  19. {
  20. DECLARE_PANEL2D( CContextMenu, panorama::CPanel2D );
  21. public:
  22. CContextMenu( CPanel2D *pParent, const char *pchName, CPanel2D *pEventParent );
  23. CContextMenu( IUIWindow *pParent, const char *pchName, CPanel2D *pEventParent );
  24. virtual ~CContextMenu();
  25. virtual bool OnClick( IUIPanel *pPanel, const panorama::MouseData_t &code );
  26. void SetMenuTarget( const CPanelPtr< IUIPanel >& targetPanelPtr );
  27. void CalculatePosition() { m_bReposition = true; InvalidateSizeAndPosition(); }
  28. protected:
  29. CPanel2D *GetEventParent() { return m_pEventParent; }
  30. private:
  31. void Initialize( CPanel2D *pEventParent );
  32. void OnLayoutTraverse( float flFinalWidth, float flFinalHeight );
  33. bool OnFireEvent( const panorama::CPanelPtr< panorama::IUIPanel > &ptrPanel, const char *pchEventText );
  34. bool OnFireEvent( const panorama::CPanelPtr< panorama::IUIPanel > &ptrPanel, IUIEvent *pEvent );
  35. bool OnCancelled( const panorama::CPanelPtr< panorama::IUIPanel > &pPanel, panorama::EPanelEventSource_t eSource );
  36. CPanel2D *m_pEventParent;
  37. CPanelPtr< IUIPanel > m_pMenuTarget;
  38. double m_flCreateTime;
  39. bool m_bReposition;
  40. };
  41. //-----------------------------------------------------------------------------
  42. // Purpose: Helper class for simple context menus that doesn't require derivation
  43. //-----------------------------------------------------------------------------
  44. class CSimpleContextMenu : public panorama::CContextMenu
  45. {
  46. DECLARE_PANEL2D( CSimpleContextMenu, panorama::CContextMenu );
  47. public:
  48. CSimpleContextMenu( CPanel2D *pParent, const char *pchName, CPanel2D *pEventParent );
  49. CSimpleContextMenu( IUIWindow *pParent, const char *pchName, CPanel2D *pEventParent );
  50. virtual ~CSimpleContextMenu();
  51. void AddMenuItem( const char *pchLabelText, const char *pchEventText );
  52. void AddMenuItemEvent( const char *pchLabel, IUIEvent *pEvent );
  53. private:
  54. };
  55. } // namespace panorama
  56. #endif // CONTEXTMENU_H