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

7 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
7 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  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 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. namespace juce
  20. {
  21. const String RelativeCoordinate::Strings::parent ("parent");
  22. const String RelativeCoordinate::Strings::left ("left");
  23. const String RelativeCoordinate::Strings::right ("right");
  24. const String RelativeCoordinate::Strings::top ("top");
  25. const String RelativeCoordinate::Strings::bottom ("bottom");
  26. const String RelativeCoordinate::Strings::x ("x");
  27. const String RelativeCoordinate::Strings::y ("y");
  28. const String RelativeCoordinate::Strings::width ("width");
  29. const String RelativeCoordinate::Strings::height ("height");
  30. RelativeCoordinate::StandardStrings::Type RelativeCoordinate::StandardStrings::getTypeOf (const String& s) noexcept
  31. {
  32. if (s == Strings::left) return left;
  33. if (s == Strings::right) return right;
  34. if (s == Strings::top) return top;
  35. if (s == Strings::bottom) return bottom;
  36. if (s == Strings::x) return x;
  37. if (s == Strings::y) return y;
  38. if (s == Strings::width) return width;
  39. if (s == Strings::height) return height;
  40. if (s == Strings::parent) return parent;
  41. return unknown;
  42. }
  43. //==============================================================================
  44. RelativeCoordinate::RelativeCoordinate()
  45. {
  46. }
  47. RelativeCoordinate::RelativeCoordinate (const Expression& term_)
  48. : term (term_)
  49. {
  50. }
  51. RelativeCoordinate::RelativeCoordinate (const RelativeCoordinate& other)
  52. : term (other.term)
  53. {
  54. }
  55. RelativeCoordinate& RelativeCoordinate::operator= (const RelativeCoordinate& other)
  56. {
  57. term = other.term;
  58. return *this;
  59. }
  60. RelativeCoordinate::RelativeCoordinate (RelativeCoordinate&& other) noexcept
  61. : term (static_cast<Expression&&> (other.term))
  62. {
  63. }
  64. RelativeCoordinate& RelativeCoordinate::operator= (RelativeCoordinate&& other) noexcept
  65. {
  66. term = static_cast<Expression&&> (other.term);
  67. return *this;
  68. }
  69. RelativeCoordinate::RelativeCoordinate (const double absoluteDistanceFromOrigin)
  70. : term (absoluteDistanceFromOrigin)
  71. {
  72. }
  73. RelativeCoordinate::RelativeCoordinate (const String& s)
  74. {
  75. String error;
  76. term = Expression (s, error);
  77. }
  78. RelativeCoordinate::~RelativeCoordinate()
  79. {
  80. }
  81. bool RelativeCoordinate::operator== (const RelativeCoordinate& other) const noexcept
  82. {
  83. return term.toString() == other.term.toString();
  84. }
  85. bool RelativeCoordinate::operator!= (const RelativeCoordinate& other) const noexcept
  86. {
  87. return ! operator== (other);
  88. }
  89. double RelativeCoordinate::resolve (const Expression::Scope* scope) const
  90. {
  91. if (scope != nullptr)
  92. return term.evaluate (*scope);
  93. return term.evaluate();
  94. }
  95. bool RelativeCoordinate::isRecursive (const Expression::Scope* scope) const
  96. {
  97. String error;
  98. if (scope != nullptr)
  99. term.evaluate (*scope, error);
  100. else
  101. term.evaluate (Expression::Scope(), error);
  102. return error.isNotEmpty();
  103. }
  104. void RelativeCoordinate::moveToAbsolute (double newPos, const Expression::Scope* scope)
  105. {
  106. if (scope != nullptr)
  107. {
  108. term = term.adjustedToGiveNewResult (newPos, *scope);
  109. }
  110. else
  111. {
  112. Expression::Scope defaultScope;
  113. term = term.adjustedToGiveNewResult (newPos, defaultScope);
  114. }
  115. }
  116. bool RelativeCoordinate::isDynamic() const
  117. {
  118. return term.usesAnySymbols();
  119. }
  120. String RelativeCoordinate::toString() const
  121. {
  122. return term.toString();
  123. }
  124. } // namespace juce