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

📄 guieditctrl.cc

📁 五行MMORPG引擎系统V1.0
💻 CC
📖 第 1 页 / 共 4 页
字号:
			dglDrawRectFill(box,m_maskColor);

			//绘画当前控件的所有子控件轮廓线
			Vector<SimObject *>::iterator i;
			for(i = mCurrentAddSet->begin(); i != mCurrentAddSet->end(); i++)
			{
				GuiControl *ctrl = dynamic_cast<GuiControl *>(*i);
				if(ctrl == NULL)
					continue;

				cext = ctrl->getExtent();
				ctOffset = ctrl->localToGlobalCoord(Point2I(0,0));
				RectI box(ctOffset.x,ctOffset.y, cext.x, cext.y);

	         dglDrawRect(box, m_outlineColor);
			}


#else
         RectI box(ctOffset.x, ctOffset.y, cext.x, cext.y);
			box.inset(-2, -2);
			dglDrawRect(box, ColorI(0,0,128,140));
			box.inset(1,1);
			dglDrawRect(box, ColorI(0,0,128,140));
			box.inset(1,1);
			dglDrawRect(box, ColorI(0,255,0,140));
			box.inset(1,1);
			dglDrawRect(box, ColorI(255,255,0,140));
			box.inset(1,1);
			dglDrawRect(box, ColorI(255,255,0,140));


#endif
      }
      Vector<GuiControl *>::iterator i;
      bool multisel = mSelectedControls.size() > 1;
      for(i = mSelectedControls.begin(); i != mSelectedControls.end(); i++)
      {
         GuiControl *ctrl = (*i);
         cext = ctrl->getExtent();
         ctOffset = ctrl->localToGlobalCoord(Point2I(0,0));
         RectI box(ctOffset.x,ctOffset.y, cext.x, cext.y);
         ColorI nutColor = multisel ? ColorI(255,255,255) : ColorI(0,0,0);
         ColorI outlineColor = multisel ? ColorI(0,0,0) : ColorI(255,255,255);
         if(!keyFocused)
            nutColor.set(128,128,128);

         drawNuts(box, outlineColor, nutColor);
      }
      if (mMouseDownMode == DragSelecting)
      {
         RectI b;
         getDragRect(b);
         b.point += offset;
         dglDrawRect(b, ColorI(255, 255, 255));
      }
   }

   renderChildControls(offset, updateRect);
}

bool GuiEditCtrl::selectionContains(GuiControl *ctrl)
{
   Vector<GuiControl *>::iterator i;
   for (i = mSelectedControls.begin(); i != mSelectedControls.end(); i++)
      if (ctrl == *i) return true;
   return false;
}

#ifdef TGE_RPG
bool GuiEditCtrl::pointInSelectionContains(const Point2I &pt)
{
   Vector<GuiControl *>::iterator i;
	Point2I	pos;
	RectI		rect;
   for (i = mSelectedControls.begin(); i != mSelectedControls.end(); i++)
	{ 
		if((*i) == NULL)
			continue;
		pos = (*i)->getPosition();
		if((*i)->getParent())
			pos = (*i)->getParent()->localToGlobalCoord(pos);
		rect.set(pos,(*i)->getExtent());
		if(rect.pointInRect(pt))
			return true;
	}
   return false;
}


void GuiEditCtrl::toggleToolBarVisible()
{
	GuiControl* pChild;
	U32 n;

	if(m_arToggleVisibles.size())
	{
		for(n=0; n<size(); n++)
		{
			pChild = m_arToggleVisibles[n];
			if(pChild == NULL)
				continue;
			pChild->setVisible(true);
		}
		m_arToggleVisibles.clear();
		return;
	}

	for(n=0; n<size(); n++)
	{
		pChild = dynamic_cast<GuiControl*>((*this)[n]);
		if(pChild == NULL || !pChild->isVisible())
			continue;
		m_arToggleVisibles.push_back(pChild);
		pChild->setVisible(false);
	}
}


#endif


void GuiEditCtrl::onRightMouseDown(const GuiEvent &event)
{
   if (! mActive)
   {
      Parent::onRightMouseDown(event);
      return;
   }
   setFirstResponder();

   //search for the control hit in any layer below the edit layer
#ifdef TGE_RPG
   GuiControl *hitCtrl = mContentControl->findAnyHitControl(globalToLocalCoord(event.mousePoint), mLayer - 1);
#else
   GuiControl *hitCtrl = mContentControl->findHitControl(globalToLocalCoord(event.mousePoint), mLayer - 1);
#endif
	setCurrentAddSet(hitCtrl);
   //if (hitCtrl != mCurrentAddSet)
   //{
   //   Con::executef(this, 1, "onClearSelected");
   //   mSelectedControls.clear();
   //   mCurrentAddSet = hitCtrl;
   //}

   //Design time mouse events
   GuiEvent designEvent = event;
   designEvent.mousePoint = mLastMousePos;
   hitCtrl->onRightMouseDownEditor( designEvent, localToGlobalCoord( Point2I(0,0) ) );

}
void GuiEditCtrl::select(GuiControl *ctrl)
{
   Con::executef(this, 1, "onClearSelected");
   mSelectedControls.clear();
   if(ctrl != mContentControl) {
      if (!(ctrl->isLocked())) {
         mSelectedControls.push_back(ctrl);
         Con::executef(this, 2, "onAddSelected", avar("%d", ctrl->getId()));
      }
   }else
      mCurrentAddSet = mContentControl;
}

void GuiEditCtrl::getCursor(GuiCursor *&cursor, bool &showCursor, const GuiEvent &lastGuiEvent)
{
   showCursor = true;
   
   Point2I ctOffset;
   Point2I cext;
   GuiControl *ctrl;

   Point2I mousePos  = globalToLocalCoord(lastGuiEvent.mousePoint);

   // first see if we hit a sizing knob on the currently selected control...
   if (mSelectedControls.size() == 1 && initCursors() == true )
   {
      ctrl = mSelectedControls.first();
      cext = ctrl->getExtent();
      ctOffset = globalToLocalCoord(ctrl->localToGlobalCoord(Point2I(0,0)));
      RectI box(ctOffset.x,ctOffset.y,cext.x, cext.y);

      GuiEditCtrl::sizingModes sizeMode = (GuiEditCtrl::sizingModes)getSizingHitKnobs(mousePos, box);

      if( mMouseDownMode == SizingSelection )
      {
         if ( ( mSizingMode == ( sizingBottom | sizingRight ) ) || ( mSizingMode == ( sizingTop | sizingLeft ) ) )
            cursor = mNWSECursor;
         else if (  ( mSizingMode == ( sizingBottom | sizingLeft ) ) || ( mSizingMode == ( sizingTop | sizingRight ) ) )
            cursor = mNESWCursor;
         else if ( mSizingMode == sizingLeft || mSizingMode == sizingRight ) 
            cursor = mLeftRightCursor;
         else if (mSizingMode == sizingTop || mSizingMode == sizingBottom )
            cursor = mUpDownCursor;
         else
            cursor = NULL;
      }
      else
      {
         // Check for current mouse position after checking for actual sizing mode
         if ( ( sizeMode == ( sizingBottom | sizingRight ) ) ||
            ( sizeMode == ( sizingTop | sizingLeft ) ) )
            cursor = mNWSECursor;
         else if ( ( sizeMode == ( sizingBottom | sizingLeft ) ) ||
            ( sizeMode == ( sizingTop | sizingRight ) ) )
            cursor = mNESWCursor;
         else if (sizeMode == sizingLeft || sizeMode == sizingRight )
            cursor = mLeftRightCursor;
         else if (sizeMode == sizingTop || sizeMode == sizingBottom )
            cursor = mUpDownCursor;
         else
            cursor = NULL;
      }
   }
   
   if( mMouseDownMode == MovingSelection && cursor == NULL )
       cursor = mMoveCursor;
}

void GuiEditCtrl::onMouseDown(const GuiEvent &event)
{
   if (! mActive)
   {
      Parent::onMouseDown(event);
      return;
   }
   if(!mContentControl)
      return;

	m_bDropCopyed = true;

   setFirstResponder();
   //lock the mouse
   mouseLock();

   Point2I ctOffset;
   Point2I cext;
   GuiControl *ctrl;

   mLastMousePos = globalToLocalCoord(event.mousePoint);

   // first see if we hit a sizing knob on the currently selected control...
   if (mSelectedControls.size() == 1)
   {
      ctrl = mSelectedControls.first();
      cext = ctrl->getExtent();
      ctOffset = globalToLocalCoord(ctrl->localToGlobalCoord(Point2I(0,0)));
      RectI box(ctOffset.x,ctOffset.y,cext.x, cext.y);

      if ((mSizingMode = (GuiEditCtrl::sizingModes)getSizingHitKnobs(mLastMousePos, box)) != 0)
      {
         mMouseDownMode = SizingSelection;
         return;
      }
   }

   if(!mCurrentAddSet)
      mCurrentAddSet = mContentControl;

#ifdef TGE_RPG
	bool bCanMove(false);
	//单击选中控件可拖动
   if (event.mouseClickCount == 1)
	{
		bCanMove = pointInSelectionContains(event.mousePoint);
		if(!bCanMove && mCurrentAddSet)
		{	
			//GuiControl* pParent = mCurrentAddSet->getParent();
			Point2I cursorPos = mCurrentAddSet->globalToLocalCoord(event.mousePoint);
			ctrl = mCurrentAddSet->findAnyHitControl(cursorPos, -2/*mCurrentAddSet->mLayer*/);
			//ctrl = mCurrentAddSet->findHitControl(cursorPos, -2/*mCurrentAddSet->mLayer*/);
		}
		else
			ctrl = mContentControl->findAnyHitControl(mLastMousePos, -2/*mCurrentAddSet->mLayer*/);
			//ctrl = mContentControl->findHitControl(mLastMousePos, -2/*mCurrentAddSet->mLayer*/);

		//}
		//else
		//	ctrl = NULL;
	}
	//双击进入目标控件内
	else if (event.mouseClickCount == 2)
	{
		//如果在当前控件外双击,则回到上一层(假如还没到根点的话)
		GuiControl*	pCurrentSet;
		//GuiControl*	pCurrentSetParent;
		Point2I		cursorPos;

		if(mCurrentAddSet)
			pCurrentSet = mCurrentAddSet;
		else
			pCurrentSet = mContentControl;

		//pCurrentSetParent = pCurrentSet->getParent();
		//if(!pCurrentSetParent)
		//	pCurrentSetParent = pCurrentSet;

		cursorPos	= pCurrentSet->globalToLocalCoord(event.mousePoint);
		ctrl			= pCurrentSet->findAnyHitControl(cursorPos,-2);
		//ctrl			= pCurrentSet->findHitControl(cursorPos,-2);
		if(ctrl && ctrl->getParent() == pCurrentSet)
		{
			setCurrentAddSet(ctrl);
		}
		else// if(pCurrentSet != mContentControl)
		{
			GuiControl* pParent = pCurrentSet->getParent();
			if(pParent && pParent != mContentControl->getParent())
			{
				Point2I cursorPos2 = pParent->globalToLocalCoord(event.mousePoint);
				if(!pCurrentSet->pointInControl(cursorPos2))
				{	
					GuiControl*	pBak = mCurrentAddSet;
					setCurrentAddSet(pParent);
					setSelection(pBak,true);
				}
			}
		}


		bCanMove = false;
	}
	else
	{
		ctrl = mContentControl->findAnyHitControl(mLastMousePos, mCurrentAddSet->mLayer);
		//ctrl = mContentControl->findHitControl(mLastMousePos, mCurrentAddSet->mLayer);
		bCanMove = selectionContains(ctrl);
	}

   if(!bCanMove)
	{
		bool bNeedCheckMove = true;
      //if we clicked in the current add set
      if (ctrl == mCurrentAddSet)
      {
         // start dragging a rectangle
         // if the shift is not down, nuke prior selection
         if (!(event.modifier & SI_SHIFT)) 
			{
            Con::executef(this, 1, "onClearSelected");
            mSelectedControls.clear();
         }
         mSelectionAnchor = mLastMousePos;
         mMouseDownMode = DragSelecting;
      }
      else
      {
         //find the new add set
         GuiControl *newAddSet = ctrl->getParent();

         //if we're holding shift and the ctrl is in the same add set
         if (event.modifier & SI_SHIFT && newAddSet == mCurrentAddSet)
         {            	
            if (!(ctrl->isLocked())) {
               mSelectedControls.push_back(ctrl);
               Con::executef(this, 2, "onAddSelected", avar("%d", ctrl->getId()));
            }
            mMouseDownMode = Selecting;
				bNeedCheckMove = false;
         }
         else if (ctrl != mContentControl)
         {
            //find and set the new add set
            mCurrentAddSet = ctrl->getParent();

            //clear and set the selected controls
            Con::executef(this, 1, "onClearSelected");
            mSelectedControls.clear();
            if (!(ctrl->isLocked())) {
               mSelectedControls.push_back(ctrl);
               Con::executef(this, 2, "onAddSelected", avar("%d", ctrl->getId()));
            }
            mMouseDownMode = Selecting;
         }
         else
            mMouseDownMode = Selecting;
      }


		//重新检测是否在选中区域内
		if(bNeedCheckMove)
			bCanMove = pointInSelectionContains(event.mousePoint);
		else
			bCanMove = false;
   }



	if(bCanMove)
#else
   //find the control we clicked
   ctrl = mContentControl->findAnyHitControl(mLastMousePos, mCurrentAddSet->mLayer);
   //ctrl = mContentControl->findHitControl(mLastMousePos, mCurrentAddSet->mLayer);

   if (selectionContains(ctrl))
#endif

   {
      //if we're holding shift, de-select the clicked ctrl
      if (event.modifier & SI_SHIFT)
      {
         Vector<GuiControl *>::iterator i;
         for(i = mSelectedControls.begin(); i != mSelectedControls.end(); i++)
         {
            if (*i == ctrl)
            {
               Con::executef(this, 2, "onRemoveSelected", avar("%d", ctrl->getId()));
               mSelectedControls.erase(i);
               break;
            }
         }

         //set the mode
         mMouseDownMode = Selecting;
      }
      else //else we hit a ctrl we've already selected, so set the mode to moving
      {
         // For calculating mouse delta
         mDragBeginPoint = event.mousePoint;

         // Allocate enough space for our selected controls
         mDragBeginPoints.reserve( mSelectedControls.size() );

         // For snapping to origin
         Vector<GuiControl *>::iterator i;
         for(i = mSelectedControls.begin(); i != mSelectedControls.end(); i++)
            mDragBeginPoints.push_back( (*i)->mBounds.point );

         // Set Mouse Mode
         mMouseDownMode = MovingSelection;
#ifdef TGE_RPG

⌨️ 快捷键说明

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