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.

149 lines
6.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_RELATIVECOORDINATE_JUCEHEADER__
  19. #define __JUCE_RELATIVECOORDINATE_JUCEHEADER__
  20. //==============================================================================
  21. /**
  22. Expresses a coordinate as a dynamically evaluated expression.
  23. @see RelativePoint, RelativeRectangle
  24. */
  25. class JUCE_API RelativeCoordinate
  26. {
  27. public:
  28. //==============================================================================
  29. /** Creates a zero coordinate. */
  30. RelativeCoordinate();
  31. RelativeCoordinate (const Expression& expression);
  32. RelativeCoordinate (const RelativeCoordinate& other);
  33. RelativeCoordinate& operator= (const RelativeCoordinate& other);
  34. #if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
  35. RelativeCoordinate (RelativeCoordinate&& other) noexcept;
  36. RelativeCoordinate& operator= (RelativeCoordinate&& other) noexcept;
  37. #endif
  38. /** Creates an absolute position from the parent origin on either the X or Y axis.
  39. @param absoluteDistanceFromOrigin the distance from the origin
  40. */
  41. RelativeCoordinate (double absoluteDistanceFromOrigin);
  42. /** Recreates a coordinate from a string description.
  43. The string will be parsed by ExpressionParser::parse().
  44. @param stringVersion the expression to use
  45. @see toString
  46. */
  47. RelativeCoordinate (const String& stringVersion);
  48. /** Destructor. */
  49. ~RelativeCoordinate();
  50. bool operator== (const RelativeCoordinate& other) const noexcept;
  51. bool operator!= (const RelativeCoordinate& other) const noexcept;
  52. //==============================================================================
  53. /** Calculates the absolute position of this coordinate.
  54. You'll need to provide a suitable Expression::Scope for looking up any coordinates that may
  55. be needed to calculate the result.
  56. */
  57. double resolve (const Expression::Scope* evaluationScope) const;
  58. /** Returns true if this coordinate uses the specified coord name at any level in its evaluation.
  59. This will recursively check any coordinates upon which this one depends.
  60. */
  61. bool references (const String& coordName, const Expression::Scope* evaluationScope) const;
  62. /** Returns true if there's a recursive loop when trying to resolve this coordinate's position. */
  63. bool isRecursive (const Expression::Scope* evaluationScope) const;
  64. /** Returns true if this coordinate depends on any other coordinates for its position. */
  65. bool isDynamic() const;
  66. //==============================================================================
  67. /** Changes the value of this coord to make it resolve to the specified position.
  68. Calling this will leave the anchor points unchanged, but will set this coordinate's absolute
  69. or relative position to whatever value is necessary to make its resultant position
  70. match the position that is provided.
  71. */
  72. void moveToAbsolute (double absoluteTargetPosition, const Expression::Scope* evaluationScope);
  73. /** Returns the expression that defines this coordinate. */
  74. const Expression& getExpression() const { return term; }
  75. //==============================================================================
  76. /** Returns a string which represents this coordinate.
  77. For details of the string syntax, see the constructor notes.
  78. */
  79. String toString() const;
  80. //==============================================================================
  81. /** A set of static strings that are commonly used by the RelativeCoordinate class.
  82. As well as avoiding using string literals in your code, using these preset values
  83. has the advantage that all instances of the same string will share the same, reference-counted
  84. String object, so if you have thousands of points which all refer to the same
  85. anchor points, this can save a significant amount of memory allocation.
  86. */
  87. struct Strings
  88. {
  89. static const String parent; /**< "parent" */
  90. static const String left; /**< "left" */
  91. static const String right; /**< "right" */
  92. static const String top; /**< "top" */
  93. static const String bottom; /**< "bottom" */
  94. static const String x; /**< "x" */
  95. static const String y; /**< "y" */
  96. static const String width; /**< "width" */
  97. static const String height; /**< "height" */
  98. };
  99. struct StandardStrings
  100. {
  101. enum Type
  102. {
  103. left, right, top, bottom,
  104. x, y, width, height,
  105. parent,
  106. unknown
  107. };
  108. static Type getTypeOf (const String& s) noexcept;
  109. };
  110. private:
  111. //==============================================================================
  112. Expression term;
  113. };
  114. #endif // __JUCE_RELATIVECOORDINATE_JUCEHEADER__