Knu
Topic Author
Posts: 4
Joined: 03 Mar 2012, 10:02

best way to manage different GUI windows

13 Apr 2012, 12:05

Hi,

i'm working with Nurbed on the noesis integration in Ogre3D. So far, we can render the first .xaml GUI and we successfully made the binding between a button and its delegate.

However now, we don't know how we should proceed to manage more different GUI (eg. main menu, option menu, etc.) - this is our GuiManager:
	class Manager : public Ogre::RenderQueueListener
	{
	public:
		Manager();

		void Init(Ogre::RenderWindow* iRenderWindow);

		void renderQueueStarted(Ogre::uint8 queueGroupId, const Ogre::String& invocation, bool& skipThisInvocation);

	private:
		Noesis::Core::Ptr<Noesis::Gui::IRenderer> mUIRenderer;
		Noesis::Core::Ptr<Noesis::Gui::UIElement> mUIRoot;
		IDirect3DStateBlock9* mStateBlock;
		IDirect3DDevice9* mDevice;

		MainMenu mMainMenu;

		// temp code
		OIS::MouseState *prevMouseState;
	};
as you can see we have a mMainMenu instance which embeds the mainmenu.xaml resource
class MainMenu
{
public:
	MainMenu() {}

	Noesis::Core::Ptr<Noesis::Gui::FrameworkElement> Load()
	{
		// Load UI resource
		Ptr<IUIResource> guiResource = NsGetSystem<Noesis::Resource::IResourceSystem>()->Load("Gui/BlindBob/MainMenu.xaml");

		Ptr<FrameworkElement> fe = guiResource->GetRoot();

		Ptr<Button> prevButton = fe->FindName("Prev");
		prevButton->Click() += MakeDelegate(&OnPrevClicked);

		Ptr<Button> nextButton = fe->FindName("Next");
		nextButton->Click() += MakeDelegate(&OnNextClicked);
		return fe;
	}
	static void OnPrevClicked(const Ptr<BaseComponent>& sender, const RoutedEventArgs& e)
	{
	}

	static void OnNextClicked(const Ptr<BaseComponent>& sender, const RoutedEventArgs& e)
	{
		Button* button = NsStaticCast<Button*>(sender);
		button->SetIsEnabled(false);
	}

};
we were wondering if this is the best course of action (each class for each window, so we load and unload the root resource every time) or if we should have one class and manage a context switch.

Any performance issue, in any of these cases?

Is there any multi-window integration sample available?

thanks!
 
User avatar
sfernandez
Site Admin
Posts: 3005
Joined: 22 Dec 2011, 19:20

Re: best way to manage different GUI windows

16 Apr 2012, 11:45

Hi,

If you want to manage several GUI windows, you should have a Noesis::Gui::IRenderer for each one. And properly feed the renderer of the active window with input events.

But if your intention is to have a single OS window, with different GUI panels who transition between them, then it would be enough to have only one Noesis::Gui::IRenderer with a container as root (Decorator, Border, or any of the available Panels) and set container's content with the appropriate panel each time.

For example:
// Noesis::Core::Ptr<Noesis::Gui::Decorator> mLayoutRoot;
mLayoutRoot = NsGetSystem<Noesis::Resource::IResourceSystem>()->Load(
    "Apps/Test/LayoutRoot.xaml")->GetRoot();

// Noesis::Core::Ptr<Noesis::Gui::IRenderer> mUIRenderer;
mUIRenderer = Noesis::Gui::CreateRenderer(mLayoutRoot);

// Load initial interface
mLayoutRoot->SetChild(NsGetSystem<Noesis::Resource::IResourceSystem>()->Load(
    "Apps/Test/MainMenu.xaml")->GetRoot());

// ... after user clicks the settings option of the menu
mLayoutRoot->SetChild(NsGetSystem<Noesis::Resource::IResourceSystem>()->Load(
    "Apps/Test/SettingsMenu.xaml")
This is a simple transition (an instant change) between two panels, but you can design a more complex layout, and add animations between panels to make the transition cooler.

In terms of performance, it is obvious that loading a new panel could be a long task (depending on its complexity), but you can use threads to parallelize the load. Or if memory is not a problem, pre-load all panels on application startup.

I also wanted to point out that when you design a GUI panel using XAML, you can directly specify handlers for control events (commonly known as code-behind), instead of doing the binding manually in the code:
<Grid
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  x:Class="MainMenu">
    <Button Content="Settings" Click="OnSettingsClick"/>
</Grid>
Notice the x:Class attribute in the XAML root element. This attribute indicates the class that implements the code-behind of the panel, it would be a Grid derived class. And also notice how we can specify a handler on the button's Click event, the OnSettingsClick will be a function in the MainMenu class. This way binding is done automatically.


I hope to be helpful.
 
Knu
Topic Author
Posts: 4
Joined: 03 Mar 2012, 10:02

Re: best way to manage different GUI windows

16 Apr 2012, 15:21

thanks :)

Who is online

Users browsing this forum: No registered users and 4 guests