Add remaining files
[juce-lv2.git] / juce / source / src / gui / components / positioning / juce_RelativeCoordinate.cpp
blobd60b3921ef351b499fc9dbd397dedc3c084418eb
1 /*
2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #include "../../../core/juce_StandardHeader.h"
28 BEGIN_JUCE_NAMESPACE
30 #include "juce_RelativeCoordinate.h"
33 //==============================================================================
34 const String RelativeCoordinate::Strings::parent ("parent");
35 const String RelativeCoordinate::Strings::left ("left");
36 const String RelativeCoordinate::Strings::right ("right");
37 const String RelativeCoordinate::Strings::top ("top");
38 const String RelativeCoordinate::Strings::bottom ("bottom");
39 const String RelativeCoordinate::Strings::x ("x");
40 const String RelativeCoordinate::Strings::y ("y");
41 const String RelativeCoordinate::Strings::width ("width");
42 const String RelativeCoordinate::Strings::height ("height");
44 RelativeCoordinate::StandardStrings::Type RelativeCoordinate::StandardStrings::getTypeOf (const String& s) noexcept
46 if (s == Strings::left) return left;
47 if (s == Strings::right) return right;
48 if (s == Strings::top) return top;
49 if (s == Strings::bottom) return bottom;
50 if (s == Strings::x) return x;
51 if (s == Strings::y) return y;
52 if (s == Strings::width) return width;
53 if (s == Strings::height) return height;
54 if (s == Strings::parent) return parent;
55 return unknown;
58 //==============================================================================
59 RelativeCoordinate::RelativeCoordinate()
63 RelativeCoordinate::RelativeCoordinate (const Expression& term_)
64 : term (term_)
68 RelativeCoordinate::RelativeCoordinate (const RelativeCoordinate& other)
69 : term (other.term)
73 RelativeCoordinate& RelativeCoordinate::operator= (const RelativeCoordinate& other)
75 term = other.term;
76 return *this;
79 RelativeCoordinate::RelativeCoordinate (const double absoluteDistanceFromOrigin)
80 : term (absoluteDistanceFromOrigin)
84 RelativeCoordinate::RelativeCoordinate (const String& s)
86 try
88 term = Expression (s);
90 catch (...)
94 RelativeCoordinate::~RelativeCoordinate()
98 bool RelativeCoordinate::operator== (const RelativeCoordinate& other) const noexcept
100 return term.toString() == other.term.toString();
103 bool RelativeCoordinate::operator!= (const RelativeCoordinate& other) const noexcept
105 return ! operator== (other);
108 double RelativeCoordinate::resolve (const Expression::Scope* scope) const
112 if (scope != nullptr)
113 return term.evaluate (*scope);
114 else
115 return term.evaluate();
117 catch (...)
120 return 0.0;
123 bool RelativeCoordinate::isRecursive (const Expression::Scope* scope) const
127 if (scope != nullptr)
128 term.evaluate (*scope);
129 else
130 term.evaluate();
132 catch (...)
134 return true;
137 return false;
140 void RelativeCoordinate::moveToAbsolute (double newPos, const Expression::Scope* scope)
144 if (scope != nullptr)
146 term = term.adjustedToGiveNewResult (newPos, *scope);
148 else
150 Expression::Scope defaultScope;
151 term = term.adjustedToGiveNewResult (newPos, defaultScope);
154 catch (...)
158 bool RelativeCoordinate::isDynamic() const
160 return term.usesAnySymbols();
163 String RelativeCoordinate::toString() const
165 return term.toString();
170 END_JUCE_NAMESPACE