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.

177 lines
4.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. BEGIN_JUCE_NAMESPACE
  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. #if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
  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. #endif
  70. RelativeCoordinate::RelativeCoordinate (const double absoluteDistanceFromOrigin)
  71. : term (absoluteDistanceFromOrigin)
  72. {
  73. }
  74. RelativeCoordinate::RelativeCoordinate (const String& s)
  75. {
  76. try
  77. {
  78. term = Expression (s);
  79. }
  80. catch (Expression::ParseError&)
  81. {}
  82. }
  83. RelativeCoordinate::~RelativeCoordinate()
  84. {
  85. }
  86. bool RelativeCoordinate::operator== (const RelativeCoordinate& other) const noexcept
  87. {
  88. return term.toString() == other.term.toString();
  89. }
  90. bool RelativeCoordinate::operator!= (const RelativeCoordinate& other) const noexcept
  91. {
  92. return ! operator== (other);
  93. }
  94. double RelativeCoordinate::resolve (const Expression::Scope* scope) const
  95. {
  96. try
  97. {
  98. if (scope != nullptr)
  99. return term.evaluate (*scope);
  100. else
  101. return term.evaluate();
  102. }
  103. catch (Expression::ParseError&)
  104. {}
  105. return 0.0;
  106. }
  107. bool RelativeCoordinate::isRecursive (const Expression::Scope* scope) const
  108. {
  109. try
  110. {
  111. if (scope != nullptr)
  112. term.evaluate (*scope);
  113. else
  114. term.evaluate();
  115. }
  116. catch (Expression::ParseError&)
  117. {
  118. return true;
  119. }
  120. return false;
  121. }
  122. void RelativeCoordinate::moveToAbsolute (double newPos, const Expression::Scope* scope)
  123. {
  124. try
  125. {
  126. if (scope != nullptr)
  127. {
  128. term = term.adjustedToGiveNewResult (newPos, *scope);
  129. }
  130. else
  131. {
  132. Expression::Scope defaultScope;
  133. term = term.adjustedToGiveNewResult (newPos, defaultScope);
  134. }
  135. }
  136. catch (Expression::ParseError&)
  137. {}
  138. }
  139. bool RelativeCoordinate::isDynamic() const
  140. {
  141. return term.usesAnySymbols();
  142. }
  143. String RelativeCoordinate::toString() const
  144. {
  145. return term.toString();
  146. }
  147. END_JUCE_NAMESPACE