CEGUI and Window App

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

ttk1001
Just popping in
Just popping in
Posts: 7
Joined: Fri Mar 14, 2008 13:04

CEGUI and Window App

Postby ttk1001 » Mon Mar 17, 2008 06:45

Hello all,

I'm a truely newbie. I 've just played around with Ogre and CEGUI for around 3weeks and I can follow all tutorials from CEGUI and Ogre forum.
Now I'm trying to redender the 3D model in a MFC window and I want to use CEGUI for my GUI. But I have some problems as follow:

1. When I resize the main window, CEGUI interface disappears for a while (say around 3 seconds) and then appears again. But the resolutions of window mouse and CEGUI mouse are different.
So how can I tell CEGUI that the window was resized and it should update new size?

2. My current event handling is: the default WndProc() of Window app will receive all events (mouse, key and window events) and then inject to CEGUI. I can see the mouse cursor moves and Hover effect when the mouse is over a button. But I'm so confusing how can I subcribe events from CEGUI widgets (buttons, menu) ??? The event handling scheme used in Example framework doesn't work when I integrated to my application.

In short, could you experts help me to solve:
- Window resizing: how to match CEGUI resolution with actual window resolution?
- How to handle events triggered from CDGUI widgets in my application?

Any clues or sugguestions are highly appreciated.
Thank you so much and please forgive my poor english.

TTK

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

Re: CEGUI and Window App

Postby CrazyEddie » Mon Mar 17, 2008 09:50

ttk1001 wrote:- Window resizing: how to match CEGUI resolution with actual window resolution?

The Ogre renderer has a member named setDisplaySize that can be used to trigger the required notifications. Depending upon exactly what you are doing, and how you are doing it, this may or may not be enough to get the two mouse cursors to match up.

ttk1001 wrote:- How to handle events triggered from CDGUI widgets in my application?

The issue with events sounds like it could be that you're not injecting both mouse button down and mouse button up events - both are required for certain events to be successfully fired. If this is not it, please post some code (event injection from WndProc, and event subscription / handler code)

CE.

ttk1001
Just popping in
Just popping in
Posts: 7
Joined: Fri Mar 14, 2008 13:04

Postby ttk1001 » Tue Mar 18, 2008 09:21

Thanks so much for your reply.

The Renderer setDisplaySize worked just fine. But CEGUI widgets inside the window were rescale according to the new window size as well. And this is not my expected behavior, for instance, when I maximize the window, widgets look too large ... I googled about this and someone said that we can solve this problem by setting the AutoScaled property of ImageSet and Font to false. I could do this with the imageset, but failed with the Font (the setAutoScalingEnabled() method was not available. I also tried the Font::setProperty() but could not find the property name for autoscale)

Regarding the event issue, I tried 2 ways of handling:
- Injecting events from WndProc: MouseMove, MouseDown and MouseUp events are injected to CEGUI and I can see click effect on buttons. My problem is I can not subscribe events from widgets. We usually subscribe an event like this:

Code: Select all

pButton = (CEGUI::PushButton *)wmgr->getWindow("cmdQuit");
   pButton->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&MyListener::Quit_OnClick, this));


this poiter here is the pointer to a class that extends WindowEventListener, FrameListener and OIS::MouseListener.

But with my Window App's event handling function, I don't have "this" pointer. So the compiler throws
error C2197: 'void (__cdecl *)(void)' : too many arguments for call

- Applying EventListener as Example framework: I tried this again and it worked. But, again, another problem. :? The mouse cursor is automatically switch to CEGUI cursor and it is limitted insize the rendering window only. I can not move the mouse outside rendering window, so can not resize of minimize the window.

To solve my problem now, I need:
1- How to subscribe CEGUI to Winow App

or

2- How to NOT limit the mouse cursor to the render window so I can use default window cursor and Example event handling frame work.

I personally prefer solution 2. So any ideas or sugguestions about this are warmly welcome.

Thank you in advance,

TTK

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

Postby CrazyEddie » Tue Mar 18, 2008 11:03

Hi,

The property to set on the font is "AutoScaled".

For event subscriptions, you do not have to use a member function, you can use a free function also:

Code: Select all

bool freeFunctionHandler(const CEGUI::EventArgs& args)
{
    // handle event!
    return true;
}

...
// somewhere else in your code
...
pButton->subscribeEvent(CEGUI::PushButton::EventClicked, freeFunctionHandler);
...


It is not possible to have the CEGUI rendered cursor appear outside of the OpenGL viewport, since it is rendered like the rest of CEGUI's output ;)

I think maybe the best solution in this case is to not use the CEGUI cursor at all (so hide the CEGUI::MouseCursor), but just use the Operating System cursor, or any other cursor you may have (and maybe subscribing to "ImageChanged" event on CEGUI::MouseCursor for cues as to when to change the other cursor image). Obviously this means you will need to correctly map the position of the cursor from the OS so that injections into CEGUI are correct based upon the area of the display used for the CEGUI rendered output (so basically subtract the viewport pixel position from the mouse pixel position), and possibly perform some scaling on those values too.

CE.

ttk1001
Just popping in
Just popping in
Posts: 7
Joined: Fri Mar 14, 2008 13:04

Postby ttk1001 » Wed Mar 19, 2008 13:09

Thank so much, Mr Eddie.

The answers seem to be very simple and it worked.

But even when I set the AutoScaled for both font and imageset (tried both setting in code and in XML files), I only got the font size remains unchanged, widgets are still auto scale to new window size. Am i missing something?

I use VS2008 and Ogre 1.4.6 (binary precompiled). Do I need to install the dependancies?


TTK

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

Postby CrazyEddie » Wed Mar 19, 2008 18:45

I think I now know what you're talking about ;)

I believe that the windows / widgets you are creating are using the scale or relative values for their sizes and therefore are automatically scaled to a given percentage of the parent element (or screen), as opposed to absolute pixel values.

You did not say whether you were loading from an XML layout or defining the windows in code. Anyway, here is an attempt to explain the situation in either case, code first:

You might be doing something like this:

Code: Select all

...
myWnd->setSize( UVector2( UDim( 0.5f, 0), UDim( 0.2f, 0) ) );
...

This is relative type values - 50% width and 20% height. What you need is something like this instead:

Code: Select all

...
myWnd->setSize( UVector2( UDim( 0, 100), UDim( 0, 35) ) );
...

This is absolute values - 100 pixels width and 35 pixels in height.

Alternatively you might have something like this:

Code: Select all

...
myWnd->setSize( UVector2( cegui_reldim( 0.5f ), cegui_reldim( 0.2f ) ) );
...

Again as above this is relative, 50% width and 20% height. This can be changed to the above absolute code, or:

Code: Select all

...
myWnd->setSize( UVector2( cegui_absdim( 100 ), cegui_absdim( 35 ) ) );
...


If you're using a layout via xml, you will likely have something like:

Code: Select all

<Property Name="UnifiedSize" Value="{{0.50,0},{0.20,0}}" />

or perhaps

Code: Select all

<Property Name="UnifiedAreaRect" Value="{{0.2,0},{0.2,0},{0.7,0},{0.7,0}}" />

These both use relative values exclusively that change size with the parent (or screen), what you need is absolute values, such as:

Code: Select all

<Property Name="UnifiedSize" Value="{{0,100},{0,35}}" />

or,

Code: Select all

<Property Name="UnifiedAreaRect" Value="{{0,32},{0,32},{0,100},{0,35}}" />


For a full explanation of these 'unified co-ordinates' see this howto and also The unified co-ordinate system from the falagard manual.

HTH

CE

ttk1001
Just popping in
Just popping in
Posts: 7
Joined: Fri Mar 14, 2008 13:04

Postby ttk1001 » Thu Mar 20, 2008 07:25

Thank you for patently replying my newbie questions.

Actually, after posting my last post, I skimmed the Beginner Help category and found some other thread related to window sizing and I knew about the absolute value and UDim.

I'm now playing around with Popup menu, color selector and skin. I may disturb you alot next few days. ^^

TTK

zarroba
Not too shy to talk
Not too shy to talk
Posts: 22
Joined: Tue Jul 11, 2006 12:54

Postby zarroba » Thu Apr 03, 2008 09:43

Since you mention Popup menu I'm posting here a problem I'm having with Popup instead of creating a new thread.
When I'm creating a popup with several sub popups the width of the first popup is the sum of all the sub popups. This is how I create the popup struture: I have a Menubar with some MenuItems that have PopupMenus, create in the popups several items and one of them has another popup.
Here it is a popup with no sub popup:
Image
Here it is one with a sub popup:
Image

I've tried to set the size, but the size remains the same, in fact in the second image the popups and menuitems have 0 width and 0 height.

Can anyone help me?

Thanks
José Tavares

zarroba
Not too shy to talk
Not too shy to talk
Posts: 22
Joined: Tue Jul 11, 2006 12:54

Postby zarroba » Thu Apr 03, 2008 11:41

Ok, sorry for posting without searching deep into the problem. It seems this is not a bug but a feature. The Menu Item widget has two sizes defined in the looknfeel: with sub popups (HasPopupContentSize) and without sub popups (ContentSize). If you don't want this to happen just redefine the HasPopupContentSize NamedArea to the size you want.

José Tavares


Return to “Help”

Who is online

Users browsing this forum: No registered users and 9 guests