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.

100 lines
3.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI 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. #pragma once
  18. //==============================================================================
  19. /**
  20. A Drawable object which draws a rectangle.
  21. For details on how to change the fill and stroke, see the DrawableShape class.
  22. @see Drawable, DrawableShape
  23. */
  24. class JUCE_API DrawableRectangle : public DrawableShape
  25. {
  26. public:
  27. //==============================================================================
  28. DrawableRectangle();
  29. DrawableRectangle (const DrawableRectangle&);
  30. /** Destructor. */
  31. ~DrawableRectangle();
  32. //==============================================================================
  33. /** Sets the rectangle's bounds. */
  34. void setRectangle (const RelativeParallelogram& newBounds);
  35. /** Returns the rectangle's bounds. */
  36. const RelativeParallelogram& getRectangle() const noexcept { return bounds; }
  37. /** Returns the corner size to be used. */
  38. const RelativePoint& getCornerSize() const noexcept { return cornerSize; }
  39. /** Sets a new corner size for the rectangle */
  40. void setCornerSize (const RelativePoint& newSize);
  41. //==============================================================================
  42. /** @internal */
  43. Drawable* createCopy() const;
  44. /** @internal */
  45. void refreshFromValueTree (const ValueTree& tree, ComponentBuilder& builder);
  46. /** @internal */
  47. ValueTree createValueTree (ComponentBuilder::ImageProvider* imageProvider) const;
  48. /** @internal */
  49. static const Identifier valueTreeType;
  50. //==============================================================================
  51. /** Internally-used class for wrapping a DrawableRectangle's state into a ValueTree. */
  52. class ValueTreeWrapper : public DrawableShape::FillAndStrokeState
  53. {
  54. public:
  55. ValueTreeWrapper (const ValueTree& state);
  56. RelativeParallelogram getRectangle() const;
  57. void setRectangle (const RelativeParallelogram& newBounds, UndoManager*);
  58. void setCornerSize (const RelativePoint& cornerSize, UndoManager*);
  59. RelativePoint getCornerSize() const;
  60. Value getCornerSizeValue (UndoManager*);
  61. static const Identifier topLeft, topRight, bottomLeft, cornerSize;
  62. };
  63. private:
  64. friend class Drawable::Positioner<DrawableRectangle>;
  65. RelativeParallelogram bounds;
  66. RelativePoint cornerSize;
  67. void rebuildPath();
  68. bool registerCoordinates (RelativeCoordinatePositionerBase&);
  69. void recalculateCoordinates (Expression::Scope*);
  70. DrawableRectangle& operator= (const DrawableRectangle&);
  71. JUCE_LEAK_DETECTOR (DrawableRectangle)
  72. };