Skip to content

Commit

Permalink
Do not open context menu after dragging mouse
Browse files Browse the repository at this point in the history
Before this commit, there has been the somewhat annoying behavior that
whenever we look around by right-clicking and dragging, if the mouse
cursor happened to be over a node in the code city, the context menu
would open after the drag has stopped. To fix this, the context menu is
now only opened if the user did not drag their mouse before letting go
of right click (or at least, if they only dragged very slightly).
  • Loading branch information
falko17 committed Sep 13, 2024
1 parent e5cca0a commit 1b75a2d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
11 changes: 10 additions & 1 deletion Assets/SEE/Controls/Actions/ContextMenuAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,23 @@ public class ContextMenuAction : MonoBehaviour
/// </summary>
private PopupMenu popupMenu;

/// <summary>
/// The position of the mouse when the user started opening the context menu.
/// </summary>
private Vector3 startMousePosition = Vector3.zero;

private void Start()
{
popupMenu = gameObject.AddComponent<PopupMenu>();
}

private void Update()
{
if (SEEInput.OpenContextMenu())
if (SEEInput.OpenContextMenuStart())
{
startMousePosition = Input.mousePosition;
}
else if (SEEInput.OpenContextMenuEnd() && (Input.mousePosition - startMousePosition).magnitude < 1)
{
// TODO (#664): Detect if multiple elements are selected and adjust options accordingly.
HitGraphElement hit = Raycasting.RaycastInteractableObject(out _, out InteractableObject o);
Expand Down
15 changes: 12 additions & 3 deletions Assets/SEE/Controls/SEEInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,19 @@ public static bool ToggleMetricHoveringSelection()
//-----------------------------------------------------

/// <summary>
/// True if the user wants to open the context menu.
/// True if the user starts the mouse interaction to open the context menu.
/// </summary>
/// <returns>True if the user wants to open the context menu.</returns>
internal static bool OpenContextMenu()
/// <returns>true if the user starts the mouse interaction to open the context menu</returns>
internal static bool OpenContextMenuStart()
{
return Input.GetMouseButtonDown(rightMouseButton) && !Raycasting.IsMouseOverGUI();
}

/// <summary>
/// True if the user ends the mouse interaction to open the context menu.
/// </summary>
/// <returns>true if the user ends the mouse interaction to open the context menu</returns>
internal static bool OpenContextMenuEnd()
{
return Input.GetMouseButtonUp(rightMouseButton) && !Raycasting.IsMouseOverGUI();
}
Expand Down

0 comments on commit 1b75a2d

Please sign in to comment.