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_FocusOutline.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
29//==============================================================================
31{
33 : target (c), props (p)
34 {
35 setVisible (true);
36 setInterceptsMouseClicks (false, false);
37
38 if (target->isOnDesktop())
39 {
40 setSize (1, 1);
44 }
45 else if (auto* parent = target->getParentComponent())
46 {
47 auto targetIndex = parent->getIndexOfChildComponent (target);
48 parent->addChildComponent (this, targetIndex + 1);
49 }
50 }
51
52 void paint (Graphics& g) override
53 {
54 if (target != nullptr)
55 props.drawOutline (g, getWidth(), getHeight());
56 }
57
58 void resized() override
59 {
60 repaint();
61 }
62
63 float getDesktopScaleFactor() const override
64 {
65 return target != nullptr ? target->getDesktopScaleFactor()
67 }
68
69private:
72
74};
75
76//==============================================================================
78 : properties (std::move (props))
79{
80}
81
83{
84 if (owner != nullptr)
85 owner->removeComponentListener (this);
86
87 if (lastParentComp != nullptr)
88 lastParentComp->removeComponentListener (this);
89}
90
92{
93 if (componentToFollow != owner)
94 {
95 if (owner != nullptr)
96 owner->removeComponentListener (this);
97
98 owner = componentToFollow;
99
100 if (owner != nullptr)
101 owner->addComponentListener (this);
102
103 updateParent();
104 updateOutlineWindow();
105 }
106}
107
108void FocusOutline::componentMovedOrResized (Component& c, bool, bool)
109{
110 if (owner == &c)
111 updateOutlineWindow();
112}
113
114void FocusOutline::componentBroughtToFront (Component& c)
115{
116 if (owner == &c)
117 updateOutlineWindow();
118}
119
120void FocusOutline::componentParentHierarchyChanged (Component& c)
121{
122 if (owner == &c)
123 {
124 updateParent();
125 updateOutlineWindow();
126 }
127}
128
129void FocusOutline::componentVisibilityChanged (Component& c)
130{
131 if (owner == &c)
132 updateOutlineWindow();
133}
134
135void FocusOutline::updateParent()
136{
137 lastParentComp = (owner != nullptr ? owner->getParentComponent()
138 : nullptr);
139}
140
141void FocusOutline::updateOutlineWindow()
142{
143 if (reentrant)
144 return;
145
146 const ScopedValueSetter<bool> setter (reentrant, true);
147
148 if (owner == nullptr)
149 {
150 outlineWindow = nullptr;
151 return;
152 }
153
154 if (owner->isShowing()
155 && owner->getWidth() > 0 && owner->getHeight() > 0)
156 {
157 if (outlineWindow == nullptr)
158 outlineWindow = std::make_unique<OutlineWindowComponent> (owner, *properties);
159
160 WeakReference<Component> deletionChecker (outlineWindow.get());
161
162 outlineWindow->setAlwaysOnTop (owner->isAlwaysOnTop());
163
164 if (deletionChecker == nullptr)
165 return;
166
167 const auto windowBounds = [this]
168 {
169 const auto bounds = properties->getOutlineBounds (*owner);
170
171 if (lastParentComp != nullptr)
172 return lastParentComp->getLocalArea (nullptr, bounds);
173
174 return bounds;
175 }();
176
177 outlineWindow->setBounds (windowBounds);
178 }
179 else
180 {
181 outlineWindow = nullptr;
182 }
183}
184
185} // namespace juce
@ windowIsTemporary
Indicates that the window is a temporary popup, like a menu, tooltip, etc.
@ windowIgnoresKeyPresses
Tells the window not to catch any keypresses.
@ windowIgnoresMouseClicks
Indicates that the window should let mouse clicks pass through it (may not be possible on some platfo...
The base class for all JUCE user-interface objects.
void setInterceptsMouseClicks(bool allowClicksOnThisComponent, bool allowClicksOnChildComponents) noexcept
Changes the default return value for the hitTest() method.
int getHeight() const noexcept
Returns the component's height in pixels.
void repaint()
Marks the whole component as needing to be redrawn.
virtual void addToDesktop(int windowStyleFlags, void *nativeWindowToAttachTo=nullptr)
Makes this component appear as a window on the desktop.
void setSize(int newWidth, int newHeight)
Changes the size of the component.
int getWidth() const noexcept
Returns the component's width in pixels.
virtual void setVisible(bool shouldBeVisible)
Makes the component visible or invisible.
virtual float getDesktopScaleFactor() const
Returns the default scale factor to use for this component when it is placed on the desktop.
void setOwner(Component *componentToFollow)
Attaches the outline to a component.
FocusOutline(std::unique_ptr< OutlineWindowProperties > props)
Creates a FocusOutline.
~FocusOutline() override
Destructor.
A graphics context, used for drawing a component or image.
This class acts as a pointer which will automatically become null if the object to which it points is...
#define JUCE_DECLARE_NON_COPYABLE(className)
This is a shorthand macro for deleting a class's copy constructor and copy assignment operator.
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
Defines the focus outline window properties.
virtual void drawOutline(Graphics &, int width, int height)=0
This method will be called to draw the focus outline.
float getDesktopScaleFactor() const override
Returns the default scale factor to use for this component when it is placed on the desktop.
void resized() override
Called when this component's size has been changed.
void paint(Graphics &g) override
Components can override this method to draw their content.