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_RelativeCoordinate.cpp 4.2KB

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