LMMS
Loading...
Searching...
No Matches
juce_ResizableBorderComponent.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
30ResizableBorderComponent::Zone::Zone (int zoneFlags) noexcept : zone (zoneFlags) {}
32
33ResizableBorderComponent::Zone& ResizableBorderComponent::Zone::operator= (const ResizableBorderComponent::Zone& other) noexcept
34{
35 zone = other.zone;
36 return *this;
37}
38
39bool ResizableBorderComponent::Zone::operator== (const ResizableBorderComponent::Zone& other) const noexcept { return zone == other.zone; }
40bool ResizableBorderComponent::Zone::operator!= (const ResizableBorderComponent::Zone& other) const noexcept { return zone != other.zone; }
41
44 Point<int> position)
45{
46 int z = 0;
47
48 if (totalSize.contains (position)
49 && ! border.subtractedFrom (totalSize).contains (position))
50 {
51 auto minW = jmax (totalSize.getWidth() / 10, jmin (10, totalSize.getWidth() / 3));
52
53 if (position.x < jmax (border.getLeft(), minW) && border.getLeft() > 0)
54 z |= left;
55 else if (position.x >= totalSize.getWidth() - jmax (border.getRight(), minW) && border.getRight() > 0)
56 z |= right;
57
58 auto minH = jmax (totalSize.getHeight() / 10, jmin (10, totalSize.getHeight() / 3));
59
60 if (position.y < jmax (border.getTop(), minH) && border.getTop() > 0)
61 z |= top;
62 else if (position.y >= totalSize.getHeight() - jmax (border.getBottom(), minH) && border.getBottom() > 0)
63 z |= bottom;
64 }
65
66 return Zone (z);
67}
68
70{
72
73 switch (zone)
74 {
76 case top: mc = MouseCursor::TopEdgeResizeCursor; break;
83 default: break;
84 }
85
86 return mc;
87}
88
89//==============================================================================
91 ComponentBoundsConstrainer* boundsConstrainer)
92 : component (componentToResize),
93 constrainer (boundsConstrainer),
94 borderSize (5)
95{
96}
97
99
100//==============================================================================
102{
103 getLookAndFeel().drawResizableFrame (g, getWidth(), getHeight(), borderSize);
104}
105
110
115
117{
118 if (component == nullptr)
119 {
120 jassertfalse; // You've deleted the component that this resizer was supposed to be using!
121 return;
122 }
123
125
126 originalBounds = component->getBounds();
127
128 if (constrainer != nullptr)
129 constrainer->resizeStart();
130}
131
133{
134 if (component == nullptr)
135 {
136 jassertfalse; // You've deleted the component that this resizer was supposed to be using!
137 return;
138 }
139
140 auto newBounds = mouseZone.resizeRectangleBy (originalBounds, e.getOffsetFromDragStart());
141
142 if (constrainer != nullptr)
143 {
144 constrainer->setBoundsForComponent (component, newBounds,
145 mouseZone.isDraggingTopEdge(),
146 mouseZone.isDraggingLeftEdge(),
147 mouseZone.isDraggingBottomEdge(),
148 mouseZone.isDraggingRightEdge());
149 }
150 else
151 {
152 if (auto* p = component->getPositioner())
153 p->applyNewBounds (newBounds);
154 else
155 component->setBounds (newBounds);
156 }
157}
158
160{
161 if (constrainer != nullptr)
162 constrainer->resizeEnd();
163}
164
166{
167 return ! borderSize.subtractedFrom (getLocalBounds()).contains (x, y);
168}
169
171{
172 if (borderSize != newBorderSize)
173 {
174 borderSize = newBorderSize;
175 repaint();
176 }
177}
178
183
185{
186 auto newZone = Zone::fromPositionOnBorder (getLocalBounds(), borderSize, e.getPosition());
187
188 if (mouseZone != newZone)
189 {
190 mouseZone = newZone;
191 setMouseCursor (newZone.getMouseCursor());
192 }
193}
194
195} // namespace juce
Type jmax(const Type a, const Type b)
Definition MathsFunctions.h:48
#define noexcept
Definition DistrhoDefines.h:72
Definition juce_BorderSize.h:42
Definition juce_ComponentBoundsConstrainer.h:44
int getHeight() const noexcept
Definition juce_Component.h:274
void setMouseCursor(const MouseCursor &cursorType)
Definition juce_Component.cpp:1859
void repaint()
Definition juce_Component.cpp:1917
Component() noexcept
Definition juce_Component.cpp:517
int getWidth() const noexcept
Definition juce_Component.h:271
LookAndFeel & getLookAndFeel() const noexcept
Definition juce_Component.cpp:2173
Rectangle< int > getLocalBounds() const noexcept
Definition juce_Component.cpp:2283
Definition juce_GraphicsContext.h:45
Definition juce_MouseCursor.h:39
@ TopLeftCornerResizeCursor
Definition juce_MouseCursor.h:67
@ BottomLeftCornerResizeCursor
Definition juce_MouseCursor.h:69
@ NormalCursor
Definition juce_MouseCursor.h:48
@ LeftEdgeResizeCursor
Definition juce_MouseCursor.h:65
@ BottomEdgeResizeCursor
Definition juce_MouseCursor.h:64
@ TopEdgeResizeCursor
Definition juce_MouseCursor.h:63
@ BottomRightCornerResizeCursor
Definition juce_MouseCursor.h:70
@ RightEdgeResizeCursor
Definition juce_MouseCursor.h:66
@ TopRightCornerResizeCursor
Definition juce_MouseCursor.h:68
Definition juce_MouseEvent.h:39
Definition juce_Point.h:42
Definition juce_Rectangle.h:67
bool contains(ValueType xCoord, ValueType yCoord) const noexcept
Definition juce_Rectangle.h:622
ValueType getHeight() const noexcept
Definition juce_Rectangle.h:136
ValueType getWidth() const noexcept
Definition juce_Rectangle.h:133
Definition juce_ResizableBorderComponent.h:94
@ right
Definition juce_ResizableBorderComponent.h:102
@ bottom
Definition juce_ResizableBorderComponent.h:103
@ top
Definition juce_ResizableBorderComponent.h:101
@ left
Definition juce_ResizableBorderComponent.h:100
MouseCursor getMouseCursor() const noexcept
Definition juce_ResizableBorderComponent.cpp:69
int zone
Definition juce_ResizableBorderComponent.h:162
static Zone fromPositionOnBorder(Rectangle< int > totalSize, BorderSize< int > border, Point< int > position)
Definition juce_ResizableBorderComponent.cpp:42
Zone(int zoneFlags) noexcept
Definition juce_ResizableBorderComponent.cpp:30
void mouseDrag(const MouseEvent &) override
Definition juce_ResizableBorderComponent.cpp:132
bool hitTest(int x, int y) override
Definition juce_ResizableBorderComponent.cpp:165
ComponentBoundsConstrainer * constrainer
Definition juce_ResizableBorderComponent.h:186
void mouseDown(const MouseEvent &) override
Definition juce_ResizableBorderComponent.cpp:116
WeakReference< Component > component
Definition juce_ResizableBorderComponent.h:185
void updateMouseZone(const MouseEvent &)
Definition juce_ResizableBorderComponent.cpp:184
void mouseUp(const MouseEvent &) override
Definition juce_ResizableBorderComponent.cpp:159
void mouseEnter(const MouseEvent &) override
Definition juce_ResizableBorderComponent.cpp:106
void paint(Graphics &) override
Definition juce_ResizableBorderComponent.cpp:101
void mouseMove(const MouseEvent &) override
Definition juce_ResizableBorderComponent.cpp:111
BorderSize< int > borderSize
Definition juce_ResizableBorderComponent.h:187
Zone mouseZone
Definition juce_ResizableBorderComponent.h:189
void setBorderThickness(BorderSize< int > newBorderSize)
Definition juce_ResizableBorderComponent.cpp:170
Rectangle< int > originalBounds
Definition juce_ResizableBorderComponent.h:188
BorderSize< int > getBorderThickness() const
Definition juce_ResizableBorderComponent.cpp:179
ResizableBorderComponent(Component *componentToResize, ComponentBoundsConstrainer *constrainer)
Definition juce_ResizableBorderComponent.cpp:90
* e
Definition inflate.c:1404
unsigned z
Definition inflate.c:1589
int y
Definition inflate.c:1588
int g
Definition inflate.c:1573
static ZCONST unsigned border[]
Definition inflate.c:749
unsigned x[BMAX+1]
Definition inflate.c:1586
#define jassertfalse
Definition carla_juce.cpp:31
constexpr Type jmin(Type a, Type b)
Definition juce_MathsFunctions.h:106
constexpr Type jmax(Type a, Type b)
Definition juce_MathsFunctions.h:94
uch * p
Definition crypt.c:594
#define const
Definition zconf.h:137