juce_RelativePoint.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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_RELATIVEPOINT_H_INCLUDED
  18. #define JUCE_RELATIVEPOINT_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. An X-Y position stored as a pair of RelativeCoordinate values.
  22. @see RelativeCoordinate, RelativeRectangle
  23. */
  24. class JUCE_API RelativePoint
  25. {
  26. public:
  27. /** Creates a point at the origin. */
  28. RelativePoint();
  29. /** Creates an absolute point, relative to the origin. */
  30. RelativePoint (Point<float> absolutePoint);
  31. /** Creates an absolute point, relative to the origin. */
  32. RelativePoint (float absoluteX, float absoluteY);
  33. /** Creates an absolute point from two coordinates. */
  34. RelativePoint (const RelativeCoordinate& x, const RelativeCoordinate& y);
  35. /** Creates a point from a stringified representation.
  36. The string must contain a pair of coordinates, separated by space or a comma. The syntax for the coordinate
  37. strings is explained in the RelativeCoordinate class.
  38. @see toString
  39. */
  40. RelativePoint (const String& stringVersion);
  41. bool operator== (const RelativePoint&) const noexcept;
  42. bool operator!= (const RelativePoint&) const noexcept;
  43. /** Calculates the absolute position of this point.
  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. Point<float> resolve (const Expression::Scope* evaluationContext) const;
  48. /** Changes the values of this point'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 (Point<float> newPos, const Expression::Scope* evaluationContext);
  54. /** Returns a string which represents this point.
  55. This returns a comma-separated pair of coordinates. For details of the string syntax used by the
  56. coordinates, see the RelativeCoordinate constructor notes.
  57. The string that is returned can be passed to the RelativePoint constructor to recreate the point.
  58. */
  59. String toString() const;
  60. /** Returns true if this point depends on any other coordinates for its position. */
  61. bool isDynamic() const;
  62. // The actual X and Y coords...
  63. RelativeCoordinate x, y;
  64. };
  65. #endif // JUCE_RELATIVEPOINT_H_INCLUDED