mouseDown and mouseUp for ResizableCorner

Hello,
Sorry, but again in my life I have problems with understanding documentation. I am trying for 2 days set method mouseDown() and mouseUp() for my resizableCornerComponent.

I have plugin, and in constructor of AudioProcessorEditor I call setResizable(true, true).
Then how to add special behaviour when mouse is down on resizableCorner. I have impression like I’ve already tried everything. But it just doesn’t work for me. I tried to create new ResizableCornerComponent, but have no idea what next. I tried
resizableCorner->juce::Component::mouseDown(const MouseEvent &event);
But have no idea what is MouseEvent. I read about that, but I don’t understand. Do I need create MouseEvent variable? For what? What event? Clicking and hold mouse isn’t already event by itself?

I overide mouseDown method. But when I click anywhere, nothing happens. Please help :slight_smile:

I also tried:
resizableCorner->addMouseListener(MouseListener *newListener, bool wantsEventsForAllNestedChildComponents);

and create MouseListener mouseListener; and then:
resizableCorner->addMouseListener(&mouseListener, true);

But nothing happens

Why do you need "special behavior " for the ResizableCornerComponent?

Anyway if you really need it, you need to subclass it, override the needed methods and create an instance of the subclass and set that on your parent component. You will likely also need to call the base class methods in your overriden methods to keep the original behavior of ResizableCornerComponent.

Yes, I want to set some std::atomic<bool> to be true. And when mouseUp() back to std::atomic<bool> false.

OK, so it looks like it’s not for me :slight_smile: but thanks for you try.

But on the other hand, if I override mouseDown method, how to call it when mouse is really down?

OK, I understand I think, I should call it for example in button.onClick() but what should I use then as a MouseEvent?

class MyCornerComponent : public ResizableCornerComponent
{
public:
	MyCornerComponent(Component *componentToResize, ComponentBoundsConstrainer *constrainer) 
		: ResizableCornerComponent(componentToResize,constrainer)
	{}
	void mouseDown(const MouseEvent& ev) override
	{
		ResizableCornerComponent::mouseDown(ev);
		// your custom behavior here
	}
	void mouseUp(const MouseEvent& ev) override
	{
		ResizableCornerComponent::mouseUp(ev);
		// your custom behavior here
	}
};

But really, do you actually need that? (You obviously also need to add into the class anything needed to get access your bool parameter or anything else you might need.)

I am not sure if I really need it. I know that at the moment I want it.
I have plugin that draws graph from FFT for impulse response. And when I have really big buffer size, and I am resizing window with my graph, it’s not smooth. So I wanted to set it like that when I am resizing, it would stop drawing in realtime fft output,and start drawing from static data which is remembered. Then resizing works smoothly. And even finally it works now, but I set drawing static data in resized() method, but then it draws both fft output, and static data one by one (or something like that) because resized() doesn’t work continously. That’s why I want to just set bool dontDrawFFT when mouse is down. Is it reasonable?

Hey, great thanks, but I am not sure if I understand it. But I think your code creates new component which is of course ResizableCornerComponent. But I have already resizable corner when I called setResizable(true, true /*that true makes corner visible*/)

And I just want to set mouseDown for that already existed corner.

if you want to replace the ResizableCornerComponent in your document window, that variable is a protected member variable. So, in your ResizableWindow-based class, just assign your custom ResizableCornerComponent to it:
https://docs.juce.com/master/classResizableWindow.html#af9e547a87f7f39ca3721e19029a46f89

struct MyResizableCornerComponent : public ResizableCornerComponent
{
    //snip...
};

struct MyWindow : public ResizableWindow
{
    //snip...
    MyWindow() : ResizableWindow(...)
    {
        resizableCorner = std::make_unique<MyResizableCornerComponent>();
        //now whenever you click on the resizableCorner, 
        //this window will receive the mouseDown/Up/enter/exit/drag/etc messages
        resizableCorner.get()->addMouseListener(this);
    }
    void mouseDown(const MouseEvent& e) override
    {
        if( e.originalComponent == resizableCorner.get() )
        {
            //user mouseDown'd on the resizableCorner
        }
    }
};
1 Like

If you’re doing this as a plugin with juce::AudioProcessorEditor you can access the ResizableCornerComponent since it’s a public member variable:

https://docs.juce.com/master/classAudioProcessorEditor.html

Combine that with @matkatmusic’s suggestion on setting a mouse listener and you’ll receive mouse events for the ResizableCornerComponent.