Issues with WidgetEventCallback

calsmurf2904

27-10-2008 15:21:36

Hello,
I am using QuickGUI for the first time with my Map Editor because remembering all those hotkeys is hard so I thought I needed to create a GUI.
So I took a look at the PlayPen example included.
This is my GUI code :

QuickGUI::Window* mGuiWindow;
#include "WidgetHandlers.h"
void createGUI()
{
WidgetHandler* mWidgetHandler = new WidgetHandler();
mGui = new QuickGUI::Root();
QuickGUI::SkinTypeManager::getSingletonPtr()->loadTypes();
QuickGUI::GUIManagerDesc d;
mGuiMgr = QuickGUI::Root::getSingletonPtr()->createGUIManager(d);
mGuiMgr->setSceneManager(mSceneMgr);
mGuiMgr->setViewport(mView);

//Window
QuickGUI::WindowDesc WindowDesc;
WindowDesc.name = "EditWindow";
WindowDesc.dimensions.position = QuickGUI::Point(1,1);
WindowDesc.dimensions.size = QuickGUI::Size(200,300);
WindowDesc.minSize = QuickGUI::Size(50,50);
WindowDesc.maxSize = QuickGUI::Size(300,300);
WindowDesc.dragable = true;
WindowDesc.resizable = true;
WindowDesc.titleBar = true;
WindowDesc.transparencyPicking = true;
WindowDesc.scrollable = true;
WindowDesc.visible = false;
mGuiWindow = mGuiMgr->getActiveSheet()->createWindow(WindowDesc);

//Toolbar
QuickGUI::ToolBarDesc tbd;
tbd.horizontalAnchor = QuickGUI::ANCHOR_HORIZONTAL_LEFT_RIGHT;
//tbd.itemLayout = QuickGUI::TOOLBAR_ITEM_LAYOUT_POSITIVE_TO_NEGATIVE;
tbd.name = "MainToolbar";
tbd.dimensions = QuickGUI::Rect(0,0,800,30);
//tbd.dimensions = QuickGUI::Rect(0,0,20,600);
QuickGUI::ToolBar* tb = mGuiMgr->getActiveSheet()->createToolBar(tbd);
QuickGUI::MenuDesc md;

//FileMenu
md.name = "File";
md.textDesc.segments.push_back(QuickGUI::TextSegment("micross.14",Ogre::ColourValue::Black,"File"));
QuickGUI::Menu* mFileMenu = tb->createMenu(md);
md.name = "EditWindowMenuItem";
md.textDesc.segments.clear();
md.textDesc.segments.push_back(QuickGUI::TextSegment("micross.14",Ogre::ColourValue::Black,"EditWindow"));
mFileMenu->createSubMenu(md)->addWidgetEventHandler(QuickGUI::WIDGET_EVENT_MOUSE_CLICK,&WidgetHandler::EditWindowHandler,mWidgetHandler);
md.name = "Open";
md.textDesc.segments.clear();
md.textDesc.segments.push_back(QuickGUI::TextSegment("micross.14",Ogre::ColourValue::Black,"Open"));
mFileMenu->createSubMenu(md);
md.name = "Save";
md.textDesc.segments.clear();
md.textDesc.segments.push_back(QuickGUI::TextSegment("micross.14",Ogre::ColourValue::Black,"Save"));
mFileMenu->createSubMenu(md);
md.name = "Exit";
md.textDesc.segments.clear();
md.textDesc.segments.push_back(QuickGUI::TextSegment("micross.14",Ogre::ColourValue::Black,"Exit"));
mFileMenu->createSubMenu(md)->addWidgetEventHandler(QuickGUI::WIDGET_EVENT_MOUSE_CLICK,&WidgetHandler::ExitButtonHandler,mWidgetHandler);

//ModeMenu
md.name = "Mode";
md.textDesc.segments.clear();
md.textDesc.segments.push_back(QuickGUI::TextSegment("micross.14",Ogre::ColourValue::Black,"Mode"));
QuickGUI::Menu* mModeMenu = tb->createMenu(md);
md.name = "Deform";
md.textDesc.segments.clear();
md.textDesc.segments.push_back(QuickGUI::TextSegment("micross.14",Ogre::ColourValue::Black,"Deform"));
mModeMenu->createSubMenu(md)->addWidgetEventHandler(QuickGUI::WIDGET_EVENT_MOUSE_CLICK,&WidgetHandler::DeformButtonHandler,mWidgetHandler);
md.name = "Paint";
md.textDesc.segments.clear();
md.textDesc.segments.push_back(QuickGUI::TextSegment("micross.14",Ogre::ColourValue::Black,"Paint"));
mModeMenu->createSubMenu(md)->addWidgetEventHandler(QuickGUI::WIDGET_EVENT_MOUSE_CLICK,&WidgetHandler::PaintButtonHandler,mWidgetHandler);
}


and

WidgetHandlers.h

class WidgetHandler
{
public:
void EditWindowHandler(const QuickGUI::EventArgs& args)
{
mGuiWindow->setVisible(true);
}
void DeformButtonHandler(const QuickGUI::EventArgs& args)
{
mMode = MODE_DEFORM;
}
void PaintButtonHandler(const QuickGUI::EventArgs& args)
{
mMode = MODE_PAINT;
}
void ExitButtonHandler(const QuickGUI::EventArgs& args)
{
mQuit = true;
}
};

The handler for the EditWindow button is getting executed when clicked.
However the rest isn't.
Did I do something wrong here ?

Thanks in advance,
Calsmurf2904

Also...How do I make the mGuiWindow transparent ?

kungfoomasta

27-10-2008 18:25:26

I noticed all of your menu options are sub menus. Sub Menus are containers for MenuItems, so clicking on them will only show/hide these Items. Instead of creating subMenus, try creating MenuLabels.

Menu::createMenuLabel

Also...How do I make the mGuiWindow transparent ?

You can either change the default skin, or create a new skin and specify it in code.

Here is the default skin for the window:


SkinType default
{
ComponentType hscrollbar
{
ClassName HScrollBar
SkinType default
}

ComponentType vscrollbar
{
ClassName VScrollBar
SkinType default
}

ComponentType titlebar
{
ClassName TitleBar
SkinType default
}

SkinElement background
{
Border_Bottom 10
Border_Left 10
Border_Right 10
Border_Top 10
Texture qgui.window.png
TileBackground true
TileBorders true
}

}


ComponentType definitions link to other Widget skins, while SkinElement definitions describe how the UI is drawn. If you remove all of the properties, the SkinElement becomes transparent:


SkinElement background
{
}


If you want a truly transparent window you'll need to create a transparent titleBar (or create a window without titlebar) and transparent scrollbars (unless you never have scrolling inside the window).

The QuickGUI wiki has an article on skinning for some additional information. Let me know if that helps. :)

calsmurf2904

27-10-2008 19:27:39

Ok...found out that it actually does execute it but only when I click precisly in the middle of the menulabel.
What can I do about this ?

kungfoomasta

27-10-2008 20:08:25

Oh, I didn't notice you were subscribing to the CLICK event. You'll probably want to subscribe to the MOUSE_BUTTON_UP event, since the CLICK event will be generated after the MOUSE_BUTTON_UP event, which is when the menu's will have been hidden.

calsmurf2904

27-10-2008 20:51:10

thanks ! it works :D
Next...some other stuff :
I keep getting :

No Definitions for type "ComponentType" found !

I do however have the

QuickGUI::registerScriptReader();

before the

Ogre::ResourceGroupManager::getSingletonPtr()->initialiseAllResourceGroups();

kungfoomasta

27-10-2008 22:03:58

The problem is not related to registering the script reader, its that one of your SkinType definitions is not valid. It doesn't seem like my error message is very helpful. You can step through and debug this, or you can reverse any recent changes you make to your SkinType definition to figure out what the problem is. Keep in mind Skin definitions *must* have the same number of SkinElements and ComponentTypes as defined by each widget. You can't simply remove any of these.

calsmurf2904

28-10-2008 14:43:42

just using the default stuff from your PlayPen example.
No changes has been made.

kungfoomasta

28-10-2008 20:00:55

Are you using SVN or the last release? The demo works by default, but there is a chance I could have packaged the release wrong, if there is a .skinType file missing, for example. The fastest way to figure out that issue is to step through the code and see where the issue is raised.

calsmurf2904

28-10-2008 20:50:00

svn.
demo is working correctly...no errors...its only my app.
But I can't find the error in my app.
Here is the complete GUI Code :

bool loadResources()
{
QuickGUI::registerScriptReader();
// Load resource paths from config file
Ogre::ConfigFile cf;
cf.load(mResourcePath + "resources.cfg");

// Go through all sections & settings in the file
ConfigFile::SectionIterator seci = cf.getSectionIterator();

String secName, typeName, archName;
while (seci.hasMoreElements())
{
secName = seci.peekNextKey();
ConfigFile::SettingsMultiMap *settings = seci.getNext();
ConfigFile::SettingsMultiMap::iterator i;
for (i = settings->begin(); i != settings->end(); ++i)
{
typeName = i->first;
archName = i->second;
ResourceGroupManager::getSingleton().addResourceLocation(
archName, typeName, secName);
}
}
Ogre::ResourceGroupManager::getSingletonPtr()->initialiseAllResourceGroups();
return true;
}

and

QuickGUI::Window* mGuiWindow;
#include "WidgetHandlers.h"
void createGUI()
{
WidgetHandler* mWidgetHandler = new WidgetHandler();
mGui = new QuickGUI::Root();
QuickGUI::SkinTypeManager::getSingletonPtr()->loadTypes();
QuickGUI::GUIManagerDesc d;
mGuiMgr = QuickGUI::Root::getSingletonPtr()->createGUIManager(d);
mGuiMgr->setSceneManager(mSceneMgr);
mGuiMgr->setViewport(mView);

//Window
QuickGUI::WindowDesc WindowDesc;
WindowDesc.name = "EditWindow";
WindowDesc.dimensions.position = QuickGUI::Point(1,1);
WindowDesc.dimensions.size = QuickGUI::Size(200,300);
WindowDesc.minSize = QuickGUI::Size(50,50);
WindowDesc.maxSize = QuickGUI::Size(300,300);
WindowDesc.dragable = true;
WindowDesc.resizable = true;
WindowDesc.titleBar = true;
WindowDesc.transparencyPicking = true;
WindowDesc.scrollable = true;
WindowDesc.visible = false;
mGuiWindow = mGuiMgr->getActiveSheet()->createWindow(WindowDesc);

//Toolbar
QuickGUI::ToolBarDesc tbd;
tbd.horizontalAnchor = QuickGUI::ANCHOR_HORIZONTAL_LEFT_RIGHT;
tbd.name = "MainToolbar";
tbd.dimensions = QuickGUI::Rect(0,0,800,30);
QuickGUI::ToolBar* tb = mGuiMgr->getActiveSheet()->createToolBar(tbd);
QuickGUI::MenuDesc md;
QuickGUI::MenuLabelDesc mdl;

//FileMenu
md.name = "File";
md.textDesc.segments.push_back(QuickGUI::TextSegment("micross.14",Ogre::ColourValue::Black,"File"));
QuickGUI::Menu* mFileMenu = tb->createMenu(md);
mdl.name = "EditWindowMenuItem";
mdl.textDesc.segments.clear();
mdl.textDesc.segments.push_back(QuickGUI::TextSegment("micross.14",Ogre::ColourValue::Black,"EditWindow"));
mFileMenu->createMenuLabel(mdl)->addWidgetEventHandler(QuickGUI::WIDGET_EVENT_MOUSE_BUTTON_UP,&WidgetHandler::EditWindowHandler,mWidgetHandler);
mdl.name = "Open";
mdl.textDesc.segments.clear();
mdl.textDesc.segments.push_back(QuickGUI::TextSegment("micross.14",Ogre::ColourValue::Black,"Open"));
mFileMenu->createMenuLabel(mdl)->addWidgetEventHandler(QuickGUI::WIDGET_EVENT_MOUSE_BUTTON_UP,&WidgetHandler::OpenButtonHandler,mWidgetHandler);
mdl.name = "Save";
mdl.textDesc.segments.clear();
mdl.textDesc.segments.push_back(QuickGUI::TextSegment("micross.14",Ogre::ColourValue::Black,"Save"));
mFileMenu->createMenuLabel(mdl)->addWidgetEventHandler(QuickGUI::WIDGET_EVENT_MOUSE_BUTTON_UP,&WidgetHandler::SaveButtonHandler,mWidgetHandler);
mdl.name = "Exit";
mdl.textDesc.segments.clear();
mdl.textDesc.segments.push_back(QuickGUI::TextSegment("micross.14",Ogre::ColourValue::Black,"Exit"));
mFileMenu->createMenuLabel(mdl)->addWidgetEventHandler(QuickGUI::WIDGET_EVENT_MOUSE_BUTTON_UP,&WidgetHandler::ExitButtonHandler,mWidgetHandler);

//ModeMenu
md.name = "Mode";
md.textDesc.segments.clear();
md.textDesc.segments.push_back(QuickGUI::TextSegment("micross.14",Ogre::ColourValue::Black,"Mode"));
QuickGUI::Menu* mModeMenu = tb->createMenu(md);
mdl.name = "Deform";
mdl.textDesc.segments.clear();
mdl.textDesc.segments.push_back(QuickGUI::TextSegment("micross.14",Ogre::ColourValue::Black,"Deform"));
mModeMenu->createMenuLabel(mdl)->addWidgetEventHandler(QuickGUI::WIDGET_EVENT_MOUSE_BUTTON_UP,&WidgetHandler::DeformButtonHandler,mWidgetHandler);
mdl.name = "Paint";
mdl.textDesc.segments.clear();
mdl.textDesc.segments.push_back(QuickGUI::TextSegment("micross.14",Ogre::ColourValue::Black,"Paint"));
mModeMenu->createMenuLabel(mdl)->addWidgetEventHandler(QuickGUI::WIDGET_EVENT_MOUSE_BUTTON_UP,&WidgetHandler::PaintButtonHandler,mWidgetHandler);
}

kungfoomasta

28-10-2008 21:43:28

Is it possible you can provide a call stack? I think the issue is not necessarily with any code you wrote, but possible with an incorrectly written SkinType definition, or missing .SkinType file. Also, what OS/IDE are you using?

calsmurf2904

29-10-2008 10:45:26

uhmm....not on the same pc now so I will give you the callstack later.
I am on Windows XP x64 Service Pack 2 with MSVC++ 2008 Express.
I am using Ogre 1.6RC1

calsmurf2904

01-11-2008 23:40:52

mmm...weird thing.....finally had some time for getting the call stack and the call stack column is empty :S
mmm....I have it linking correctly.I don't see the demo doing anything else then what I have done so I don't know what is causing the error.

kungfoomasta

02-11-2008 18:37:28

Can you put a breakpoint in the first line in function void createGUI()? Just click on the first line:

WidgetHandler* mWidgetHandler = new WidgetHandler();

And press F9. (Or you can find option to set breakpoint in the Debug Menu) Then run your application with debugger on, which is F5 for me. If the crash occurs before the breakpoint is hit, there is a problem loading QuickGUI. Otherwise, you can step through the code by pressing F10, and see which line causes the exception to be thrown.

calsmurf2904

02-11-2008 19:35:17

the error happens in the code

QuickGUI::SkinTypeManager::getSingletonPtr()->loadTypes();

kungfoomasta

02-11-2008 19:42:47

So there is definately something incorrect with one of your .SkinSet files. If you press F11 you can step into the "loadTypes" function and continue to debug. What is the last .SkinSet file you modified, you can post it and we should see the problem.

calsmurf2904

02-11-2008 20:06:05

I only use the default non-modified example skintypes from the playpen demo.And in the playpen demo there isn't any error.

kungfoomasta

02-11-2008 21:08:34

You'll have to step into loadTypes function and see whats going on.

Michavk

28-05-2010 04:56:15

(I know this is an old thread. But still ..)

Hello,
(..)
This is my GUI code :

(..)
mFileMenu->createSubMenu(md)->addWidgetEventHandler(QuickGUI::WIDGET_EVENT_MOUSE_CLICK,
&WidgetHandler::EditWindowHandler,mWidgetHandler);
(..)

(..)



Oh, I didn't notice you were subscribing to the CLICK event. You'll probably want to subscribe to the MOUSE_BUTTON_UP event, since the CLICK event will be generated after the MOUSE_BUTTON_UP event, which is when the menu's will have been hidden.


Pherhaps you should also update Beginner Tutorial 4. It clearly states to use WIDGET_EVENT_MOUSE_CLICK as event. Took me quite a while to figure this one out. And this post wasn't easy to find .. :roll:

Thanks :)

kungfoomasta

28-05-2010 18:51:47

oops! Sorry about that, I have updated the wiki. Thanks for bringing this up. :)