CGUIImage.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Copyright (C) 2002-2012 Nikolaus Gebhardt
  2. // This file is part of the "Irrlicht Engine".
  3. // For conditions of distribution and use, see copyright notice in irrlicht.h
  4. #pragma once
  5. #include "IGUIImage.h"
  6. namespace irr
  7. {
  8. namespace gui
  9. {
  10. class CGUIImage : public IGUIImage
  11. {
  12. public:
  13. //! constructor
  14. CGUIImage(IGUIEnvironment *environment, IGUIElement *parent, s32 id, core::rect<s32> rectangle);
  15. //! destructor
  16. virtual ~CGUIImage();
  17. //! sets an image
  18. void setImage(video::ITexture *image) override;
  19. //! Gets the image texture
  20. video::ITexture *getImage() const override;
  21. //! sets the color of the image
  22. void setColor(video::SColor color) override;
  23. //! sets if the image should scale to fit the element
  24. void setScaleImage(bool scale) override;
  25. //! draws the element and its children
  26. void draw() override;
  27. //! sets if the image should use its alpha channel to draw itself
  28. void setUseAlphaChannel(bool use) override;
  29. //! Gets the color of the image
  30. video::SColor getColor() const override;
  31. //! Returns true if the image is scaled to fit, false if not
  32. bool isImageScaled() const override;
  33. //! Returns true if the image is using the alpha channel, false if not
  34. bool isAlphaChannelUsed() const override;
  35. //! Sets the source rectangle of the image. By default the full image is used.
  36. void setSourceRect(const core::rect<s32> &sourceRect) override;
  37. //! Returns the customized source rectangle of the image to be used.
  38. core::rect<s32> getSourceRect() const override;
  39. //! Restrict drawing-area.
  40. void setDrawBounds(const core::rect<f32> &drawBoundUVs) override;
  41. //! Get drawing-area restrictions.
  42. core::rect<f32> getDrawBounds() const override;
  43. //! Sets whether to draw a background color (EGDC_3D_DARK_SHADOW) when no texture is set
  44. void setDrawBackground(bool draw) override
  45. {
  46. DrawBackground = draw;
  47. }
  48. //! Checks if a background is drawn when no texture is set
  49. bool isDrawBackgroundEnabled() const override
  50. {
  51. return DrawBackground;
  52. }
  53. protected:
  54. void checkBounds(core::rect<s32> &rect)
  55. {
  56. f32 clipWidth = (f32)rect.getWidth();
  57. f32 clipHeight = (f32)rect.getHeight();
  58. rect.UpperLeftCorner.X += core::round32(DrawBounds.UpperLeftCorner.X * clipWidth);
  59. rect.UpperLeftCorner.Y += core::round32(DrawBounds.UpperLeftCorner.Y * clipHeight);
  60. rect.LowerRightCorner.X -= core::round32((1.f - DrawBounds.LowerRightCorner.X) * clipWidth);
  61. rect.LowerRightCorner.Y -= core::round32((1.f - DrawBounds.LowerRightCorner.Y) * clipHeight);
  62. }
  63. private:
  64. video::ITexture *Texture;
  65. video::SColor Color;
  66. bool UseAlphaChannel;
  67. bool ScaleImage;
  68. core::rect<s32> SourceRect;
  69. core::rect<f32> DrawBounds;
  70. bool DrawBackground;
  71. };
  72. } // end namespace gui
  73. } // end namespace irr