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.

144 lines
5.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-10 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 "../imaging/juce_Image.h"
  22. #include "../../components/positioning/juce_RelativeParallelogram.h"
  23. //==============================================================================
  24. /**
  25. A drawable object which is a bitmap image.
  26. @see Drawable
  27. */
  28. class JUCE_API DrawableImage : public Drawable
  29. {
  30. public:
  31. //==============================================================================
  32. DrawableImage();
  33. DrawableImage (const DrawableImage& other);
  34. /** Destructor. */
  35. ~DrawableImage();
  36. //==============================================================================
  37. /** Sets the image that this drawable will render. */
  38. void setImage (const Image& imageToUse);
  39. /** Returns the current image. */
  40. const Image getImage() const { return image; }
  41. /** Sets the opacity to use when drawing the image. */
  42. void setOpacity (float newOpacity);
  43. /** Returns the image's opacity. */
  44. float getOpacity() const throw() { return opacity; }
  45. /** Sets a colour to draw over the image's alpha channel.
  46. By default this is transparent so isn't drawn, but if you set a non-transparent
  47. colour here, then it will be overlaid on the image, using the image's alpha
  48. channel as a mask.
  49. This is handy for doing things like darkening or lightening an image by overlaying
  50. it with semi-transparent black or white.
  51. */
  52. void setOverlayColour (const Colour& newOverlayColour);
  53. /** Returns the overlay colour. */
  54. const Colour& getOverlayColour() const throw() { return overlayColour; }
  55. /** Sets the bounding box within which the image should be displayed. */
  56. void setBoundingBox (const RelativeParallelogram& newBounds);
  57. /** Returns the position to which the image's top-left corner should be remapped in the target
  58. coordinate space when rendering this object.
  59. @see setTransform
  60. */
  61. const RelativeParallelogram& getBoundingBox() const throw() { return bounds; }
  62. //==============================================================================
  63. /** @internal */
  64. void paint (Graphics& g);
  65. /** @internal */
  66. bool hitTest (int x, int y) const;
  67. /** @internal */
  68. Drawable* createCopy() const;
  69. /** @internal */
  70. const Rectangle<float> getDrawableBounds() const;
  71. /** @internal */
  72. void refreshFromValueTree (const ValueTree& tree, ComponentBuilder& builder);
  73. /** @internal */
  74. const ValueTree createValueTree (ComponentBuilder::ImageProvider* imageProvider) const;
  75. /** @internal */
  76. static const Identifier valueTreeType;
  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. const var getImageIdentifier() const;
  84. void setImageIdentifier (const var& newIdentifier, UndoManager* undoManager);
  85. Value getImageIdentifierValue (UndoManager* undoManager);
  86. float getOpacity() const;
  87. void setOpacity (float newOpacity, UndoManager* undoManager);
  88. Value getOpacityValue (UndoManager* undoManager);
  89. const Colour getOverlayColour() const;
  90. void setOverlayColour (const Colour& newColour, UndoManager* undoManager);
  91. Value getOverlayColourValue (UndoManager* undoManager);
  92. const RelativeParallelogram getBoundingBox() const;
  93. void setBoundingBox (const RelativeParallelogram& newBounds, UndoManager* 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::EvaluationContext*);
  105. DrawableImage& operator= (const DrawableImage&);
  106. JUCE_LEAK_DETECTOR (DrawableImage);
  107. };
  108. #endif // __JUCE_DRAWABLEIMAGE_JUCEHEADER__