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_ResizableCornerComponent.h"
31 #include "../juce_Desktop.h"
32 #include "../lookandfeel/juce_LookAndFeel.h"
33 #include "../../graphics/geometry/juce_Line.h"
36 //==============================================================================
37 ResizableCornerComponent::ResizableCornerComponent (Component
* const componentToResize
,
38 ComponentBoundsConstrainer
* const constrainer_
)
39 : component (componentToResize
),
40 constrainer (constrainer_
)
42 setRepaintsOnMouseActivity (true);
43 setMouseCursor (MouseCursor::BottomRightCornerResizeCursor
);
46 ResizableCornerComponent::~ResizableCornerComponent()
50 //==============================================================================
51 void ResizableCornerComponent::paint (Graphics
& g
)
54 .drawCornerResizer (g
, getWidth(), getHeight(),
55 isMouseOverOrDragging(),
59 void ResizableCornerComponent::mouseDown (const MouseEvent
&)
61 if (component
== nullptr)
63 jassertfalse
; // You've deleted the component that this resizer is supposed to be controlling!
67 originalBounds
= component
->getBounds();
69 if (constrainer
!= nullptr)
70 constrainer
->resizeStart();
73 void ResizableCornerComponent::mouseDrag (const MouseEvent
& e
)
75 if (component
== nullptr)
77 jassertfalse
; // You've deleted the component that this resizer is supposed to be controlling!
81 Rectangle
<int> r (originalBounds
.withSize (originalBounds
.getWidth() + e
.getDistanceFromDragStartX(),
82 originalBounds
.getHeight() + e
.getDistanceFromDragStartY()));
84 if (constrainer
!= nullptr)
86 constrainer
->setBoundsForComponent (component
, r
, false, false, true, true);
90 Component::Positioner
* const pos
= component
->getPositioner();
93 pos
->applyNewBounds (r
);
95 component
->setBounds (r
);
99 void ResizableCornerComponent::mouseUp (const MouseEvent
&)
101 if (constrainer
!= nullptr)
102 constrainer
->resizeEnd();
105 bool ResizableCornerComponent::hitTest (int x
, int y
)
110 const int yAtX
= getHeight() - (getHeight() * x
/ getWidth());
112 return y
>= yAtX
- getHeight() / 4;