Jump to content

[SOLVED] remove assert in WidgetButton::isToggled()


photo

Recommended Posts

Unigine's button seems only can be toggled or not toggled, for example, I need some button to behave this way, when mouse pressed on button, the button is down state, and when I release the button, button returns to up state, of course this button can not be a toggleable button. just a normal button. And When the button is down(mouse pressed on that button and stay pressing on that button), I need to detect if this button is down in some update function and do some continues work, and combined this with debug version of engine. engine will crash because of the assert in isToggled function.

 

I assume this is a normal behavior of a button, so there is no need for that assert in engine source's WidgetButton::isToggled() function.

 

And this also applies to WidgetIcon class.

Link to comment

Hi Steve,

 

You can easily handle such situations with the current implementation of WidgetButton, just set two callbacks: one for GUI_PRESSED and another for GUI_RELEASED. Here is a code sample:

 

WidgetButton btn;
int is_button_pressed = false;


/*
*/
int init() {

 Gui gui = engine.getGui();

 // btn button
 btn = new WidgetButton(gui,"Press me");
 btn.setFontSize(24);
 btn.setPosition(128,128);

 gui.addChild(btn,GUI_ALIGN_OVERLAP);

 btn.setCallback(GUI_PRESSED,"btn_pressed");
 btn.setCallback(GUI_RELEASED,"btn_released");

 return 1;
}

/*
*/
int update()
 if(is_button_pressed) {
   // do your work
   log.message("i'm doing some stuff here: %d\n",rand(40,506));
 }
}


/*
*/
void btn_pressed() {
 if(is_button_pressed) return;

 log.message("pressed\n");
 is_button_pressed = true;
}

/*
*/
void btn_released() {
 if(!is_button_pressed) return;

 log.message("released\n");
 is_button_pressed = false;
}

Link to comment

does this means btn_pressed will be called on each frame that button remains down state(hold mouse button and not release it)?

 

Because this is what I want. I want process it on every frame until mouse button released on that button, not just once...

Link to comment
×
×
  • Create New...