Counter Strike : Global Offensive Source Code
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.

106 lines
3.5 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include <vgui/vgui.h>
  8. #include <color.h>
  9. #include <vgui_controls/ImageList.h>
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include <tier0/memdbgon.h>
  12. using namespace vgui;
  13. //-----------------------------------------------------------------------------
  14. // Purpose: blank image, intentially draws nothing
  15. //-----------------------------------------------------------------------------
  16. class BlankImage : public IImage
  17. {
  18. public:
  19. virtual void Paint() {}
  20. virtual void SetPos(int x, int y) {}
  21. virtual void GetContentSize(int &wide, int &tall) { wide = 0; tall = 0; }
  22. virtual void GetSize(int &wide, int &tall) { wide = 0; tall = 0; }
  23. virtual void SetSize(int wide, int tall) {}
  24. virtual void SetColor(Color col) {}
  25. virtual bool Evict() { return false; }
  26. virtual int GetNumFrames() { return 0; }
  27. virtual void SetFrame( int nFrame ) {}
  28. virtual HTexture GetID() { return 0; }
  29. virtual void SetRotation( int iRotation ) { return; };
  30. };
  31. //-----------------------------------------------------------------------------
  32. // Purpose: Constructor
  33. //-----------------------------------------------------------------------------
  34. ImageList::ImageList(bool deleteImagesWhenDone)
  35. {
  36. m_bDeleteImagesWhenDone = deleteImagesWhenDone;
  37. AddImage(new BlankImage());
  38. }
  39. //-----------------------------------------------------------------------------
  40. // Purpose: Destructor
  41. //-----------------------------------------------------------------------------
  42. ImageList::~ImageList()
  43. {
  44. if (m_bDeleteImagesWhenDone)
  45. {
  46. // delete all the images, except for the first image (which is always the blank image)
  47. for (int i = 1; i < m_Images.Count(); i++)
  48. {
  49. delete m_Images[i];
  50. }
  51. }
  52. }
  53. //-----------------------------------------------------------------------------
  54. // Purpose: adds a new image to the list, returning the index it was placed at
  55. //-----------------------------------------------------------------------------
  56. int ImageList::AddImage(vgui::IImage *image)
  57. {
  58. return m_Images.AddToTail(image);
  59. }
  60. //-----------------------------------------------------------------------------
  61. // Purpose: sets an image at a specified index, growing and adding NULL images if necessary
  62. //-----------------------------------------------------------------------------
  63. void ImageList::SetImageAtIndex(int index, vgui::IImage *image)
  64. {
  65. // allocate more images if necessary
  66. while (m_Images.Count() <= index)
  67. {
  68. m_Images.AddToTail(NULL);
  69. }
  70. m_Images[index] = image;
  71. }
  72. //-----------------------------------------------------------------------------
  73. // Purpose: returns the number of images
  74. //-----------------------------------------------------------------------------
  75. int ImageList::GetImageCount()
  76. {
  77. return m_Images.Count();
  78. }
  79. //-----------------------------------------------------------------------------
  80. // Purpose: gets an image, imageIndex is of range [0, GetImageCount)
  81. //-----------------------------------------------------------------------------
  82. vgui::IImage *ImageList::GetImage(int imageIndex)
  83. {
  84. return m_Images[imageIndex];
  85. }
  86. //-----------------------------------------------------------------------------
  87. // Purpose: returns true if an index is valid
  88. //-----------------------------------------------------------------------------
  89. bool ImageList::IsValidIndex(int imageIndex)
  90. {
  91. return m_Images.IsValidIndex(imageIndex);
  92. }