//pie menu only public void circuitInkCanvas_StylusMove(object sender, StylusEventArgs e) { DateTime now = DateTime.Now; StylusPointCollection points = e.GetStylusPoints(this.circuitInkCanvas); //check if the current stroke is trigger pie menu stroke //debug only TimeSpan testSpan = now - _stylusDownTime; if(!IsPieMenuVisible) { if (StrokeAnalyzer.IsTriggerPieMenuStroke(testSpan, StrokeInfo.pointDistance(StartPoint, points[points.Count - 1]))) { PieMenuEventArgs args = new PieMenuEventArgs(true); args.Position = e.GetPosition(this); triggerPieMenuHandler(this, args); IsPieMenuVisible = true; PieMenuHitTestEventArgs hitargs = new PieMenuHitTestEventArgs(e.GetPosition(this), e, PieMenuHitTestEventArgs.EventType.Down); hitPieMenuHandler(this, hitargs); } } if(IsPieMenuVisible) { PieMenuHitTestEventArgs hitargs = new PieMenuHitTestEventArgs(e.GetPosition(this), e, PieMenuHitTestEventArgs.EventType.Move); hitPieMenuHandler(this, hitargs); } }
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 inkCanvas_triggerPieMenuHandler(object sender, PieMenuEventArgs e) { DisableInkEventArgs args; if (e.IsVisible) { args = new DisableInkEventArgs(true); disableInkHandler(sender, args); pieMenuGateSelector.Background = Brushes.Transparent; pieMenuGateSelector.Visibility = Visibility.Visible; pieMenuGateSelector.UserControlToolTipX = e.Position.X - pieMenuGateSelector.ActualWidth * 0.5; pieMenuGateSelector.UserControlToolTipY = e.Position.Y - pieMenuGateSelector.ActualHeight * 0.5; //pieMenuGateSelector.UserControlToolTipX = e.Position.X; //pieMenuGateSelector.UserControlToolTipY = e.Position.Y; } else { args = new DisableInkEventArgs(false); disableInkHandler(sender, args); pieMenuGateSelector.Visibility = Visibility.Collapsed; } }