c++user-interfacecegui

CEGUI change button image at runtime


I've been looking through online docs and I've not found a way to update a button or a label image at runtime. I'm trying to display thumbnails within a layout of buttons. The thumbnails will need to update depending upon which images are available, while keeping the layout.

So for example, I've a layout with a "Previous" button, three buttons to show thumbnails, and a "Next" button, when the user clicks "Next" the three buttons change to show the next three thumbnails. They need to be buttons, to allow for the Normal, Hover, Pushed mouse interaction. So when the user clicks a thumbnail, that image the action is triggered.

Any help is appreciated.


Solution

  • I found the answer I was looking for. Within the looknfeel file I defined a property: "BackgroundImage" of type "Image"

    <WidgetLook name="MyLook/Thumbnail">
        <Property name="CursorImage" value="MyImageSet/cursorOn" />
        <Property name="CursorPassThroughEnabled" value="true" />
        <PropertyDefinition name="BackgroundImage" redrawOnWrite="true" initialValue="MyImageSet/defaultImage" type="Image"/>
        <Property name="Size" value="{{1, 0}, {1, 0}}" />
        <ImagerySection name="frame">
            <FrameComponent>
                <ImageProperty name="BackgroundImage" />
                <VertFormat type="Stretched" />
                <HorzFormat type="Stretched" />
            </FrameComponent>
        </ImagerySection>
        <StateImagery name="Enabled">
            <Layer>
                <Section section="frame" />
            </Layer>
        </StateImagery>
    </WidgetLook>
    

    Then within the code I set the image using the property defined:

    CEGUI::DefaultWindow* thumbnail = static_cast<CEGUI::DefaultWindow*>( parrentWindow->getChild( "Thunbnail_1" ));
    thumbnail->setProperty( "BackgroundImage", "MyImageSet/movieClipIcon" );