[Solved]Window Button Caption

mprestia

19-05-2010 16:54:16

I am altering the window widgets in my skin file. I am wondering if I am able to set a caption on a button defined inside the window skin. Here is my new window defined in my skin file:


<Resource type="ResourceSkin" name = "WindowCS" size = "190 196" texture = "#{MyGUI_Theme_Texture}" >
<Property key="ToStick" value = "true" />
<Child type="Widget" skin="TileClient" offset = "15 51 165 87" align = "Stretch" name = "Client"/>
<Child type="Button" skin="NoCaptionLeft" offset = "0 33 42 103" align = "Left VStretch" name = "Caption">
<Property key="Scale" value = "1 1 0 0"/>
</Child>
<Child type="Button" skin="NoCaptionRight" offset = "147 33 42 103" align = "Right VStretch" name = "Caption">
<Property key="Scale" value = "1 1 0 0"/>
</Child>
<Child type="Button" skin="WindowCaption" offset = "0 0 190 54" align = "HStretch Top" name = "Caption">
<Property key="Scale" value = "1 1 0 0"/>
</Child>
<Child type="Button" skin="WindowBottomCaption" offset = "0 136 189 62" align = "HStretch Bottom" name = "Bottom">
<Property key="Scale" value = "1 1 0 0"/>
</Child>
<Child type="Button" skin="Button" offset = "43 144 150 37" align = "Bottom Center" name = "Button">
<Property key="Event" value = "close"/>
</Child>
</Resource>


I took the button definition from the WindowCSX skin but changed the button skin from 'ButtonX' to 'Button.' I need the button the button caption to display "Close." Is there any way I can search the window for a button widget and set the caption that way?

Altren

19-05-2010 17:26:42

Well, we are tending to change skin definitions to layouts, but right now only small set of properties supported in Skin format.
There's two way of doing this:
1) make texture with "Close" word on it and make ButtonClose skin.
2) alter MyGUI code a bit:
void Widget::initialiseWidgetSkin(ResourceSkin* _info, const IntSize& _size)in this function
after next lines (line 254 or so in MyGUI_Widget.cpp) MapString::const_iterator iter = properties.end();
if ((iter = properties.find("NeedKey")) != properties.end()) setNeedKeyFocus(utility::parseBool(iter->second));
if ((iter = properties.find("NeedMouse")) != properties.end()) setNeedMouseFocus(utility::parseBool(iter->second));
if ((iter = properties.find("Pointer")) != properties.end()) mPointer = iter->second;
if ((iter = properties.find("Visible")) != properties.end()) { setVisible(utility::parseBool(iter->second)); }
add one line if ((iter = properties.find("Caption")) != properties.end()) { setCaption(iter->second); } and you will be able to use <Property key="Caption" value = "Close" />

mprestia

20-05-2010 14:58:40

So the first option worked, but the text on the button started to look terrible as button size increased. I tried the second option and the caption didn't show up, so I kind of combined the two.

I modified the MyGUI code like you said in MyGUI_Widget.cpp:


if ((iter = properties.find("NeedKey")) != properties.end()) setNeedKeyFocus(utility::parseBool(iter->second));
if ((iter = properties.find("NeedMouse")) != properties.end()) setNeedMouseFocus(utility::parseBool(iter->second));
if ((iter = properties.find("Pointer")) != properties.end()) mPointer = iter->second;
if ((iter = properties.find("Visible")) != properties.end()) { setVisible(utility::parseBool(iter->second)); }
if ((iter = properties.find("Caption")) != properties.end()) { setCaption(iter->second); }


then made a 'ButtonClose' skin:


<Resource type="ResourceSkin" name = "ButtonClose" size = "46 38" texture = "#{MyGUI_Theme_Texture}">
<Property key="FontName" value = "Default" />
<Property key="TextAlign" value = "HCenter VCenter" />
<Property key="Caption" value = "Close" />
<BasisSkin type="SubSkin" offset = "0 0 13 38" align = "Left VStretch">
<State name="disabled" offset = "612 378 13 38"/>
<State name="normal" offset = "612 241 13 38"/>
<State name="highlighted" offset = "612 286 13 38"/>
<State name="normal_checked" offset = "612 426 13 38"/>
<State name="pushed" offset = "612 332 13 38"/>
</BasisSkin>
<BasisSkin type="SubSkin" offset = "13 0 20 38" align = "HStretch VStretch">
<State name="disabled" offset = "645 378 20 38"/>
<State name="normal" offset = "645 241 20 38"/>
<State name="highlighted" offset = "645 286 20 38"/>
<State name="normal_checked" offset = "645 426 20 38"/>
<State name="pushed" offset = "645 332 20 38"/>
</BasisSkin>
<BasisSkin type="SubSkin" offset = "33 0 13 38" align = "Right VStretch">
<State name="disabled" offset = "701 378 13 38"/>
<State name="normal" offset = "701 241 13 38"/>
<State name="highlighted" offset = "701 286 13 38"/>
<State name="normal_checked" offset = "701 426 13 38"/>
<State name="pushed" offset = "701 332 13 38"/>
</BasisSkin>
<BasisSkin type="SimpleText" offset = "1 4 40 30" align = "Stretch">
<State name="disabled" colour="#{MyGUI_Theme_Button_ColourNormal}" shift = "false"/>
<State name="normal" colour="#{MyGUI_Theme_Button_ColourNormal}" shift = "false"/>
<State name="highlighted" colour="#{MyGUI_Theme_Button_ColourNormal}" shift = "false"/>
<State name="normal_checked" colour="#{MyGUI_Theme_Button_ColourPushed}" shift = "true"/>
<State name="pushed" colour="#{MyGUI_Theme_Button_ColourPushed}" shift = "true"/>
</BasisSkin>
</Resource>


and modified the window skin to use this new button:


<Resource type="ResourceSkin" name = "WindowCS" size = "190 196" texture = "#{MyGUI_Theme_Texture}" >
<Property key="ToStick" value = "true" />
<Child type="Widget" skin="TileClient" offset = "15 51 165 87" align = "Stretch" name = "Client"/>
<Child type="Button" skin="NoCaptionLeft" offset = "0 33 42 103" align = "Left VStretch" name = "SideLeft">
<Property key="Scale" value = "1 1 0 0"/>
</Child>
<Child type="Button" skin="NoCaptionRight" offset = "147 33 42 103" align = "Right VStretch" name = "SideRight">
<Property key="Scale" value = "1 1 0 0"/>
</Child>
<Child type="Button" skin="WindowCaption" offset = "0 0 190 54" align = "HStretch Top" name = "Caption">
<Property key="Scale" value = "1 1 0 0"/>
</Child>
<Child type="Button" skin="WindowBottomCaption" offset = "0 136 189 62" align = "HStretch Bottom" name = "Bottom">
<Property key="Scale" value = "1 1 0 0"/>
</Child>
<Child type="Button" skin="ButtonClose" offset = "43 144 150 37" align = "Bottom Center" name = "Button">
<Property key="Event" value = "close"/>
</Child>
</Resource>


This works perfectly. Thanks for the guidance Altren!