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_ResizableBorderComponent.h
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
29//==============================================================================
47class JUCE_API ResizableBorderComponent : public Component
48{
49public:
50 //==============================================================================
68 ResizableBorderComponent (Component* componentToResize,
69 ComponentBoundsConstrainer* constrainer);
70
73
74
75 //==============================================================================
80 void setBorderThickness (BorderSize<int> newBorderSize);
81
86 BorderSize<int> getBorderThickness() const;
87
88
89 //==============================================================================
93 class Zone
94 {
95 public:
96 //==============================================================================
97 enum Zones
98 {
99 centre = 0,
100 left = 1,
101 top = 2,
102 right = 4,
103 bottom = 8
104 };
105
106 //==============================================================================
108 explicit Zone (int zoneFlags) noexcept;
109
110 Zone() noexcept;
111 Zone (const Zone&) noexcept;
112 Zone& operator= (const Zone&) noexcept;
113
114 bool operator== (const Zone&) const noexcept;
115 bool operator!= (const Zone&) const noexcept;
116
117 //==============================================================================
121 static Zone fromPositionOnBorder (Rectangle<int> totalSize,
122 BorderSize<int> border,
123 Point<int> position);
124
126 MouseCursor getMouseCursor() const noexcept;
127
129 bool isDraggingWholeObject() const noexcept { return zone == centre; }
131 bool isDraggingLeftEdge() const noexcept { return (zone & left) != 0; }
133 bool isDraggingRightEdge() const noexcept { return (zone & right) != 0; }
135 bool isDraggingTopEdge() const noexcept { return (zone & top) != 0; }
137 bool isDraggingBottomEdge() const noexcept { return (zone & bottom) != 0; }
138
142 template <typename ValueType>
144 const Point<ValueType>& distance) const noexcept
145 {
146 if (isDraggingWholeObject())
147 return original + distance;
148
149 if (isDraggingLeftEdge()) original.setLeft (jmin (original.getRight(), original.getX() + distance.x));
150 if (isDraggingRightEdge()) original.setWidth (jmax (ValueType(), original.getWidth() + distance.x));
151 if (isDraggingTopEdge()) original.setTop (jmin (original.getBottom(), original.getY() + distance.y));
152 if (isDraggingBottomEdge()) original.setHeight (jmax (ValueType(), original.getHeight() + distance.y));
153
154 return original;
155 }
156
158 int getZoneFlags() const noexcept { return zone; }
159
160 private:
161 //==============================================================================
162 int zone = centre;
163 };
164
166 Zone getCurrentZone() const noexcept { return mouseZone; }
167
168protected:
170 void paint (Graphics&) override;
172 void mouseEnter (const MouseEvent&) override;
174 void mouseMove (const MouseEvent&) override;
176 void mouseDown (const MouseEvent&) override;
178 void mouseDrag (const MouseEvent&) override;
180 void mouseUp (const MouseEvent&) override;
182 bool hitTest (int x, int y) override;
183
184private:
185 WeakReference<Component> component;
186 ComponentBoundsConstrainer* constrainer;
187 BorderSize<int> borderSize;
188 Rectangle<int> originalBounds;
189 Zone mouseZone;
190
191 void updateMouseZone (const MouseEvent&);
192
194};
195
196} // namespace juce
Specifies a set of gaps to be left around the sides of a rectangle.
A class that imposes restrictions on a Component's size or position.
The base class for all JUCE user-interface objects.
A graphics context, used for drawing a component or image.
Represents a mouse cursor image.
Contains position and status information about a mouse event.
A pair of (x, y) coordinates.
Definition juce_Point.h:42
Manages a rectangle and allows geometric operations to be performed on it.
Represents the different sections of a resizable border, which allow it to resized in different ways.
bool isDraggingWholeObject() const noexcept
Returns true if dragging this zone will move the entire object without resizing it.
bool isDraggingBottomEdge() const noexcept
Returns true if dragging this zone will move the object's bottom edge.
Rectangle< ValueType > resizeRectangleBy(Rectangle< ValueType > original, const Point< ValueType > &distance) const noexcept
Resizes this rectangle by the given amount, moving just the edges that this zone applies to.
bool isDraggingLeftEdge() const noexcept
Returns true if dragging this zone will move the object's left edge.
bool isDraggingTopEdge() const noexcept
Returns true if dragging this zone will move the object's top edge.
bool isDraggingRightEdge() const noexcept
Returns true if dragging this zone will move the object's right edge.
int getZoneFlags() const noexcept
Returns the raw flags for this zone.
A component that resizes its parent component when dragged.
~ResizableBorderComponent() override
Destructor.
Zone getCurrentZone() const noexcept
Returns the zone in which the mouse was last seen.
This class acts as a pointer which will automatically become null if the object to which it points is...
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
This is a shorthand way of writing both a JUCE_DECLARE_NON_COPYABLE and JUCE_LEAK_DETECTOR macro for ...
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.