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.

juce_DrawableImage.h 5.0KB

7 years ago
7 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 (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&);
  71. /** @internal */
  72. ValueTree createValueTree (ComponentBuilder::ImageProvider*) const override;
  73. /** @internal */
  74. static const Identifier valueTreeType;
  75. /** @internal */
  76. Path getOutlineAsPath() const override;
  77. //==============================================================================
  78. /** Internally-used class for wrapping a DrawableImage's state into a ValueTree. */
  79. class ValueTreeWrapper : public Drawable::ValueTreeWrapperBase
  80. {
  81. public:
  82. ValueTreeWrapper (const ValueTree& state);
  83. var getImageIdentifier() const;
  84. void setImageIdentifier (const var&, UndoManager*);
  85. Value getImageIdentifierValue (UndoManager*);
  86. float getOpacity() const;
  87. void setOpacity (float newOpacity, UndoManager*);
  88. Value getOpacityValue (UndoManager*);
  89. Colour getOverlayColour() const;
  90. void setOverlayColour (Colour newColour, UndoManager*);
  91. Value getOverlayColourValue (UndoManager*);
  92. RelativeParallelogram getBoundingBox() const;
  93. void setBoundingBox (const RelativeParallelogram&, UndoManager*);
  94. static const Identifier opacity, overlay, image, topLeft, topRight, bottomLeft;
  95. };
  96. private:
  97. //==============================================================================
  98. Image image;
  99. float opacity;
  100. Colour overlayColour;
  101. RelativeParallelogram bounds;
  102. friend class Drawable::Positioner<DrawableImage>;
  103. bool registerCoordinates (RelativeCoordinatePositionerBase&);
  104. void recalculateCoordinates (Expression::Scope*);
  105. DrawableImage& operator= (const DrawableImage&);
  106. JUCE_LEAK_DETECTOR (DrawableImage)
  107. };
  108. } // namespace juce