Drawing weirdness while extending TextButton

I’ll start with the code: [code]class FileSelectorButton : public ActionBroadcaster, public TextButton, public ButtonListener
File currentFile;
FileChooser chooser;
FileSelectorButton(String name) : TextButton(name), chooser(“Select a file”)
setButtonText(“Load a file”);

void buttonClicked(Button* button)
		currentFile = chooser.getResult();

bool filesDropped(const StringArray& filenames, int mouseX, int mouseY)
	if(filenames.size() == 1)
		currentFile = File(filenames[0]);
		return true;
	return false;

void paintButton(Graphics& g, bool isMouseOverButton, bool isButtonDown)

	//a few lines being drawn; omitted here because they're irrelevant
	TextButton::paintButton(g, isMouseOverButton, isButtonDown);


So basically, it’s a subclass of TextButton that opens up a FileChooser when you click it and notifies ActionListeners of the result. It also allows you to drag a file onto the button and do the same thing.

Both the click and filesDropped are working, but there’s a drawing problem when dragging files onto the button. Steps to reproduce:

  1. Click a file somewhere in Explorer
  2. Drag onto the button
  3. Move the mouse off the button, somewhere onto the parent component
  4. Move the mouse back over the button

At the end of step 2, I call setState(ButtonState::buttonOver) as that’s the only possible state if a file was dropped over the button, and it draws fine. When I do step 3, the button draws as it should, with ButtonState::normal.

At step 4 half the time it’ll render it properly (ButtonState::buttonOver, isButtonDown=false), and the other half it appears to render with isButtonDown=true.

As I was writing this, it occurred to me that I could try using the isDown() method instead of using isButtonDown. I tried doing that and it seems to work fine. So it seems isButtonDown isn’t always being set appropriately.

but if you look at the line that actually calls paintButton, it’s:

    paintButton (g, isOver(), isDown());

…so how could isButtonDown be different to isDown()??

After trying it a few more times, isDown() does seem to give the same result as isButtonDown. Guess I should have tried it a few more times. Either way, there’s something not quite right here. I’m not really sure where to look next.

The only way that value could ever be different is if you’re changing it or corrupting the stack in the code you described as “irrelevent”…