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.

96 lines
2.8KB

  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. namespace RelativePointHelpers
  19. {
  20. inline void skipComma (String::CharPointerType& s)
  21. {
  22. s = s.findEndOfWhitespace();
  23. if (*s == ',')
  24. ++s;
  25. }
  26. }
  27. //==============================================================================
  28. RelativePoint::RelativePoint()
  29. {
  30. }
  31. RelativePoint::RelativePoint (const Point<float>& absolutePoint)
  32. : x (absolutePoint.x), y (absolutePoint.y)
  33. {
  34. }
  35. RelativePoint::RelativePoint (const float x_, const float y_)
  36. : x (x_), y (y_)
  37. {
  38. }
  39. RelativePoint::RelativePoint (const RelativeCoordinate& x_, const RelativeCoordinate& y_)
  40. : x (x_), y (y_)
  41. {
  42. }
  43. RelativePoint::RelativePoint (const String& s)
  44. {
  45. String::CharPointerType text (s.getCharPointer());
  46. x = RelativeCoordinate (Expression::parse (text));
  47. RelativePointHelpers::skipComma (text);
  48. y = RelativeCoordinate (Expression::parse (text));
  49. }
  50. bool RelativePoint::operator== (const RelativePoint& other) const noexcept
  51. {
  52. return x == other.x && y == other.y;
  53. }
  54. bool RelativePoint::operator!= (const RelativePoint& other) const noexcept
  55. {
  56. return ! operator== (other);
  57. }
  58. const Point<float> RelativePoint::resolve (const Expression::Scope* scope) const
  59. {
  60. return Point<float> ((float) x.resolve (scope),
  61. (float) y.resolve (scope));
  62. }
  63. void RelativePoint::moveToAbsolute (const Point<float>& newPos, const Expression::Scope* scope)
  64. {
  65. x.moveToAbsolute (newPos.x, scope);
  66. y.moveToAbsolute (newPos.y, scope);
  67. }
  68. String RelativePoint::toString() const
  69. {
  70. return x.toString() + ", " + y.toString();
  71. }
  72. bool RelativePoint::isDynamic() const
  73. {
  74. return x.isDynamic() || y.isDynamic();
  75. }