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.

109 lines
4.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software 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. #ifndef __JUCE_RELATIVERECTANGLE_JUCEHEADER__
  18. #define __JUCE_RELATIVERECTANGLE_JUCEHEADER__
  19. #include "juce_RelativeCoordinate.h"
  20. class Component;
  21. //==============================================================================
  22. /**
  23. An rectangle stored as a set of RelativeCoordinate values.
  24. The rectangle's top, left, bottom and right edge positions are each stored as a RelativeCoordinate.
  25. @see RelativeCoordinate, RelativePoint
  26. */
  27. class JUCE_API RelativeRectangle
  28. {
  29. public:
  30. //==============================================================================
  31. /** Creates a zero-size rectangle at the origin. */
  32. RelativeRectangle();
  33. /** Creates an absolute rectangle, relative to the origin. */
  34. explicit RelativeRectangle (const Rectangle<float>& rect);
  35. /** Creates a rectangle from four coordinates. */
  36. RelativeRectangle (const RelativeCoordinate& left, const RelativeCoordinate& right,
  37. const RelativeCoordinate& top, const RelativeCoordinate& bottom);
  38. /** Creates a rectangle from a stringified representation.
  39. The string must contain a sequence of 4 coordinates, separated by commas, in the order
  40. left, top, right, bottom. The syntax for the coordinate strings is explained in the
  41. RelativeCoordinate class.
  42. @see toString
  43. */
  44. explicit RelativeRectangle (const String& stringVersion);
  45. bool operator== (const RelativeRectangle& other) const noexcept;
  46. bool operator!= (const RelativeRectangle& other) const noexcept;
  47. //==============================================================================
  48. /** Calculates the absolute position of this rectangle.
  49. You'll need to provide a suitable Expression::Scope for looking up any coordinates that may
  50. be needed to calculate the result.
  51. */
  52. const Rectangle<float> resolve (const Expression::Scope* scope) const;
  53. /** Changes the values of this rectangle's coordinates to make it resolve to the specified position.
  54. Calling this will leave any anchor points unchanged, but will set any absolute
  55. or relative positions to whatever values are necessary to make the resultant position
  56. match the position that is provided.
  57. */
  58. void moveToAbsolute (const Rectangle<float>& newPos, const Expression::Scope* scope);
  59. /** Returns true if this rectangle depends on any external symbols for its position.
  60. Coordinates that refer to symbols based on "this" are assumed not to be dynamic.
  61. */
  62. bool isDynamic() const;
  63. /** Returns a string which represents this point.
  64. This returns a comma-separated list of coordinates, in the order left, top, right, bottom. For details of
  65. the string syntax used by the coordinates, see the RelativeCoordinate constructor notes.
  66. The string that is returned can be passed to the RelativeRectangle constructor to recreate the rectangle.
  67. */
  68. String toString() const;
  69. /** Renames a symbol if it is used by any of the coordinates.
  70. This calls Expression::withRenamedSymbol() on the rectangle's coordinates.
  71. */
  72. void renameSymbol (const Expression::Symbol& oldSymbol, const String& newName, const Expression::Scope& scope);
  73. /** Creates and sets an appropriate Component::Positioner object for the given component, which will
  74. keep it positioned with this rectangle.
  75. */
  76. void applyToComponent (Component& component) const;
  77. //==============================================================================
  78. // The actual rectangle coords...
  79. RelativeCoordinate left, right, top, bottom;
  80. };
  81. #endif // __JUCE_RELATIVERECTANGLE_JUCEHEADER__