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.

80 lines
2.1 KiB

  1. //=========== Copyright Valve Corporation, All rights reserved. ===============//
  2. //
  3. // Purpose:
  4. //=============================================================================//
  5. #ifndef PANORAMA_TOOLTIP_H
  6. #define PANORAMA_TOOLTIP_H
  7. #ifdef _WIN32
  8. #pragma once
  9. #endif
  10. #include "panel2d.h"
  11. #include "../uievent.h"
  12. #include "label.h"
  13. namespace panorama
  14. {
  15. DECLARE_PANEL_EVENT0( TooltipVisible );
  16. //-----------------------------------------------------------------------------
  17. // Purpose: Top level panel for a tooltip
  18. //-----------------------------------------------------------------------------
  19. class CTooltip : public CPanel2D
  20. {
  21. DECLARE_PANEL2D( CTooltip, CPanel2D );
  22. public:
  23. CTooltip( IUIWindow *pParent, const char *pchName );
  24. CTooltip( CPanel2D *pParent, const char *pchName );
  25. virtual ~CTooltip();
  26. void SetTooltipTarget( const CPanelPtr< IUIPanel >& targetPanelPtr );
  27. // Get/set tooltip visibility. This is actually determined by a .css class,
  28. // so that transitions can be supported
  29. bool IsTooltipVisible() const;
  30. void SetTooltipVisible( bool bVisible );
  31. virtual void OnLayoutTraverse( float flFinalWidth, float flFinalHeight );
  32. // request the tooltip to do positioning on the next layout
  33. virtual void CalculatePosition() { m_bReposition = true; InvalidateSizeAndPosition(); }
  34. private:
  35. void Init();
  36. void UpdatePosition();
  37. bool EventTooltipVisible( const panorama::CPanelPtr< panorama::IUIPanel > &pPanel );
  38. bool m_bReposition;
  39. CPanelPtr< IUIPanel > m_pTooltipTarget;
  40. };
  41. //-----------------------------------------------------------------------------
  42. // Purpose: Simple tooltip that just shows a string of text
  43. //-----------------------------------------------------------------------------
  44. class CTextTooltip : public CTooltip
  45. {
  46. DECLARE_PANEL2D( CTextTooltip, CTooltip );
  47. public:
  48. CTextTooltip( IUIWindow *pParent, const char *pchName );
  49. CTextTooltip( CPanel2D *pParent, const char *pchName );
  50. virtual ~CTextTooltip();
  51. void SetText( const char *pchText, CLabel::ETextType eTextType = CLabel::k_ETextTypePlain );
  52. private:
  53. void Init();
  54. CLabel *m_pText;
  55. };
  56. } // namespace panorama
  57. #endif // PANORAMA_TOOLTIP_H