Game Development Community

dev|Pro Game Development Curriculum

GuiWindowCtrl - minimize to title bar

by Akuma · 01/31/2009 (2:24 pm) · 2 comments

this feature makes the window has two options to minimize the first is the standard and the second is how to minimize to title bar


in guiWindowCtrl.h find
bool mPressMaximize;
and insert
bool mMinimizeToTitle;
find void GuiWindowCtrl::initPersistFields()
and insert
addField("MinimizeToTitle",       TypeBool,         Offset(mMinimizeToTitle, GuiWindowCtrl));
find bool GuiWindowCtrl::onWake()
and repleace
mTitleHeight = buttonHeight + 4;
mResizeRightWidth = mTitleHeight / 2;
mResizeBottomHeight = mTitleHeight / 2;
to
mTitleHeight = mBitmapBounds[BorderTopKey].extent.y;
U32 szx = mBitmapBounds[BorderLeft].extent.x;
U32 szy = mBitmapBounds[BorderBottom].extent.y;
mResizeRightWidth = szx + (U32)(szx/2);
mResizeBottomHeight = szy + (U32)(szy/2);

in void GuiWindowCtrl::onMouseDown(const GuiEvent &event)
change
else if (mCanMaximize && mMaximizeButton.pointInRect(localPoint))
to
else if (mCanMaximize && mMaximizeButton.pointInRect(localPoint) && !mMinimized)

in void GuiWindowCtrl::onMouseUp(const GuiEvent &event)
find
else if (minimizing && mMinimizeButton.pointInRect(localPoint))
and repleace to
else if (minimizing && mMinimizeButton.pointInRect(localPoint))
   {
      if (mMinimized)
      {			
         //resize to the previous position and extent, bounded by the parent
			if(mMinimizeToTitle)
				resize(mBounds.point, mStandardBounds.extent);
			else resize(Point2I(getMax(0, getMin(parent->mBounds.extent.x - mStandardBounds.extent.x, mStandardBounds.point.x)),
                        getMax(0, getMin(parent->mBounds.extent.y - mStandardBounds.extent.y, mStandardBounds.point.y))),
                        mStandardBounds.extent);

			mResizeChildFlag = true;
         //set the flag
         mMinimized = false;
      }
      else
      {
         if(!mMinimizeToTitle && parent->mBounds.extent.x < 100 || parent->mBounds.extent.y < mTitleHeight + 3)
            return;

         //only save the position if we're not maximized
         if (! mMaximized)
         {
            mStandardBounds = mBounds;
         }
         else
         {
            mMaximized = false;
         }

			mResizeChildFlag = false;

         if(mMinimizeToTitle)
			{
            //this algorithm assumes all window have the same title height, and will minimize to 98 pix
			   Point2I newExtent(mBounds.extent.x, mTitleHeight + mBitmapBounds[BorderBottom].extent.y);
			   
			   resize(mBounds.point, newExtent);
			} else {
				//first find the lowest unused minimized index up to 32 minimized windows
            U32 indexMask = 0;
            iterator i;
            S32 count = 0;
            for (i = parent->begin(); i != parent->end() && count < 32; i++)
            {
               count++;
               S32 index;
               GuiWindowCtrl *ctrl = dynamic_cast<GuiWindowCtrl *>(*i);
               if (ctrl && ctrl->isMinimized(index))
               {
                  indexMask |= (1 << index);
               }
            }

            //now find the first unused bit
            for (count = 0; count < 32; count++)
            {
               if (! (indexMask & (1 << count))) break;
            }

            //if we have more than 32 minimized windows, use the first position
            count = getMax(0, count);

            //this algorithm assumes all window have the same title height, and will minimize to 98 pix
            Point2I newExtent(98, mTitleHeight);

            //first, how many can fit across
            S32 numAcross = getMax(1, (parent->mBounds.extent.x / newExtent.x + 2));

            //find the new "mini position"
            Point2I newPosition;
            newPosition.x = (count % numAcross) * (newExtent.x + 2) + 2;
            newPosition.y = parent->mBounds.extent.y - (((count / numAcross) + 1) * (newExtent.y + 2)) - 2;

            //find the minimized position and extent
            resize(newPosition, newExtent);

            //set the index so other windows will not try to minimize to the same location
            mMinimizeIndex = count;         
			}
			//set the flag
         mMinimized = true;
      }
   }
in guiControl.h find
RectI   mBounds;
and insert
// This variable is used for the children do not receive the required function parentResized 
// that if this happens when you restore the window he can change the size, etc.
bool    mResizeChildFlag;
find GuiControl::GuiControl() and insert
mResizeChildFlag = true;
find void GuiControl::resize(const Point2I &newPosition, const Point2I &newExtent)
and change
iterator i;
         for(i = begin(); i != end(); i++)
         {
            GuiControl *ctrl = static_cast<GuiControl *>(*i);
            ctrl->parentResized(mBounds.extent, actualNewExtent);
         }
to
if(mResizeChildFlag)
      {
         iterator i;
         for(i = begin(); i != end(); i++)
         {
            GuiControl *ctrl = static_cast<GuiControl *>(*i);
            ctrl->parentResized(mBounds.extent, actualNewExtent);
         }
      }

About the author


#1
01/31/2009 (10:24 pm)
Cool, thanks. You should put this in a code block though... use [ code] and [ /code]. =)
#2
02/01/2009 (4:52 am)
thanks for the tip