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.

172 lines
4.8KB

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