juce_DrawableImage.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. namespace juce
  20. {
  21. //==============================================================================
  22. /**
  23. A drawable object which is a bitmap image.
  24. @see Drawable
  25. @tags{GUI}
  26. */
  27. class JUCE_API DrawableImage : public Drawable
  28. {
  29. public:
  30. //==============================================================================
  31. DrawableImage();
  32. DrawableImage (const DrawableImage&);
  33. /** Destructor. */
  34. ~DrawableImage() override;
  35. //==============================================================================
  36. /** Sets the image that this drawable will render. */
  37. void setImage (const Image& imageToUse);
  38. /** Returns the current image. */
  39. const Image& getImage() const noexcept { return image; }
  40. /** Sets the opacity to use when drawing the image. */
  41. void setOpacity (float newOpacity);
  42. /** Returns the image's opacity. */
  43. float getOpacity() const noexcept { return opacity; }
  44. /** Sets a colour to draw over the image's alpha channel.
  45. By default this is transparent so isn't drawn, but if you set a non-transparent
  46. colour here, then it will be overlaid on the image, using the image's alpha
  47. channel as a mask.
  48. This is handy for doing things like darkening or lightening an image by overlaying
  49. it with semi-transparent black or white.
  50. */
  51. void setOverlayColour (Colour newOverlayColour);
  52. /** Returns the overlay colour. */
  53. Colour getOverlayColour() const noexcept { return overlayColour; }
  54. /** Sets the bounding box within which the image should be displayed. */
  55. void setBoundingBox (Parallelogram<float> newBounds);
  56. /** Sets the bounding box within which the image should be displayed. */
  57. void setBoundingBox (Rectangle<float> newBounds);
  58. /** Returns the position to which the image's top-left corner should be remapped in the target
  59. coordinate space when rendering this object.
  60. @see setTransform
  61. */
  62. Parallelogram<float> getBoundingBox() const noexcept { return bounds; }
  63. //==============================================================================
  64. /** @internal */
  65. void paint (Graphics&) override;
  66. /** @internal */
  67. bool hitTest (int x, int y) override;
  68. /** @internal */
  69. std::unique_ptr<Drawable> createCopy() const override;
  70. /** @internal */
  71. Rectangle<float> getDrawableBounds() const override;
  72. /** @internal */
  73. Path getOutlineAsPath() const override;
  74. private:
  75. //==============================================================================
  76. Image image;
  77. float opacity = 1.0f;
  78. Colour overlayColour { 0 };
  79. Parallelogram<float> bounds;
  80. DrawableImage& operator= (const DrawableImage&);
  81. JUCE_LEAK_DETECTOR (DrawableImage)
  82. };
  83. } // namespace juce