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_RelativeCoordinate.h 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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_RELATIVECOORDINATE_H_INCLUDED
  18. #define JUCE_RELATIVECOORDINATE_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. Expresses a coordinate as a dynamically evaluated expression.
  22. @see RelativePoint, RelativeRectangle
  23. */
  24. class JUCE_API RelativeCoordinate
  25. {
  26. public:
  27. //==============================================================================
  28. /** Creates a zero coordinate. */
  29. RelativeCoordinate();
  30. RelativeCoordinate (const Expression& expression);
  31. RelativeCoordinate (const RelativeCoordinate&);
  32. RelativeCoordinate& operator= (const RelativeCoordinate&);
  33. #if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
  34. RelativeCoordinate (RelativeCoordinate&&) noexcept;
  35. RelativeCoordinate& operator= (RelativeCoordinate&&) noexcept;
  36. #endif
  37. /** Creates an absolute position from the parent origin on either the X or Y axis.
  38. @param absoluteDistanceFromOrigin the distance from the origin
  39. */
  40. RelativeCoordinate (double absoluteDistanceFromOrigin);
  41. /** Recreates a coordinate from a string description.
  42. The string will be parsed by ExpressionParser::parse().
  43. @param stringVersion the expression to use
  44. @see toString
  45. */
  46. RelativeCoordinate (const String& stringVersion);
  47. /** Destructor. */
  48. ~RelativeCoordinate();
  49. bool operator== (const RelativeCoordinate&) const noexcept;
  50. bool operator!= (const RelativeCoordinate&) const noexcept;
  51. //==============================================================================
  52. /** Calculates the absolute position of this coordinate.
  53. You'll need to provide a suitable Expression::Scope for looking up any coordinates that may
  54. be needed to calculate the result.
  55. */
  56. double resolve (const Expression::Scope* evaluationScope) const;
  57. /** Returns true if this coordinate uses the specified coord name at any level in its evaluation.
  58. This will recursively check any coordinates upon which this one depends.
  59. */
  60. bool references (const String& coordName, const Expression::Scope* evaluationScope) const;
  61. /** Returns true if there's a recursive loop when trying to resolve this coordinate's position. */
  62. bool isRecursive (const Expression::Scope* evaluationScope) const;
  63. /** Returns true if this coordinate depends on any other coordinates for its position. */
  64. bool isDynamic() const;
  65. //==============================================================================
  66. /** Changes the value of this coord to make it resolve to the specified position.
  67. Calling this will leave the anchor points unchanged, but will set this coordinate's absolute
  68. or relative position to whatever value is necessary to make its resultant position
  69. match the position that is provided.
  70. */
  71. void moveToAbsolute (double absoluteTargetPosition, const Expression::Scope* evaluationScope);
  72. /** Returns the expression that defines this coordinate. */
  73. const Expression& getExpression() const { return term; }
  74. //==============================================================================
  75. /** Returns a string which represents this coordinate.
  76. For details of the string syntax, see the constructor notes.
  77. */
  78. String toString() const;
  79. //==============================================================================
  80. /** A set of static strings that are commonly used by the RelativeCoordinate class.
  81. As well as avoiding using string literals in your code, using these preset values
  82. has the advantage that all instances of the same string will share the same, reference-counted
  83. String object, so if you have thousands of points which all refer to the same
  84. anchor points, this can save a significant amount of memory allocation.
  85. */
  86. struct Strings
  87. {
  88. static const String parent; /**< "parent" */
  89. static const String left; /**< "left" */
  90. static const String right; /**< "right" */
  91. static const String top; /**< "top" */
  92. static const String bottom; /**< "bottom" */
  93. static const String x; /**< "x" */
  94. static const String y; /**< "y" */
  95. static const String width; /**< "width" */
  96. static const String height; /**< "height" */
  97. };
  98. struct StandardStrings
  99. {
  100. enum Type
  101. {
  102. left, right, top, bottom,
  103. x, y, width, height,
  104. parent,
  105. unknown
  106. };
  107. static Type getTypeOf (const String& s) noexcept;
  108. };
  109. private:
  110. //==============================================================================
  111. Expression term;
  112. };
  113. #endif // JUCE_RELATIVECOORDINATE_H_INCLUDED