Can't get the button to respond to mouseUp


#1

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.

[code]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();
}

}[/code]

So, the documentation for button says:

So I tried

[code]void chordButton::mouseDown(MouseEvent e){

getProcessor()->killChord(80);

kill = ("Kill Chord Called");

setDebugInt();

}[/code] 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!


#2

‘chordButton’ is a variable, not a class?


#3

Hi cpr,

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


#4

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… :slight_smile:

-cpr


#5

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:

[code]if (event.eventComponent==chordButton){

    getProcessor()->killChord(80);
   
    kill = ("Kill Chord Called");
   
    setDebugInt();
}[/code] 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


#6

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.


#7

haydxn,

Thanks. :smiley:

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