⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 guitoolwindowctrl.cc

📁 五行MMORPG引擎系统V1.0
💻 CC
📖 第 1 页 / 共 3 页
字号:

      //see if we clicked on the bottom edge (as well)
      if (mResizeHeight && (localPoint.y > mBounds.extent.y - mResizeBottomHeight))
      {
         mMouseResizeHeight = true;
			mMouseMovingWin = false;
      }
   }


   if (mMouseMovingWin || mMouseResizeWidth || mMouseResizeHeight ||
         mPressClose /*|| mPressMaximize || mPressMinimize*/)
   {
      mouseLock();
   }
   else
   {
      GuiControl *ctrl = findHitControl(localPoint);
      if (ctrl && ctrl != this)
         ctrl->onMouseDown(event);
   }


}

void GuiToolWindowCtrl::onMouseDragged(const GuiEvent &event)
{
   GuiControl *parent	= getParent();
   GuiCanvas *root		= getRoot();
   if (! root) return;

   Point2I deltaMousePosition = event.mousePoint - mMouseDownPosition;

   Point2I newPosition = mBounds.point;
   Point2I newExtent = mBounds.extent;
   bool update = false;
   if (mMouseMovingWin && parent)
   {
      newPosition.x = getMax(0, getMin(parent->mBounds.extent.x - mBounds.extent.x, mOrigBounds.point.x + deltaMousePosition.x));
      newPosition.y = getMax(0, getMin(parent->mBounds.extent.y - mBounds.extent.y, mOrigBounds.point.y + deltaMousePosition.y));
      update = true;
   }
   else if(mPressClose /*|| mPressMaximize || mPressMinimize*/)
   {
      setUpdate();
   }
   else
   {
      if (mMouseResizeWidth && parent)
      {
         newExtent.x = getMax(0, getMax(mMinSize.x, getMin(parent->mBounds.extent.x, mOrigBounds.extent.x + deltaMousePosition.x)));
         update = true;
      }

      if (mMouseResizeHeight && parent)
      {
         newExtent.y = getMax(0, getMax(mMinSize.y, getMin(parent->mBounds.extent.y, mOrigBounds.extent.y + deltaMousePosition.y)));
         update = true;
      }
   }

   if (update)
   {
      Point2I pos = parent->localToGlobalCoord(mBounds.point);
      root->addUpdateRegion(pos, mBounds.extent);
      resize(newPosition, newExtent);
   }
}

void GuiToolWindowCtrl::onMouseUp(const GuiEvent &event)
{
	if(!mMinimized && ms_pAutoExpandTool == this)
		ms_pAutoExpandTool = NULL;

   bool closing = mPressClose;
   mPressClose = false;

   event;
   mouseUnlock();

   mMouseMovingWin = false;
   mMouseResizeWidth = false;
   mMouseResizeHeight = false;

   GuiControl *parent = getParent();
   if (! parent)
      return;

   //see if we take an action
   Point2I localPoint = globalToLocalCoord(event.mousePoint);
   if (closing && mCloseButton.pointInRect(localPoint))
   {

   	char buf[16];
      dSprintf(buf, sizeof(buf), "%d", getId());
      Con::setVariable("$ThisControl", buf);
      Con::evaluate(mCloseCommand);
   }
	//else
	//	setAlwaysShow();



}

void GuiToolWindowCtrl::onRightMouseDown(const GuiEvent &event)
{
   setUpdate();
}


void GuiToolWindowCtrl::onRightMouseUp(const GuiEvent &event)
{
   setUpdate();

	if( event.modifier == SI_LCTRL || event.modifier == SI_RCTRL)
	{
		ToggleVertMode(/*event*/);
	}
	else
		setAlwaysShow();
}


void GuiToolWindowCtrl::setAlwaysShow()
{
	if(mCanMinimize)
	{
		//如自动展开状态取消计时器,并设为expand状态,否则

		if(m_nExpandTimer != 0 && ms_pAutoExpandTool == this)
		{	
			ms_pAutoExpandTool = NULL;
		}

		if(m_nExpandTimer > 0)
		{
			m_nExpandTimer = 0;
			m_bAlwaysShow = true;
		}
		else
		{
			m_bAlwaysShow = !m_bAlwaysShow;
		}
		ToggleMiniMode(!m_bAlwaysShow);
	}
}



void GuiToolWindowCtrl::ToggleVertMode(/*const GuiEvent &event*/)
{
	if(mMinimized || !m_bCanVerticalBar)
		return;
	//把 w,h值互换
	//把所有 子控件 x,y坐标互换,只处理直接子控件
	m_bVerticalBar = !m_bVerticalBar;
	ToggleVH(m_bVerticalBar,this);
	GuiControl* pChild;
	for(iterator it = begin(); it != end(); it++)
	{
		pChild = dynamic_cast<GuiControl*>(*it);
		if(pChild)
			pChild->ToggleVH(m_bVerticalBar,this);
	}
	//PositionButtons();
	autoSizeToContent();

	//Point2I ptCursor(mBounds.point.x + event.mousePoint.y - mBounds.point.y , 
	//					mBounds.point.y + event.mousePoint.x - mBounds.point.x);
	//Canvas->setCursorPos(ptCursor);

}


void GuiToolWindowCtrl::autoSizeToContent()
{

	if(!mBitmapBounds)
		return;

	if(m_bAutoSize)//m_marginTopLeft.isZero() && m_marginBottomRight.isZero() )
	{
		if(m_bVerticalBar)
		{	
			m_marginTopLeft.set(mBitmapBounds[VBorderLeftKey].extent.x,mBitmapBounds[VBorderTop].extent.y);
			m_marginBottomRight	= Point2I(mBitmapBounds[VBorderRight].extent.x,mBitmapBounds[VBorderBottom].extent.y);
		}
		else if(m_marginTopLeft.isZero())
		{	
			m_marginTopLeft.set(mBitmapBounds[BorderLeft].extent.x,mBitmapBounds[BorderTopKey].extent.y);
			m_marginBottomRight	= Point2I(mBitmapBounds[BorderRight].extent.x,mBitmapBounds[BorderBottom].extent.y);
		}
	}

	Parent::autoSizeToContent();

	m_boundBak = mBounds.extent;
	if(m_boundBak.x < mTitleHeight*2)
		m_boundBak.x = m_boundOrigin.x;
	if(m_boundBak.y < mTitleHeight*2)
		m_boundBak.y = m_boundOrigin.y;
}



void GuiToolWindowCtrl::ToggleMiniMode(bool bMin)
{
	if(!mCanMinimize)
		return; 

	mMinimized = bMin;
	if(mMinimized)
	{
		//m_boundBak			= mBounds.extent;//都备份,以免缩小状态下进行水平切换,引起错误
		if(m_bVerticalBar)
			mBounds.extent.x	= mTitleHeight;
		else
			mBounds.extent.y	= mTitleHeight;
	}
	else
	{
		if(m_bVerticalBar)
			mBounds.extent.x	= m_boundBak.x;
		else
			mBounds.extent.y	= m_boundBak.y;
	}

	//GuiControl::re;
}


GuiControl *GuiToolWindowCtrl::findNextTabable(GuiControl *curResponder, bool firstCall)
{
   //set the global if this is the first call (directly from the canvas)
   if (firstCall)
   {
      GuiControl::smCurResponder = NULL;
   }

   //if the window does not already contain the first responder, return false
   //ie.  Can't tab into or out of a window
   if (! ControlIsChild(curResponder))
   {
      return NULL;
   }

   //loop through, checking each child to see if it is the one that follows the firstResponder
   GuiControl *tabCtrl = NULL;
   iterator i;
   for (i = begin(); i != end(); i++)
   {
      GuiControl *ctrl = static_cast<GuiControl *>(*i);
      tabCtrl = ctrl->findNextTabable(curResponder, false);
      if (tabCtrl) break;
   }

   //to ensure the tab cycles within the current window...
   if (! tabCtrl)
   {
      tabCtrl = findFirstTabable();
   }

   mFirstResponder = tabCtrl;
   return tabCtrl;
}

GuiControl *GuiToolWindowCtrl::findPrevTabable(GuiControl *curResponder, bool firstCall)
{
   if (firstCall)
   {
      GuiControl::smPrevResponder = NULL;
   }

   //if the window does not already contain the first responder, return false
   //ie.  Can't tab into or out of a window
   if (! ControlIsChild(curResponder))
   {
      return NULL;
   }

   //loop through, checking each child to see if it is the one that follows the firstResponder
   GuiControl *tabCtrl = NULL;
   iterator i;
   for (i = begin(); i != end(); i++)
   {
      GuiControl *ctrl = static_cast<GuiControl *>(*i);
      tabCtrl = ctrl->findPrevTabable(curResponder, false);
      if (tabCtrl) break;
   }

   //to ensure the tab cycles within the current window...
   if (! tabCtrl)
   {
      tabCtrl = findLastTabable();
   }

   mFirstResponder = tabCtrl;
   return tabCtrl;
}

bool GuiToolWindowCtrl::onKeyDown(const GuiEvent &event)
{
   //if this control is a dead end, kill the event
   if ((! mVisible) || (! mActive) || (! mAwake)) return true;

   if ((event.keyCode == KEY_TAB) && (event.modifier & SI_CTRL))
   {
      //find the next sibling window, and select it
      GuiControl *parent = getParent();
      if (parent)
      {
         GuiToolWindowCtrl *firstWindow = NULL;
         iterator i;
         for (i = parent->begin(); i != parent->end(); i++)
         {
            GuiToolWindowCtrl *ctrl = dynamic_cast<GuiToolWindowCtrl *>(*i);
            if (ctrl && ctrl->getTabIndex() == mTabIndex + 1)
            {
               ctrl->selectWindow();
               return true;
            }
            else if (ctrl && ctrl->getTabIndex() == 0)
            {
               firstWindow = ctrl;
            }
         }
         //recycle from the beginning
         if (firstWindow != this)
         {
            firstWindow->selectWindow();
            return true;
         }
      }
   }

   return Parent::onKeyDown(event);
}


bool GuiToolWindowCtrl::toggleVisible()
{
   if(isVisible())
	{	
		GuiControl *parent = getParent();
		if(parent && parent->last() == this )
		{
			setVisible(FALSE);
		}
		else
		{
			selectWindow();
		}
	}
	else
	{
		setVisible(TRUE);
		selectWindow();
	}
	return isVisible();


}


void GuiToolWindowCtrl::selectWindow(void)
{
   //first make sure this window is the front most of its siblings
   GuiControl *parent = getParent();
   if (parent)
   {
      parent->pushObjectToBack(this);
   }

   //also set the first responder to be the one within this window
   setFirstResponder(mFirstResponder);
}

void GuiToolWindowCtrl::drawWinRect(const RectI &myRect)
{
   Point2I bl = myRect.point;
   Point2I tr;
   tr.x = myRect.point.x + myRect.extent.x - 1;
   tr.y = myRect.point.y + myRect.extent.y - 1;
   dglDrawRectFill(myRect, mProfile->mFillColor);
   dglDrawLine(Point2I(bl.x + 1, tr.y), Point2I(bl.x + 1, bl.y), ColorI(255, 255, 255));
   dglDrawLine(Point2I(bl.x, tr.y + 1), Point2I(tr.x, tr.y + 1), ColorI(255, 255, 255));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -