Code: Texture Palette - by request

SongOfTheWeave

04-02-2008 05:09:34

I received a couple requests for elements of my editor's GUI. Since I'm not making available the source of my project, I figured I'd post this element here in case anyone else would like it.

TexturePalette using modified TaharezLook:


------

How to modify this code for use in your application:

This class is coupled to my application object, so to use this class in your own project you will need to replace all references to Sanguis::Toolset::ToolsetApplication with your own application. Looking over this code again, I should just uncouple the thing by using a templatised callback... but that's not on my todo list right now.

Your application object will need to implement the setActiveTexture(int) method, which sets the index of the texture you're currently painting with. This is the method the TexturePalette calls when you click on one of the textures. The int argument is the texture index consumed by ET::SplattingManager::paint()

You should also either remove any namespace references to namespace Sanguis or namespace Sanguis::Toolset or replace them with namespaces specific to your own project.

-----

Structure Description:

TexturePalette is a subclass of Palette which is simply a container that handles creating a CEGUI window from a .layout file and does some setup that I needed for all palettes so I didn't have to do it every time.

Palette is a subclass of my Object class, which merely implements reference counting. Feel free to remove this inheritance relationship.

------

I started pasting all of the code in here in code tags but it's really rather long. I'll attach the files instead.

Files: http://www.cutthroatstudios.com/Storage/TexturePalette.zip

------

Edit: I almost forgot! You'll need to add the following widget definition to your CEGUI looknfeel file. If you are not modifying TaharezLook you'll need to change the names in this snippet and in the .layout file in the above zip.

Note: You'll also need to register this widget by adding this line to your .scheme file

<FalagardMapping WindowType="TaharezLook/LabelImageListItem" TargetType="CEGUI/ItemEntry" Renderer="Falagard/ItemEntry" LookNFeel="TaharezLook/LabelImageListItem" />


<!--
***************************************************
TaharezLook/LabelImageListItem
***************************************************
-->
<WidgetLook name="TaharezLook/LabelImageListItem">
<PropertyLinkDefinition name="SwatchColour" widget="__auto_staticimage__" targetProperty="ImageColours" initialValue="tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF" />
<PropertyLinkDefinition name="SwatchImage" widget="__auto_staticimage__" targetProperty="Image" initialValue="set:TaharezLook image:ListboxSelectionBrush" />
<PropertyLinkDefinition name="SwatchBackgroundEnabled" widget="__auto_staticimage__" targetProperty="BackgroundEnabled" initialValue="True" />
<PropertyLinkDefinition name="SwatchFrameEnabled" widget="__auto_staticimage__" targetProperty="FrameEnabled" initialValue="False" />
<PropertyDefinition name="AdditionalData" initialValue="" />
<PropertyDefinition name="TextColour" initialValue="FFFFFFFF" redrawOnWrite="true" />
<PropertyDefinition name="SelectedTextColour" initialValue="FFFFFFFF" redrawOnWrite="true" />
<PropertyDefinition name="SelectionBrush" initialValue="set:TaharezLook image:ListboxSelectionBrush" redrawOnWrite="true" />
<PropertyDefinition name="SelectionColour" initialValue="FF6080FF" redrawOnWrite="true" />
<Property name="Selectable" value="True" />
<NamedArea name="ContentSize">
<Area>
<Dim type="LeftEdge" >
<AbsoluteDim value="0" />
</Dim>
<Dim type="TopEdge" >
<AbsoluteDim value="0" />
</Dim>
<Dim type="Width" >
<FontDim type="HorzExtent" padding="6" />
<DimOperator op="Add">
<FontDim type="LineSpacing" padding="3" />
</DimOperator>
</Dim>
<Dim type="Height" >
<!--<AbsoluteDim value="22" />-->
<FontDim type="LineSpacing" padding="6"/>
</Dim>
</Area>
</NamedArea>

<Child type ="TaharezLook/StaticImage" nameSuffix="__auto_staticimage__">
<Area>
<Dim type="LeftEdge">
<UnifiedDim scale="0" type="LeftEdge" />
<AbsoluteDim value="3" />
</Dim>
<Dim type="TopEdge">
<UnifiedDim scale="0" offset="1" type="TopEdge" />
</Dim>
<Dim type="Width">
<FontDim type="LineSpacing" padding="3" />
<!--<AbsoluteDim value="20" />-->
</Dim>
<Dim type="Height">
<!--<UnifiedDim scale="1" type="Height"/>-->
<FontDim type="LineSpacing" padding="3" />
<!--<AbsoluteDim value="20" />-->
</Dim>
</Area>
</Child>

<ImagerySection name="label">
<TextComponent>
<Area>
<Dim type="TopEdge">
<AbsoluteDim value="0" />
</Dim>
<Dim type="LeftEdge">
<FontDim type="LineSpacing" padding="10"/>
<!--<UnifiedDim scale="0.0" offset="28" type="LeftEdge" />-->
</Dim>
<Dim type="RightEdge">
<UnifiedDim scale="1" offset="-3" type="RightEdge" />
</Dim>
<Dim type="BottomEdge">
<UnifiedDim scale="1" type="BottomEdge" />
</Dim>
</Area>
</TextComponent>
</ImagerySection>

<ImagerySection name="selection">
<ImageryComponent>
<Area>
<Dim type="TopEdge">
<AbsoluteDim value="0" />
</Dim>
<Dim type="LeftEdge">
<AbsoluteDim value="0" />
</Dim>
<Dim type="RightEdge">
<UnifiedDim scale="1" type="RightEdge" />
</Dim>
<Dim type="BottomEdge">
<UnifiedDim scale="1" type="BottomEdge" />
</Dim>
</Area>
<ImageProperty name="SelectionBrush" />
<ColourProperty name="SelectionColour" />
<VertFormat type="Stretched" />
<HorzFormat type="Stretched" />
</ImageryComponent>
</ImagerySection>
<StateImagery name="Enabled">
<Layer>
<Section section="label">
<ColourProperty name="TextColour" />
</Section>
</Layer>
</StateImagery>
<StateImagery name="Disabled">
<Layer>
<Section section="label">
<ColourProperty name="TextColour" />
</Section>
</Layer>
</StateImagery>
<StateImagery name="SelectedEnabled">
<Layer>
<Section section="selection" />
<Section section="label">
<ColourProperty name="SelectedTextColour" />
</Section>
</Layer>
</StateImagery>
<StateImagery name="SelectedDisabled">
<Layer>
<Section section="selection" />
<Section section="label">
<ColourProperty name="SelectedTextColour" />
</Section>
</Layer>
</StateImagery>
</WidgetLook>


So much for keeping the post short.