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_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
29ResizableBorderComponent::Zone::Zone() noexcept {}
30ResizableBorderComponent::Zone::Zone (int zoneFlags) noexcept : zone (zoneFlags) {}
31ResizableBorderComponent::Zone::Zone (const ResizableBorderComponent::Zone& other) noexcept : zone (other.zone) {}
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
43 BorderSize<int> border,
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 {
75 case (left | top): mc = MouseCursor::TopLeftCornerResizeCursor; break;
76 case top: mc = MouseCursor::TopEdgeResizeCursor; break;
77 case (right | top): mc = MouseCursor::TopRightCornerResizeCursor; break;
78 case left: mc = MouseCursor::LeftEdgeResizeCursor; break;
79 case right: mc = MouseCursor::RightEdgeResizeCursor; break;
80 case (left | bottom): mc = MouseCursor::BottomLeftCornerResizeCursor; break;
81 case bottom: mc = MouseCursor::BottomEdgeResizeCursor; break;
82 case (right | bottom): mc = MouseCursor::BottomRightCornerResizeCursor; break;
83 default: break;
84 }
85
86 return mc;
87}
88
89//==============================================================================
97
99
100//==============================================================================
102{
103 getLookAndFeel().drawResizableFrame (g, getWidth(), getHeight(), borderSize);
104}
105
107{
108 updateMouseZone (e);
109}
110
112{
113 updateMouseZone (e);
114}
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
124 updateMouseZone (e);
125
126 originalBounds = component->getBounds();
127
128 if (auto* peer = component->getPeer())
129 if (&peer->getComponent() == component)
130 peer->startHostManagedResize (peer->globalToLocal (localPointToGlobal (e.getPosition())), mouseZone);
131
132 if (constrainer != nullptr)
133 constrainer->resizeStart();
134}
135
137{
138 if (component == nullptr)
139 {
140 jassertfalse; // You've deleted the component that this resizer was supposed to be using!
141 return;
142 }
143
144 auto newBounds = mouseZone.resizeRectangleBy (originalBounds, e.getOffsetFromDragStart());
145
146 if (constrainer != nullptr)
147 {
148 constrainer->setBoundsForComponent (component, newBounds,
149 mouseZone.isDraggingTopEdge(),
150 mouseZone.isDraggingLeftEdge(),
151 mouseZone.isDraggingBottomEdge(),
152 mouseZone.isDraggingRightEdge());
153 }
154 else
155 {
156 if (auto* p = component->getPositioner())
157 p->applyNewBounds (newBounds);
158 else
159 component->setBounds (newBounds);
160 }
161}
162
164{
165 if (constrainer != nullptr)
166 constrainer->resizeEnd();
167}
168
170{
171 return ! borderSize.subtractedFrom (getLocalBounds()).contains (x, y);
172}
173
175{
176 if (borderSize != newBorderSize)
177 {
178 borderSize = newBorderSize;
179 repaint();
180 }
181}
182
184{
185 return borderSize;
186}
187
188void ResizableBorderComponent::updateMouseZone (const MouseEvent& e)
189{
191
192 if (mouseZone != newZone)
193 {
194 mouseZone = newZone;
195 setMouseCursor (newZone.getMouseCursor());
196 }
197}
198
199} // namespace juce
Specifies a set of gaps to be left around the sides of a rectangle.
ValueType getTop() const noexcept
Returns the gap that should be left at the top of the region.
ValueType getLeft() const noexcept
Returns the gap that should be left at the left of the region.
Rectangle< ValueType > subtractedFrom(const Rectangle< ValueType > &original) const noexcept
Returns a rectangle with these borders removed from it.
ValueType getRight() const noexcept
Returns the gap that should be left at the right of the region.
ValueType getBottom() const noexcept
Returns the gap that should be left at the bottom of the region.
A class that imposes restrictions on a Component's size or position.
void setBoundsForComponent(Component *component, Rectangle< int > bounds, bool isStretchingTop, bool isStretchingLeft, bool isStretchingBottom, bool isStretchingRight)
Checks the given bounds, and then sets the component to the corrected size.
virtual void resizeEnd()
This callback happens when the resizer has finished dragging.
virtual void resizeStart()
This callback happens when the resizer is about to start dragging.
The base class for all JUCE user-interface objects.
int getHeight() const noexcept
Returns the component's height in pixels.
void setMouseCursor(const MouseCursor &cursorType)
Changes the mouse cursor shape to use when the mouse is over this component.
void repaint()
Marks the whole component as needing to be redrawn.
int getWidth() const noexcept
Returns the component's width in pixels.
Point< int > localPointToGlobal(Point< int > localPoint) const
Converts a point relative to this component's top-left into a screen coordinate.
LookAndFeel & getLookAndFeel() const noexcept
Finds the appropriate look-and-feel to use for this component.
Rectangle< int > getLocalBounds() const noexcept
Returns the component's bounds, relative to its own origin.
A graphics context, used for drawing a component or image.
Represents a mouse cursor image.
@ TopLeftCornerResizeCursor
A platform-specific cursor for resizing the top-left-corner of a window.
@ BottomLeftCornerResizeCursor
A platform-specific cursor for resizing the bottom-left-corner of a window.
@ NormalCursor
The standard arrow cursor.
@ LeftEdgeResizeCursor
A platform-specific cursor for resizing the left-edge of a window.
@ BottomEdgeResizeCursor
A platform-specific cursor for resizing the bottom-edge of a window.
@ TopEdgeResizeCursor
A platform-specific cursor for resizing the top-edge of a window.
@ BottomRightCornerResizeCursor
A platform-specific cursor for resizing the bottom-right-corner of a window.
@ RightEdgeResizeCursor
A platform-specific cursor for resizing the right-edge of a window.
@ TopRightCornerResizeCursor
A platform-specific cursor for resizing the top-right-corner of a window.
Contains position and status information about a mouse event.
Point< int > getOffsetFromDragStart() const noexcept
Returns the difference between the mouse's current position and where it was when the button was last...
Point< int > getPosition() const noexcept
The position of the mouse when the event occurred.
A pair of (x, y) coordinates.
Definition juce_Point.h:42
ValueType y
The point's Y coordinate.
Definition juce_Point.h:252
ValueType x
The point's X coordinate.
Definition juce_Point.h:251
Manages a rectangle and allows geometric operations to be performed on it.
bool contains(ValueType xCoord, ValueType yCoord) const noexcept
Returns true if this coordinate is inside the rectangle.
ValueType getWidth() const noexcept
Returns the width of the rectangle.
ValueType getHeight() const noexcept
Returns the height of the rectangle.
Represents the different sections of a resizable border, which allow it to resized in different ways.
bool isDraggingBottomEdge() const noexcept
Returns true if dragging this zone will move the object's bottom edge.
Rectangle< ValueType > resizeRectangleBy(Rectangle< ValueType > original, const Point< ValueType > &distance) const noexcept
Resizes this rectangle by the given amount, moving just the edges that this zone applies to.
bool isDraggingLeftEdge() const noexcept
Returns true if dragging this zone will move the object's left edge.
bool isDraggingTopEdge() const noexcept
Returns true if dragging this zone will move the object's top edge.
MouseCursor getMouseCursor() const noexcept
Returns an appropriate mouse-cursor for this resize zone.
bool isDraggingRightEdge() const noexcept
Returns true if dragging this zone will move the object's right edge.
static Zone fromPositionOnBorder(Rectangle< int > totalSize, BorderSize< int > border, Point< int > position)
Given a point within a rectangle with a resizable border, this returns the zone that the point lies w...
void mouseDrag(const MouseEvent &) override
Called when the mouse is moved while a button is held down.
bool hitTest(int x, int y) override
Tests whether a given point is inside the component.
~ResizableBorderComponent() override
Destructor.
void mouseDown(const MouseEvent &) override
Called when a mouse button is pressed.
void mouseUp(const MouseEvent &) override
Called when a mouse button is released.
void mouseEnter(const MouseEvent &) override
Called when the mouse first enters a component.
void paint(Graphics &) override
Components can override this method to draw their content.
void mouseMove(const MouseEvent &) override
Called when the mouse moves inside a component.
void setBorderThickness(BorderSize< int > newBorderSize)
Specifies how many pixels wide the draggable edges of this component are.
BorderSize< int > getBorderThickness() const
Returns the number of pixels wide that the draggable edges of this component are.
ResizableBorderComponent(Component *componentToResize, ComponentBoundsConstrainer *constrainer)
Creates a resizer.
#define jassertfalse
This will always cause an assertion failure.
JUCE Namespace.
constexpr Type jmin(Type a, Type b)
Returns the smaller of two values.
constexpr Type jmax(Type a, Type b)
Returns the larger of two values.
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