Hello
I wanted to create a momentary button. So I used a KickButton but was having weird behavior (it gets stuck in “pressed” state). So thinking it was an issue with KickButton I created my own MomentaryButton class. But I am experiencing the exact same behavior and cannot figure out what is going on… Something seems to be updating CControl::value under my feet…
Here are the details:
void MomentaryButton::draw(CDrawContext *fContext)
{
DLOG_F(INFO, "MomentaryButton::draw(%f)", value);
...
setDirty(false);
}
void MomentaryButton::updateValue(float fNewValue)
{
if(value != fNewValue)
{
beginEdit();
value = fNewValue;
DLOG_F(INFO, "MomentaryButton::updateValue(%f)", value);
invalid();
valueChanged();
endEdit();
}
}
CMouseEventResult MomentaryButton::onMouseDown(CPoint &where, const CButtonState &buttons)
{
DLOG_F(INFO, "MomentaryButton::onMouseDown");
if(!(buttons & kLButton))
return kMouseEventNotHandled;
updateValue(getMax());
return kMouseEventHandled;
}
CMouseEventResult MomentaryButton::onMouseUp(CPoint &where, const CButtonState &buttons)
{
DLOG_F(INFO, "MomentaryButton::onMouseUp");
updateValue(getMin());
return kMouseEventHandled;
}
The issue is when you click the mouse too fast… (100% reproducible and SAME behavior with CKickButton) (I am printing outputs from the processor and controller as well)
MomentaryButton::onMouseDown
MomentaryButton::updateValue(1.000000)
MomentaryButton::draw(1.000000)
VAC6Processor::processParameters => kMaxLevelReset=1.000000
MomentaryButton::onMouseUp
MomentaryButton::updateValue(0.000000)
MomentaryButton::draw(0.000000)
VAC6Processor::processParameters => kMaxLevelReset=0.000000
VAC6Processor::getState()
VAC6Controller::getState()
VAC6Processor::getState()
VAC6Controller::getState()
VAC6Processor::processParameters => kMaxLevelReset=1.000000
MomentaryButton::draw(1.000000)
The last call MomentaryButton::draw(1.000000) is happening without the value being updated and I don’t understand why draw is being called again…
This is what the call looks like if you click and release “slowly”
MomentaryButton::onMouseDown
MomentaryButton::updateValue(1.000000)
MomentaryButton::draw(1.000000)
VAC6Processor::processParameters => kMaxLevelReset=1.000000
VAC6Processor::getState()
VAC6Controller::getState()
MomentaryButton::onMouseUp
MomentaryButton::updateValue(0.000000)
MomentaryButton::draw(0.000000)
VAC6Processor::processParameters => kMaxLevelReset=0.000000
VAC6Processor::getState()
VAC6Controller::getState()
Thanks
Yan