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.

juce_RelativePoint.cpp 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. namespace RelativePointHelpers
  21. {
  22. inline void skipComma (String::CharPointerType& s)
  23. {
  24. s = s.findEndOfWhitespace();
  25. if (*s == ',')
  26. ++s;
  27. }
  28. }
  29. //==============================================================================
  30. RelativePoint::RelativePoint()
  31. {
  32. }
  33. RelativePoint::RelativePoint (Point<float> absolutePoint)
  34. : x (absolutePoint.x), y (absolutePoint.y)
  35. {
  36. }
  37. RelativePoint::RelativePoint (const float x_, const float y_)
  38. : x (x_), y (y_)
  39. {
  40. }
  41. RelativePoint::RelativePoint (const RelativeCoordinate& x_, const RelativeCoordinate& y_)
  42. : x (x_), y (y_)
  43. {
  44. }
  45. RelativePoint::RelativePoint (const String& s)
  46. {
  47. String error;
  48. String::CharPointerType text (s.getCharPointer());
  49. x = RelativeCoordinate (Expression::parse (text, error));
  50. RelativePointHelpers::skipComma (text);
  51. y = RelativeCoordinate (Expression::parse (text, error));
  52. }
  53. bool RelativePoint::operator== (const RelativePoint& other) const noexcept
  54. {
  55. return x == other.x && y == other.y;
  56. }
  57. bool RelativePoint::operator!= (const RelativePoint& other) const noexcept
  58. {
  59. return ! operator== (other);
  60. }
  61. Point<float> RelativePoint::resolve (const Expression::Scope* scope) const
  62. {
  63. return Point<float> ((float) x.resolve (scope),
  64. (float) y.resolve (scope));
  65. }
  66. void RelativePoint::moveToAbsolute (Point<float> newPos, const Expression::Scope* scope)
  67. {
  68. x.moveToAbsolute (newPos.x, scope);
  69. y.moveToAbsolute (newPos.y, scope);
  70. }
  71. String RelativePoint::toString() const
  72. {
  73. return x.toString() + ", " + y.toString();
  74. }
  75. bool RelativePoint::isDynamic() const
  76. {
  77. return x.isDynamic() || y.isDynamic();
  78. }
  79. } // namespace juce