Audio plugin host https://kx.studio/carla
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.

139 lines
5.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software 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. #ifndef JUCE_DRAWABLEIMAGE_H_INCLUDED
  18. #define JUCE_DRAWABLEIMAGE_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. A drawable object which is a bitmap image.
  22. @see Drawable
  23. */
  24. class JUCE_API DrawableImage : public Drawable
  25. {
  26. public:
  27. //==============================================================================
  28. DrawableImage();
  29. DrawableImage (const DrawableImage& other);
  30. /** Destructor. */
  31. ~DrawableImage();
  32. //==============================================================================
  33. /** Sets the image that this drawable will render. */
  34. void setImage (const Image& imageToUse);
  35. /** Returns the current image. */
  36. const Image& getImage() const noexcept { return image; }
  37. /** Sets the opacity to use when drawing the image. */
  38. void setOpacity (float newOpacity);
  39. /** Returns the image's opacity. */
  40. float getOpacity() const noexcept { return opacity; }
  41. /** Sets a colour to draw over the image's alpha channel.
  42. By default this is transparent so isn't drawn, but if you set a non-transparent
  43. colour here, then it will be overlaid on the image, using the image's alpha
  44. channel as a mask.
  45. This is handy for doing things like darkening or lightening an image by overlaying
  46. it with semi-transparent black or white.
  47. */
  48. void setOverlayColour (Colour newOverlayColour);
  49. /** Returns the overlay colour. */
  50. Colour getOverlayColour() const noexcept { return overlayColour; }
  51. /** Sets the bounding box within which the image should be displayed. */
  52. void setBoundingBox (const RelativeParallelogram& newBounds);
  53. /** Returns the position to which the image's top-left corner should be remapped in the target
  54. coordinate space when rendering this object.
  55. @see setTransform
  56. */
  57. const RelativeParallelogram& getBoundingBox() const noexcept { return bounds; }
  58. //==============================================================================
  59. /** @internal */
  60. void paint (Graphics&) override;
  61. /** @internal */
  62. bool hitTest (int x, int y) override;
  63. /** @internal */
  64. Drawable* createCopy() const override;
  65. /** @internal */
  66. Rectangle<float> getDrawableBounds() const override;
  67. /** @internal */
  68. void refreshFromValueTree (const ValueTree& tree, ComponentBuilder&);
  69. /** @internal */
  70. ValueTree createValueTree (ComponentBuilder::ImageProvider*) const override;
  71. /** @internal */
  72. static const Identifier valueTreeType;
  73. //==============================================================================
  74. /** Internally-used class for wrapping a DrawableImage's state into a ValueTree. */
  75. class ValueTreeWrapper : public Drawable::ValueTreeWrapperBase
  76. {
  77. public:
  78. ValueTreeWrapper (const ValueTree& state);
  79. var getImageIdentifier() const;
  80. void setImageIdentifier (const var&, UndoManager*);
  81. Value getImageIdentifierValue (UndoManager*);
  82. float getOpacity() const;
  83. void setOpacity (float newOpacity, UndoManager*);
  84. Value getOpacityValue (UndoManager*);
  85. Colour getOverlayColour() const;
  86. void setOverlayColour (Colour newColour, UndoManager*);
  87. Value getOverlayColourValue (UndoManager*);
  88. RelativeParallelogram getBoundingBox() const;
  89. void setBoundingBox (const RelativeParallelogram&, UndoManager*);
  90. static const Identifier opacity, overlay, image, topLeft, topRight, bottomLeft;
  91. };
  92. private:
  93. //==============================================================================
  94. Image image;
  95. float opacity;
  96. Colour overlayColour;
  97. RelativeParallelogram bounds;
  98. friend class Drawable::Positioner<DrawableImage>;
  99. bool registerCoordinates (RelativeCoordinatePositionerBase&);
  100. void recalculateCoordinates (Expression::Scope*);
  101. DrawableImage& operator= (const DrawableImage&);
  102. JUCE_LEAK_DETECTOR (DrawableImage)
  103. };
  104. #endif // JUCE_DRAWABLEIMAGE_H_INCLUDED