Add remaining files
[juce-lv2.git] / juce / source / src / gui / components / layout / juce_ResizableEdgeComponent.cpp
blob674900221a88b88383aad26add5f22d942983b53
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_ResizableEdgeComponent.h"
31 #include "../lookandfeel/juce_LookAndFeel.h"
34 //==============================================================================
35 ResizableEdgeComponent::ResizableEdgeComponent (Component* const componentToResize,
36 ComponentBoundsConstrainer* const constrainer_,
37 Edge edge_)
38 : component (componentToResize),
39 constrainer (constrainer_),
40 edge (edge_)
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!
68 return;
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!
82 return;
85 Rectangle<int> newBounds (originalBounds);
87 switch (edge)
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,
99 edge == topEdge,
100 edge == leftEdge,
101 edge == bottomEdge,
102 edge == rightEdge);
104 else
106 Component::Positioner* const pos = component->getPositioner();
108 if (pos != nullptr)
109 pos->applyNewBounds (newBounds);
110 else
111 component->setBounds (newBounds);
115 void ResizableEdgeComponent::mouseUp (const MouseEvent&)
117 if (constrainer != nullptr)
118 constrainer->resizeEnd();
121 END_JUCE_NAMESPACE