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_LassoComponent.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//==============================================================================
40template <class SelectableItemType>
42{
43public:
45 virtual ~LassoSource() = default;
46
57 const Rectangle<int>& area) = 0;
58
67};
68
69
70//==============================================================================
99template <class SelectableItemType>
101{
102public:
103 //==============================================================================
105 LassoComponent() = default;
106
107 //==============================================================================
119 {
120 jassert (source == nullptr); // this suggests that you didn't call endLasso() after the last drag...
121 jassert (lassoSource != nullptr); // the source can't be null!
122 jassert (getParentComponent() != nullptr); // you need to add this to a parent component for it to work!
123
124 source = lassoSource;
125
126 if (lassoSource != nullptr)
127 originalSelection = lassoSource->getLassoSelection().getItemArray();
128
129 setSize (0, 0);
130 dragStartPos = e.getMouseDownPosition();
131 }
132
145 void dragLasso (const MouseEvent& e)
146 {
147 if (source != nullptr)
148 {
149 setBounds (Rectangle<int> (dragStartPos, e.getPosition()));
150 setVisible (true);
151
153 source->findLassoItemsInArea (itemsInLasso, getBounds());
154
155 if (e.mods.isShiftDown())
156 {
157 itemsInLasso.removeValuesIn (originalSelection); // to avoid duplicates
158 itemsInLasso.addArray (originalSelection);
159 }
160 else if (e.mods.isCommandDown() || e.mods.isAltDown())
161 {
162 auto originalMinusNew = originalSelection;
164
165 itemsInLasso.removeValuesIn (originalSelection);
167 }
168
169 source->getLassoSelection() = SelectedItemSet<SelectableItemType> (itemsInLasso);
170 }
171 }
172
176 void endLasso()
177 {
178 source = nullptr;
179 originalSelection.clear();
180 setVisible (false);
181 }
182
183 //==============================================================================
195 {
196 lassoFillColourId = 0x1000440,
198 };
199
200 //==============================================================================
202 void paint (Graphics& g) override
203 {
204 getLookAndFeel().drawLasso (g, *this);
205
206 // this suggests that you've left a lasso comp lying around after the
207 // mouse drag has finished.. Be careful to call endLasso() when you get a
208 // mouse-up event.
210 }
211
213 bool hitTest (int, int) override { return false; }
214
215private:
216 //==============================================================================
217 Array<SelectableItemType> originalSelection;
218 LassoSource<SelectableItemType>* source = nullptr;
219 Point<int> dragStartPos;
220
222};
223
224} // namespace juce
Holds a resizable array of primitive or copy-by-value objects.
Definition juce_Array.h:56
void removeValuesIn(const OtherArrayType &otherArray)
Removes any elements which are also in another array.
Definition juce_Array.h:936
void clear()
Removes all elements from the array.
Definition juce_Array.h:188
The base class for all JUCE user-interface objects.
static bool JUCE_CALLTYPE isMouseButtonDownAnywhere() noexcept
Returns true if a mouse button is currently down.
Component * getParentComponent() const noexcept
Returns the component which this component is inside.
Rectangle< int > getBounds() const noexcept
Returns this component's bounding box.
void setBounds(int x, int y, int width, int height)
Changes the component's position and size.
void setSize(int newWidth, int newHeight)
Changes the size of the component.
LookAndFeel & getLookAndFeel() const noexcept
Finds the appropriate look-and-feel to use for this component.
virtual void setVisible(bool shouldBeVisible)
Makes the component visible or invisible.
A graphics context, used for drawing a component or image.
A component that acts as a rectangular selection region, which you drag with the mouse to select grou...
void endLasso()
Call this in your mouseUp event, after the lasso has been dragged.
LassoComponent()=default
Creates a Lasso component.
bool hitTest(int, int) override
Tests whether a given point is inside the component.
void beginLasso(const MouseEvent &e, LassoSource< SelectableItemType > *lassoSource)
Call this in your mouseDown event, to initialise a drag.
void paint(Graphics &g) override
Components can override this method to draw their content.
void dragLasso(const MouseEvent &e)
Call this in your mouseDrag event, to update the lasso's position.
ColourIds
A set of colour IDs to use to change the colour of various aspects of the label.
@ lassoFillColourId
The colour to fill the lasso rectangle with.
@ lassoOutlineColourId
The colour to draw the outline with.
A class used by the LassoComponent to manage the things that it selects.
virtual ~LassoSource()=default
Destructor.
virtual void findLassoItemsInArea(Array< SelectableItemType > &itemsFound, const Rectangle< int > &area)=0
Returns the set of items that lie within a given lassoable region.
virtual SelectedItemSet< SelectableItemType > & getLassoSelection()=0
Returns the SelectedItemSet that the lasso should update.
bool isAltDown() const noexcept
Checks whether the ALT key's flag is set.
bool isCommandDown() const noexcept
Checks whether the 'command' key flag is set (or 'ctrl' on Windows/Linux).
bool isShiftDown() const noexcept
Checks whether the shift key's flag is set.
Contains position and status information about a mouse event.
const ModifierKeys mods
The key modifiers associated with the event.
Point< int > getPosition() const noexcept
The position of the mouse when the event occurred.
Point< int > getMouseDownPosition() const noexcept
Returns the coordinates of the last place that a mouse was pressed.
A pair of (x, y) coordinates.
Definition juce_Point.h:42
Manages a rectangle and allows geometric operations to be performed on it.
Manages a list of selectable items.
#define jassert(expression)
Platform-independent assertion macro.
#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.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88