QuickGUI::Image and storage

KickingBear

07-01-2011 18:33:05

Hi all.

Have some problems with a lot of objects of QuickGUI::Image.
I used that class to construct my gui ("control panel", cool) and i want to store them in vector<QuickGUI::Image*> m_pGuiImages;
Ok, but each object must have few callback functions for events ( QuickGUI::Image::addWidgetEventHandler(...)) , for example there are:
QuickGUI::WIDGET_EVENT_MOUSE_ENTER
QuickGUI::WIDGET_EVENT_MOUSE_LEAVE
QuickGUI::WIDGET_EVENT_MOUSE_CLICK
and other.

So, i really don't want to create a lot of functions with names like this:
void Shortcut1_MouseEnter();
void Shortcut1_MouseLeave();
void Shortcut2_MouseEnter();
void Shortcut2_MouseLeave();

And then i try using template:

template<QuickGUI::Image*>
static void ShortcutMouseEnter();

img->addWidgetEventHandler(QuickGUI::WIDGET_EVENT_MOUSE_ENTER, &EditorMenu::ShortcutMouseEnter<img>, this);
But the are error: error C2660: 'QuickGUI::Widget::addWidgetEventHandler' : function does not take 3 arguments

So, can you tell me, how can i fix that problem? Maybe exist another way to create gui?

P.S.
sorry for my english
Dmitry

BronzeBeard

09-01-2011 07:46:53

I think you want to make 2 functions, enter and leave,

then you want to dynamically cast your eventarg to a widgiteventarg, at that point you can get the pointer to the calling widget and then get the name, a simple conditional will work at that point.


http://www.ogre3d.org/tikiwiki/QuickGUI ... _EventArgs


I hope i read your question right... I've got a programmer headache :D

KickingBear

09-01-2011 09:38:05

2 BronzeBeard
thx for answer!)

Not only mouse enter/leave, and mouseUP/mouseDOWN to.
Total required four functions for each widget (enter/leave/up/down). A widget will be about ten, more can be less. And it turns out that the required forty (!!!) functions for simple gui
So, this is no my way)

I want smth like this:
template<QuickGUI::Image* img>
void MyClass::ShortcutMouseEnter()
{
img->setImage(GetNeedFileName(img));
}

But apparently I was not well understand the templates, and so have an error

KickingBear

10-01-2011 08:12:26

How would you have done such an interface with QuickGUI:

Black dots indicate items that need to be interactive for the events: mouse enter/leave/mouseUP/mouseDOWN
I chose to implement my interface class QuickGUI:: Image, maybe I'm wrong?
Please help advice

KickingBear

10-01-2011 15:14:10

there anybody in there?)

BronzeBeard

11-01-2011 02:34:34

Sorry, I don't check these forums as often as I should...

I would put an image there, you will only need 4 functions, 1 for each widget event...

Something like this in code....


void Foo::guiWidgetSet()
{
...

QuickGUI::Image* image1 = dynamic_cast<QuickGUI::Image*>(gameSheet->findWidget("NameofImage1"));
image1->addWidgetEventHandler(QuickGUI::WIDGET_EVENT_MOUSE_ENTER, &Foo::mouseEnteredFunction,this);
image1->addWidgetEventHandler(QuickGUI::WIDGET_EVENT_MOUSE_LEAVE, &Foo::mouseLeftFunction,this);

QuickGUI::Image* image2 = dynamic_cast<QuickGUI::Image*>(gameSheet->findWidget("NameofImage2"));
image2->addWidgetEventHandler(QuickGUI::WIDGET_EVENT_MOUSE_ENTER, &Foo::mouseEnteredFunction,this);
image2->addWidgetEventHandler(QuickGUI::WIDGET_EVENT_MOUSE_LEAVE, &Foo::mouseLeftFunction,this);

...
}


void Foo::mouseEnteredFunction(const QuickGUI::EventArgs& args)
{
const QuickGUI::WidgetEventArgs& wevent = dynamic_cast<const QuickGUI::WidgetEventArgs&>(args);
if(wevent.widget->getName().compare("NameofImage1") == 0)
{

//Do Image1 crap

}
else if(wevent.widget->getName().compare("NameofImage2") == 0)
{

//Do Image2 crap

}
}

KickingBear

11-01-2011 18:22:35

Yes, that's exactly what I needed!
Looking through the EventArgs class and derived from it but missed it
Widget * widget
Thanks that took the time and helped me