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.

143 lines
5.5KB

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