Fixing GUI element resizing
by Stephen Lujan · in Torque Game Engine · 06/27/2007 (4:14 am) · 1 replies
I'm not sure how many people have noticed this, but GUI elements don't remember all of their initial positions and sizes when their parents are resized and so it gets messed up pretty quickly with all of the scaling, especially if you scroll down enough for the the min extent values of gui elements to kick in. There's a good resource here, but it doesn't fix problems I was having with with tables. I'm still working on a solution, I just need to know how to copy the special vectors torque uses. For some reason I couldn't find this information anywhere and it wasn't working the way I thought it would. Anyways here is what I've gotten so far.
in "engine/gui/containers/guiFrameCtrl.h" at line 107 add
EDIT: SEE NEXT POST:
in "engine/gui/containers/guiFrameCtrl.h" at line 107 add
Vector<S32> mOriginalColumnOffsets; Vector<S32> mOriginalRowOffsets;then in "engine/gui/containers/guiFrameCtrl.h" replace function GuiFrameSetCtrl::rebalance with
EDIT: SEE NEXT POST:
About the author
Torque Owner Stephen Lujan
void GuiFrameSetCtrl::rebalance(const Point2I &newExtent) { newExtent; // look at old_width and old_height - current extent F32 newe = (F32)newExtent.x; F32 olde = (F32)mOriginalBounds.extent.x; F32 widthScale = newe / olde; //Con::errorf("F32 widthScale %f = newe %f/ olde %f;",widthScale, newe, olde); newe = (F32)newExtent.y; olde = (F32)mOriginalBounds.extent.y; F32 heightScale = newe / olde; //Con::errorf("F32 heightScale %f = newe %f/ olde %f;",heightScale, newe, olde); //Con::errorf("GuiFrameSetCtrl::rebalance! mOriginalRowOffsets.size()=%d mRowOffsets.size()=%d",mOriginalRowOffsets.size(),mRowOffsets.size()); if (! (mOriginalRowOffsets.size() == mRowOffsets.size())) { //Con::errorf("COPYING ROW OFFSETS!"); mOriginalRowOffsets = mRowOffsets; } if (! (mOriginalColumnOffsets.size() == mColumnOffsets.size())) { //Con::errorf("COPYING COLUMN OFFSETS!"); mOriginalColumnOffsets = mColumnOffsets; } Vector<S32>::iterator itr; Vector<S32>::iterator itrOriginal; // look at old width offsets itr = mColumnOffsets.begin() + 1; itrOriginal = mOriginalColumnOffsets.begin() + 1; while (itr < mColumnOffsets.end() && itrOriginal < mOriginalColumnOffsets.end()) { //Con::errorf("previous *itr = %d",*itr); *itr = S32(F32(*itrOriginal) * widthScale); //Con::errorf("%d = S32(F32(%d) * %f)",*itr,*itrOriginal,widthScale); itr++; itrOriginal++; } // look at old height offsets itr = mRowOffsets.begin() + 1; itrOriginal = mOriginalRowOffsets.begin() + 1; while (itr < mRowOffsets.end() && itrOriginal < mOriginalColumnOffsets.end()) { //Con::errorf("previous *itr = %d",*itr); *itr = S32(F32(*itrOriginal) * heightScale); //Con::errorf("%d = S32(F32(%d) * %f)",*itr,*itrOriginal,heightScale); itr++; itrOriginal++; } }Also I edited the resize function to call its parent function sooner. This eliminated a possible error with the autobalance function.void GuiFrameSetCtrl::resize(const Point2I &newPos, const Point2I &newExtent) { [b]Parent::resize(newPos, newExtent);[/b] // rebalance before losing the old extent (if required) if (mAutoBalance == true) rebalance(newExtent); // compute new sizing info for the frames - takes care of resizing the children computeSizes( !mAutoBalance ); }