From 54c2ae145f554fafdcb045de634d80d11b206ae5 Mon Sep 17 00:00:00 2001 From: Peter Robinson Date: Wed, 20 Dec 2023 20:09:56 -0500 Subject: [PATCH] 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. --- engine/source/gui/editor/guiEditCtrl.cc | 15 +++++---------- engine/source/gui/guiControl.cc | 11 +++++++---- engine/source/gui/guiControl.h | 2 +- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/engine/source/gui/editor/guiEditCtrl.cc b/engine/source/gui/editor/guiEditCtrl.cc index 19b553b6..6873d7b0 100755 --- a/engine/source/gui/editor/guiEditCtrl.cc +++ b/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. diff --git a/engine/source/gui/guiControl.cc b/engine/source/gui/guiControl.cc index 27a295cf..400c77bd 100755 --- a/engine/source/gui/guiControl.cc +++ b/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; } } diff --git a/engine/source/gui/guiControl.h b/engine/source/gui/guiControl.h index a7056245..68fcc908 100755 --- a/engine/source/gui/guiControl.h +++ b/engine/source/gui/guiControl.h @@ -561,7 +561,7 @@ class GuiControl : public SimGroup, public virtual Tickable /// 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