Should I use a juce::Button?


#1

I need to have buttons in my application which perform different actions, one on the mouse down, and one on the mouse up. Well, more accurately, when the mouse up causes the button which was previously in the down state to release. This can happen whether the mouse up is in the client area of the Component, or outside (or at least, it should).

To make things more interesting I would also like to have keyboard shortcuts that can depress the button when the corresponding key is pressed, and cause the button component to release when the corresponding keyboard key is let go.

Is juce::Button appropriate for this or do I need to make a copy of the file and adapt it? Or is there a way to accomplish this using a derived class? It seems that juce::Button either lets you pay attention to the mouse down, or the mouse up, via the use of setTriggeredOnMouseDown(), but not both.

Feel free to ridicule me if I seem hopelessly confused.


#2

In addition, I want the button to stay down if, during the mouse down, the cursor leaves the client area of the button (or returns).

I thought to override buttonStateChanged(), which says “Subclasses can override this if they need to do something special when the button goes up or down.” But there is no way to know if the function is being called for a button up. Only down. The ButtonState enumeration only has normal, over, and down…no “up.”


#3

I was going to suggest using buttonStateChanged, but if that doesn’t to do what you need, I think you might need to write a custom component. Or if you can suggest an addition to the button class that will do what you need and which might be useful to other people too, it might be something I could add.