LMMS
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
152 Array<SelectableItemType> itemsInLasso;
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;
163 originalMinusNew.removeValuesIn (itemsInLasso);
164
165 itemsInLasso.removeValuesIn (originalSelection);
166 itemsInLasso.addArray (originalMinusNew);
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 //==============================================================================
220
222};
223
224} // namespace juce
Definition juce_Array.h:56
void addArray(const Type *elementsToAdd, int numElementsToAdd)
Definition juce_Array.h:583
void removeValuesIn(const OtherArrayType &otherArray)
Definition juce_Array.h:961
static bool JUCE_CALLTYPE isMouseButtonDownAnywhere() noexcept
Definition juce_Component.cpp:3205
Component * getParentComponent() const noexcept
Definition juce_Component.h:804
Rectangle< int > getBounds() const noexcept
Definition juce_Component.h:304
Component() noexcept
Definition juce_Component.cpp:517
void setBounds(int x, int y, int width, int height)
Definition juce_Component.cpp:1147
void setSize(int newWidth, int newHeight)
Definition juce_Component.cpp:1262
LookAndFeel & getLookAndFeel() const noexcept
Definition juce_Component.cpp:2173
virtual void setVisible(bool shouldBeVisible)
Definition juce_Component.cpp:575
Definition juce_GraphicsContext.h:45
Array< SelectableItemType > originalSelection
Definition juce_LassoComponent.h:217
void endLasso()
Definition juce_LassoComponent.h:176
LassoComponent()=default
bool hitTest(int, int) override
Definition juce_LassoComponent.h:213
void beginLasso(const MouseEvent &e, LassoSource< SelectableItemType > *lassoSource)
Definition juce_LassoComponent.h:118
void paint(Graphics &g) override
Definition juce_LassoComponent.h:202
Point< int > dragStartPos
Definition juce_LassoComponent.h:219
void dragLasso(const MouseEvent &e)
Definition juce_LassoComponent.h:145
LassoSource< SelectableItemType > * source
Definition juce_LassoComponent.h:218
ColourIds
Definition juce_LassoComponent.h:195
@ lassoFillColourId
Definition juce_LassoComponent.h:196
@ lassoOutlineColourId
Definition juce_LassoComponent.h:197
Definition juce_LassoComponent.h:42
virtual ~LassoSource()=default
virtual void findLassoItemsInArea(Array< SelectableItemType > &itemsFound, const Rectangle< int > &area)=0
virtual SelectedItemSet< SelectableItemType > & getLassoSelection()=0
Definition juce_MouseEvent.h:39
Definition juce_Point.h:42
Definition juce_Rectangle.h:67
Definition juce_SelectedItemSet.h:46
* e
Definition inflate.c:1404
int g
Definition inflate.c:1573
#define jassert(expression)
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
Definition carla_juce.cpp:31