JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_ComponentMovementWatcher.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 : component (comp),
31 wasShowing (comp->isShowing())
32{
33 jassert (component != nullptr); // can't use this with a null pointer..
34
35 component->addComponentListener (this);
36 registerWithParentComps();
37}
38
40{
41 if (component != nullptr)
42 component->removeComponentListener (this);
43
44 unregister();
45}
46
47//==============================================================================
49{
50 if (component != nullptr && ! reentrant)
51 {
52 const ScopedValueSetter<bool> setter (reentrant, true);
53
54 auto* peer = component->getPeer();
55 auto peerID = peer != nullptr ? peer->getUniqueID() : 0;
56
57 if (peerID != lastPeerID)
58 {
60
61 if (component == nullptr)
62 return;
63
64 lastPeerID = peerID;
65 }
66
67 unregister();
68 registerWithParentComps();
69
70 componentMovedOrResized (*component, true, true);
71
72 if (component != nullptr)
73 componentVisibilityChanged (*component);
74 }
75}
78{
79 if (component != nullptr)
80 {
81 if (wasMoved)
82 {
84 auto* top = component->getTopLevelComponent();
85
86 if (top != component)
87 newPos = top->getLocalPoint (component, Point<int>());
88 else
89 newPos = top->getPosition();
90
91 wasMoved = lastBounds.getPosition() != newPos;
92 lastBounds.setPosition (newPos);
93 }
94
95 wasResized = (lastBounds.getWidth() != component->getWidth() || lastBounds.getHeight() != component->getHeight());
96 lastBounds.setSize (component->getWidth(), component->getHeight());
97
98 if (wasMoved || wasResized)
100 }
101}
102
104{
105 registeredParentComps.removeFirstMatchingValue (&comp);
106
107 if (component == &comp)
108 unregister();
109}
110
112{
113 if (component != nullptr)
114 {
115 const bool isShowingNow = component->isShowing();
116
117 if (wasShowing != isShowingNow)
118 {
119 wasShowing = isShowingNow;
121 }
122 }
123}
124
125void ComponentMovementWatcher::registerWithParentComps()
126{
127 for (auto* p = component->getParentComponent(); p != nullptr; p = p->getParentComponent())
128 {
129 p->addComponentListener (this);
130 registeredParentComps.add (p);
131 }
132}
133
134void ComponentMovementWatcher::unregister()
135{
136 for (auto* c : registeredParentComps)
137 c->removeComponentListener (this);
138
139 registeredParentComps.clear();
140}
141
142} // namespace juce
void componentBeingDeleted(Component &) override
Called when the component is in the process of being deleted.
virtual void componentMovedOrResized(bool wasMoved, bool wasResized)=0
This callback happens when the component that is being watched is moved relative to its top-level pee...
void componentParentHierarchyChanged(Component &) override
Called to indicate that the component's parents have changed.
virtual void componentPeerChanged()=0
This callback happens when the component's top-level peer is changed.
virtual void componentVisibilityChanged()=0
This callback happens when the component's visibility state changes, possibly due to one of its paren...
ComponentMovementWatcher(Component *componentToWatch)
Creates a ComponentMovementWatcher to watch a given target component.
The base class for all JUCE user-interface objects.
A pair of (x, y) coordinates.
Definition juce_Point.h:42
Point< ValueType > getPosition() const noexcept
Returns the rectangle's top-left position as a Point.
void setSize(ValueType newWidth, ValueType newHeight) noexcept
Changes the rectangle's size, leaving the position of its top-left corner unchanged.
ValueType getWidth() const noexcept
Returns the width of the rectangle.
void setPosition(Point< ValueType > newPos) noexcept
Changes the position of the rectangle's top-left corner (leaving its size unchanged).
ValueType getHeight() const noexcept
Returns the height of the rectangle.
Helper class providing an RAII-based mechanism for temporarily setting and then re-setting a value.
#define jassert(expression)
Platform-independent assertion macro.
JUCE Namespace.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88