LMMS
Loading...
Searching...
No Matches
juce_RelativeRectangle.cpp
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
30{
31 inline void skipComma (String::CharPointerType& s)
32 {
33 s.incrementToEndOfWhitespace();
34
35 if (*s == ',')
36 ++s;
37 }
38
40 {
41 if (e.getType() == Expression::operatorType && e.getSymbolOrFunction() == ".")
42 return true;
43
44 if (e.getType() == Expression::symbolType)
45 {
46 switch (RelativeCoordinate::StandardStrings::getTypeOf (e.getSymbolOrFunction()))
47 {
58
59 default: break;
60 }
61
62 return true;
63 }
64 else
65 {
66 for (int i = e.getNumInputs(); --i >= 0;)
67 if (dependsOnSymbolsOtherThanThis (e.getInput(i)))
68 return true;
69 }
70
71 return false;
72 }
73}
74
75//==============================================================================
79
81 const RelativeCoordinate& top_, const RelativeCoordinate& bottom_)
82 : left (left_), right (right_), top (top_), bottom (bottom_)
83{
84}
85
87 : left (rect.getX()),
88 right (Expression::symbol (RelativeCoordinate::Strings::left) + Expression ((double) rect.getWidth())),
89 top (rect.getY()),
90 bottom (Expression::symbol (RelativeCoordinate::Strings::top) + Expression ((double) rect.getHeight()))
91{
92}
93
106
107bool RelativeRectangle::operator== (const RelativeRectangle& other) const noexcept
108{
109 return left == other.left && top == other.top && right == other.right && bottom == other.bottom;
110}
111
112bool RelativeRectangle::operator!= (const RelativeRectangle& other) const noexcept
113{
114 return ! operator== (other);
115}
116
117//==============================================================================
118// An expression context that can evaluate expressions using "this"
149
151{
152 if (scope == nullptr)
153 {
154 RelativeRectangleLocalScope defaultScope (*this);
155 return resolve (&defaultScope);
156 }
157 else
158 {
159 const double l = left.resolve (scope);
160 const double r = right.resolve (scope);
161 const double t = top.resolve (scope);
162 const double b = bottom.resolve (scope);
163
164 return Rectangle<float> ((float) l, (float) t, (float) jmax (0.0, r - l), (float) jmax (0.0, b - t));
165 }
166}
167
169{
170 left.moveToAbsolute (newPos.getX(), scope);
171 right.moveToAbsolute (newPos.getRight(), scope);
172 top.moveToAbsolute (newPos.getY(), scope);
173 bottom.moveToAbsolute (newPos.getBottom(), scope);
174}
175
177{
178 using namespace RelativeRectangleHelpers;
179
180 return dependsOnSymbolsOtherThanThis (left.getExpression())
181 || dependsOnSymbolsOtherThanThis (right.getExpression())
182 || dependsOnSymbolsOtherThanThis (top.getExpression())
183 || dependsOnSymbolsOtherThanThis (bottom.getExpression());
184}
185
187{
188 return left.toString() + ", " + top.toString() + ", " + right.toString() + ", " + bottom.toString();
189}
190
192{
193 left = left.getExpression().withRenamedSymbol (oldSymbol, newName, scope);
194 right = right.getExpression().withRenamedSymbol (oldSymbol, newName, scope);
195 top = top.getExpression().withRenamedSymbol (oldSymbol, newName, scope);
196 bottom = bottom.getExpression().withRenamedSymbol (oldSymbol, newName, scope);
197}
198
199//==============================================================================
201{
202public:
208
209 bool registerCoordinates() override
210 {
211 bool ok = addCoordinate (rectangle.left);
212 ok = addCoordinate (rectangle.right) && ok;
213 ok = addCoordinate (rectangle.top) && ok;
214 ok = addCoordinate (rectangle.bottom) && ok;
215 return ok;
216 }
217
218 bool isUsingRectangle (const RelativeRectangle& other) const noexcept
219 {
220 return rectangle == other;
221 }
222
224 {
225 for (int i = 32; --i >= 0;)
226 {
228 const Rectangle<int> newBounds (rectangle.resolve (&scope).getSmallestIntegerContainer());
229
230 if (newBounds == getComponent().getBounds())
231 return;
232
233 getComponent().setBounds (newBounds);
234 }
235
236 jassertfalse; // Seems to be a recursive reference!
237 }
238
239 void applyNewBounds (const Rectangle<int>& newBounds) override
240 {
241 if (newBounds != getComponent().getBounds())
242 {
244 rectangle.moveToAbsolute (newBounds.toFloat(), &scope);
245
247 }
248 }
249
250private:
252
254};
255
257{
258 if (isDynamic())
259 {
261
262 if (current == nullptr || ! current->isUsingRectangle (*this))
263 {
265
266 component.setPositioner (p);
267 p->apply();
268 }
269 }
270 else
271 {
272 component.setPositioner (nullptr);
273 component.setBounds (resolve (nullptr).getSmallestIntegerContainer());
274 }
275}
276
277} // namespace juce
static Audio_Scope * scope
Definition player.cpp:26
Component & getComponent() const noexcept
Definition juce_Component.h:2363
Definition juce_Component.h:36
void setPositioner(Positioner *newPositioner)
Definition juce_Component.cpp:2275
Positioner * getPositioner() const noexcept
Definition juce_Component.cpp:2270
void setBounds(int x, int y, int width, int height)
Definition juce_Component.cpp:1147
Definition juce_Expression.h:109
virtual Expression getSymbolValue(const String &symbol) const
Definition juce_Expression.cpp:1123
Definition juce_Expression.h:44
static Expression parse(String::CharPointerType &stringToParse, String &parseError)
Definition juce_Expression.cpp:976
@ symbolType
Definition juce_Expression.h:223
@ operatorType
Definition juce_Expression.h:222
Definition juce_Rectangle.h:67
ValueType getRight() const noexcept
Definition juce_Rectangle.h:139
Rectangle< float > toFloat() const noexcept
Definition juce_Rectangle.h:873
ValueType getBottom() const noexcept
Definition juce_Rectangle.h:142
ValueType getX() const noexcept
Definition juce_Rectangle.h:127
ValueType getY() const noexcept
Definition juce_Rectangle.h:130
Definition juce_RelativeCoordinate.h:73
Definition juce_RelativeCoordinatePositioner.h:58
RelativeCoordinatePositionerBase(Component &)
Definition juce_RelativeCoordinatePositioner.cpp:236
bool addCoordinate(const RelativeCoordinate &)
Definition juce_RelativeCoordinatePositioner.cpp:291
Definition juce_RelativeRectangle.cpp:201
RelativeRectangle rectangle
Definition juce_RelativeRectangle.cpp:251
bool isUsingRectangle(const RelativeRectangle &other) const noexcept
Definition juce_RelativeRectangle.cpp:218
void applyToComponentBounds() override
Definition juce_RelativeRectangle.cpp:223
RelativeRectangleComponentPositioner(Component &comp, const RelativeRectangle &r)
Definition juce_RelativeRectangle.cpp:203
bool registerCoordinates() override
Definition juce_RelativeRectangle.cpp:209
void applyNewBounds(const Rectangle< int > &newBounds) override
Definition juce_RelativeRectangle.cpp:239
Definition juce_RelativeRectangle.h:40
RelativeRectangle()
Definition juce_RelativeRectangle.cpp:76
void moveToAbsolute(const Rectangle< float > &newPos, const Expression::Scope *scope)
Definition juce_RelativeRectangle.cpp:168
const Rectangle< float > resolve(const Expression::Scope *scope) const
Definition juce_RelativeRectangle.cpp:150
RelativeCoordinate left
Definition juce_RelativeRectangle.h:105
RelativeCoordinate right
Definition juce_RelativeRectangle.h:105
void applyToComponent(Component &component) const
Definition juce_RelativeRectangle.cpp:256
bool isDynamic() const
Definition juce_RelativeRectangle.cpp:176
String toString() const
Definition juce_RelativeRectangle.cpp:186
RelativeCoordinate top
Definition juce_RelativeRectangle.h:105
void renameSymbol(const Expression::Symbol &oldSymbol, const String &newName, const Expression::Scope &scope)
Definition juce_RelativeRectangle.cpp:191
RelativeCoordinate bottom
Definition juce_RelativeRectangle.h:105
Definition juce_RelativeRectangle.cpp:120
const RelativeRectangle & rect
Definition juce_RelativeRectangle.cpp:145
Expression getSymbolValue(const String &symbol) const
Definition juce_RelativeRectangle.cpp:124
RelativeRectangleLocalScope(const RelativeRectangle &rect_)
Definition juce_RelativeRectangle.cpp:122
Definition juce_String.h:53
* e
Definition inflate.c:1404
int * l
Definition inflate.c:1579
struct huft * t
Definition inflate.c:943
register unsigned i
Definition inflate.c:1575
unsigned s
Definition inflate.c:1555
#define JUCE_DECLARE_NON_COPYABLE(className)
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
#define jassertfalse
static int JUCE_CDECL comp(const void *a, const void *b)
Definition lsp.c:298
Definition juce_RelativeRectangle.cpp:30
void skipComma(String::CharPointerType &s)
Definition juce_RelativeRectangle.cpp:31
static bool dependsOnSymbolsOtherThanThis(const Expression &e)
Definition juce_RelativeRectangle.cpp:39
Definition carla_juce.cpp:31
constexpr Type jmax(Type a, Type b)
Definition juce_MathsFunctions.h:94
Definition juce_Expression.h:186
@ y
Definition juce_RelativeCoordinate.h:168
@ top
Definition juce_RelativeCoordinate.h:167
@ left
Definition juce_RelativeCoordinate.h:167
@ unknown
Definition juce_RelativeCoordinate.h:170
@ right
Definition juce_RelativeCoordinate.h:167
@ parent
Definition juce_RelativeCoordinate.h:169
@ x
Definition juce_RelativeCoordinate.h:168
@ height
Definition juce_RelativeCoordinate.h:168
@ width
Definition juce_RelativeCoordinate.h:168
@ bottom
Definition juce_RelativeCoordinate.h:167
static Type getTypeOf(const String &s) noexcept
Definition juce_RelativeCoordinate.cpp:39
const char * text
Definition swell-functions.h:167
uch * p
Definition crypt.c:594
int r
Definition crypt.c:458
b
Definition crypt.c:628
int error
Definition extract.c:1038