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.

106 lines
4.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  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 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #pragma once
  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. */
  26. class JUCE_API RelativeRectangle
  27. {
  28. public:
  29. //==============================================================================
  30. /** Creates a zero-size rectangle at the origin. */
  31. RelativeRectangle();
  32. /** Creates an absolute rectangle, relative to the origin. */
  33. explicit RelativeRectangle (const Rectangle<float>& rect);
  34. /** Creates a rectangle from four coordinates. */
  35. RelativeRectangle (const RelativeCoordinate& left, const RelativeCoordinate& right,
  36. const RelativeCoordinate& top, const RelativeCoordinate& bottom);
  37. /** Creates a rectangle from a stringified representation.
  38. The string must contain a sequence of 4 coordinates, separated by commas, in the order
  39. left, top, right, bottom. The syntax for the coordinate strings is explained in the
  40. RelativeCoordinate class.
  41. @see toString
  42. */
  43. explicit RelativeRectangle (const String& stringVersion);
  44. bool operator== (const RelativeRectangle&) const noexcept;
  45. bool operator!= (const RelativeRectangle&) const noexcept;
  46. //==============================================================================
  47. /** Calculates the absolute position of this rectangle.
  48. You'll need to provide a suitable Expression::Scope for looking up any coordinates that may
  49. be needed to calculate the result.
  50. */
  51. const Rectangle<float> resolve (const Expression::Scope* scope) const;
  52. /** Changes the values of this rectangle's coordinates to make it resolve to the specified position.
  53. Calling this will leave any anchor points unchanged, but will set any absolute
  54. or relative positions to whatever values are necessary to make the resultant position
  55. match the position that is provided.
  56. */
  57. void moveToAbsolute (const Rectangle<float>& newPos, const Expression::Scope* scope);
  58. /** Returns true if this rectangle depends on any external symbols for its position.
  59. Coordinates that refer to symbols based on "this" are assumed not to be dynamic.
  60. */
  61. bool isDynamic() const;
  62. /** Returns a string which represents this point.
  63. This returns a comma-separated list of coordinates, in the order left, top, right, bottom.
  64. If you're using this to position a Component, then see the notes for
  65. Component::setBounds (const RelativeRectangle&) for details of the syntax used.
  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. };