Retrieve Child Object

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

mrGREEN
Just popping in
Just popping in
Posts: 12
Joined: Wed Apr 01, 2009 12:49

Retrieve Child Object

Postby mrGREEN » Wed May 13, 2009 11:45

Hi

For my app I need to retrieve all the Child Objects Names from a Father Object. I'm using a layout to load every single object.

Basically, what I'm doing is

Code: Select all

CEGUI::Window *cWindowFather = poWindowManager->getWindow("Root/MainWindow");
for (U32 k = 0; k < cWindowFather->getChildCount(); k++)
{
   CEGUI::Window *cWindowChild = cWindowFather->getChild(k);
   LOG ("name %s",cWindowChild->getName().c_str());
}


From the test that I'm running, "Root/MainWindow" has 18 child. I got only two child names, and then I got an exception. :cry:
Another weird thing if that one of the two names that I retrieve is wrong. I got something like "Root/MainWindow__auto_tilebar__".

I can't see where is the problem :!:

This is the Layout file that I'm using

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>

<GUILayout >
    <Window Type="DefaultWindow" Name="Root" >

        <Window Type="TaharezLook/FrameWindow" Name="Root/MainWindow" >
            <Property Name="UnifiedAreaRect" Value="{{0,480},{0,30},{0,780},{0,550}" />
            <Property Name="Text" Value="GUI Demo" />
            <Property Name="RollUpEnabled" Value="False" />
            <Property Name="SizingEnabled" Value="False" />
            <Property Name="Alpha" Value="0.8" />
   
            <Window Type="TaharezLook/Menubar" Name="Root/MainWindow/MenuBar">
                <Property Name="AlwaysOnTop" Value="1" />
                <Property Name="UnifiedAreaRect" Value="{{0,0},{0,25},{1,0},{0,60}}" />
                  <Window Type="TaharezLook/MenuItem" Name="Root/MainWindow/MenuItemDemo">
                           <Property Name="Text" Value="Demo" />
                           <Window Type="TaharezLook/PopupMenu" Name="Root/MainWindow/PopItemDemo">
                              <Window Type="TaharezLook/MenuItem" Name="Root/MainWindow/MenuItemQuit">
                                 <Property Name="Text" Value="Quit" />
                                 <Property Name="Tooltip" Value="Hotkey: Q" />
                              </Window>
                           </Window>
                  </Window>
                  <Window Type="TaharezLook/MenuItem" Name="Root/MainWindow/MenuItemFX">
                           <Property Name="Text" Value="FX" />
                           <Window Type="TaharezLook/PopupMenu" Name="Root/MainWindow/PopItemFX">
                              <Window Type="TaharezLook/MenuItem" Name="Root/MainWindow/MenuItemFX1">
                                 <Property Name="Text" Value="Another FX 1" />
                              </Window>
                              <Window Type="TaharezLook/MenuItem" Name="Root/MainWindow/MenuItemFX2">
                                 <Property Name="Text" Value="Another FX 2" />
                              </Window>
                              <Window Type="TaharezLook/MenuItem" Name="Root/MainWindow/MenuItemFX3">
                                 <Property Name="Text" Value="Another FX 3" />
                              </Window>                                                                   
                           </Window>
                  </Window>                                   
            </Window>
           
            <Window Type="TaharezLook/StaticText" Name="Root/MainWindow/AnimeInfo">
                <Property Name="UnifiedPosition" Value="{{0,10},{0,70}}" />
                <Property Name="UnifiedSize" Value="{{0,70},{0,25}}" />
                <Property Name="HorzFormatting" Value="WordWrapLeft" />
                <Property Name="Text" Value="Animation" />
            </Window>
                                   
            <Window Type="TaharezLook/Combobox" Name="Root/MainWindow/Combobox" >
                <Property Name="UnifiedPosition" Value="{{0,10},{0,100}}" />
                <Property Name="UnifiedSize" Value="{{0,280},{0,150}}" />               
            </Window>     

            <Window Type="TaharezLook/StaticText" Name="Root/MainWindow/ColorInfo">
                <Property Name="UnifiedPosition" Value="{{0,10},{0,140}}" />
                <Property Name="UnifiedSize" Value="{{0,110},{0,25}}" />
                <Property Name="HorzFormatting" Value="WordWrapLeft" />
                <Property Name="Text" Value="Color and Alpha" />
            </Window>

            <Window Type="TaharezLook/HorizontalScrollbar" Name="Root/MainWindow/Controls/Red">
                <Property Name="UnifiedPosition" Value="{{0,10},{0,170}}" />
                <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
                <Property Name="UnifiedSize" Value="{{0,200},{0,20}}" />
                <Property Name="DocumentSize" Value="1" />
                <Property Name="PageSize" Value="0.0625" />
                <Property Name="StepSize" Value="0.00392" />
                <Property Name="OverlapSize" Value="0.00392" />
                <Property Name="Tooltip" Value="Slider to adjust the red colour component." />
            </Window>

            <Window Type="TaharezLook/HorizontalScrollbar" Name="Root/MainWindow/Controls/Green">
                <Property Name="UnifiedPosition" Value="{{0,10},{0,200}}" />
                <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
                <Property Name="UnifiedSize" Value="{{0,200},{0,20}}" />
                <Property Name="DocumentSize" Value="1" />
                <Property Name="PageSize" Value="0.0625" />
                <Property Name="StepSize" Value="0.00392" />
                <Property Name="OverlapSize" Value="0.00392" />
                <Property Name="Tooltip" Value="Slider to adjust the green colour component." />
            </Window>

            <Window Type="TaharezLook/HorizontalScrollbar" Name="Root/MainWindow/Controls/Blue">
                <Property Name="UnifiedPosition" Value="{{0,10},{0,230}}" />
                <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
                <Property Name="UnifiedSize" Value="{{0,200},{0,20}}" />
                <Property Name="DocumentSize" Value="1" />
                <Property Name="PageSize" Value="0.0625" />
                <Property Name="StepSize" Value="0.00392" />
                <Property Name="OverlapSize" Value="0.00392" />
                <Property Name="Tooltip" Value="Slider to adjust the blue colour component." />
            </Window>

            <Window Type="TaharezLook/HorizontalScrollbar" Name="Root/MainWindow/Controls/Alpha">
                <Property Name="UnifiedPosition" Value="{{0,10},{0,260}}" />
                <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
                <Property Name="UnifiedSize" Value="{{0,200},{0,20}}" />
                <Property Name="DocumentSize" Value="1" />
                <Property Name="PageSize" Value="0.0625" />
                <Property Name="StepSize" Value="0.00392" />
                <Property Name="OverlapSize" Value="0.00392" />
                <Property Name="Tooltip" Value="Slider to adjust the Alpha component." />
            </Window>

            <Window Type="TaharezLook/RadioButton" Name="Root/MainWindow/Controls/Left" >
                <Property Name="Text" Value="Flip Left" />
                <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
                <Property Name="UnifiedAreaRect" Value="{{0,10},{0,290},{0,100},{0,310}}" />
            </Window>
           
            <Window Type="TaharezLook/RadioButton" Name="Root/MainWindow/Controls/Right" >
                <Property Name="ID" Value="1" />
                <Property Name="Text" Value="Flip Right" />
                <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
                <Property Name="UnifiedAreaRect" Value="{{0,10},{0,320},{0,100},{0,340}}" />
            </Window>

            <Window Type="TaharezLook/StaticText" Name="Root/MainWindow/SizeInfo">
                <Property Name="UnifiedPosition" Value="{{0,110},{0,290}}" />
                <Property Name="UnifiedSize" Value="{{0,35},{0,25}}" />
                <Property Name="HorzFormatting" Value="WordWrapLeft" />
                <Property Name="Text" Value="Size" />
            </Window>
           
            <Window Type="TaharezLook/Slider" Name="Root/MainWindow/Controls/Size" >
                <Property Name="CurrentValue" Value="4" />
                <Property Name="MaximumValue" Value="10" />
                <Property Name="ClickStepSize" Value="0.01" />
                <Property Name="UnifiedSize" Value="{{0,10},{0,50}}" />
                <Property Name="UnifiedPosition" Value="{{0,150},{0,290}}" />
            </Window>

            <Window Type="TaharezLook/Button" Name="Root/MainWindow/Controls/FX1" >
                <Property Name="Text" Value="FX 1" />
                <Property Name="UnifiedSize" Value="{{0,70},{0,30}}" />
                <Property Name="UnifiedPosition" Value="{{0,10},{0,350}}" />
            </Window>
                                                                                                                       
            <Window Type="TaharezLook/Button" Name="Root/MainWindow/Controls/FX2" >
                <Property Name="Text" Value="FX 2" />
                <Property Name="UnifiedSize" Value="{{0,70},{0,30}}" />
                <Property Name="UnifiedPosition" Value="{{0,115},{0,350}}" />
            </Window>

            <Window Type="TaharezLook/Button" Name="Root/MainWindow/Controls/FX3" >
                <Property Name="Text" Value="FX 3" />
                <Property Name="UnifiedSize" Value="{{0,70},{0,30}}" />
                <Property Name="UnifiedPosition" Value="{{0,220},{0,350}}" />
            </Window>

            <Window Type="TaharezLook/MultiLineEditbox" Name="Root/MainWindow/MultiText" >
                <Property Name="Text" />
                <Property Name="MaxTextLength" Value="1073741823" />
                 <Property Name="UnifiedPosition" Value="{{0,10},{0,400}}" />
                 <Property Name="UnifiedSize" Value="{{0,280},{0,80}}" />
            </Window>
                                                                   
        </Window>
    </Window>
</GUILayout>

Jamarr
CEGUI MVP
CEGUI MVP
Posts: 812
Joined: Tue Jun 03, 2008 23:59
Location: USA

Re: Retrieve Child Object

Postby Jamarr » Wed May 13, 2009 16:16

There are a couple of issues here.

First, the reason your application is crashing is because you are using the API incorrectly. The getChild() function expects a user-defined window-id, but you are passing a child-index. You should be using getChildAtIdx() instead.

Second, you are forgetting (or never knew) about auto-windows. Auto-windows are child-windows defined in the .looknfeel file that are created automatically. The "Root/MainWindow__auto_tilebar__" is a perfectly valid child of a FrameWindow. By default a frame-window is composed of several child-windows including the titlebar among others. You can determine if a window is an auto-window or not by calling isAutoWindow() on the window in question.
If somebody helps you by replying to your thread, upvote him/her as a thanks! Make sure to include your CEGUI.log and everything you tried when posting! And remember that we are not magicians!


Return to “Help”

Who is online

Users browsing this forum: No registered users and 29 guests