Page 1 of 1

[Solved] How set PropertyCallback?

Posted: Mon Apr 04, 2011 13:58
by djphilipe
Hi,
I want call loadWindowLayout(const String& filename, const String& name_prefix = "", const String& resourceGroup = "", PropertyCallback* callback = 0, void* userdata = 0) with set custom PropertyCallback method.
But I'm confused about function pointers etc...
Can somebody give me an example how can I set custom method?

Thanks

Re: How set PropertyCallback?

Posted: Mon Apr 04, 2011 14:51
by Kulik
This is a small example of how to make it work:

Code: Select all

bool PropertyCallback(Window* window, String& propname, String& propvalue, void* userdata)
{
  // some value transformation
  propValue = propValue + "_something";

  return true; // we want the property to be set in the end
}

void main()
{
  WindowManager::getSingleton().loadWindowLayout("File.layout", "", "", &PropertyCallback);
}


If you need to translate values if the property name is text you do:

Code: Select all

bool PropertyCallback(Window* window, String& propname, String& propvalue, void* userdata)
{
  if (propName == "Text")
  {
    propValue = translateToSK(propValue);
  }

  return true;
}

void main()
{
  WindowManager::getSingleton().loadWindowLayout("File.layout", "", "", &PropertyCallback);
}


To make it tidier, put the PropertyCallback function into a class and make it static.

PS: I have not tried compiling this code, it's off the top of my head. HTH!

Re: How set PropertyCallback?

Posted: Fri Apr 08, 2011 07:13
by djphilipe
I had tried this way even before you wrote me this answer. But I had method PropertyCallback in class (GUIMgr) and it wasn't static method and a compiler fell. I have added keyword "static" before this method and now it's work :)

Thanks for help ;)

PS: I'm looking forward to World Hockey Championship 2011 - Final = Slovakia - Czech republic :P