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.

135 lines
5.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #pragma once
  18. //==============================================================================
  19. /**
  20. A drawable object which is a bitmap image.
  21. @see Drawable
  22. */
  23. class JUCE_API DrawableImage : public Drawable
  24. {
  25. public:
  26. //==============================================================================
  27. DrawableImage();
  28. DrawableImage (const DrawableImage&);
  29. /** Destructor. */
  30. ~DrawableImage();
  31. //==============================================================================
  32. /** Sets the image that this drawable will render. */
  33. void setImage (const Image& imageToUse);
  34. /** Returns the current image. */
  35. const Image& getImage() const noexcept { return image; }
  36. /** Sets the opacity to use when drawing the image. */
  37. void setOpacity (float newOpacity);
  38. /** Returns the image's opacity. */
  39. float getOpacity() const noexcept { return opacity; }
  40. /** Sets a colour to draw over the image's alpha channel.
  41. By default this is transparent so isn't drawn, but if you set a non-transparent
  42. colour here, then it will be overlaid on the image, using the image's alpha
  43. channel as a mask.
  44. This is handy for doing things like darkening or lightening an image by overlaying
  45. it with semi-transparent black or white.
  46. */
  47. void setOverlayColour (Colour newOverlayColour);
  48. /** Returns the overlay colour. */
  49. Colour getOverlayColour() const noexcept { return overlayColour; }
  50. /** Sets the bounding box within which the image should be displayed. */
  51. void setBoundingBox (const RelativeParallelogram& newBounds);
  52. /** Returns the position to which the image's top-left corner should be remapped in the target
  53. coordinate space when rendering this object.
  54. @see setTransform
  55. */
  56. const RelativeParallelogram& getBoundingBox() const noexcept { return bounds; }
  57. //==============================================================================
  58. /** @internal */
  59. void paint (Graphics&) override;
  60. /** @internal */
  61. bool hitTest (int x, int y) override;
  62. /** @internal */
  63. Drawable* createCopy() const override;
  64. /** @internal */
  65. Rectangle<float> getDrawableBounds() const override;
  66. /** @internal */
  67. void refreshFromValueTree (const ValueTree& tree, ComponentBuilder&);
  68. /** @internal */
  69. ValueTree createValueTree (ComponentBuilder::ImageProvider*) const override;
  70. /** @internal */
  71. static const Identifier valueTreeType;
  72. //==============================================================================
  73. /** Internally-used class for wrapping a DrawableImage's state into a ValueTree. */
  74. class ValueTreeWrapper : public Drawable::ValueTreeWrapperBase
  75. {
  76. public:
  77. ValueTreeWrapper (const ValueTree& state);
  78. var getImageIdentifier() const;
  79. void setImageIdentifier (const var&, UndoManager*);
  80. Value getImageIdentifierValue (UndoManager*);
  81. float getOpacity() const;
  82. void setOpacity (float newOpacity, UndoManager*);
  83. Value getOpacityValue (UndoManager*);
  84. Colour getOverlayColour() const;
  85. void setOverlayColour (Colour newColour, UndoManager*);
  86. Value getOverlayColourValue (UndoManager*);
  87. RelativeParallelogram getBoundingBox() const;
  88. void setBoundingBox (const RelativeParallelogram&, UndoManager*);
  89. static const Identifier opacity, overlay, image, topLeft, topRight, bottomLeft;
  90. };
  91. private:
  92. //==============================================================================
  93. Image image;
  94. float opacity;
  95. Colour overlayColour;
  96. RelativeParallelogram bounds;
  97. friend class Drawable::Positioner<DrawableImage>;
  98. bool registerCoordinates (RelativeCoordinatePositionerBase&);
  99. void recalculateCoordinates (Expression::Scope*);
  100. DrawableImage& operator= (const DrawableImage&);
  101. JUCE_LEAK_DETECTOR (DrawableImage)
  102. };