Audio plugin host https://kx.studio/carla
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.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI 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. namespace RelativePointHelpers
  18. {
  19. inline void skipComma (String::CharPointerType& s)
  20. {
  21. s = s.findEndOfWhitespace();
  22. if (*s == ',')
  23. ++s;
  24. }
  25. }
  26. //==============================================================================
  27. RelativePoint::RelativePoint()
  28. {
  29. }
  30. RelativePoint::RelativePoint (Point<float> absolutePoint)
  31. : x (absolutePoint.x), y (absolutePoint.y)
  32. {
  33. }
  34. RelativePoint::RelativePoint (const float x_, const float y_)
  35. : x (x_), y (y_)
  36. {
  37. }
  38. RelativePoint::RelativePoint (const RelativeCoordinate& x_, const RelativeCoordinate& y_)
  39. : x (x_), y (y_)
  40. {
  41. }
  42. RelativePoint::RelativePoint (const String& s)
  43. {
  44. String error;
  45. String::CharPointerType text (s.getCharPointer());
  46. x = RelativeCoordinate (Expression::parse (text, error));
  47. RelativePointHelpers::skipComma (text);
  48. y = RelativeCoordinate (Expression::parse (text, error));
  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. 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 (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. }