DrawableButton not showing the correct image


#1

I'm using Windows 8.1/VS2012

I've no idea when this happened exactly, but I just noticed that my DrawableButtons aren't drawn correctly.
The button is set to setClickingTogglesState(true). If I click the button (with the mouse), it would behave normally, but will only update its image after I move the mouse outside of the button's area. 

To reproduce, take a clean juce repository (tip) and go to juce_demo, widgets demo and replace the lines 479-481

DrawableImage down;
down.setImage (ImageCache::getFromMemory (BinaryData::juce_png, BinaryData::juce_pngSize));
down.setOverlayColour (Colours::black.withAlpha (0.3f));

with:

DrawableImage down;
down.setImage (ImageCache::getFromMemory (BinaryData::juce_png, BinaryData::juce_pngSize));
down.setOverlayColour (Colours::purple);
DrawableImage* d2 = new DrawableImage(down);
d2->setOverlayColour(Colours::blue);
DrawableImage* d3 = new DrawableImage(down);
d3->setOverlayColour(Colours::red);
DrawableImage* d4 = new DrawableImage(down);
d4->setOverlayColour(Colours::green);
DrawableImage* d5 = new DrawableImage(down);
d5->setOverlayColour(Colours::white);
DrawableImage* d6 = new DrawableImage(down);
d6->setOverlayColour(Colours::black);

And replace line 494:

db->setImages (&normal, &over, &down);

With this:

db->setImages (d5, d6, &down, nullptr, d2, d3, d4);

Paste for the lazy: http://tny.cz/09d36e65

 

Now notice how this button behaves:

Click it, then move the mouse somewhere else. You'll notice the mouseExit forces it to refresh, and display the correct image.


I don't know how to fix it, but adding the call 'sendStateMessage();' in juce_button::312 (between the setToggle and the sendClickMessage seem to fix it, but probably not in a good way :) I was just messing with it.

Oh, and manual triggerClick works just fine.


#2

Thanks - should be fixed now!


#3

As always - thanks for the quick fix!


#4

Apparently this is not quite resolved.

Now the clickMessage is sent twice!

Probably because of the sendNofitication flag in the setToggleState in juce_button.cpp:internalClickCallback (311)

How about this:


void Button::internalClickCallback (const ModifierKeys& modifiers)
{
    if (clickTogglesState)
        setToggleState (radioGroupId != 0 || ! lastToggleState, sendNotification);
    else
        sendClickMessage (modifiers);
}

 


#5

Ah yes, good idea, thanks!


#6

All good now - thanks!