public override void GestureEnd(CircuitEditor editor, Vector2d endOffset) { SelectionSize = editor.RoundDistToGrid(endOffset); Selecting = false; // Make sure we don't have a negitive size if (SelectionSize.X < 0) { SelectionSize.X = -SelectionSize.X; SelectionStart.X -= SelectionSize.X; } if (SelectionSize.Y < 0) { SelectionSize.Y = -SelectionSize.Y; SelectionStart.Y -= SelectionSize.Y; } // FIXME: Do the selecting var wires = editor.Scene.Wires; ClearSelection(editor); // If the size is zero we want to check if we clicked a wire or gate if (SelectionSize == Vector2i.Zero) { foreach (var wire in wires.WiresList) { if (wire.IsPointOnWire(SelectionStart)) { SelectedWires.Add(wire); break; } } } else { // Here we should loop through all wires and see if they are contained in the area Recti selectionRect = new Recti(SelectionStart, SelectionSize); foreach (var wire in wires.WiresList) { if (selectionRect.Contains(wire.Pos) && selectionRect.Contains(wire.EndPos)) { SelectedWires.Add(wire); Console.WriteLine($"Selected wire: {wire}"); } } } editor.DrawingArea.QueueDraw(); }
public override void GestureEnd(CircuitEditor editor, Vector2d endOffset) { SelectionSize = editor.RoundDistToGrid(endOffset); Selecting = false; // Make sure we don't have a negitive size if (SelectionSize.X < 0) { SelectionSize.X = -SelectionSize.X; SelectionStart.X -= SelectionSize.X; } if (SelectionSize.Y < 0) { SelectionSize.Y = -SelectionSize.Y; SelectionStart.Y -= SelectionSize.Y; } if (Poking) { Poking = false; LogikUI.Simulation.ReleaseComponent(SelectedGates[0].ID); } // FIXME: Do the selecting var wires = editor.Scene.Wires; // If the size is zero we want to check if we clicked a wire or gate if (SelectionSize == Vector2i.Zero) { ClearSelection(editor); bool foundGate = false; var pos = editor.FromGridToWorld(SelectionStart); foreach (var instance in editor.Scene.Gates.Instances) { Rect r = editor.Scene.Gates.GetBounds(instance); r = r.Rotate(instance.Position * CircuitEditor.DotSpacing, instance.Orientation); if (r.Contains(pos)) { SelectedGates.Add(instance); break; } } if (foundGate == false) { foreach (var wire in wires.WiresList) { if (wire.IsPointOnWire(SelectionStart)) { SelectedWires.Add(wire); foundGate = true; break; } } } } else { ClearSelection(editor); // Here we should loop through all wires and see if they are contained in the area Recti selectionRect = new Recti(SelectionStart, SelectionSize); foreach (var wire in wires.WiresList) { if (selectionRect.Contains(wire.Pos) && selectionRect.Contains(wire.EndPos)) { SelectedWires.Add(wire); Console.WriteLine($"Selected wire: {wire}"); } } Rect worldRect = editor.FromGridToWorld(selectionRect); foreach (var instance in editor.Scene.Gates.Instances) { Rect r = editor.Scene.Gates.GetBounds(instance); r = r.Rotate(instance.Position * CircuitEditor.DotSpacing, instance.Orientation); if (worldRect.Contains(r)) { SelectedGates.Add(instance); } } } editor.DrawingArea.QueueDraw(); }