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

📄 guieditctrl.cc

📁 五行MMORPG引擎系统V1.0
💻 CC
📖 第 1 页 / 共 4 页
字号:
			m_bDropCopyed	= false;	//可以拖拉复制了
#endif
      }
   }

#ifdef TGE_RPG
   //else if(ctrl)
#else
   //else we clicked on an unselected control
   else
   {
      //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;
         }
         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;
      }
   }
#endif

   //Design time mouse events
   GuiEvent designEvent = event;
   designEvent.mousePoint = mLastMousePos;

#ifdef TGE_RPG
	if(ctrl)
#endif
   ctrl->onMouseDownEditor( designEvent, localToGlobalCoord( Point2I(0,0) ) );

}

void GuiEditCtrl::addSelection(S32 id)
{
   GuiControl * ctrl;
   if(Sim::findObject(id, ctrl))
      mSelectedControls.push_back(ctrl);

}
void GuiEditCtrl::removeSelection(S32 id)
{
   GuiControl * ctrl;
   if (Sim::findObject(id, ctrl)) {
      Vector<GuiControl *>::iterator i;
      for(i = mSelectedControls.begin(); i != mSelectedControls.end(); i++)
      {
         if (*i == ctrl)
         {
            mSelectedControls.erase(i);
            break;
         }
      }
   }
}
void GuiEditCtrl::onMouseUp(const GuiEvent &event)
{
   if (! mActive)
   {
      Parent::onMouseUp(event);
      return;
   }

   //unlock the mouse
   mouseUnlock();

//#ifdef TGE_RPG
//   if ((event.modifier&SI_CTRL) && mMouseDownMode == MovingSelection && mSelectedControls.size())
//	{
//		copySelection();
//		parseSelection();
//		//return;
//	}
//#endif

   // Reset Drag Axis Alignment Information
   mDragBeginPoint.set(-1,-1);
   mDragBeginPoints.clear();

   mLastMousePos = globalToLocalCoord(event.mousePoint);
   if (mMouseDownMode == DragSelecting)
   {
      RectI b;
      getDragRect(b);
      GuiControl::iterator i;
      for(i = mCurrentAddSet->begin(); i != mCurrentAddSet->end(); i++)
      {
         GuiControl *ctrl = dynamic_cast<GuiControl *>(*i);
         Point2I upperL = globalToLocalCoord(ctrl->localToGlobalCoord(Point2I(0,0)));
         Point2I lowerR = upperL + ctrl->mBounds.extent - Point2I(1, 1);

         if (b.pointInRect(upperL) && b.pointInRect(lowerR) && !selectionContains(ctrl)) {
            if (!(ctrl->isLocked())) {
               mSelectedControls.push_back(ctrl);
               Con::executef(this, 2, "onAddSelected", avar("%d", ctrl->getId()));
            }
         }
      }
   }
   if (mSelectedControls.size() == 1)
      Con::executef(this, 2, "onSelect", avar("%d", mSelectedControls[0]->getId()));

   setFirstResponder();
   //reset the mouse mode
   mMouseDownMode = Selecting;
}

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

   if(!mCurrentAddSet)
      mCurrentAddSet = mContentControl;

   Point2I mousePoint = globalToLocalCoord(event.mousePoint);

   if (mMouseDownMode == SizingSelection)
   {
      if (mGridSnap.x)
         mousePoint.x -= mousePoint.x % mGridSnap.x;
      if (mGridSnap.y)
         mousePoint.y -= mousePoint.y % mGridSnap.y;

      GuiControl *ctrl = mSelectedControls.first();
      Point2I ctrlPoint = mCurrentAddSet->globalToLocalCoord(event.mousePoint);
      Point2I newPosition = ctrl->getPosition();
      Point2I newExtent = ctrl->getExtent();
      Point2I minExtent = ctrl->getMinExtent();

      if (mSizingMode & sizingLeft)
      {
         newPosition.x = ctrlPoint.x;
         newExtent.x = ctrl->mBounds.extent.x + ctrl->mBounds.point.x - ctrlPoint.x;
         if(newExtent.x < minExtent.x)
         {
            newPosition.x -= minExtent.x - newExtent.x;
            newExtent.x = minExtent.x;
         }
      }
      else if (mSizingMode & sizingRight)
      {
         newExtent.x = ctrlPoint.x - ctrl->mBounds.point.x;
         if(newExtent.x < minExtent.x)
            newExtent.x = minExtent.x;
      }

      if (mSizingMode & sizingTop)
      {
         newPosition.y = ctrlPoint.y;
         newExtent.y = ctrl->mBounds.extent.y + ctrl->mBounds.point.y - ctrlPoint.y;
         if(newExtent.y < minExtent.y)
         {
            newPosition.y -= minExtent.y - newExtent.y;
            newExtent.y = minExtent.y;
         }
      }
      else if (mSizingMode & sizingBottom)
      {
         newExtent.y = ctrlPoint.y - ctrl->mBounds.point.y;
         if(newExtent.y < minExtent.y)
            newExtent.y = minExtent.y;
      }

      ctrl->resize(newPosition, newExtent);
      mCurrentAddSet->childResized(ctrl);
      Con::executef(this, 2, "onSelect", avar("%d", mSelectedControls[0]->getId()));
   }

#ifdef TGE_RPG

   else if (mMouseDownMode == MovingSelection && mSelectedControls.size())
	{
		if (!m_bDropCopyed  && (event.modifier&SI_CTRL))
		{
			copySelection();
			parseSelection();
			m_bDropCopyed = true;
			//return;
		}

#else
   else if (mMouseDownMode == MovingSelection && mSelectedControls.size())
#endif
   {
      Vector<GuiControl *>::iterator i = mSelectedControls.begin();
      Point2I minPos = (*i)->mBounds.point;
      for(; i != mSelectedControls.end(); i++)
      {
         if ((*i)->mBounds.point.x < minPos.x)
            minPos.x = (*i)->mBounds.point.x;
         if ((*i)->mBounds.point.y < minPos.y)
            minPos.y = (*i)->mBounds.point.y;
      }
      Point2I delta = mousePoint - mLastMousePos;
      delta += minPos; // find new minPos;

      if (mGridSnap.x)
         delta.x -= delta.x % mGridSnap.x;
      if (mGridSnap.y)
         delta.y -= delta.y % mGridSnap.y;

      delta -= minPos;

      // Do we want to align this drag to the X and Y axes within a certain threshold?
      if( event.modifier & SI_SHIFT )
      {
         Point2I dragTotalDelta = event.mousePoint - mDragBeginPoint;
         bool snapToOriginX = false;
         bool snapToOriginY = false;
         if( dragTotalDelta.y < 10 && dragTotalDelta.y > -10 )
         {
            for(S32 i = 0; i < mSelectedControls.size(); i++)
            {
               Point2I snapBackPoint( mSelectedControls[i]->mBounds.point.x, mDragBeginPoints[i].y);
               // This is kind of nasty but we need to snap back if we're not at origin point with selection - JDD
               if( mSelectedControls[i]->mBounds.point.y != mDragBeginPoints[i].y )
                  mSelectedControls[i]->resize( snapBackPoint, mSelectedControls[i]->mBounds.extent);
            }
            delta.y = 0;
         }
         if( dragTotalDelta.x < 10 && dragTotalDelta.x > -10 )
         {
            for(S32 i = 0; i < mSelectedControls.size(); i++)
            {
               Point2I snapBackPoint( mDragBeginPoints[i].x,mSelectedControls[i]->mBounds.point.y);
               // This is kind of nasty but we need to snap back if we're not at origin point with selection - JDD
               if( mSelectedControls[i]->mBounds.point.x != mDragBeginPoints[i].x )
                  mSelectedControls[i]->resize( snapBackPoint, mSelectedControls[i]->mBounds.extent);
            }
            delta.x = 0;
         }


      }

      moveSelection(delta);
      mLastMousePos += delta;
   }
#ifdef TGE_RPG
	}
#endif
   else
      mLastMousePos = mousePoint;
}

void GuiEditCtrl::moveSelection(const Point2I &delta)
{
   Vector<GuiControl *>::iterator i;

   for(i = mSelectedControls.begin(); i != mSelectedControls.end(); i++)
      (*i)->resize((*i)->mBounds.point + delta, (*i)->mBounds.extent);

	/// TGE_Gui 移动单个控件时,解决发生焦点转移的BUG
   //if (mSelectedControls.size() == 1)
   //   Con::executef(this, 2, "onSelect", avar("%d", mSelectedControls[0]->getId()));
}

void GuiEditCtrl::justifySelection(Justification j)
{
   S32 minX, maxX;
   S32 minY, maxY;
   S32 extentX, extentY;
#ifdef TGE_RPG
   S32 minTop, maxTop;
   S32 minBottom, maxBottom;
   S32 minLeft, maxLeft;
   S32 minRight, maxRight;
#endif

   if (mSelectedControls.size() < 2)
      return;

   Vector<GuiControl *>::iterator i = mSelectedControls.begin();
   minX = (*i)->mBounds.point.x;
   maxX = minX + (*i)->mBounds.extent.x;
   minY = (*i)->mBounds.point.y;
   maxY = minY + (*i)->mBounds.extent.y;
#ifdef TGE_RPG
	maxLeft  = minX;
	minRight = maxX;
	maxTop	= minY;
	minBottom= maxY;
#endif
   extentX = (*i)->mBounds.extent.x;
   extentY = (*i)->mBounds.extent.y;
   i++;
   for(;i != mSelectedControls.end(); i++)
   {
      minX = getMin(minX, (*i)->mBounds.point.x);
      maxX = getMax(maxX, (*i)->mBounds.point.x + (*i)->mBounds.extent.x);
      minY = getMin(minY, (*i)->mBounds.point.y);
      maxY = getMax(maxY, (*i)->mBounds.point.y + (*i)->mBounds.extent.y);
#ifdef TGE_RPG
      maxLeft   = getMax(maxLeft, (*i)->mBounds.point.x);
      minRight  = getMin(minRight, (*i)->mBounds.point.x + (*i)->mBounds.extent.x);
      maxTop    = getMax(maxTop , (*i)->mBounds.point.y);
      minBottom = getMin(minBottom, (*i)->mBounds.point.y + (*i)->mBounds.extent.y);
#endif
      extentX += (*i)->mBounds.extent.x;
      extentY += (*i)->mBounds.extent.y;
   }
#ifdef TGE_RPG
	minLeft	= minX;
	maxRight = maxX;
	minTop	= minY;
	maxBottom= maxY;

   S32 leftDeltaX  = maxLeft - minLeft;
   S32 rightDeltaY = maxRight - minRight;
   S32 topDeltaY  = maxTop - minTop;
   S32 bottomDeltaY  = maxBottom - minBottom;

#endif

   S32 deltaX = maxX - minX;
   S32 deltaY = maxY - minY;
   switch(j)
   {
      case JUSTIFY_LEFT:
         for(i = mSelectedControls.begin(); i != mSelectedControls.end(); i++)
            (*i)->resize(Point2I(minX, (*i)->mBounds.point.y), (*i)->mBounds.extent);
         break;
      case JUSTIFY_TOP:
         for(i = mSelectedControls.begin(); i != mSelectedControls.end(); i++)
            (*i)->resize(Point2I((*i)->mBounds.point.x, minY), (*i)->mBounds.extent);
         break;
      case JUSTIFY_RIGHT:
         for(i = mSelectedControls.begin(); i != mSelectedControls.end(); i++)
            (*i)->resize(Point2I(maxX - (*i)->mBounds.extent.x + 1, (*i)->mBounds.point.y), (*i)->mBounds.extent);
         break;
      case JUSTIFY_BOTTOM:
         for(i = mSelectedControls.begin(); i != mSelectedControls.end(); i++)
            (*i)->resize(Point2I((*i)->mBounds.point.x, maxY - (*i)->mBounds.extent.y + 1), (*i)->mBounds.extent);
         break;

#ifdef TGE_RPG
      case JUSTIFY_HCENTER:
         for(i = mSelectedControls.begin(); i != mSelectedControls.end(); i++)
            (*i)->resize(Point2I(minX + ((deltaX - (*i)->mBounds.extent.x) >> 1), (*i)->mBounds.point.y),
                                                                                 (*i)->mBounds.extent);
         break;

      case JUSTIFY_VCENTER:
         for(i = mSelectedControls.begin(); i != mSelectedControls.end(); i++)
            (*i)->resize(Point2I( (*i)->mBounds.point.x,  minY + ((deltaY - (*i)->mBounds.extent.y) >> 1) ),
                                                                                 (*i)->mBounds.extent);
         break;

      case SPACING_TOP:
      case SPACING_BOTTOM:
      case SPACING_VAVERAGE:
         {
            Vector<GuiControl *> sortedList;
            Vector<GuiControl *>::iterator k;
            for(i = mSelectedControls.begin(); i != mSelectedControls.end(); i++)
            {
               for(k = sortedList.begin(); k != sortedList.end(); k++)
               {
                  if ((*i)->mBounds.point.y < (*k)->mBounds.point.y)
                     break;
               }
               sortedList.insert(k, *i);
            }

            S32 space;
            S32 curY;
				curY = minY;
				if(j == SPACING_VAVERAGE)
				{	
					space = (deltaY - extentY) / (mSelectedControls.size() - 1);
					for(k = sortedList.begin(); k != sortedList.end(); k++)
					{
						(*k)->resize(Point2I((*k)->mBounds.point.x, curY), (*k)->mBounds.extent);
						curY += (*k)->mBounds.extent.y + space;
					}
				}
				else if(j == SPACING_BOTTOM)
				{	
					space = (bottomDeltaY) / (mSelectedControls.size() - 1);
					k = sortedList.begin();
					curY += (*k)->mBounds.extent.y;
					for(;k != sortedList.end() ;k++)
					{
						curY -= (*k)->mBounds.extent.y;
						(*k)->resize(Point2I((*k)->mBounds.point.x, curY), (*k)->mBounds.extent);
						curY += (*k)->mBounds.extent.y + space;
					}
				}
				else
				{
					space = (topDeltaY) / (mSelectedControls.size() - 1);
					for(k = sortedList.begin();k != sortedList.end() ;k++)

⌨️ 快捷键说明

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