Page 1 of 1

Creating window from code using WindowLook

Posted: Wed Aug 16, 2006 16:18
by Rakkar
I copied from the Falagard sample this edit box

Code: Select all



  <!--
    ***************************************************
        TaharezLook/Editbox
    ***************************************************
    -->
    <WidgetLook name="TaharezLook/Editbox">
        <Property name="MouseCursorImage" value="set:TaharezLook image:MouseTextBar" />
        <NamedArea name="TextArea">
            <Area>
                <Dim type="LeftEdge" ><AbsoluteDim value="5" /></Dim>
                <Dim type="TopEdge" ><AbsoluteDim value="5" /></Dim>
                <Dim type="RightEdge" ><UnifiedDim scale="1.0" offset="-5" type="RightEdge" /></Dim>
                <Dim type="BottomEdge" ><UnifiedDim scale="1.0" offset="-5" type="BottomEdge" /></Dim>
            </Area>
        </NamedArea>
        <ImagerySection name="container_normal">
            <FrameComponent>
                <Area>
                    <Dim type="LeftEdge" ><AbsoluteDim value="0" /></Dim>
                    <Dim type="TopEdge" ><AbsoluteDim value="0" /></Dim>
                    <Dim type="Width" ><UnifiedDim scale="1" type="Width" /></Dim>
                    <Dim type="Height" ><UnifiedDim scale="1" type="Height" /></Dim>
                </Area>
                <Image type="LeftEdge" imageset="TaharezLook" image="EditBoxLeft" />
                <Image type="RightEdge" imageset="TaharezLook" image="EditBoxRight" />
                <Image type="Background" imageset="TaharezLook" image="EditBoxMiddle" />
            </FrameComponent>
        </ImagerySection>
        <ImagerySection name="selection">
            <ImageryComponent>
                <Area>
                    <Dim type="LeftEdge" ><AbsoluteDim value="0" /></Dim>
                    <Dim type="TopEdge" ><AbsoluteDim value="0" /></Dim>
                    <Dim type="RightEdge" ><UnifiedDim scale="1.0" type="RightEdge" /></Dim>
                    <Dim type="BottomEdge" ><UnifiedDim scale="1.0" type="BottomEdge" /></Dim>
                </Area>
                <Image imageset="TaharezLook" image="TextSelectionBrush" />
                <VertFormat type="Stretched" />
                <HorzFormat type="Stretched" />
            </ImageryComponent>
        </ImagerySection>
        <ImagerySection name="Carat">
            <ImageryComponent>
                <Area>
                    <Dim type="LeftEdge" ><AbsoluteDim value="0" /></Dim>
                    <Dim type="TopEdge" ><AbsoluteDim value="0" /></Dim>
                    <Dim type="Width" ><ImageDim imageset="TaharezLook" image="EditBoxCarat" dimension="Width" /></Dim>
                    <Dim type="BottomEdge" ><UnifiedDim scale="1.0" type="BottomEdge" /></Dim>
                </Area>
                <Image imageset="TaharezLook" image="EditBoxCarat" />
                <VertFormat type="Stretched" />
                <HorzFormat type="Stretched" />
            </ImageryComponent>
        </ImagerySection>
        <StateImagery name="Enabled">
            <Layer>
                <Section section="container_normal" />
            </Layer>
        </StateImagery>
        <StateImagery name="ReadOnly">
            <Layer>
                <Section section="container_normal" />
            </Layer>
        </StateImagery>
        <StateImagery name="Disabled">
            <Layer>
                <Section section="container_normal">
                    <Colours topLeft="FF7F7F7F" topRight="FF7F7F7F" bottomLeft="FF7F7F7F" bottomRight="FF7F7F7F" />
                </Section>
            </Layer>
        </StateImagery>
        <StateImagery name="ActiveSelection">
            <Layer>
                <Section section="selection">
                    <ColourProperty name="ActiveSelectionColour" />
                </Section>
            </Layer>
        </StateImagery>
        <StateImagery name="InactiveSelection">
            <Layer>
                <Section section="selection">
                    <ColourProperty name="InactiveSelectionColour" />
                </Section>
            </Layer>
        </StateImagery>
    </WidgetLook>
   


I want to create it in code. Right now I have a layout which defines some stuff by default:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<GUILayout>
<Window Type="DefaultWindow" Name="Root" >
<Property Name="InheritsAlpha" Value="False" />
<Property Name="UnifiedAreaRect" Value="{{0.000000,0.000000},{0.000000,0.000000},{1.000000,0.000000},{1.000000,0.000000}}" />
<Property Name="UnifiedMaxSize" Value="{{1.000000,0.000000},{1.000000,0.000000}}" />
<Window Type="TaharezLook/Button" Name="PlaySound" >
<Property Name="MouseCursorImage" Value="set:TaharezLook image:MouseArrow" />
<Property Name="Text" Value="Play Sound" />
<Property Name="UnifiedAreaRect" Value="{{0.100000,0.000000},{0.100000,0.000000},{0.227499,0.000000},{0.190846,0.000000}}" />
<Property Name="UnifiedMaxSize" Value="{{1.000000,0.000000},{1.000000,0.000000}}" />
</Window>
<Window Type="TaharezLook/Button" Name="Quit" >
<Property Name="MouseCursorImage" Value="set:TaharezLook image:MouseArrow" />
<Property Name="Text" Value="Quit" />
<Property Name="UnifiedAreaRect" Value="{{0.095000,0.000000},{0.211959,0.000000},{0.231250,0.000000},{0.298206,0.000000}}" />
<Property Name="UnifiedMaxSize" Value="{{1.000000,0.000000},{1.000000,0.000000}}" />
</Window>
</Window>

</GUILayout>


I don't want the editbox to show up by default, only from code.

So I tried this:

Code: Select all

CEGUI::Window* win = CEGUI::WindowManager::getSingleton().createWindow(type, name);
   rootWindow->addChildWindow(win);


However, createWindow always returns 0.

Where should I put the WindowLook XML block inside my layout to make this work? I tried several places and createWindow still returns 0.

Posted: Thu Aug 17, 2006 16:39
by lindquist
I'm a little confused what you're trying to do here. The first XML is Falagard. The second is GUILayout.

To use the looknfeel you must map it to a widget, with a FalagardMapping, this is done in Schemes. Look at TaharezLookSkin.scheme for details.

createWindow should never return zero :S it throws an exception on error.

HTH

Posted: Thu Aug 17, 2006 20:33
by Rackle
You could configure (within the Layout Editor) your editbox to not be visible and then use setVisible(true) to make your editbox visible. The problem with that approach is that your editbox will be invisible within the Layout Editor itself, which can make it difficult to align with other widgets.

Another approach would be to leave the editbox visible within the Layout Editor, from code call loadLayout(), and then hide your editbox with setVisible(false). When the time is right you can then show your editbox with setVisible(true). This will work as long as you do not call Ogre::RenderOneFrame() between loadLayout() and setVisible(false).