Game Development Community

Vertical Progress Bar

by Ronald J Nelson · in Torque Game Engine Advanced · 08/10/2008 (9:54 pm) · 1 replies

Well I am trying to set up the progress bar so it can do vertical displays. I added a flag to indicate if it is going to be used. The problem I am having is that it is updating from the top downward instead of the preferred down to upward.

Here is my code:
void GuiProgressCtrl::onRender(Point2I offset, const RectI &updateRect)
{
   RectI ctrlRect(offset, mBounds.extent);

   //draw the progress
   if(mVertical)
   {
	   S32 height = (S32)((F32)mBounds.extent.y * mProgress);
	   if (height > 0)
	   {
		   RectI progressRect = ctrlRect;
		   progressRect.extent.y = height;
		   GFX->drawRectFill(progressRect, mProfile->mFillColor);
	   }
   }
   else
   {
	   S32 width = (S32)((F32)mBounds.extent.x * mProgress);
	   if (width > 0)
	   {
		   RectI progressRect = ctrlRect;
		   progressRect.extent.x = width;
		   GFX->drawRectFill(progressRect, mProfile->mFillColor);
	   }
   }

I am sure I am doing something simple wrong, I am just not sure where.

Thanks in advance.

#1
08/10/2008 (10:12 pm)
Nevermind I figured it out. Here it is.

void GuiProgressCtrl::onRender(Point2I offset, const RectI &updateRect)
{
   RectI ctrlRect(offset, mBounds.extent);

   //draw the progress
   if(mVertical)
   {
	   S32 height = (S32)((F32)mBounds.extent.y * mProgress);
	   if (height > 0)
	   {
		   RectI progressRect = ctrlRect;
		   S32 bottomY = progressRect.point.y + progressRect.extent.y;
		   progressRect.extent.y = (S32)(progressRect.extent.y * mProgress);
		   progressRect.point.y = bottomY - progressRect.extent.y;

		   GFX->drawRectFill(progressRect, mProfile->mFillColor);
	   }
   }
   else
   {
	   S32 width = (S32)((F32)mBounds.extent.x * mProgress);
	   if (width > 0)
	   {
		   RectI progressRect = ctrlRect;
		   progressRect.extent.x = width;
		   GFX->drawRectFill(progressRect, mProfile->mFillColor);
	   }
   }

   //now draw the border
   if (mProfile->mBorder)
   {
      GFX->drawRect(ctrlRect, mProfile->mBorderColor);

      RectI copyRect = ctrlRect;
      copyRect.point.x += 1;
      copyRect.point.y += 1;
      copyRect.extent.x -= 2;
      copyRect.extent.y -= 2;
      ColorI color = mProfile->mBorderColor*0.75f;
      color.alpha = 255;
      GFX->drawRect(copyRect, color);
   }

   //render the children
   renderChildControls(offset, updateRect);
}