Add remaining files
[juce-lv2.git] / juce / source / src / gui / components / layout / juce_ResizableCornerComponent.cpp
blob81d0d06660dace481e2ed42e181208d1f4ff9db6
1 /*
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"
28 BEGIN_JUCE_NAMESPACE
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)
53 getLookAndFeel()
54 .drawCornerResizer (g, getWidth(), getHeight(),
55 isMouseOverOrDragging(),
56 isMouseButtonDown());
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!
64 return;
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!
78 return;
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);
88 else
90 Component::Positioner* const pos = component->getPositioner();
92 if (pos != nullptr)
93 pos->applyNewBounds (r);
94 else
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)
107 if (getWidth() <= 0)
108 return false;
110 const int yAtX = getHeight() - (getHeight() * x / getWidth());
112 return y >= yAtX - getHeight() / 4;
116 END_JUCE_NAMESPACE