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.

148 lines
4.2KB

  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. const String RelativeCoordinate::Strings::parent ("parent");
  18. const String RelativeCoordinate::Strings::left ("left");
  19. const String RelativeCoordinate::Strings::right ("right");
  20. const String RelativeCoordinate::Strings::top ("top");
  21. const String RelativeCoordinate::Strings::bottom ("bottom");
  22. const String RelativeCoordinate::Strings::x ("x");
  23. const String RelativeCoordinate::Strings::y ("y");
  24. const String RelativeCoordinate::Strings::width ("width");
  25. const String RelativeCoordinate::Strings::height ("height");
  26. RelativeCoordinate::StandardStrings::Type RelativeCoordinate::StandardStrings::getTypeOf (const String& s) noexcept
  27. {
  28. if (s == Strings::left) return left;
  29. if (s == Strings::right) return right;
  30. if (s == Strings::top) return top;
  31. if (s == Strings::bottom) return bottom;
  32. if (s == Strings::x) return x;
  33. if (s == Strings::y) return y;
  34. if (s == Strings::width) return width;
  35. if (s == Strings::height) return height;
  36. if (s == Strings::parent) return parent;
  37. return unknown;
  38. }
  39. //==============================================================================
  40. RelativeCoordinate::RelativeCoordinate()
  41. {
  42. }
  43. RelativeCoordinate::RelativeCoordinate (const Expression& term_)
  44. : term (term_)
  45. {
  46. }
  47. RelativeCoordinate::RelativeCoordinate (const RelativeCoordinate& other)
  48. : term (other.term)
  49. {
  50. }
  51. RelativeCoordinate& RelativeCoordinate::operator= (const RelativeCoordinate& other)
  52. {
  53. term = other.term;
  54. return *this;
  55. }
  56. RelativeCoordinate::RelativeCoordinate (RelativeCoordinate&& other) noexcept
  57. : term (static_cast<Expression&&> (other.term))
  58. {
  59. }
  60. RelativeCoordinate& RelativeCoordinate::operator= (RelativeCoordinate&& other) noexcept
  61. {
  62. term = static_cast<Expression&&> (other.term);
  63. return *this;
  64. }
  65. RelativeCoordinate::RelativeCoordinate (const double absoluteDistanceFromOrigin)
  66. : term (absoluteDistanceFromOrigin)
  67. {
  68. }
  69. RelativeCoordinate::RelativeCoordinate (const String& s)
  70. {
  71. String error;
  72. term = Expression (s, error);
  73. }
  74. RelativeCoordinate::~RelativeCoordinate()
  75. {
  76. }
  77. bool RelativeCoordinate::operator== (const RelativeCoordinate& other) const noexcept
  78. {
  79. return term.toString() == other.term.toString();
  80. }
  81. bool RelativeCoordinate::operator!= (const RelativeCoordinate& other) const noexcept
  82. {
  83. return ! operator== (other);
  84. }
  85. double RelativeCoordinate::resolve (const Expression::Scope* scope) const
  86. {
  87. if (scope != nullptr)
  88. return term.evaluate (*scope);
  89. return term.evaluate();
  90. }
  91. bool RelativeCoordinate::isRecursive (const Expression::Scope* scope) const
  92. {
  93. String error;
  94. if (scope != nullptr)
  95. term.evaluate (*scope, error);
  96. else
  97. term.evaluate (Expression::Scope(), error);
  98. return error.isNotEmpty();
  99. }
  100. void RelativeCoordinate::moveToAbsolute (double newPos, const Expression::Scope* scope)
  101. {
  102. if (scope != nullptr)
  103. {
  104. term = term.adjustedToGiveNewResult (newPos, *scope);
  105. }
  106. else
  107. {
  108. Expression::Scope defaultScope;
  109. term = term.adjustedToGiveNewResult (newPos, defaultScope);
  110. }
  111. }
  112. bool RelativeCoordinate::isDynamic() const
  113. {
  114. return term.usesAnySymbols();
  115. }
  116. String RelativeCoordinate::toString() const
  117. {
  118. return term.toString();
  119. }