The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

109 lines
3.7KB

  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. */
  26. class JUCE_API DrawableImage : public Drawable
  27. {
  28. public:
  29. //==============================================================================
  30. DrawableImage();
  31. DrawableImage (const DrawableImage&);
  32. /** Destructor. */
  33. ~DrawableImage();
  34. //==============================================================================
  35. /** Sets the image that this drawable will render. */
  36. void setImage (const Image& imageToUse);
  37. /** Returns the current image. */
  38. const Image& getImage() const noexcept { return image; }
  39. /** Sets the opacity to use when drawing the image. */
  40. void setOpacity (float newOpacity);
  41. /** Returns the image's opacity. */
  42. float getOpacity() const noexcept { return opacity; }
  43. /** Sets a colour to draw over the image's alpha channel.
  44. By default this is transparent so isn't drawn, but if you set a non-transparent
  45. colour here, then it will be overlaid on the image, using the image's alpha
  46. channel as a mask.
  47. This is handy for doing things like darkening or lightening an image by overlaying
  48. it with semi-transparent black or white.
  49. */
  50. void setOverlayColour (Colour newOverlayColour);
  51. /** Returns the overlay colour. */
  52. Colour getOverlayColour() const noexcept { return overlayColour; }
  53. /** Sets the bounding box within which the image should be displayed. */
  54. void setBoundingBox (Parallelogram<float> newBounds);
  55. /** Sets the bounding box within which the image should be displayed. */
  56. void setBoundingBox (Rectangle<float> newBounds);
  57. /** Returns the position to which the image's top-left corner should be remapped in the target
  58. coordinate space when rendering this object.
  59. @see setTransform
  60. */
  61. Parallelogram<float> getBoundingBox() const noexcept { return bounds; }
  62. //==============================================================================
  63. /** @internal */
  64. void paint (Graphics&) override;
  65. /** @internal */
  66. bool hitTest (int x, int y) override;
  67. /** @internal */
  68. Drawable* createCopy() const override;
  69. /** @internal */
  70. Rectangle<float> getDrawableBounds() const override;
  71. /** @internal */
  72. Path getOutlineAsPath() const override;
  73. private:
  74. //==============================================================================
  75. Image image;
  76. float opacity = 1.0f;
  77. Colour overlayColour { 0 };
  78. Parallelogram<float> bounds;
  79. DrawableImage& operator= (const DrawableImage&);
  80. JUCE_LEAK_DETECTOR (DrawableImage)
  81. };
  82. } // namespace juce