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_RelativeRectangle.h 4.5KB

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