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_ResizableEdgeComponent.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
40
42
43//==============================================================================
44bool ResizableEdgeComponent::isVertical() const noexcept
45{
46 return edge == leftEdge || edge == rightEdge;
47}
48
50{
51 getLookAndFeel().drawStretchableLayoutResizerBar (g, getWidth(), getHeight(), isVertical(),
53}
54
56{
57 if (component == nullptr)
58 {
59 jassertfalse; // You've deleted the component that this resizer was supposed to be using!
60 return;
61 }
62
63 originalBounds = component->getBounds();
64
66
67 const Zone zone { [&]
68 {
69 switch (edge)
70 {
71 case Edge::leftEdge: return Zone::left;
72 case Edge::rightEdge: return Zone::right;
73 case Edge::topEdge: return Zone::top;
74 case Edge::bottomEdge: return Zone::bottom;
75 }
76
77 return Zone::centre;
78 }() };
79
80 if (auto* peer = component->getPeer())
81 if (&peer->getComponent() == component)
82 peer->startHostManagedResize (peer->globalToLocal (localPointToGlobal (e.getPosition())), zone);
83
84 if (constrainer != nullptr)
85 constrainer->resizeStart();
86}
87
89{
90 if (component == nullptr)
91 {
92 jassertfalse; // You've deleted the component that this resizer was supposed to be using!
93 return;
94 }
95
96 auto newBounds = originalBounds;
97
98 switch (edge)
99 {
100 case leftEdge: newBounds.setLeft (jmin (newBounds.getRight(), newBounds.getX() + e.getDistanceFromDragStartX())); break;
101 case rightEdge: newBounds.setWidth (jmax (0, newBounds.getWidth() + e.getDistanceFromDragStartX())); break;
102 case topEdge: newBounds.setTop (jmin (newBounds.getBottom(), newBounds.getY() + e.getDistanceFromDragStartY())); break;
103 case bottomEdge: newBounds.setHeight (jmax (0, newBounds.getHeight() + e.getDistanceFromDragStartY())); break;
104 default: jassertfalse; break;
105 }
106
107 if (constrainer != nullptr)
108 {
109 constrainer->setBoundsForComponent (component, newBounds,
110 edge == topEdge,
111 edge == leftEdge,
112 edge == bottomEdge,
113 edge == rightEdge);
114 }
115 else
116 {
117 if (auto* p = component->getPositioner())
118 p->applyNewBounds (newBounds);
119 else
120 component->setBounds (newBounds);
121 }
122}
123
125{
126 if (constrainer != nullptr)
127 constrainer->resizeEnd();
128}
129
130} // namespace juce
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.
bool isMouseButtonDown(bool includeChildren=false) const
Returns true if the mouse button is currently held down in this component.
void setRepaintsOnMouseActivity(bool shouldRepaint) noexcept
Causes automatic repaints when the mouse enters or exits this component.
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.
bool isMouseOver(bool includeChildren=false) const
Returns true if the mouse is currently over this component.
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.
A graphics context, used for drawing a component or image.
@ LeftRightResizeCursor
An arrow pointing left and right.
@ UpDownResizeCursor
an arrow pointing up and down.
Contains position and status information about a mouse event.
Point< int > getPosition() const noexcept
The position of the mouse when the event occurred.
int getDistanceFromDragStartY() const noexcept
Returns the difference between the mouse's current y position and where it was when the button was la...
int getDistanceFromDragStartX() const noexcept
Returns the difference between the mouse's current x position and where it was when the button was la...
void setLeft(ValueType newLeft) noexcept
Moves the x position, adjusting the width so that the right-hand edge remains in the same place.
Represents the different sections of a resizable border, which allow it to resized in different ways.
~ResizableEdgeComponent() override
Destructor.
void mouseDown(const MouseEvent &) override
Called when a mouse button is pressed.
ResizableEdgeComponent(Component *componentToResize, ComponentBoundsConstrainer *constrainer, Edge edgeToResize)
Creates a resizer bar.
void paint(Graphics &) override
Components can override this method to draw their content.
void mouseDrag(const MouseEvent &) override
Called when the mouse is moved while a button is held down.
void mouseUp(const MouseEvent &) override
Called when a mouse button is released.
@ rightEdge
Indicates a vertical bar that can be dragged left/right to move the component's right-hand edge.
@ topEdge
Indicates a horizontal bar that can be dragged up/down to move the top of the component.
@ bottomEdge
Indicates a horizontal bar that can be dragged up/down to move the bottom of the component.
@ leftEdge
Indicates a vertical bar that can be dragged left/right to move the component's left-hand edge.
#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