C++ Loop through all child GUI objects.
by Peterjohn Griffiths · in Torque Game Engine · 09/17/2006 (7:35 pm) · 5 replies
I am trying to make the GuiMLTextCtrl take into account any GUI object that are a child of it when resizing on the Y axix.
To do this I need to be able to loop though all the child objects of the current parent object in the function "GuiMLTextCtrl::reflow()" that can be found in the "guiMLTextCtrl.cc" file.
I think to achieve this I need to amend the value of mMaxY in the function GuiMLTextCtrl::reflow() just before the line
Does anyone have anyidea how I would find out what child objects a parent control has so I can loop through them.
If I was in script, I would use something like the following where mBounds points to the ID of the parent object.
Many thanks in advance.
To do this I need to be able to loop though all the child objects of the current parent object in the function "GuiMLTextCtrl::reflow()" that can be found in the "guiMLTextCtrl.cc" file.
I think to achieve this I need to amend the value of mMaxY in the function GuiMLTextCtrl::reflow() just before the line
resize(mBounds.point, Point2I(mBounds.extent.x, mMaxY));
Does anyone have anyidea how I would find out what child objects a parent control has so I can loop through them.
If I was in script, I would use something like the following where mBounds points to the ID of the parent object.
%group = mBounds;
%count = %group.getCount();
for (%i=0; %i<%count; %i++){
%tmpObj = %group.getObject(%i)
if ((%tmpObj.position.y + %tmpObj.Extent.y) > %mMaxY){
%mMaxY = ((%tmpObj.position.y + %tmpObj.Extent.y;
}
}Many thanks in advance.
#2
I noticed the use of the parent in the for loop's begin() and end().
I have come up with the following to find all child objects.
Does this look like i'm on the right track with the for loop?. At the line "//ctrl is a child object of this" would they all be child objects or would all GuiControls in existance be looped through in the for loop?.
Many thanks again in advance.
09/17/2006 (10:34 pm)
After digesting your post and having a look around in the guiControl.cc 's "GuiControl::messageSiblings" function that looks like this.void GuiControl::messageSiblings(S32 message)
{
GuiControl *parent = getParent();
if (! parent) return;
GuiControl::iterator i;
for(i = parent->begin(); i != parent->end(); i++)
{
GuiControl *ctrl = dynamic_cast<GuiControl *>(*i);
if (ctrl != this)
ctrl->onMessage(this, message);
}
}I noticed the use of the parent in the for loop's begin() and end().
I have come up with the following to find all child objects.
GuiControl::iterator i;
for(i = this->begin(); i != this->end(); i++)
{
GuiControl *ctrl = dynamic_cast<GuiControl *>(*i);
//ctrl is a child object of this.
}Does this look like i'm on the right track with the for loop?. At the line "//ctrl is a child object of this" would they all be child objects or would all GuiControls in existance be looped through in the for loop?.
Many thanks again in advance.
#3
but you need to test ctrl for NULL to see if it's actuall a GuiControl and not some other random simObject:
09/18/2006 (12:08 am)
Yes, you are in the right track w/ the begin() and end() stuff,but you need to test ctrl for NULL to see if it's actuall a GuiControl and not some other random simObject:
...
GuiControl *ctrl = dynamic_cast<GuiControl *>(*i);
if (ctrl != NULL)
// ctrl is a child GuiControl of this control
else
// Could be anything; Skip it.
...
#4
I will give it a go tonight and see if I can get it to work.
Thanks again.
09/18/2006 (12:39 am)
Thanks Orion Elenzil,I will give it a go tonight and see if I can get it to work.
Thanks again.
#5
I have managed to implement it into several guiMLTextCtrl functions so that the control expands its extent to include any child gui controls.
This is great for when you want to add rich text to scroll bar's.
I am still working on a bug where the scroll bar scrolls to the top when ever the scrollbar resizes.
When this is fixed I will post the code.
09/20/2006 (7:46 pm)
This code works great.I have managed to implement it into several guiMLTextCtrl functions so that the control expands its extent to include any child gui controls.
This is great for when you want to add rich text to scroll bar's.
I am still working on a bug where the scroll bar scrolls to the top when ever the scrollbar resizes.
When this is fixed I will post the code.
Torque 3D Owner Matthew Langley
Torque
Hope this helps :)
bool GuiCanvas::checkForT2DEdit(GuiControl *guiControl) { t2dSceneWindow *t2dControl = dynamic_cast<t2dSceneWindow*>(guiControl); if(t2dControl) { if(t2dControl->getSceneGraph() && t2dControl->getSceneGraph()->getIsEditorScene()) return true; } iterator i; for(i = guiControl->begin(); i != guiControl->end(); i++) { GuiControl *ctrl = dynamic_cast<GuiControl*>(*i); if(ctrl && checkForT2DEdit(ctrl)) return true; } return false; }