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.

95 lines
2.4KB

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