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. return term.evaluate();
  99. }
  100. catch (Expression::ParseError&)
  101. {}
  102. return 0.0;
  103. }
  104. bool RelativeCoordinate::isRecursive (const Expression::Scope* scope) const
  105. {
  106. try
  107. {
  108. if (scope != nullptr)
  109. term.evaluate (*scope);
  110. else
  111. term.evaluate();
  112. }
  113. catch (Expression::ParseError&)
  114. {
  115. return true;
  116. }
  117. return false;
  118. }
  119. void RelativeCoordinate::moveToAbsolute (double newPos, const Expression::Scope* scope)
  120. {
  121. try
  122. {
  123. if (scope != nullptr)
  124. {
  125. term = term.adjustedToGiveNewResult (newPos, *scope);
  126. }
  127. else
  128. {
  129. Expression::Scope defaultScope;
  130. term = term.adjustedToGiveNewResult (newPos, defaultScope);
  131. }
  132. }
  133. catch (Expression::ParseError&)
  134. {}
  135. }
  136. bool RelativeCoordinate::isDynamic() const
  137. {
  138. return term.usesAnySymbols();
  139. }
  140. String RelativeCoordinate::toString() const
  141. {
  142. return term.toString();
  143. }