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.

102 lines
4.2KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. namespace juce
  14. {
  15. //==============================================================================
  16. /**
  17. A rectangle stored as a set of RelativeCoordinate values.
  18. The rectangle's top, left, bottom and right edge positions are each stored as a RelativeCoordinate.
  19. @see RelativeCoordinate, RelativePoint
  20. @tags{GUI}
  21. */
  22. class JUCE_API RelativeRectangle
  23. {
  24. public:
  25. //==============================================================================
  26. /** Creates a zero-size rectangle at the origin. */
  27. RelativeRectangle();
  28. /** Creates an absolute rectangle, relative to the origin. */
  29. explicit RelativeRectangle (const Rectangle<float>& rect);
  30. /** Creates a rectangle from four coordinates. */
  31. RelativeRectangle (const RelativeCoordinate& left, const RelativeCoordinate& right,
  32. const RelativeCoordinate& top, const RelativeCoordinate& bottom);
  33. /** Creates a rectangle from a stringified representation.
  34. The string must contain a sequence of 4 coordinates, separated by commas, in the order
  35. left, top, right, bottom. The syntax for the coordinate strings is explained in the
  36. RelativeCoordinate class.
  37. @see toString
  38. */
  39. explicit RelativeRectangle (const String& stringVersion);
  40. bool operator== (const RelativeRectangle&) const noexcept;
  41. bool operator!= (const RelativeRectangle&) const noexcept;
  42. //==============================================================================
  43. /** Calculates the absolute position of this rectangle.
  44. You'll need to provide a suitable Expression::Scope for looking up any coordinates that may
  45. be needed to calculate the result.
  46. */
  47. const Rectangle<float> resolve (const Expression::Scope* scope) const;
  48. /** Changes the values of this rectangle's coordinates to make it resolve to the specified position.
  49. Calling this will leave any anchor points unchanged, but will set any absolute
  50. or relative positions to whatever values are necessary to make the resultant position
  51. match the position that is provided.
  52. */
  53. void moveToAbsolute (const Rectangle<float>& newPos, const Expression::Scope* scope);
  54. /** Returns true if this rectangle depends on any external symbols for its position.
  55. Coordinates that refer to symbols based on "this" are assumed not to be dynamic.
  56. */
  57. bool isDynamic() const;
  58. /** Returns a string which represents this point.
  59. This returns a comma-separated list of coordinates, in the order left, top, right, bottom.
  60. If you're using this to position a Component, then see the notes for
  61. Component::setBounds (const RelativeRectangle&) for details of the syntax used.
  62. The string that is returned can be passed to the RelativeRectangle constructor to recreate the rectangle.
  63. */
  64. String toString() const;
  65. /** Renames a symbol if it is used by any of the coordinates.
  66. This calls Expression::withRenamedSymbol() on the rectangle's coordinates.
  67. */
  68. void renameSymbol (const Expression::Symbol& oldSymbol, const String& newName, const Expression::Scope& scope);
  69. /** Creates and sets an appropriate Component::Positioner object for the given component, which will
  70. keep it positioned with this rectangle.
  71. */
  72. void applyToComponent (Component& component) const;
  73. //==============================================================================
  74. // The actual rectangle coords...
  75. RelativeCoordinate left, right, top, bottom;
  76. };
  77. } // namespace juce