/// <summary> /// Unselect any selected objects. /// </summary> public void UnSelect() { nodes.ForEach(node => { node.Selected = false; }); arcs.ForEach(arc => { arc.Selected = false; }); SelectedObject = null; SelectedObject2 = null; mouseDown = false; isDragging = false; // Redraw area. drawable.QueueDraw(); OnGraphObjectSelected?.Invoke(this, new GraphObjectSelectedArgs(null)); }
/// <summary>Mouse button has been pressed</summary> private void OnMouseButtonPress(object o, ButtonPressEventArgs args) { try { // Get the point clicked by the mouse. PointD clickPoint = new PointD(args.Event.X, args.Event.Y); if (args.Event.Button == 1) { mouseDown = true; // Delselect existing object if (SelectedObject != null) { SelectedObject.Selected = false; } // Look through nodes for the click point SelectedObject = nodes.FindLast(node => node.HitTest(clickPoint)); // If not found, look through arcs for the click point if (SelectedObject == null) { SelectedObject = arcs.FindLast(arc => arc.HitTest(clickPoint)); } // If found object, select it. if (SelectedObject != null) { SelectedObject.Selected = true; lastPos = clickPoint; OnGraphObjectSelected?.Invoke(this, new GraphObjectSelectedArgs(SelectedObject)); } // Redraw area. (o as DrawingArea).QueueDraw(); } else { if (SelectedObject2 != null) { SelectedObject2.Selected = false; } SelectedObject2 = nodes.FindLast(node => node.HitTest(clickPoint)); if (SelectedObject2 == null) { SelectedObject2 = arcs.FindLast(arc => arc.HitTest(clickPoint)); } // If the user has right-clicked in the middle of nowhere, unselect everything. if (SelectedObject2 == null) { UnSelect(); } else if (SelectedObject2 == SelectedObject) { SelectedObject2 = null; } } } catch (Exception err) { ShowError(err); } }