PDA

View Full Version : GUI + Display Question



Seltzer
03-27-2014, 03:43 PM
I was reading through the GUI Framework (http://clanlib.org/documentation/3.0/GUIFramework.html) article and it mentioned something about using clanGUI compared to clanDisplay rendering.


A common mistake is to assume that if you want to render the GUI, you can simply add a call to gui_manager.exec() just before the displaywindow.flip() line. This will not work. The gui_manager.exec() function will not exit until something in the GUI calls clan::GUIComponent::exit_with_code(), causing only the GUI to be rendered and your game will disappear and hang.

Does this mean using the GUI framework and the Display rendering are mutually exclusive? That is, if I'm making a 2D game and I want to add GUI components (like an inventory), do I need to wrap it in one big custom GUI component for it to work correctly?

Perhaps I'm misinterpreting the article, but that's what it sounded like.

rombust
03-27-2014, 05:11 PM
That's just referring to the gui_manager.exec() call.

Personally, I dislike using .exec(), other clanlib users love using .exec(). It depends on what you are doing, and how you prefer the code to be structured.

ClanLib\Examples\Display_Render\Blend\Sources\app. cpp contains:


clan::GUIWindowManagerTexture wm(window);
clan::GUIManager gui(wm, "theme");
...
while (!quit)
{
...
wm.process();
wm.draw_windows(canvas);
window.flip(1);

clan::KeepAlive::process();
}

Seltzer
03-27-2014, 05:21 PM
That's just referring to the gui_manager.exec() call.

Personally, I dislike using .exec(), other clanlib users love using .exec(). It depends on what you are doing, and how you prefer the code to be structured.

Thanks for the prompt reply!

I agree, that looked messy to me. What exactly is the rationale for using exec vs. any other alternative? I guess I don't exactly understand what exec is supposed to do and how one goes about getting the same behavior without it. The manual should clarify that there's more than one way to solve the problem. It says the example shown is "the best way", which may not be accurate if it's a matter of opinion.

rombust
03-27-2014, 09:09 PM
gui.exec() is event driven

Some (most) other frameworks, and some operating systems use this model.

It just means that you do not have direct control of the main loop. Instead you use events and callbacks to determine what's called within the main loop (eg a timer event or input event)

gui.exec() doesn't do any magic. It's quite simple:

To explain in more detail, this is an example of how GUIManager::exec() runs (with the functions collapsed together and reduced, so it's more clearer)


int GUIManager::exec()
{
while (!impl->exit_flag)
{
impl->exit_code = 0;

int timeout = -1;
if (impl->is_constant_repaint_enabled())
timeout = 0;

KeepAlive::process(timeout);
impl->invalidate_constant_repaint_components();
impl->window_manager.update();

}

}

void GUIWindowManagerProvider_Texture::update()
{
update_paint();
canvas_window.clear(Colorf::black); // Do not change this to Colorf::transparent. It has unintended side effects on windows with an alpha channel.
draw_windows(canvas_window);
display_window.flip();
}

So it's basically doing the exactly the same thing as I mentioned in the ClanLib\Examples\Display_Render\Blend\Sources example.





clan::GUIWindowManagerTexture wm(window);
clan::GUIManager gui(wm, "theme");
...
while (!quit)
{
...
wm.process();
wm.draw_windows(canvas);
window.flip(1);

clan::KeepAlive::process();
}
[In clanlib, wm.process() is...]

void GUIWindowManagerProvider_Texture::process()
{
invalidate_constant_repaint_components();
update_paint();
}

On a side note, if you want control of the main display when using gui.exec(). There is the "func_repaint" GUITextureWM callback.

Please note, I had to look all of this up by looking at the source code, it's laid out quite logically. (i.e. I didn't code it :) )

Seltzer
03-27-2014, 10:56 PM
Thanks again. Perhaps I'll make a pull request later and document some of the more obvious stuff.