I just tried that. It kinda works.
I used ButtonListener::buttonStateChanged(Button*) and setTriggeredOnMouseDown(true).
The trouble with this is that I cannot determine the previous state of the button, just the current one.
What I’m looking for is some test that could tell me that the button just went from down to normal/over. (some kind of “buttonReleased” event)
Anyway, I also noticed something very weird, that looks like a bug:
When setTriggeredOnMouseDown is enabled on a Button instance, it seems to never lose the focus after having been clicked once.
In my application, its buttonStateChanged callback is called at every single click on any other component, from the Button::focusLost function.
I tried to simplify the bug and managed to reproduce it on a very simple application.
Here’s the code for the test component I used:
struct ButtonTestComponent : public Component, public ButtonListener
{
ButtonTestComponent ()
{
button1 = new TextButton("triggeredOnMouseDOWN");
button1->setTriggeredOnMouseDown(true);
button2 = new TextButton("triggeredOnMouseUP ");
addAndMakeVisible(button1);
addAndMakeVisible(button2);
button1->addButtonListener(this);
button2->addButtonListener(this);
}
virtual void resized ()
{
const int y = getHeight() / 2;
button1->setBounds(0, 0, getWidth(), y);
button2->setBounds(0, y, getWidth(), getHeight() - y);
}
static const String describeState (Button* button)
{
if (button->isDown())
return "down";
else if (button->isOver())
return "over";
else
return "normal";
}
virtual void buttonStateChanged (Button* button)
{
String s;
s << button->getName() << " -> " << describeState(button);
Logger::outputDebugString(s);
}
virtual void buttonClicked (Button* button)
{
String s;
s << button->getName() << " -> clicked";
Logger::outputDebugString(s);
}
TextButton* button1;
TextButton* button2;
};
The following image shows the mouse events used to reproduce the bug:
And this is what my program log contains after the two clicks on the buttons:
triggeredOnMouseDOWN -> over
triggeredOnMouseDOWN -> down
triggeredOnMouseDOWN -> clicked
triggeredOnMouseDOWN -> over
triggeredOnMouseDOWN -> normal
triggeredOnMouseUP -> over
triggeredOnMouseDOWN -> down
triggeredOnMouseUP -> down
triggeredOnMouseUP -> over
triggeredOnMouseUP -> clicked
triggeredOnMouseUP -> normal
This is the last “triggeredOnMouseDOWN -> down” that really bothers me.
Is there any way to get rid of it ?
I’m using Juce 1.43 on windows XP, with Visual C++ 8.0.
Thanks.