Skip to content

Commit

Permalink
GuiEditor and UseInput
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
greenfire27 committed Dec 21, 2023
1 parent ea83724 commit 54c2ae1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
15 changes: 5 additions & 10 deletions engine/source/gui/editor/guiEditCtrl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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.
Expand Down
11 changes: 7 additions & 4 deletions engine/source/gui/guiControl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion engine/source/gui/guiControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 54c2ae1

Please sign in to comment.