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

📄 guicanvas.cc

📁 五行MMORPG引擎系统V1.0
💻 CC
📖 第 1 页 / 共 3 页
字号:
         Point2F pt(cursorPt.x, cursorPt.y);

         if (event->objType == SI_XAXIS)
         {
            pt.x += (event->fValue * mPixelsPerMickey);
            cursorPt.x = getMax(0, getMin((S32)pt.x, mBounds.extent.x - 1));
            if (oldpt.x != S32(cursorPt.x))
               moved = true;
         }
         else
         {
            pt.y += (event->fValue * mPixelsPerMickey);
            cursorPt.y = getMax(0, getMin((S32)pt.y, mBounds.extent.y - 1));
            if (oldpt.y != S32(cursorPt.y))
               moved = true;
         }
         if (moved)
         {
            mLastEvent.mousePoint.x = S32(cursorPt.x);
            mLastEvent.mousePoint.y = S32(cursorPt.y);

#ifdef TGE_RPG
				if (mMouseButtonDrag)
				{
					if (mMouseButtonDown)
						rootMouseDragged(mLastEvent);
					else if (mMouseRightButtonDown)
						rootRightMouseDragged(mLastEvent);
					else if(mMouseMiddleButtonDown)
						rootMiddleMouseDragged(mLastEvent);
					else
						rootMouseMove(mLastEvent);
				}
				else
				{
					rootMouseMove(mLastEvent);
				}
#else
            if (mMouseButtonDown)
               rootMouseDragged(mLastEvent);
            else if (mMouseRightButtonDown)
               rootRightMouseDragged(mLastEvent);
            else if(mMouseMiddleButtonDown)
               rootMiddleMouseDragged(mLastEvent);
            else
               rootMouseMove(mLastEvent);
#endif
         }
         return true;
      }
		else if ( event->objType == SI_ZAXIS )
		{
         mLastEvent.mousePoint.x = S32( cursorPt.x );
         mLastEvent.mousePoint.y = S32( cursorPt.y );

			if ( event->fValue < 0.0f )
            rootMouseWheelDown( mLastEvent );
			else
            rootMouseWheelUp( mLastEvent );
      }
      else if(event->objType == SI_BUTTON)
      {
#ifdef TGE_RPG
			bool bDBlk;
			F32	cx = m_dblClkCursorPt.x - cursorPt.x;
			F32	cy = m_dblClkCursorPt.y - cursorPt.y;
			m_dblClkCursorPt	= cursorPt;
			bDBlk	 = (cx*cx + cy*cy < 100.f);
#endif
         //copy the cursor point into the event
         mLastEvent.mousePoint.x = S32(cursorPt.x);
         mLastEvent.mousePoint.y = S32(cursorPt.y);

         if(event->objInst == KEY_BUTTON0) // left button
         {
            //see if button was pressed
            if (event->action == SI_MAKE)
            {
               U32 curTime = Platform::getVirtualMilliseconds();
               mNextMouseTime = curTime + mInitialMouseDelay;

               //if the last button pressed was the left...
               if (mLeftMouseLast)
               {
#ifdef TGE_RPG
                  if (curTime - mLastMouseDownTime <= 500 && bDBlk)
#else
                  //if it was within the double click time count the clicks
                  if (curTime - mLastMouseDownTime <= 500)
#endif
                     mLastMouseClickCount++;
                  else
                     mLastMouseClickCount = 1;
               }
               else
               {
                  mLeftMouseLast = true;
                  mLastMouseClickCount = 1;
               }

               mLastMouseDownTime = curTime;
               mLastEvent.mouseClickCount = mLastMouseClickCount;

               rootMouseDown(mLastEvent);
            }
            //else button was released
            else
            {
               mNextMouseTime = 0xFFFFFFFF;
               rootMouseUp(mLastEvent);
            }
            return true;
         }
         else if(event->objInst == KEY_BUTTON1) // right button
         {
            if(event->action == SI_MAKE)
            {
               U32 curTime = Platform::getVirtualMilliseconds();

               //if the last button pressed was the right...
               if (! mLeftMouseLast)
               {
                  //if it was within the double click time count the clicks
#ifdef TGE_RPG
                  if (curTime - mLastMouseDownTime <= 50 && bDBlk)
#else
                  if (curTime - mLastMouseDownTime <= 50)
#endif
                     mLastMouseClickCount++;
                  else
                     mLastMouseClickCount = 1;
               }
               else
               {
                  mLeftMouseLast = false;
                  mLastMouseClickCount = 1;
               }

               mLastMouseDownTime = curTime;
               mLastEvent.mouseClickCount = mLastMouseClickCount;

               rootRightMouseDown(mLastEvent);
            }
            else // it was a mouse up
               rootRightMouseUp(mLastEvent);
            return true;
         }
         else if(event->objInst == KEY_BUTTON2) // middle button
         {
            if(event->action == SI_MAKE)
            {
               U32 curTime = Platform::getVirtualMilliseconds();

               //if the last button pressed was the right...
               if (! mMiddleMouseLast)
               {
                  //if it was within the double click time count the clicks
#ifdef TGE_RPG
                  if (curTime - mLastMouseDownTime <= 50 && bDBlk)
#else
                  if (curTime - mLastMouseDownTime <= 50)
#endif
                     mLastMouseClickCount++;
                  else
                     mLastMouseClickCount = 1;
               }
               else
               {
                  mMiddleMouseLast = false;
                  mLastMouseClickCount = 1;
               }

               mLastMouseDownTime = curTime;
               mLastEvent.mouseClickCount = mLastMouseClickCount;

               rootMiddleMouseDown(mLastEvent);
            }
            else // it was a mouse up
               rootMiddleMouseUp(mLastEvent);
            return true;
         }
      }
   }
   return false;
}

void GuiCanvas::rootMouseDown(const GuiEvent &event)
{
#ifdef TGE_RPG
	mMouseButtonDrag = false;
   mPointDragStart = event.mousePoint;
#endif
   mPrevMouseTime = Platform::getVirtualMilliseconds();
   mMouseButtonDown = true;

   //pass the event to the mouse locked control
   if (bool(mMouseCapturedControl))
      mMouseCapturedControl->onMouseDown(event);

   //else pass it to whoever is underneath the cursor
   else
   {
      iterator i;
      i = end();
      while (i != begin())
      {
         i--;
         GuiControl *ctrl = static_cast<GuiControl *>(*i);
#ifdef TGE_RPG
			/*ctrl->m_bAutoSize &&*/
			if(!ctrl->mProfile->mModal &&  !ctrl->pointInControl(event.mousePoint))
				continue;
         GuiControl *controlHit = ctrl->findHitControl(event.mousePoint - ctrl->getPosition());

#else
         GuiControl *controlHit = ctrl->findHitControl(event.mousePoint);
#endif
         //see if the controlHit is a modeless dialog...
         if ((! controlHit->mActive) && (! controlHit->mProfile->mModal))
            continue;
         else
         {
            controlHit->onMouseDown(event);
            break;
         }
      }
   }
   if (bool(mMouseControl))
      mMouseControlClicked = true;
}

void GuiCanvas::findMouseControl(const GuiEvent &event)
{
   if(size() == 0)
   {
      mMouseControl = NULL;
      return;
   }
   GuiControl *controlHit = findHitControl(event.mousePoint);
   if(controlHit != static_cast<GuiControl*>(mMouseControl))
   {
      if(bool(mMouseControl))
         mMouseControl->onMouseLeave(event);
      mMouseControl = controlHit;
      mMouseControl->onMouseEnter(event);
   }
}

void GuiCanvas::refreshMouseControl()
{
   GuiEvent evt;
   evt.mousePoint.x = S32(cursorPt.x);
   evt.mousePoint.y = S32(cursorPt.y);
   findMouseControl(evt);
}

void GuiCanvas::rootMouseUp(const GuiEvent &event)
{
   mPrevMouseTime = Platform::getVirtualMilliseconds();
   mMouseButtonDown = false;

   //pass the event to the mouse locked control
   if (bool(mMouseCapturedControl))
      mMouseCapturedControl->onMouseUp(event);
   else
   {
      findMouseControl(event);
      if(bool(mMouseControl))
         mMouseControl->onMouseUp(event);
   }
#ifdef TGE_RPG
	mMouseButtonDrag = false;
#endif
}

void GuiCanvas::checkLockMouseMove(const GuiEvent &event)
{
	GuiControl *controlHit = findHitControl(event.mousePoint);
   if(controlHit != mMouseControl)
   {
      if(mMouseControl == mMouseCapturedControl)
         mMouseCapturedControl->onMouseLeave(event);
      else if(controlHit == mMouseCapturedControl)
         mMouseCapturedControl->onMouseEnter(event);
      mMouseControl = controlHit;
   }
}

void GuiCanvas::rootMouseDragged(const GuiEvent &event)
{
   //pass the event to the mouse locked control
   if (bool(mMouseCapturedControl))
   {
      checkLockMouseMove(event);
      mMouseCapturedControl->onMouseDragged(event);
   }
   else
   {
      findMouseControl(event);
      if(bool(mMouseControl))
         mMouseControl->onMouseDragged(event);
   }
}

void GuiCanvas::rootMouseMove(const GuiEvent &event)
{

#ifdef TGE_RPG
	if((mMouseButtonDown || mMouseRightButtonDown || mMouseMiddleButtonDown) && !mMouseButtonDrag)
	{
		Point2I ptDiff = mPointDragStart - event.mousePoint;
		if(ptDiff.x * ptDiff.x + ptDiff.y * ptDiff.y < MOUSE_DRAG_DIFF)
			mMouseButtonDrag = false;
		else
			mMouseButtonDrag = true;
	}
#endif

   if (bool(mMouseCapturedControl))
   {
      checkLockMouseMove(event);
      mMouseCapturedControl->onMouseMove(event);
   }
   else
   {
      findMouseControl(event);
      if(bool(mMouseControl))
         mMouseControl->onMouseMove(event);
   }
}

void GuiCanvas::rootRightMouseDown(const GuiEvent &event)
{
#ifdef TGE_RPG
	mMouseButtonDrag = false;
   mPointDragStart = event.mousePoint;
#endif
   mPrevMouseTime = Platform::getVirtualMilliseconds();
   mMouseRightButtonDown = true;

   if (bool(mMouseCapturedControl))
      mMouseCapturedControl->onRightMouseDown(event);
   else
   {
      findMouseControl(event);

      if(bool(mMouseControl))
      {
         mMouseControl->onRightMouseDown(event);
      }
   }
}

void GuiCanvas::rootRightMouseUp(const GuiEvent &event)
{
   mPrevMouseTime = Platform::getVirtualMilliseconds();
   mMouseRightButtonDown = false;

   if (bool(mMouseCapturedControl))
      mMouseCapturedControl->onRightMouseUp(event);
   else
   {
      findMouseControl(event);

      if(bool(mMouseControl))
         mMouseControl->onRightMouseUp(event);
   }
#ifdef TGE_RPG
	mMouseButtonDrag = false;
#endif
}

void GuiCanvas::rootRightMouseDragged(const GuiEvent &event)
{
   mPrevMouseTime = Platform::getVirtualMilliseconds();

   if (bool(mMouseCapturedControl))
   {
      checkLockMouseMove(event);
      mMouseCapturedControl->onRightMouseDragged(event);
   }
   else
   {
      findMouseControl(event);

      if(bool(mMouseControl))
         mMouseControl->onRightMouseDragged(event);
   }
}

void GuiCanvas::rootMiddleMouseDown(const GuiEvent &event)
{
#ifdef TGE_RPG
	mMouseButtonDrag = false;
   mPointDragStart = event.mousePoint;
#endif

   mPrevMouseTime = Platform::getVirtualMilliseconds();
   mMouseMiddleButtonDown = true;

   if (bool(mMouseCapturedControl))
      mMouseCapturedControl->onMiddleMouseDown(event);
   else
   {
      findMouseControl(event);

      if(bool(mMouseControl))
      {
         mMouseControl->onMiddleMouseDown(event);
      }
   }
}

void GuiCanvas::rootMiddleMouseUp(const GuiEvent &event)
{
   mPrevMouseTime = Platform::getVirtualMilliseconds();
   mMouseMiddleButtonDown = false;

   if (bool(mMouseCapturedControl))
      mMouseCapturedControl->onMiddleMouseUp(event);
   else
   {
      findMouseControl(event);

      if(bool(mMouseControl))
         mMouseControl->onMiddleMouseUp(event);
   }
#ifdef TGE_RPG
	mMouseButtonDrag = false;
#endif
}

void GuiCanvas::rootMiddleMouseDragged(const GuiEvent &event)
{
   mPrevMouseTime = Platform::getVirtualMilliseconds();

   if (bool(mMouseCapturedControl))
   {
      checkLockMouseMove(event);
      mMouseCapturedControl->onMiddleMouseDragged(event);
   }
   else
   {
      findMouseControl(event);

      if(bool(mMouseControl))
         mMouseControl->onMiddleMouseDragged(event);
   }
}

void GuiCanvas::rootMouseWheelUp(const GuiEvent &event)
{
   if (bool(mMouseCapturedControl))
      mMouseCapturedControl->onMouseWheelUp(event);
   else
   {
      findMouseControl(event);

      if (bool(mMouseControl))
         mMouseControl->onMouseWheelUp(event);
   }
}

void GuiCanvas::rootMouseWheelDown(const GuiEvent &event)
{
//#ifdef TGE_RPG
//	mMouseButtonDrag = false;
//   mPointDragStart = event.mousePoint;
//#endif
   if (bool(mMouseCapturedControl))
      mMouseCapturedControl->onMouseWheelDown(event);
   else
   {
      findMouseControl(event);

      if (bool(mMouseControl))
         mMouseControl->onMouseWheelDown(event);
   }
}





//-----------------------------------------------------
//IME

void GuiCanvas::PushIMEControl(GuiControl *gui)
{
	if(gui == NULL || m_pIMEControl != NULL)// || m_pTopControl == gui)
		return;

	//从堆栈中找出顶层窗口
	m_pTopControl = static_cast<GuiControl*>(last());
	m_pIMEControl = gui;

   addObject(gui);

	if(m_pTopControl)
		gui->mLayer = m_pTopControl->mLayer+1;
	else
		gui->mLayer = 1;

   resetUpdateRegions();
   
   //rebuild the accelerator map
   //mAcceleratorMap.clear();
   //if (size() > 0)
   //{
   //   GuiControl *ctrl = m_pTopControl ;//static_cast<GuiControl *>(last());  //IME
   //   ctrl->buildAcceleratorMap();
   //}
   //refreshMouseControl();
}


void GuiCanvas::PopIMEControl()
{
	if(m_pIMEControl == NULL )
		return;

	removeObject(m_pIMEControl);
	m_pTopControl = static_cast<GuiControl*>(last());
	m_pIMEControl = NULL;
}


void GuiCanvas::UpdateTopControl()
{
	//最高层窗口调整
	if(m_pIMEControl)
	{
		//获取倒数第2个为代理顶层窗口
		U32 nSize = size();
		if(nSize > 1)
			m_pTopControl = static_cast<GuiControl*>((*this)[nSize-2]);
		else
			m_pTopControl = NULL;
	}
	else
		m_pTopControl = static_cast<GuiControl*>(last());
}

//-------------------------------------------------------------




void GuiCanvas::setContentControl(GuiControl *gui)
{
   if(!gui)
      return;

   //remove all dialogs on layer 0
   U32 index = 0;
   while (size() > index)
   {
      GuiControl *ctrl = static_cast<GuiControl*>((*this)[index]);
      if (ctrl == gui || ctrl->mLayer != 0)
         index++;

      removeObject(ctrl);
      Sim::getGuiGroup()->addObject(ctrl);
   }

   // lose the first responder from the old GUI
   GuiControl *oldResponder = mFirstResponder;
   mFirstResponder = gui->findFirstTabable();
   if(oldResponder && oldResponder != mFirstResponder)
      oldResponder->onLoseFirstResponder();

   //add the gui to the front
   if(!size() || gui != (*this)[0])
   {
      // automatically wakes objects in GuiControl::onWake
      addObject(gui);
      if (size() >= 2)
         reOrder(gui, *begin());
   }
   //refresh the entire gui
   resetUpdateRegions();

#ifdef TGE_RPG
	removeAllAccelMaps();
	addAccelMaps(gui);
#else
   //rebuild the accelerator map
   mAcceleratorMap.clear();

   for(iterator i = end(); i != begin() ; )
   {
      i--;

⌨️ 快捷键说明

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