GuiContol: reposition() instead of resize()
by Orion Elenzil · 02/23/2006 (10:51 am) · 2 comments
In stock TGE, if you want to move a GuiControl, you call resize(newPosition, newSize).
For my own controls, i've added reposition(newPosition), but the vast bulk of the code is using resize().
Resize is a little brain-dead in that it always calls parentResized() on all the control's children, which in turn calls resize(), and so on.
This is a very simple mod to simply not call resize on the children unless the size has actually changed.
The code doesn't even really deserve to be a resource, just the idea, but here it is anyhow.
The only thing i'm a little unsure of is that i cut the call to SetUpdate() out of the loop if it's only a reposition. I'm not sure what SetUpdate does, but my gui's are working fine, including the GuiEditor.
in GuiControl.cc, replave the whole resize() method with this:
For my own controls, i've added reposition(newPosition), but the vast bulk of the code is using resize().
Resize is a little brain-dead in that it always calls parentResized() on all the control's children, which in turn calls resize(), and so on.
This is a very simple mod to simply not call resize on the children unless the size has actually changed.
The code doesn't even really deserve to be a resource, just the idea, but here it is anyhow.
The only thing i'm a little unsure of is that i cut the call to SetUpdate() out of the loop if it's only a reposition. I'm not sure what SetUpdate does, but my gui's are working fine, including the GuiEditor.
in GuiControl.cc, replave the whole resize() method with this:
void GuiControl::resize(const Point2I &newPosition, const Point2I &newExtent)
{
Point2I actualNewExtent = Point2I(getMax(mMinExtent.x, newExtent.x),
getMax(mMinExtent.y, newExtent.y));
// only do the child control resizing stuff if you really need to.
bool extentChanged = (actualNewExtent != mBounds.extent);
if (extentChanged) {
//call set update both before and after
setUpdate();
iterator i;
for(i = begin(); i != end(); i++)
{
GuiControl *ctrl = static_cast<GuiControl *>(*i);
ctrl->parentResized(mBounds.extent, actualNewExtent);
}
mBounds.set(newPosition, actualNewExtent);
GuiControl *parent = getParent();
if (parent)
parent->childResized(this);
setUpdate();
}
else {
mBounds.point = newPosition;
}
}About the author
#2
I'm working on animated controls - eg a button bar at the bottom of the screen which will animate up and down, so i figured i better do this too.
SetUpdate() looks like it has to do with clip region stuff.
Hmmmm, it might be needed even for just a position move.
02/17/2006 (4:38 pm)
Thanks Stefan !I'm working on animated controls - eg a button bar at the bottom of the screen which will animate up and down, so i figured i better do this too.
SetUpdate() looks like it has to do with clip region stuff.
Hmmmm, it might be needed even for just a position move.

Torque Owner Stefan Lundmark
Good resource!