radiobutton triggering twice

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

duindain
Just popping in
Just popping in
Posts: 19
Joined: Sat Jun 09, 2007 08:51

radiobutton triggering twice

Postby duindain » Wed Mar 26, 2008 15:17

Hey ive got a set of 3 radio buttons grouped together

using code from the wiki and other places i have a subscribed event for them as follows

Code: Select all

CEGUI::WindowManager::getSingleton().getWindow("preFold")->
      subscribeEvent(CEGUI::RadioButton::EventSelectStateChanged, CEGUI::Event::Subscriber(&menuDlg::radioPreselect,this));
   CEGUI::WindowManager::getSingleton().getWindow("preCheckfold")->
      subscribeEvent(CEGUI::RadioButton::EventSelectStateChanged, CEGUI::Event::Subscriber(&menuDlg::radioPreselect,this));
   CEGUI::WindowManager::getSingleton().getWindow("preBet")->
      subscribeEvent(CEGUI::RadioButton::EventSelectStateChanged, CEGUI::Event::Subscriber(&menuDlg::radioPreselect,this));


this is the radioPreselect function

Code: Select all

bool menuDlg::radioPreselect(const CEGUI::EventArgs &args)
{
   CEGUI::RadioButton * preBet = static_cast<CEGUI::RadioButton*>(CEGUI::WindowManager::getSingletonPtr()->getWindow("preBet"));
   CEGUI::RadioButton * preFold = static_cast<CEGUI::RadioButton*>(CEGUI::WindowManager::getSingletonPtr()->getWindow("preFold"));
   CEGUI::RadioButton * preCheckfold = static_cast<CEGUI::RadioButton*>(CEGUI::WindowManager::getSingletonPtr()->getWindow("preCheckfold"));
   
   if (preBet->isSelected())
   {
      CEGUI::WindowManager::getSingleton().getWindow("preBetSlidebar")->show();
   }
   if (preFold->isSelected())
   {
}
}
//and so on

the problem anyway is that the EventSelectStateChanged state is being called when the mouseclick down event selects the radio button and is called again when mouseclick up event is over the radio button after clicking on it

I am assuming the EventSelectStateChanged state is not correct for this window type at least to me selectstate changed means a single trigger once per change only. I hesitate to say its a bug since its such a simple component surely someone else would have noticed it by now heh

anyway does anyone know a workaround probably to check the radio button is selected and the mouse state is up at the same time

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Postby CrazyEddie » Wed Mar 26, 2008 19:13

Hi,

First, that is the correct event to be using.

I have looked at the code for the RadioButton, and there should be no such events firing in response to a mouse button down on the radio button.

A 'common' handler for a radio button group can get called twice because it is called once for the radio button that gets deselected and once for the radio button that gets selected (this is by design).

If it's possible this is your issue, what you might want is something like this:

Code: Select all

bool menuDlg::radioPreselect(const CEGUI::EventArgs &args)
{
    const CEGUI::WindowEventArgs& wnd_args =
        static_cast<const CEGUI::WindowEventArgs&>(args);

    // if this is a 'deselection' event, do nothing!
    if (!static_cast<const CEGUI::RadioButton*>(wnd_args.window)->isSelected())
        return false;

    // Rest of your code here...
}


If this still exhibits wrong behaviour when filtering out the deselections, I'll investigate further.

Oh, and I'm all in!

HTH

CE

duindain
Just popping in
Just popping in
Posts: 19
Joined: Sat Jun 09, 2007 08:51

Postby duindain » Wed Mar 26, 2008 21:23

hehe All in quick

ok that fixed the problem now it only runs the code once

i dont understand why this works

how did this if statement get evaluated as true

Code: Select all

if (preFold->isSelected())

both times the code was called from the one event

unless it unselects the old radio selects the new one then calls the EventSelectStateChanged once for deselect and once for reselect after that assignment then both calls would trigger that same if statement

I understand that it calls the event twice now i just dont know why both times would evaluate that if statement as true

anyway thankyou for the code working good now :)

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Postby CrazyEddie » Thu Mar 27, 2008 10:51

Hi,

The sequence is as follows:

* Newly selected radio button marked as selected - no event fired yet.
* Previously selected radio button deselected - event fired for this radio button.
* Event fired for newly selected radio button (from item 1)

Seems kind of wrong, I agree. I'll make a note of this and add it to Mantis later on (along with some other stuff I have to add).

CE.


Return to “Help”

Who is online

Users browsing this forum: No registered users and 12 guests