2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #include "../../../core/juce_StandardHeader.h"
30 #include "juce_ResizableEdgeComponent.h"
31 #include "../lookandfeel/juce_LookAndFeel.h"
34 //==============================================================================
35 ResizableEdgeComponent::ResizableEdgeComponent (Component
* const componentToResize
,
36 ComponentBoundsConstrainer
* const constrainer_
,
38 : component (componentToResize
),
39 constrainer (constrainer_
),
42 setRepaintsOnMouseActivity (true);
43 setMouseCursor (MouseCursor (isVertical() ? MouseCursor::LeftRightResizeCursor
44 : MouseCursor::UpDownResizeCursor
));
47 ResizableEdgeComponent::~ResizableEdgeComponent()
51 //==============================================================================
52 bool ResizableEdgeComponent::isVertical() const noexcept
54 return edge
== leftEdge
|| edge
== rightEdge
;
57 void ResizableEdgeComponent::paint (Graphics
& g
)
59 getLookAndFeel().drawStretchableLayoutResizerBar (g
, getWidth(), getHeight(), isVertical(),
60 isMouseOver(), isMouseButtonDown());
63 void ResizableEdgeComponent::mouseDown (const MouseEvent
&)
65 if (component
== nullptr)
67 jassertfalse
; // You've deleted the component that this resizer was supposed to be using!
71 originalBounds
= component
->getBounds();
73 if (constrainer
!= nullptr)
74 constrainer
->resizeStart();
77 void ResizableEdgeComponent::mouseDrag (const MouseEvent
& e
)
79 if (component
== nullptr)
81 jassertfalse
; // You've deleted the component that this resizer was supposed to be using!
85 Rectangle
<int> newBounds (originalBounds
);
89 case leftEdge
: newBounds
.setLeft (jmin (newBounds
.getRight(), newBounds
.getX() + e
.getDistanceFromDragStartX())); break;
90 case rightEdge
: newBounds
.setWidth (jmax (0, newBounds
.getWidth() + e
.getDistanceFromDragStartX())); break;
91 case topEdge
: newBounds
.setTop (jmin (newBounds
.getBottom(), newBounds
.getY() + e
.getDistanceFromDragStartY())); break;
92 case bottomEdge
: newBounds
.setHeight (jmax (0, newBounds
.getHeight() + e
.getDistanceFromDragStartY())); break;
93 default: jassertfalse
; break;
96 if (constrainer
!= nullptr)
98 constrainer
->setBoundsForComponent (component
, newBounds
,
106 Component::Positioner
* const pos
= component
->getPositioner();
109 pos
->applyNewBounds (newBounds
);
111 component
->setBounds (newBounds
);
115 void ResizableEdgeComponent::mouseUp (const MouseEvent
&)
117 if (constrainer
!= nullptr)
118 constrainer
->resizeEnd();