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.

92 lines
3.5 KiB

  1. //=========== Copyright Valve Corporation, All rights reserved. ===============//
  2. //
  3. // Purpose:
  4. //=============================================================================//
  5. #ifndef IIMAGESOURCE_H
  6. #define IIMAGESOURCE_H
  7. #ifdef _WIN32
  8. #pragma once
  9. #endif
  10. namespace panorama
  11. {
  12. enum EImageFormat
  13. {
  14. k_EImageFormatUnknown,
  15. k_EImageFormatR8G8B8A8,
  16. k_EImageFormatB8G8R8A8_PreMultiplied,
  17. k_EImageFormatA8
  18. };
  19. class CPanel2D;
  20. //
  21. // Data source for image data used to render an asset
  22. //
  23. class IImageSource: public panorama::IUIJSObject
  24. {
  25. public:
  26. virtual bool BIsValid() = 0;
  27. virtual uint32 GetTextureID() = 0;
  28. virtual int GetWidth() = 0;
  29. virtual int GetHeight() = 0;
  30. virtual EImageFormat ImageFormat() = 0;
  31. virtual bool BIsAnimating() = 0;
  32. // Ref counting
  33. virtual int GetRefCount() = 0;
  34. virtual int AddRef() = 0;
  35. virtual int Release() = 0;
  36. virtual const char *GetJSTypeName() { return "IImageSource"; }
  37. #ifdef DBGFLAG_VALIDATE
  38. virtual void Validate( CValidator &validator, const tchar *pchName ) = 0;
  39. #endif
  40. protected:
  41. friend class CImageResourceManager;
  42. };
  43. //
  44. // main interface to load images for display in the ui
  45. //
  46. const int k_ResizeNone = -1;
  47. class IUIImageManager
  48. {
  49. public:
  50. // load image data from a URL (file://blah, http://blah/bob.tga, etc), pchDefaultResourceURL may be null, and is what will be used while the real resource is loaded
  51. // if it is set. As such it must be a local file. bPrioritizeLoad will make your request jump to the head of the queue if it is an image over HTTP, use sparingly!
  52. // nResizeWidth and nResizeHeight do nothing if -1, if one is set and the other -1 the image is resized before being made into a texture, but aspect ratio is maintained
  53. // with the specified dimension at the set size, if both are set the image will be stretched if needed.
  54. virtual IImageSource *LoadImageFromURL( const IUIPanel *pPanel, const char *pchDefaultResourceURL, const char *pchResourceURL, bool bPrioritizeLoad, EImageFormat imgFormatOut, int32 nResizeWidth = k_ResizeNone, int32 nResizeHeight = k_ResizeNone, bool bAllowAnimation = true ) = 0;
  55. // load image data from image file (png/jpg/tga) bytes you already have in memory, pchDefaultResourceURL may be null, and is what will be used while the real resource is loaded
  56. // if it is set. As such it must be a local file.
  57. virtual IImageSource *LoadImageFileFromMemory( const IUIPanel *pPanel, const char *pchResourceURLDefault, const CUtlBuffer &bufFile, int nResizeWidth = panorama::k_ResizeNone, int nResizeHeight = panorama::k_ResizeNone, bool bAllowAnimation = true ) = 0;
  58. // load image data from RGBA bytes you already have in memory, pchDefaultResourceURL may be null, and is what will be used while the real resource is loaded
  59. // if it is set. As such it must be a local file.
  60. virtual IImageSource *LoadImageFromMemory( const IUIPanel *pPanel, const char *pchDefaultResourceURL, const CUtlBuffer &bufData, int nWide, int nTall, EImageFormat imgFormatIn = k_EImageFormatR8G8B8A8, int nResizeWidth = k_ResizeNone, int nResizeHeight = k_ResizeNone, bool bAllowAnimation = true ) = 0;
  61. virtual CUtlString GetPchImageSourcePath( IImageSource *pImageSource ) = 0;
  62. virtual void ReloadChangedImage( IImageSource *pImageToReload ) = 0;
  63. virtual void ReloadChangedFile( const char *pchFile ) = 0;
  64. #ifdef DBGFLAG_VALIDATE
  65. virtual void Validate( CValidator &validator, const tchar *pchName ) = 0;
  66. #endif
  67. };
  68. DECLARE_PANEL_EVENT1( ImageLoaded, IImageSource * );
  69. DECLARE_PANEL_EVENT1( ImageFailedLoad, IImageSource * );
  70. } // namespace panorama
  71. #endif // IIMAGESOURCE_H