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.

139 lines
6.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-10 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. #include "../../graphics/geometry/juce_Path.h"
  21. #include "../../graphics/geometry/juce_Rectangle.h"
  22. #include "../../../maths/juce_Expression.h"
  23. //==============================================================================
  24. /**
  25. Expresses a coordinate as a dynamically evaluated expression.
  26. @see RelativePoint, RelativeRectangle
  27. */
  28. class JUCE_API RelativeCoordinate
  29. {
  30. public:
  31. //==============================================================================
  32. /** Creates a zero coordinate. */
  33. RelativeCoordinate();
  34. RelativeCoordinate (const Expression& expression);
  35. RelativeCoordinate (const RelativeCoordinate& other);
  36. RelativeCoordinate& operator= (const RelativeCoordinate& other);
  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& other) const throw();
  50. bool operator!= (const RelativeCoordinate& other) const throw();
  51. //==============================================================================
  52. /** Calculates the absolute position of this coordinate.
  53. You'll need to provide a suitable Expression::EvaluationContext for looking up any coordinates that may
  54. be needed to calculate the result.
  55. */
  56. double resolve (const Expression::EvaluationContext* evaluationContext) 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::EvaluationContext* evaluationContext) const;
  61. /** Returns true if there's a recursive loop when trying to resolve this coordinate's position. */
  62. bool isRecursive (const Expression::EvaluationContext* evaluationContext) 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::EvaluationContext* evaluationContext);
  72. /** Changes the name of a symbol if it is used as part of the coordinate's expression. */
  73. void renameSymbolIfUsed (const String& oldName, const String& newName);
  74. /** Returns the expression that defines this coordinate. */
  75. const Expression& getExpression() const { return term; }
  76. //==============================================================================
  77. /** Returns a string which represents this coordinate.
  78. For details of the string syntax, see the constructor notes.
  79. */
  80. const String toString() const;
  81. //==============================================================================
  82. /** A set of static strings that are commonly used by the RelativeCoordinate class.
  83. As well as avoiding using string literals in your code, using these preset values
  84. has the advantage that all instances of the same string will share the same, reference-counted
  85. String object, so if you have thousands of points which all refer to the same
  86. anchor points, this can save a significant amount of memory allocation.
  87. */
  88. struct Strings
  89. {
  90. static const String parent; /**< "parent" */
  91. static const String this_; /**< "this" */
  92. static const String left; /**< "left" */
  93. static const String right; /**< "right" */
  94. static const String top; /**< "top" */
  95. static const String bottom; /**< "bottom" */
  96. static const String parentLeft; /**< "parent.left" */
  97. static const String parentTop; /**< "parent.top" */
  98. static const String parentRight; /**< "parent.right" */
  99. static const String parentBottom; /**< "parent.bottom" */
  100. };
  101. private:
  102. //==============================================================================
  103. Expression term;
  104. };
  105. #endif // __JUCE_RELATIVECOORDINATE_JUCEHEADER__