public void circuitInkCanvas_StylusUp(object sender, StylusEventArgs e) { if (IsPieMenuVisible) { PieMenuHitTestEventArgs hitargs = new PieMenuHitTestEventArgs(e.GetPosition(this), e, PieMenuHitTestEventArgs.EventType.Up); hitPieMenuHandler(this, hitargs); } //Make Pie Menu Invisible PieMenuEventArgs args = new PieMenuEventArgs(false); triggerPieMenuHandler(this, args); Point mp2 = e.GetPosition(circuitInkCanvas); foreach (UIElement gate in circuitInkCanvas.Children) { if (gate is Gate) { Gate g = gate as Gate; Rect grect = new Rect(g.Margin.Left - 10, g.Margin.Top - 10, g.Width + 10, g.Height + 10); bool condition = false; condition = grect.Contains(mp2); if (condition) { uigate_StylusUp(g ,e); break; } }else if(gate is ConnectedWire) { HitTestResult result = VisualTreeHelper.HitTest(gate, mp2); if(result != null) { Debug.WriteLine("Hit Test Wire circuitInkCanvas_StylusUp"); //Image stroke starts from one terminal and stop at this wire //1. through this wire, create new wire to connect existing wire's //if stroke starts from input terminal from one gate, then search for input terminal from existing wire. //otherwise stroke starts from the output termianl from one gate, then search for output terminal from existing wire. ConnectedWire myWire = gate as ConnectedWire; //new wire's destination is mp2; new wire's orignal is ??? if (onGateStroke) { //start the stroke from gate terminal Gate.TerminalID tid = myWire.OriginTerminalID; Gates.Terminal origin = null, dest = null; if (tid.isInput && dragging == DragState.CONNECT_FROM && !wires.ContainsKey(new Gates.Terminal(tid.ID, tid.abgate))) { origin = new Gates.Terminal(beginTID.ID, beginTID.abgate); dest = new Gates.Terminal(tid.ID, tid.abgate); } if (!tid.isInput && dragging == DragState.CONNECT_TO) { origin = new Gates.Terminal(tid.ID, tid.abgate); dest = new Gates.Terminal(beginTID.ID, beginTID.abgate); } if (origin != null) { c[dest] = origin; UndoRedo.ConnectWire cw = new UndoRedo.ConnectWire(c, origin, dest); if (UndoProvider != null) UndoProvider.Add(cw); } } break; } } } dragging = DragState.NONE; //dragSelect.Width = 0; //dragSelect.Height = 0; //dragSelect.Margin = new Thickness(0, 0, 0, 0); //dragSelect.Visibility = Visibility.Hidden; dragWire.Destination = new Point(0, 0); dragWire.Origin = new Point(0, 0); // unhightlight all foreach (Gates.AbstractGate ag in gates.Keys) { for (int i = 0; i < ag.Output.Length; i++) { gates[ag].FindTerminal(false, i).t.Highlight = false; } for (int i = 0; i < ag.NumberOfInputs; i++) { gates[ag].FindTerminal(true, i).t.Highlight = false; } } if (UndoProvider != null && moves != null && moves.Count > 0) UndoProvider.Add(moves); moves = null; ReadyToSelect = false; }
void uigate_StylusUp(object sender, StylusEventArgs e) { Point mp2 = e.GetPosition(circuitInkCanvas); Gate tg = (Gate)sender; Rect gRect = new Rect(tg.Margin.Left, tg.Margin.Top, tg.Width, tg.Height); if (dragging == DragState.CONNECT_FROM || dragging == DragState.CONNECT_TO) { foreach (Gate.TerminalID tid in (Gate)sender) { Rect tRect = GetTerminalBounds(tg, gRect, tid); bool condition = tRect.Contains(mp2); if(condition) //if (mp2.X >= tRect.Value.Left - 10 && mp2.X <= tRect.Value.Right + 10 // && mp2.Y >= tRect.Value.Top - 10 && mp2.Y <= tRect.Value.Bottom + 10) //if (tid.t.IsMouseOver) { Gates.Terminal origin = null, dest = null; if (tid.isInput && dragging == DragState.CONNECT_FROM && !wires.ContainsKey(new Gates.Terminal(tid.ID, tid.abgate))) { origin = new Gates.Terminal(beginTID.ID, beginTID.abgate); dest = new Gates.Terminal(tid.ID, tid.abgate); } if (!tid.isInput && dragging == DragState.CONNECT_TO) { origin = new Gates.Terminal(tid.ID, tid.abgate); dest = new Gates.Terminal(beginTID.ID, beginTID.abgate); } if (origin != null) { c[dest] = origin; UndoRedo.ConnectWire cw = new UndoRedo.ConnectWire(c, origin, dest); if (UndoProvider != null) UndoProvider.Add(cw); } break; } } } }