I think the most easy way to do it (if you load a layout from a xml blabla.layout file) is the following:
Create a picture with the four button states (normal, over, pressed, disabled). The picture's size should be in powers of two. create an imageset file for that picture and put both the picture and the imageset file into the "imagesets" directory. The imageset file can look somawhat like this:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<Imageset Name="FTSUI" Imagefile="ftsui.png" >
<Image Name="btnNormal" XPos="0" YPos="0" Width="256" Height="50" />
<Image Name="btnHover" XPos="0" YPos="50" Width="256" Height="50" />
<Image Name="btnPushed" XPos="0" YPos="100" Width="256" Height="50" />
<Image Name="btnDisabl" XPos="0" YPos="150" Width="256" Height="50" />
</Imageset>
That defines four named images: btnNormal, btnHover, btnPushed and btnDisabl that are located in the imageset FTSUI
Now, in your program's initialisation code, load that imageset:
Code: Select all
// Load the FTSUI Imageset.
CEGUI::ImagesetManager::getSingleton().createImageset( "ftsui.imageset" );
This loads the imageset into CEGUI. If later on, for some reason, you need to acces that imageset, you can get it by calling the following function:
Code: Select all
CEGUI::Imageset *m_pImageSet = CEGUI::ImagesetManager::getSingleton().getImageset( "FTSUI" );
Now let's go on creating the buttons. we'll do this in the layout file of your window or UI. We first create an imagebutton using the images we put in the imageset, and then we'll create a child into it of the type StaticText, so we can put some caption into the button. There we go (I assume you know how to work with layouts. If not, just ask
):
Code: Select all
<!-- Create the new button. -->
<Window Type="TaharezLook/ImageButton" Name="btnNewGame">
<Property Name="UnifiedPosition" Value="{{0.67,0},{0.5,0}}" />
<Property Name="UnifiedSize" Value="{{0,256},{0,50}}" />
<!-- Here we choose what images to take. set:FTSUI means they are stored -->
<!-- in the imageset named FTSUI and image:btnNormal specifies wich image it is. -->
<Property Name="NormalImage" Value="set:FTSUI image:btnNormal" />
<Property Name="HoverImage" Value="set:FTSUI image:btnHover" />
<Property Name="PushedImage" Value="set:FTSUI image:btnPushed" />
<Property Name="DisabledImage" Value="set:FTSUI image:btnDisabl" />
<!-- Now the button would be ready, but without caption ... So we add a caption. -->
<Window Type="TaharezLook/StaticText" Name="btnNewGame_text__">
<!-- We make the text take all the space of the button to center the text. -->
<!-- You should adapt these values to your pictures, just play a bit with em ;) -->
<Property Name="UnifiedPosition" Value="{{0,0},{0,0}}" />
<Property Name="UnifiedSize" Value="{{1,0},{1,0}}" />
<!-- Disable the frame and background, so we got only the text and not a StaticText widget. -->
<Property Name="FrameEnabled" Value="False" />
<Property Name="BackgroundEnabled" Value="False" />
<!-- Here we center the text into the button -->
<Property Name="HorzFormatting" Value="WordWrapCentred" />
<!-- We MUST disable the text so that it is the button that gets our mouse events, -->
<!-- and not the static text ! If you forget that line, the buttons graphics will correspond, -->
<!-- but the clicks on the button won't work ! because they are "eaten" by the staticText. -->
<Property Name="Disabled" Value="True" />
<!-- finally, this is the caption we want the button to have. -->
<Property Name="Text">New game</Property>
</Window>
</Window>
That's it basically. Try it out, give me feedback, test it, tell me the typos, ... because I think i'll write a wiki page about this