Vertical GuiProgressCtrl
by Mattias Oldenborg · in Torque Game Engine · 01/16/2007 (2:21 am) · 3 replies
Is it possible to have the GuiProgressCtrl fill up vertically, i.e from bottom to top instead of left to right?
#2
Of course the mHorizontal parameter have to be added and set somewhere. To easily allow changes I then made this a script parameter.
This way the progressbar can be made vertical (bottom to top) by setting horizontal = false; when creating the GuiCtrl.
01/16/2007 (5:57 am)
Yeah I also found this a reasonable place to add vertical functionality to the Ctrl. If anyone else is interested these are the changes I made.void GuiProgressCtrl::onRender(Point2I offset, const RectI &updateRect)
{
RectI ctrlRect(offset, mBounds.extent);
//draw the progress
if (mHorizontal)
{
S32 width = (S32)((F32)mBounds.extent.x * mProgress);
if (width > 0)
{
RectI progressRect = ctrlRect;
progressRect.extent.x = width;
dglDrawRectFill(progressRect, mProfile->mFillColor);
}
}
else
{
S32 height = (S32)((F32)mBounds.extent.y * mProgress);
if (height > 0)
{
RectI progressRect(ctrlRect.point.x, ctrlRect.point.y + ctrlRect.extent.y, ctrlRect.extent.x, -ctrlRect.extent.y);
progressRect.extent.y = -height;
dglDrawRectFill(progressRect, mProfile->mFillColor);
}
}
//now draw the border
if (mProfile->mBorder)
dglDrawRect(ctrlRect, mProfile->mBorderColor);
Parent::onRender( offset, updateRect );
//render the children
renderChildControls(offset, updateRect);
}Of course the mHorizontal parameter have to be added and set somewhere. To easily allow changes I then made this a script parameter.
void GuiProgressCtrl::initPersistFields()
{
Parent::initPersistFields();
addField("horizontal", TypeBool, Offset(mHorizontal, GuiProgressCtrl));
}This way the progressbar can be made vertical (bottom to top) by setting horizontal = false; when creating the GuiCtrl.
#3
01/16/2007 (6:15 am)
Hey thanks this will come in handy.
Employee Michael Perry
ZombieShortbus
In guiProgressCtrl.cc
void GuiProgressCtrl::onRender(Point2I offset, const RectI &updateRect) { RectI ctrlRect(offset, mBounds.extent); //draw the progress [b]S32 width = (S32)((F32)mBounds.extent.x * mProgress); if (width > 0) { RectI progressRect = ctrlRect; progressRect.extent.x = width; dglDrawRectFill(progressRect, mProfile->mFillColor); }[/b] //now draw the border if (mProfile->mBorder) dglDrawRect(ctrlRect, mProfile->mBorderColor); Parent::onRender( offset, updateRect ); //render the children renderChildControls(offset, updateRect); }The code in bold shows where the horizontal rendering (fill) occurs. Seems like a good place to start changing the way the progress control fills.