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.

101 lines
2.9KB

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