Page 1 of 1

Changing background colour of CEGUI::MenuItem

Posted: Tue Feb 12, 2008 13:09
by schnorr
Hello,

I tried to change the background colour of a CEGUI::MenuItem to indicate that this "option" is selected. I am using the WindowsLook looknfeel, so I checked the entry for MenuItem there. I added
<PropertyDefinition name="SelectedColour" initialValue="F0FF0000" redrawOnWrite="true" />
and also
<StateImagery name="EnabledSelected">
<Layer>
<Section section="label">
<ColourProperty name="SelectedColour" />
</Section>
</Layer>
</StateImagery>
<StateImagery name="DisabledSelected">
<Layer>
<Section section="label">
<ColourProperty name="DisabledSelectedColour" />
</Section>
</Layer>
</StateImagery>

Now, how do I change the colour during the runtime? I tried to use the methods of CEGUI::PropertySet, superclass of CEGUI::MenuItem but I actually do not know if I really created a new property, or if there is a property for the color. The alterations above I did based in the Falagard tutorial. What am I missing? :(

Posted: Tue Feb 12, 2008 18:53
by CrazyEddie
Forgive me if I misunderstood the nature of what you're trying to do, but don't the existing properties:
    HoverColour
    PushedColour
    PushedOffColour
    OpenedColour

Offer what you want?

I do seriously get the feeling I missed the point somewhere, though

CE

Posted: Tue Feb 12, 2008 20:07
by Rackle
WidgetGalore to the rescue. Within the code for the StaticText you'll find this line

Code: Select all

// The colors are aarrggbb in Hexadecimal
// Where aa is alpha, rr is red, gg is green, and bb is blue
// tl: top left,  tr: top right,  bl: bottom left,  br: bottom right
staticText->setProperty("TextColours", "tl:FFFF0000 tr:FFFF0000 bl:FFFF0000 br:FFFF0000");


You would use the same principle to modify the properties of the menu items, something like

Code: Select all

// 100% alpha, 100% red, 0% green, 0% blue
myNewMenuItem->setProperty("OpenedColour", "FFFF0000");

Is this what you were asking for?

Posted: Wed Feb 13, 2008 09:02
by schnorr
Hello,

It is the perfect solution if the MenuItem keeps its colour after
that, which I think so. To give a try, I changed the callback function that receives the clicks of the MenuItems involved to this:

Code: Select all

bool CEGUIManager::bundleMenuOption (const CEGUI::EventArgs &e)
{
        const CEGUI::WindowEventArgs& we = static_cast<const
CEGUI::WindowEventArgs&>(e);

        CEGUI::MenuItem *m = (CEGUI::MenuItem*) &we.window;
        m->setProperty("OpenedColour", "tl:FFFF0000 tr:FFFF0000 bl:FFFF0000 br:FFFF0000");
        return true;
}

I executed the app, but it gives me a SegFault. GDB tells me this:
(gdb) up
#7 0xb78d9987 in CEGUI::PropertySet::setProperty (this=0xbfb351b8,
name=@0xbfb35018, value=@0xbfb34f80) at CEGUIPropertySet.cpp:124
124 CEGUIPropertySet.cpp: No such file or directory.
in CEGUIPropertySet.cpp
Current language: auto; currently c++
(gdb) up
Segmentation fault (core dumped)

I changed the

Code: Select all

m->setProperty("OpenedColour", "tl:FFFF0000 tr:FFFF0000 bl:FFFF0000 br:FFFF0000");
to this

Code: Select all

m->setProperty("OpenedColour", "FFFF0000");
but it also gives me the same segfault.

So, my setProperty has anything wrong?

Posted: Wed Feb 13, 2008 09:58
by CrazyEddie
Line 124 of CEGUIPropertySet.cpp is an exception throw for when it can't find the property.

Does the property in question exist in your version of the skin? Does CEGUI.log mention anything about missing properties (right before it crashes)?

Posted: Wed Feb 13, 2008 12:00
by Rackle
Have a read through the Property Finder thread, which points to the source code for that tool. With it you'll be able to examine the properties available to you.