LassoComponent help

Hi,

I would like to understand the LassoComponent but I'm having an hard time reading from the IntroJucer files.
I have a parent component with several child components (Cable) that I want to select.

In my parent component declaration I have this:

class myParentClass : public Component, public LassoSource<Cable*>
public:
    void findLassoItemsInArea (Array <Cable*>& results, const Rectangle<int>& area);
    SelectedItemSet<Cable*> selected;
    SelectedItemSet<Cable*>& getLassoSelection();

then:

void myParentClass::mouseDown(const juce::MouseEvent &e)
{
    addChildComponent(lassoCable);
    lassoCable.beginLasso(e, this);
}


void myParentClass::mouseDrag(const juce::MouseEvent &e)
{
    lassoCable.toFront(false);
    lassoCable.dragLasso(e);
}

void myParentClass::mouseUp(const juce::MouseEvent &e)
{
    lassoCable.endLasso();
    removeChildComponent(&lassoCable);
}


void ModularSpace::findLassoItemsInArea (Array <Cable*>& results, const Rectangle<int>& area)
{

}

SelectedItemSet<Cable*>& ModularSpace::getLassoSelection()
{
    return selected;
}

 

The lasso drawing is fine, but I don't understand how can I manage which component (Cable) is selected.
How am I supposed to use findLassoItemsInArea and the getLassoSelection?

Thanks!

Hello!

You can use findLassoItemsInArea to decide what is "selected" and what is not. Here's a simple example (C++11, if you're using an older compiler you'll have to change the for loop syntax):

void YourClass::findLassoItemsInArea (Array<YourComponentType*>& itemsFound, const Rectangle<int>& area)
{
    for (auto& element : components)
    {
        if (area.contains (element.getBounds()))
        {
            itemsFound.add (&element);
        }
    }
}

...where components is an iteratable collection of components you'd like to check against. Of course, you're welcome to implement this however you like, the important part is that you add to itemsFound.

Hope this helps!

1 Like

I spent 36 hours trying to figure out the basics of this class. I’m a little bit of a noob, but I’ve made this project to help anyone in the future stuck on this:

As I keep working on my own project I’ll add more to the example, like what I’ve written in the TO-DO. In the meantime if anyone actually capable would like to help, feel free to pull-request, it would be greatly appreciated.

1 Like