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.

93 lines
3.5KB

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