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.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. //==============================================================================
  21. /**
  22. A rectangle stored as a set of RelativeCoordinate values.
  23. The rectangle's top, left, bottom and right edge positions are each stored as a RelativeCoordinate.
  24. @see RelativeCoordinate, RelativePoint
  25. @tags{GUI}
  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&) const noexcept;
  46. bool operator!= (const RelativeRectangle&) 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.
  65. If you're using this to position a Component, then see the notes for
  66. Component::setBounds (const RelativeRectangle&) for details of the syntax used.
  67. The string that is returned can be passed to the RelativeRectangle constructor to recreate the rectangle.
  68. */
  69. String toString() const;
  70. /** Renames a symbol if it is used by any of the coordinates.
  71. This calls Expression::withRenamedSymbol() on the rectangle's coordinates.
  72. */
  73. void renameSymbol (const Expression::Symbol& oldSymbol, const String& newName, const Expression::Scope& scope);
  74. /** Creates and sets an appropriate Component::Positioner object for the given component, which will
  75. keep it positioned with this rectangle.
  76. */
  77. void applyToComponent (Component& component) const;
  78. //==============================================================================
  79. // The actual rectangle coords...
  80. RelativeCoordinate left, right, top, bottom;
  81. };
  82. } // namespace juce