Awesome gui, But im stuck. Please help.

scratchyrice

21-02-2009 00:14:48

Hi, Basically how can i go about passing a newDelegate through my own method, And to setting the callback? Its kind of hard to explain.

For my engine, Im trying to create a small "layer" between the game using the engine, And the mygui libary. For each widget type, I have a setCallback method. How do i go about passing the result from a newDelegate, Through the setCallback method, And too the (for eg) buttonWidget->eventButtonClick = newDelegate.

I cant really make it much clearer

Cheers

Scratchy.

scratchyrice

21-02-2009 00:28:58

Ok i tried the following. Here is my callback function(Just a test function):

void setCallback(MyGUI::delegates::IDelegate0 * _callback)
{
_myGuiButton->eventMouseButtonClick = _callback;
}


And here is the call to it:

myRoot->gui->getWidget->button("Welcome/TestButton")->setCallback(MyGUI::newDelegate(&testfunction));


Now in theory, I see no reason why this should not work. The reason i think this is because, Well in the demo's MyGUI::NewDelegate is passed directly to the event storers like _myGuiButton->eventMouseButtonClick. Now MyGUI::NewDelegate returns a pointer of the type MyGUI::delegates::IDelegate0 *. So i have no idea why this method does not work. The way i see it, Is _callback, Should contain the exact same thing as a direct MyGUI::newDelegate(&testfunction), Am i not correct?

I get a very long error message:
1>h:\projects\vc\chaosengine\chaosengine\chaosengine\chaosGui.h(39) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 'MyGUI::delegates::IDelegate0 *' (or there is no acceptable conversion)
1> h:\mygui\trunk\myguiengine\include\MyGUI_DelegateImplement.h(156): could be 'MyGUI::delegates::CDelegate1<TP1> &MyGUI::delegates::CDelegate1<TP1>::operator =(MyGUI::delegates::IDelegate1<TP1> *)'
1> with
1> [
1> TP1=MyGUI::WidgetPtr
1> ]
1> h:\mygui\trunk\myguiengine\include\MyGUI_DelegateImplement.h(173): or 'MyGUI::delegates::CDelegate1<TP1> &MyGUI::delegates::CDelegate1<TP1>::operator =(const MyGUI::delegates::CDelegate1<TP1> &)'
1> with
1> [
1> TP1=MyGUI::WidgetPtr
1> ]
1> while trying to match the argument list '(MyGUI::EventHandle_WidgetVoid, MyGUI::delegates::IDelegate0 *)'


Please excuse my c++ noobness lol

Cheers

Scratchy

my.name

21-02-2009 11:09:43


//MyGUI_WidgetEvent.h

/** Event : Mouse button pressed and released.\n
signature : void method(MyGUI::WidgetPtr _sender)
@param _sender widget that called this event
*/
EventHandle_WidgetVoid eventMouseButtonClick;



//MyGUI_WidgetEvent.h

typedef delegates::CDelegate1<WidgetPtr> EventHandle_WidgetVoid;




void setCallback(MyGUI::EventHandle_WidgetVoid::IDelegate * _callback)
{
_myGuiButton->eventMouseButtonClick = _callback;
}
//or
void setCallback(MyGUI::delegates::CDelegate1<MyGUI::WidgetPtr>::IDelegate * _callback)
{
_myGuiButton->eventMouseButtonClick = _callback;
}



void testfunction(MyGUI::WdgetPtr _sender)
{
}

myRoot->gui->getWidget->button("Welcome/TestButton")->setCallback(MyGUI::newDelegate(&testfunction));

scratchyrice

21-02-2009 15:28:29

Thanks a lot man, Works like a dream. Im in the process of learning how to use c++ templates fully, Then im on to callbacks. I just do not currently have a clue how this callback stuff works. I looked at your code, and i was so confused lol.

Cheers

Scratchy

scratchyrice

21-02-2009 16:46:17

Ah, I have one problem Which i have a solution to already, But its not exactly ideal. Basicly, The setCallback function ive created, Will have a second parameter, With the event type (an enum id). So is there a way of passing a generic newdelegate through? My current solution is to have an override for each type of delegate, And only switch-case the corresponding id's, But its not exactly "tidy". Is this the only way tho?

Cheers

Scratchy