Change ToggleButton's state without triggering EventSelectStateChanged?

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

zuur
Not too shy to talk
Not too shy to talk
Posts: 31
Joined: Tue Apr 01, 2008 21:17

Change ToggleButton's state without triggering EventSelectStateChanged?

Postby zuur » Thu Mar 29, 2018 07:33

...or "how to tell in a callback whether the state was changed through code or by a user?"

Your first though is: "if he's asking this question, he must be structuring something wrong"... - maybe? Please let me know!

As some background: I need to save user interactions so I can "play them back later", which works fine in 99% of my application. My general approach is that when the user performs any interactions I don't perform the action right away, I save them into a queue of actions which both gets serialized as well as getting performed and cleared out at the end of each frame. Eg: if the user clicks the [Beep] button I save a "DO_BEEP" action into a queue, then at the end of the frame I serialize the queue to disk as well as performing all the actions so the "beep" gets played then.

In the case I'm having problems with I have a ToggleButton - when the user clicks it I get a "state changed" callback, so I record the fact that it was set to a certain value (true/false). At the end of the frame I save this and also play back eg: "SET_TOGGLE:TRUE" - when I play this back the first thing I do is update the UI state of the toggle (in case it needs it) and then perform the action that's supposed to happen when it's toggled.

My problem is that when I update the UI state I call something like myToggleButton->setSelected(True); - this then calls the callback which creates another action and saves it to the queue! (so it tries to play back again next frame as well).

If I put enough "check the value's not the right value already" around things I can get it to work most of the time, but it's very reliant on making sure things are synced up in the first place, and restarting things or playing a replay tends to start with them out of sync.

My solution would be a lot more robust if I could update the button state in code without triggering the callback, or if I could tell from within the callback if it was triggered by the user or me calling it through code...

Any thoughts?

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: Change ToggleButton's state without triggering EventSelectStateChanged?

Postby Ident » Thu Mar 29, 2018 19:11

Set the window's eventset to be muted if you don't want the callback to be fired:
http://static.cegui.org.uk/docs/0.8.7/c ... d4ee065df1

The Window is the Eventset itself, so just call it on it.

Does that help?
CrazyEddie: "I don't like GUIs"

zuur
Not too shy to talk
Not too shy to talk
Posts: 31
Joined: Tue Apr 01, 2008 21:17

Re: Change ToggleButton's state without triggering EventSelectStateChanged?

Postby zuur » Sun Apr 01, 2018 02:38

I think that's exactly exactly what I needed - thanks very much! I'll try it as soon as I get back to the keyboard.

I had started doing something with a similar effect by setting the userData() on the Window to indicate that I should ignore the events and then checking the userData in the event handler, but this will clean things up a whole lot if my understanding is correct.


Return to “Help”

Who is online

Users browsing this forum: No registered users and 9 guests