Can't get the button to respond to mouseUp

7 posts / 0 new
Last post
Zoabis
Offline
Last seen: 2 months 5 days ago
Joined: 14 Jun 2012 - 20:34
Can't get the button to respond to mouseUp

Hi,

Yet another embarrassingly easy question to answer - I hope! OK, so basically, I have a button called 'chordButton' but confusingly labeled 'Note On Button' on my background component. Hardly worth a picture but here it is:

So, I have the following method which should display the text 'Kill Chord Called' when chordButton is the event component and I lift my finger after a click (or so I thought) but as you can see above, entering the area of the chordButton and clicking and releasing the mouse only displays 'mouseExit Entered' (this happens when the button has the mouse focus. mouseExit Entered only works for the background as I've also implemented mouseExit and mouseDown.

void ZS1AudioProcessorEditor::mouseUp(const MouseEvent &event)
{
          
    kill = ("mouseUp Entered");
    
    setDebugInt();
              
    if (event.eventComponent==chordButton){
        
        getProcessor()->killChord(80);
        
        kill = ("Kill Chord Called");
        
        setDebugInt();
    }
    
        
}

void ZS1AudioProcessorEditor::mouseExit(const MouseEvent &event)
{
    
    kill = ("mouseExit Entered");
    
    setDebugInt();
    
    
    
    if (event.eventComponent==chordButton){
        
        getProcessor()->killChord(80);
        
        kill = ("Exit Called");
        
        setDebugInt();
    }
    
}

void ZS1AudioProcessorEditor::mouseDown(const MouseEvent &event)
{
    
    kill = ("mouseDown Entered");
    
    setDebugInt();
    
    if (event.eventComponent==chordButton){
        
        //getProcessor()->killChord(80);
        
        kill = ("Down Called");
        
        setDebugInt();
    }
    
}

So, the documentation for button says:
void Button::mouseUp ( const MouseEvent & ) [protected, virtual]

So I tried

void chordButton::mouseDown(MouseEvent e){
    
    getProcessor()->killChord(80);
    
    kill = ("Kill Chord Called");
    
    setDebugInt();
}
but XCode said 'Use of undeclared identifier 'chordButton'

I'm a complete novice, as is probably obvious, but can somebody tell me where and how to get my chordButton responding to a mouse up!

cpr
cpr's picture
Offline
Last seen: 1 hour 28 min ago
Joined: 25 Apr 2008 - 23:49
Re: Can't get the button to respond to mouseUp

'chordButton' is a variable, not a class?

Zoabis
Offline
Last seen: 2 months 5 days ago
Joined: 14 Jun 2012 - 20:34
Re: Can't get the button to respond to mouseUp

Hi cpr,

Thanks for replying. chordButton is an instance of TextButton. Is that wrong?

cpr
cpr's picture
Offline
Last seen: 1 hour 28 min ago
Joined: 25 Apr 2008 - 23:49
Re: Can't get the button to respond to mouseUp

Zoabis, yes, that (void chordButton::mouseDown(MouseEvent e)) is wrong. In general, these forums are for supporting the usage of the JUCE framework, where your problems are about understanding C++. I don't mind helping out with those questions, but you will get more support if you go and figure out how to use the language before asking your questions here. Not understanding the difference between classes and instances of classes is a large barrier, I can only imagine what pointers will be like for you.. :)

-cpr

Zoabis
Offline
Last seen: 2 months 5 days ago
Joined: 14 Jun 2012 - 20:34
Re: Can't get the button to respond to mouseUp

Hi,

No, I do know the difference between a class and it's instance, although yes, looking at that line, that does look like I don't. Not sure why I tried that. Now I understand that your ''chordButton' is a variable, not a class?' was a joke! So, can you actually tell me why:

if (event.eventComponent==chordButton){
       
        getProcessor()->killChord(80);
       
        kill = ("Kill Chord Called");
       
        setDebugInt();
    }
doesn't work/ tell me the lines of code to tell me when my Button instance chordButton has experienced a mouseUp?

Seriously I do appreciate your help and will try to refrain from asking questions where C++ understanding is the problem in the future.

Dave

haydxn
Offline
Last seen: 1 hour 58 min ago
Joined: 10 Apr 2005 - 14:46
Re: Can't get the button to respond to mouseUp

Well, the main problem is that you're implementing the mouseUp callback of the *editor*. When you're clicking on a button, the button is the object receiving the events, not the editor [which explains why you're seeing the mouseExit notification; as far as the editor is concerned, that is the last thing to have happened, since the mouse moved from the editor to the button].

Probably the easiest solution would be to register the editor with the button as a mouse listener [ chordButton->addMouseListener(this) ] - which will forward the component's events to you. Alternatively, you might want to make your own button subclass, and override the mouseUp there - though make sure that you call the base mouseUp from your implementation (e.g. TextButton::mouseUp(e)), as the Button class already has some logic in that function.

xh

Zoabis
Offline
Last seen: 2 months 5 days ago
Joined: 14 Jun 2012 - 20:34
Re: Can't get the button to respond to mouseUp

haydxn,

Thanks. :D

Works like a charm. One line of code, 33 views on the post and you answered it without sarcasm in one line. Cheers :lol: