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.

94 lines
3.7KB

  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_RELATIVEPOINT_JUCEHEADER__
  19. #define __JUCE_RELATIVEPOINT_JUCEHEADER__
  20. #include "juce_RelativeCoordinate.h"
  21. //==============================================================================
  22. /**
  23. An X-Y position stored as a pair of RelativeCoordinate values.
  24. @see RelativeCoordinate, RelativeRectangle
  25. */
  26. class JUCE_API RelativePoint
  27. {
  28. public:
  29. /** Creates a point at the origin. */
  30. RelativePoint();
  31. /** Creates an absolute point, relative to the origin. */
  32. RelativePoint (const Point<float>& absolutePoint);
  33. /** Creates an absolute point, relative to the origin. */
  34. RelativePoint (float absoluteX, float absoluteY);
  35. /** Creates an absolute point from two coordinates. */
  36. RelativePoint (const RelativeCoordinate& x, const RelativeCoordinate& y);
  37. /** Creates a point from a stringified representation.
  38. The string must contain a pair of coordinates, separated by space or a comma. The syntax for the coordinate
  39. strings is explained in the RelativeCoordinate class.
  40. @see toString
  41. */
  42. RelativePoint (const String& stringVersion);
  43. bool operator== (const RelativePoint& other) const noexcept;
  44. bool operator!= (const RelativePoint& other) const noexcept;
  45. /** Calculates the absolute position of this point.
  46. You'll need to provide a suitable Expression::Scope for looking up any coordinates that may
  47. be needed to calculate the result.
  48. */
  49. const Point<float> resolve (const Expression::Scope* evaluationContext) const;
  50. /** Changes the values of this point's coordinates to make it resolve to the specified position.
  51. Calling this will leave any anchor points unchanged, but will set any absolute
  52. or relative positions to whatever values are necessary to make the resultant position
  53. match the position that is provided.
  54. */
  55. void moveToAbsolute (const Point<float>& newPos, const Expression::Scope* evaluationContext);
  56. /** Returns a string which represents this point.
  57. This returns a comma-separated pair of coordinates. For details of the string syntax used by the
  58. coordinates, see the RelativeCoordinate constructor notes.
  59. The string that is returned can be passed to the RelativePoint constructor to recreate the point.
  60. */
  61. String toString() const;
  62. /** Returns true if this point depends on any other coordinates for its position. */
  63. bool isDynamic() const;
  64. // The actual X and Y coords...
  65. RelativeCoordinate x, y;
  66. };
  67. #endif // __JUCE_RELATIVEPOINT_JUCEHEADER__