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.

137 lines
4.9KB

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