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.

142 lines
5.3KB

  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_JUCEHEADER__
  18. #define __JUCE_DRAWABLEIMAGE_JUCEHEADER__
  19. #include "juce_Drawable.h"
  20. #include "../positioning/juce_RelativeParallelogram.h"
  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& other);
  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 (const Colour& newOverlayColour);
  51. /** Returns the overlay colour. */
  52. const Colour& getOverlayColour() const noexcept { return overlayColour; }
  53. /** Sets the bounding box within which the image should be displayed. */
  54. void setBoundingBox (const RelativeParallelogram& newBounds);
  55. /** Returns the position to which the image's top-left corner should be remapped in the target
  56. coordinate space when rendering this object.
  57. @see setTransform
  58. */
  59. const RelativeParallelogram& getBoundingBox() const noexcept { return bounds; }
  60. //==============================================================================
  61. /** @internal */
  62. void paint (Graphics&) override;
  63. /** @internal */
  64. bool hitTest (int x, int y) override;
  65. /** @internal */
  66. Drawable* createCopy() const override;
  67. /** @internal */
  68. Rectangle<float> getDrawableBounds() const override;
  69. /** @internal */
  70. void refreshFromValueTree (const ValueTree& tree, ComponentBuilder& builder);
  71. /** @internal */
  72. ValueTree createValueTree (ComponentBuilder::ImageProvider* imageProvider) const override;
  73. /** @internal */
  74. static const Identifier valueTreeType;
  75. //==============================================================================
  76. /** Internally-used class for wrapping a DrawableImage's state into a ValueTree. */
  77. class ValueTreeWrapper : public Drawable::ValueTreeWrapperBase
  78. {
  79. public:
  80. ValueTreeWrapper (const ValueTree& state);
  81. var getImageIdentifier() const;
  82. void setImageIdentifier (const var& newIdentifier, UndoManager* undoManager);
  83. Value getImageIdentifierValue (UndoManager* undoManager);
  84. float getOpacity() const;
  85. void setOpacity (float newOpacity, UndoManager* undoManager);
  86. Value getOpacityValue (UndoManager* undoManager);
  87. Colour getOverlayColour() const;
  88. void setOverlayColour (const Colour& newColour, UndoManager* undoManager);
  89. Value getOverlayColourValue (UndoManager* undoManager);
  90. RelativeParallelogram getBoundingBox() const;
  91. void setBoundingBox (const RelativeParallelogram& newBounds, UndoManager* undoManager);
  92. static const Identifier opacity, overlay, image, topLeft, topRight, bottomLeft;
  93. };
  94. private:
  95. //==============================================================================
  96. Image image;
  97. float opacity;
  98. Colour overlayColour;
  99. RelativeParallelogram bounds;
  100. friend class Drawable::Positioner<DrawableImage>;
  101. bool registerCoordinates (RelativeCoordinatePositionerBase&);
  102. void recalculateCoordinates (Expression::Scope*);
  103. DrawableImage& operator= (const DrawableImage&);
  104. JUCE_LEAK_DETECTOR (DrawableImage)
  105. };
  106. #endif // __JUCE_DRAWABLEIMAGE_JUCEHEADER__