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.

147 lines
3.9KB

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