mygui delegates boost::bind support


03-04-2009 09:50:23

The last time I've checked MyGUI is about half a year ago, and I'm impressed with the progress this library did. I really like the new features like controllers, and the upcoming features like layout helpers!
But I'm a bit unsure if I like MyGUI's own delegate system, as I am using boost::bind internally for all my callbacks...
If you have experience with boost::bind, is it easy to make the two systems compatible (or are they already?) so I can just assign a boost::function to a MyGUI delegate?


08-04-2009 02:50:32

I can also see the usefulness of this feature. I have just spent a while wrapping the delegate system so I can use it in Python. I was initially planning to use boost::bind to bind a Python function to a callable C++ wrapper object, then pass the object to MyGUI as a delegate, but it didn't seem as though MyGUI supported this. Instead, I ended up storing the wrapper objects in a static std::map using WidgetPtr as a key, and passing MyGUI a method delegate, which isn't quite as neat, and also raises potential problems if I change a delegate from C++ which was initially set through the Python wrapper system. If I could use the object itself as a delegate, this problem would go away as MyGUI would control its lifetime directly.


12-04-2009 09:02:05

You could probably do something like: MyGUI::newDelegate(&myFunction, &boost::function<void (MyGUI::WidgetPtr)>::operator()), which basically calls operator() on a boost::function. I haven't tested this though.


12-04-2009 09:58:11

I got this far:-

void testBoostFunction(MyGUI::WidgetPtr)
LogManager::getSingleton().logMessage("This is a message!");


boost::function<void (MyGUI::WidgetPtr)> testFunc(testBoostFunction);
//I'm just binding operator() as a member function of boost::function.
runButton->eventMouseButtonClick = MyGUI::newDelegate(&testFunc, &boost::function<void (MyGUI::WidgetPtr)>::operator());


//This code gives this error:
In member function ‘virtual void NGFExampleApplication::createScene()’:
include/NGFExampleApplication.h|82| error: cannot convert ‘boost::function<void ()(MyGUI::Widget*)>*’ to ‘void (*)()’ for argument ‘1’ to ‘MyGUI::delegates::IDelegate0* MyGUI::delegates::newDelegate(void (*)())’