Finding out what type a window has?

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

matches81
Just popping in
Just popping in
Posts: 11
Joined: Sun Dec 21, 2008 22:03

Finding out what type a window has?

Postby matches81 » Sun Dec 21, 2008 22:11

Hello!
First post here. I've tried searching for an answer, but didn't fine one.
I've been using CEGUI for a bit now with Ogre3D. So far, it works pretty well.

Now I wanted to add a simple thing: Scrolling the mouse wheel should move the scroll bar of comboboxes' drop down lists, if the mouse is hovering over them. I can get the window the mouse is hovering over by calling CEGUI::System::getWindowContainingMouse(), which works fine.
However, I seem unable to check whether the Window* I get actually is a Combobox*, ComboDropList* or an Editbox*.
Using dynamic_cast doesn't work and ends with an exception.
Calling getType() on the Window* I receive works, however I don't know what to compare that String against.

So... yeah... would be nice if someone could point me in the right direction.

songge3604
Quite a regular
Quite a regular
Posts: 60
Joined: Tue Oct 28, 2008 10:46

Postby songge3604 » Mon Dec 22, 2008 06:09

On my opinion, you can use setUserString("type", "atypename")

and use getUserString("type") to know what type it is.

User avatar
scriptkid
Home away from home
Home away from home
Posts: 1178
Joined: Wed Jan 12, 2005 12:06
Location: The Hague, The Netherlands
Contact:

Postby scriptkid » Mon Dec 22, 2008 08:18

^^ It can even be done easier :)

you can use Window::testClassName which accepts a class name from the cegui namespace.

For example to test for combobox, use:

Code: Select all

if (win->testClassName("Combobox"))
{
}


These classnames are case sensitive!

HTH.
Check out my released snake game using Cegui!

songge3604
Quite a regular
Quite a regular
Posts: 60
Joined: Tue Oct 28, 2008 10:46

Postby songge3604 » Mon Dec 22, 2008 11:15

You slove my problem also, hoho~


Thank you!

dmail
Quite a regular
Quite a regular
Posts: 46
Joined: Mon Nov 27, 2006 16:49

Postby dmail » Mon Dec 22, 2008 11:56

Using dynamic_cast doesn't work and ends with an exception.

Out of curiosity what exception is thrown? The window class has a vtable and a dynamic cast should work fine, in fact a dynamic cast does not throw so something funny maybe going on here.

matches81
Just popping in
Just popping in
Posts: 11
Joined: Sun Dec 21, 2008 22:03

Postby matches81 » Tue Dec 23, 2008 16:22

The exception thrown said something about the type not being an _rtti type. I'll just check it again before I give scriptkid's solution a try.

edit:
Okay, just tried the dynamic_cast again, here's the exception:
Unhandled exception at 0x7c812aeb in TankGameW32.exe: Microsoft C++ exception: std::__non_rtti_object at memory location 0x0012f1b4..

This occurs at "CEGUI::Combobox* cbb = dynamic_cast<CEGUI::Combobox*>(wnd);"

dmail
Quite a regular
Quite a regular
Posts: 46
Joined: Mon Nov 27, 2006 16:49

Postby dmail » Tue Dec 23, 2008 17:42

matches81 wrote:The exception thrown said something about the type not being an _rtti type. I'll just check it again before I give scriptkid's solution a try.

edit:
Okay, just tried the dynamic_cast again, here's the exception:
Unhandled exception at 0x7c812aeb in TankGameW32.exe: Microsoft C++ exception: std::__non_rtti_object at memory location 0x0012f1b4..

This occurs at "CEGUI::Combobox* cbb = dynamic_cast<CEGUI::Combobox*>(wnd);"

Thanks for the info, could you answer a few more questions please.
Which version of Visual Studio?
Which service pack?
Do you have RTTI enabled?
Did you also get a linker warning

I will assume visual studio 2005 and no service pack until you can confirm otherwise, this is a bug which was fixed with sp1.
Last edited by dmail on Tue Dec 23, 2008 17:48, edited 1 time in total.

matches81
Just popping in
Just popping in
Posts: 11
Joined: Sun Dec 21, 2008 22:03

Postby matches81 » Tue Dec 23, 2008 17:46

dmail wrote:Thanks for the info, could you answer a few more questions please.
Which version of Visual Studio?
Which service pack?
Do you have RTTI enabled?

Sure. VS2005 with SP1 (Version 8.0.50727.762 (SP.050727-7600)), Windows XP SP3.
how do I enable RTTI?


Btw: Scriptkid's solution worked flawlessly, thanks for the help.

dmail
Quite a regular
Quite a regular
Posts: 46
Joined: Mon Nov 27, 2006 16:49

Postby dmail » Tue Dec 23, 2008 17:50

Project Properites -> c/c++ -> Language -> Enable RTTI

The problem was that pre sp1 RTTI was enabled whether you asked for it or not, in SP1 it does the correct thing. So if it is not enabled you will get an error.

matches81
Just popping in
Just popping in
Posts: 11
Joined: Sun Dec 21, 2008 22:03

Postby matches81 » Wed Dec 24, 2008 09:12

dmail wrote:Project Properites -> c/c++ -> Language -> Enable RTTI

The problem was that pre sp1 RTTI was enabled whether you asked for it or not, in SP1 it does the correct thing. So if it is not enabled you will get an error.

Well, it seems RTTI is already enabled for the project.
Also, the project currently compiles and links fine without any warnings.


Return to “Help”

Who is online

Users browsing this forum: No registered users and 15 guests