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.

121 lines
3.8 KiB

  1. //=========== Copyright Valve Corporation, All rights reserved. ===============//
  2. //
  3. // Purpose:
  4. //=============================================================================//
  5. #ifndef PANORAMA_IMAGEPANEL_H
  6. #define PANORAMA_IMAGEPANEL_H
  7. #ifdef _WIN32
  8. #pragma once
  9. #endif
  10. #include "panel2d.h"
  11. #include "../data/iimagesource.h"
  12. namespace panorama
  13. {
  14. DECLARE_PANEL_EVENT1( SetImageSource, const char * );
  15. DECLARE_PANEL_EVENT0( ClearImageSource );
  16. enum EImageScaling
  17. {
  18. k_EImageScalingNone,
  19. k_EImageScalingStretchBoth,
  20. k_EImageScalingStretchX,
  21. k_EImageScalingStretchY,
  22. k_EImageScalingStretchBothToFitPreserveAspectRatio,
  23. k_EImageScalingStretchXToFitPreserveAspectRatio,
  24. k_EImageScalingStretchYToFitPreserveAspectRatio,
  25. k_EImageScalingStretchBothToCoverPreserveAspectRatio
  26. };
  27. enum EImageHorizontalAlignment
  28. {
  29. k_EImageHorizontalAlignmentCenter,
  30. k_EImageHorizontalAlignmentLeft,
  31. k_EImageHorizontalAlignmentRight,
  32. };
  33. enum EImageVerticalAlignment
  34. {
  35. k_EImageVerticalAlignmentCenter,
  36. k_EImageVerticalAlignmentTop,
  37. k_EImageVerticalAlignmentBottom,
  38. };
  39. //-----------------------------------------------------------------------------
  40. // Purpose: ImagePanel
  41. //-----------------------------------------------------------------------------
  42. class CImagePanel : public CPanel2D
  43. {
  44. DECLARE_PANEL2D( CImagePanel, CPanel2D );
  45. public:
  46. CImagePanel( CPanel2D *parent, const char * pchPanelID );
  47. virtual ~CImagePanel();
  48. virtual void Paint();
  49. virtual bool BSetProperties( const CUtlVector< ParsedPanelProperty_t > &vecProperties );
  50. bool OnImageLoaded( const CPanelPtr< IUIPanel > &pPanel, IImageSource *pImage );
  51. bool OnSetImageSource( const CPanelPtr<IUIPanel> &pPanel, const char *pchImageSource );
  52. bool OnClearImageSource( const CPanelPtr<IUIPanel> &pPanel );
  53. IImageSource *GetImage() { return m_pImage; }
  54. // Set an image from a URL (file://, http://), if pchDefaultImage is specified it must be a file:// url and will be
  55. // used while the actual image is loaded asynchronously, it will also remain in use if the actual image fails to load
  56. void SetImage( const char *pchImageURL, const char *pchDefaultImageURL = NULL, bool bPrioritizeLoad = false, int nResizeWidth = -1, int nResizeHeight = -1 );
  57. // Set an image from an already created IImageSource, you should almost always use the simpler SetImage( pchImageURL, pchDefaultImageURL ) call.
  58. void SetImage( IImageSource *pImage );
  59. void Clear();
  60. bool IsSet() { return (m_pImage != NULL); }
  61. void SetScaling( EImageScaling eScale );
  62. void SetScaling( CPanoramaSymbol symScale );
  63. void SetAlignment( EImageHorizontalAlignment horAlign, EImageVerticalAlignment verAlign );
  64. void SetVisibleImageSlice( int nX, int nY, int nWidth, int nHeight );
  65. virtual void SetupJavascriptObjectTemplate() OVERRIDE;
  66. void GetDebugPropertyInfo( CUtlVector< DebugPropertyOutput_t *> *pvecProperties );
  67. virtual bool BRequiresContentClipLayer();
  68. void SetImageJS( const char *pchImageURL );
  69. virtual bool IsClonable() OVERRIDE { return AreChildrenClonable(); }
  70. virtual CPanel2D *Clone() OVERRIDE;
  71. #ifdef DBGFLAG_VALIDATE
  72. virtual void ValidateClientPanel( CValidator &validator, const tchar *pchName ) OVERRIDE;
  73. #endif
  74. protected:
  75. virtual void OnContentSizeTraverse( float *pflContentWidth, float *pflContentHeight, float flMaxWidth, float flMaxHeight, bool bFinalDimensions );
  76. virtual void InitClonedPanel( CPanel2D *pPanel ) OVERRIDE;
  77. private:
  78. EImageScaling m_eScaling;
  79. EImageHorizontalAlignment m_eHorAlignment;
  80. EImageVerticalAlignment m_eVerAlignment;
  81. int m_nVisibleSliceX;
  82. int m_nVisibleSliceY;
  83. int m_nVisibleSliceWidth;
  84. int m_nVisibleSliceHeight;
  85. CUtlString m_strSource;
  86. CUtlString m_strSourceDefault;
  87. bool m_bAnimate;
  88. IImageSource *m_pImage;
  89. float m_flPrevAnimateWidth;
  90. float m_flPrevAnimateHeight;
  91. };
  92. } // namespace panorama
  93. #endif // PANORAMA_IMAGEPANEL_H