Ver Fonte

GuiEditor and UseInput

The flag GuiControl.useInput allows a control to interact with an input device such as the keyboard or mouse. When off input is ignored by the control and its children. However, the flag should be ignored in the editor so that the control can still be clicked on and dragged around. This code fixes that.
Peter Robinson há 1 ano atrás
pai
commit
54c2ae145f

+ 5 - 10
engine/source/gui/editor/guiEditCtrl.cc

@@ -594,7 +594,7 @@ void GuiEditCtrl::onRightMouseDown(const GuiEvent& event)
 	setFirstResponder();
 
 	//search for the control hit in any layer below the edit layer
-	GuiControl* hitCtrl = mEditorRoot->findHitControl(globalToLocalCoord(event.mousePoint), mLayer - 1);
+	GuiControl* hitCtrl = mEditorRoot->findHitControl(globalToLocalCoord(event.mousePoint), mLayer - 1, true, true);
 	if (hitCtrl != mCurrentAddSet)
 	{
 		Con::executef(this, 1, "onClearSelected");
@@ -733,7 +733,7 @@ void GuiEditCtrl::onTouchDown(const GuiEvent& event)
 	else
 	{
 		//find the control we clicked
-		ctrl = mEditorRoot->findHitControl(mLastMousePos, mCurrentAddSet->mLayer);
+		ctrl = mEditorRoot->findHitControl(mLastMousePos, mCurrentAddSet->mLayer, true, true);
 		handledEvent = ctrl->onMouseDownEditor(event, editorOffset);
 	}
 	if (handledEvent)
@@ -854,7 +854,7 @@ void GuiEditCtrl::onTouchUp(const GuiEvent& event)
 	}
 
 	//find the control we clicked
-	GuiControl* ctrl = mEditorRoot->findHitControl(mLastMousePos, mCurrentAddSet->mLayer);
+	GuiControl* ctrl = mEditorRoot->findHitControl(mLastMousePos, mCurrentAddSet->mLayer, true, true);
 
 	Point2I localOffset = localToGlobalCoord(Point2I(0, 0));
 	bool handledEvent = false;
@@ -938,7 +938,7 @@ void GuiEditCtrl::onTouchDragged(const GuiEvent& event)
 	}
 	else
 	{
-		GuiControl* ctrl = mEditorRoot->findHitControl(mousePoint, mCurrentAddSet->mLayer);
+		GuiControl* ctrl = mEditorRoot->findHitControl(mousePoint, mCurrentAddSet->mLayer, true, true);
 		handledEvent = ctrl->onMouseDraggedEditor(event, localOffset);
 	}
 
@@ -1091,12 +1091,7 @@ void GuiEditCtrl::onTouchDragged(const GuiEvent& event)
 		moveSelection(delta);
 
 		// find the current control under the mouse but not in the selected set.
-		// setting a control invisible makes sure it wont be seen by findHitControl()
-		for (int i = 0; i < mSelectedControls.size(); i++)
-			mSelectedControls[i]->setVisible(false);
-		GuiControl* inCtrl = mEditorRoot->findHitControl(mousePoint, mCurrentAddSet->mLayer);
-		for (int i = 0; i < mSelectedControls.size(); i++)
-			mSelectedControls[i]->setVisible(true);
+		GuiControl* inCtrl = mEditorRoot->findHitControl(mousePoint, mCurrentAddSet->mLayer, true, false);
 
 		// find the nearest control up the heirarchy from the control the mouse is in
 		// that is flagged as a container.

+ 7 - 4
engine/source/gui/guiControl.cc

@@ -1425,7 +1425,7 @@ bool GuiControl::pointInControl(const Point2I& parentCoordPoint)
 }
 
 
-GuiControl* GuiControl::findHitControl(const Point2I &pt, S32 initialLayer)
+GuiControl* GuiControl::findHitControl(const Point2I &pt, S32 initialLayer, const bool ignoreUseInput, const bool ignoreEditSelected)
 {
    iterator i = end(); // find in z order (last to first)
    while (i != begin())
@@ -1436,12 +1436,15 @@ GuiControl* GuiControl::findHitControl(const Point2I &pt, S32 initialLayer)
       {
          continue;
       }
-      else if (ctrl->mVisible && ctrl->pointInControl(pt - ctrl->mRenderInsetLT) && ctrl->mUseInput)
+      else if (ctrl->pointInControl(pt - ctrl->mRenderInsetLT) && 
+		ctrl->mVisible && 
+		(ignoreUseInput || ctrl->mUseInput) && 
+		(ignoreEditSelected || (isEditMode() && !ctrl->isEditSelected())))
       {
          Point2I ptemp = pt - (ctrl->mBounds.point + ctrl->mRenderInsetLT);
-         GuiControl *hitCtrl = ctrl->findHitControl(ptemp);
+         GuiControl *hitCtrl = ctrl->findHitControl(ptemp, -1, ignoreUseInput, ignoreEditSelected);
 
-         if(hitCtrl->mUseInput)
+         if(ignoreUseInput || hitCtrl->mUseInput)
             return hitCtrl;
       }
    }

+ 1 - 1
engine/source/gui/guiControl.h

@@ -561,7 +561,7 @@ public:
     /// Returns the control which the provided point is under, with layering
     /// @param   pt   Point to test
     /// @param   initialLayer  Layer of gui objects to begin the search
-    virtual GuiControl* findHitControl(const Point2I &pt, S32 initialLayer = -1);
+    virtual GuiControl* findHitControl(const Point2I &pt, S32 initialLayer = -1, const bool ignoreUseInput = false, const bool ignoreEditSelected = true);
 
     /// Lock the mouse within the provided control
     /// @param   lockingControl   Control to lock the mouse within