Results 1 to 5 of 5

Thread: GUI + Display Question

  1. #1

    Default GUI + Display Question

    I was reading through the GUI Framework 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.

  2. #2
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    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:
    Code:
    	clan::GUIWindowManagerTexture wm(window);
    	clan::GUIManager gui(wm, "theme");
    	...
    	while (!quit)
    	{
    		...	
    		wm.process();
    		wm.draw_windows(canvas);
    		window.flip(1);
    
    		clan::KeepAlive::process();
    	}

  3. #3

    Default

    Quote Originally Posted by rombust View Post
    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.

  4. #4
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    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)

    Code:
    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.


    Code:
    	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 )

  5. #5

    Default

    Thanks again. Perhaps I'll make a pull request later and document some of the more obvious stuff.

Similar Threads

  1. Display Box Leash
    By LordofEarth in forum Suggestion Box
    Replies: 2
    Last Post: 02-17-2014, 08:18 PM
  2. Display Box Leash
    By Pentonix in forum Suggestion Box
    Replies: 4
    Last Post: 02-15-2014, 11:08 AM
  3. Display Case
    By IAmABrodie in forum Suggestion Box
    Replies: 14
    Last Post: 05-26-2013, 11:13 PM
  4. Unable to display anything.
    By Dermark in forum Official ClanLib SDK Forums
    Replies: 3
    Last Post: 06-11-2008, 01:08 PM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •