How to create a simple colored rectangle?


04-01-2009 07:09:49

I've been workign with MyGUI and the Editable Terrain Library over the past few weeks to build a basic terrain editor. One of the functiosn I added allows the user to select a color for painting the terrain surface.
I had no problem figuring out how to use scroll bars and capture the events when they're modified. The problem aros when I wanted to display a simple (I thought) rectangle showing the currently selected color.

Note that I am *not* using XML files to define my widgets. I'm building everything in my program in C++ code.

Looking through the header files it appeared that ColourRect would do the job. Unfortunately it appears to be a skin and not a "real" widget and I couldn't figure out how to dynamically create one (there's no ColourRectPtr class).

Looking through the code it seemed that ColourRect uses a CroppedRectanglePtr so I tried the following:

MyGUI::CroppedRectanglePtr clr_Color;

But get a compile error of: error: ‘_getType’ is not a member of ‘MyGUI::ColourRect’

I then tried making use of the RenderBox class. This did exactly what I needed as far as displaying the color patch and having it change color when the scroll bars were moved. However, I ran into a problem with my program constatnly crashing with the error:

owed: OgreRenderQueueSortingGrouping.cpp:376: void Ogre::QueuedRenderableCollection::addRenderable(Ogre::Pass*, Ogre::Renderable*): Assertion `retPair.second && "Error inserting new pass entry into PassGroupRenderableMap"' failed.

Digging around, the only reference I could find to this error was:
which led me to the following bug:

Looking throught eh code for RenderBox it does indeed create it's own scene manager. Once I took the RenderBox object out of my code the crashes went away.

I then looked into creating StaticText objects or buttons. Unfortunately I couldn't discover any way to change their color dynamically.

So, the question is:

Is there a way to create a simple square widget in MyGUI and change the color dynamically that's not based on RenderBox (something that does not require the creation of it's own scene manager).

Again, all of my widgets are being created directly in C++ code.


04-01-2009 10:32:11

MyGUI::WidgetPtr widget = mGUI->createWidget<MyGUI::Widget>("RawRect", MyGUI::IntCoord(20, 20, 20, 20), MyGUI::Align::Default, "Main");
MyGUI::RawRect* colour_rect = widget->getSubWidgetMain()->castType<MyGUI::RawRect>();

colour_rect->setRectColour(MyGUI::Colour::Green, MyGUI::Colour::Green, MyGUI::Colour::Green, MyGUI::Colour::Green);


04-01-2009 16:36:37

Thanks for the help but ... I'm using MyGUI version 2.2.0_RC1 and there's no RawRect class defined anywhere in the header files.

Is your example based on an older version or an svn development version?

04-01-2009 16:42:44


please wait ...