///////////////////////////////////////////////////////////////////// internal override void FireNotifications(UIElement uie, ContentElement ce, UIElement3D uie3D, bool oldValue) { // This is all very sketchy... // // Tablet can support multiple stylus devices concurrently. They can each // be over a different element. They all update the IsStylusOver property, // which calls into here, but ends up using the "current" stylus device, // instead of each using their own device. Worse, all of these will end up // writing to the same bits in the UIElement. They are going to step all over // each other. if(Stylus.CurrentStylusDevice == null) { return; } StylusEventArgs stylusEventArgs = new StylusEventArgs(Stylus.CurrentStylusDevice, Environment.TickCount); stylusEventArgs.RoutedEvent = oldValue ? Stylus.StylusLeaveEvent : Stylus.StylusEnterEvent; if (uie != null) { uie.RaiseEvent(stylusEventArgs); } else if (ce != null) { ce.RaiseEvent(stylusEventArgs); } else if (uie3D != null) { uie3D.RaiseEvent(stylusEventArgs); } }
/// <summary> /// Tells the gate that's currently being rotated that it's being rotated to a new point. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void sketchPanel_StylusMove(object sender, System.Windows.Input.StylusEventArgs e) { if (RotateGates && activatedGate != null) { System.Windows.Point point = e.GetPosition(sketchPanel.InkCanvas); activatedGate.update(point); } }
// Touch up event handler. private void OnTouchUpHandler(object sender, StylusEventArgs e) { // Find the stroke in the collection of the strokes in drawing. Stroke stroke; if (_activeStrokes.TryGetValue(e.StylusDevice.Id, out stroke)) { FinishStroke(stroke); } }
public void ProcessMove(object sender, StylusEventArgs args) { PictureTracker pictureTracker = GetPictureTracker(args.StylusDevice.Id); if (pictureTracker == null) return; Point location = args.GetPosition(_canvas); pictureTracker.ProcessMove(args.StylusDevice.Id, location); }
protected override void OnLostStylusCapture(StylusEventArgs args) { base.OnLostStylusCapture(args); // ���������� ���� : �ش� ���������� ���� if (isDrawing) { canv.Children.Remove(polyStylus); canv.Children.Remove(polyShadow); isDrawing = false; } }
protected override void OnLostStylusCapture(StylusEventArgs args) { base.OnLostStylusCapture(args); // Abnormal end of drawing: Remove child shapes. if (isDrawing) { canv.Children.Remove(polyStylus); canv.Children.Remove(polyShadow); isDrawing = false; } }
/// <summary> /// Tells the gate that's currently being rotated that it's been dropped. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void sketchPanel_StylusUp(object sender, System.Windows.Input.StylusEventArgs e) { if (RotateGates && activatedGate != null) { System.Windows.Point point = e.GetPosition(sketchPanel.InkCanvas); activatedGate.finish(point); RemoveGate(activatedGate); activatedGate = null; sketchPanel.UseCustomCursor = false; sketchPanel.EnableDrawing(); } }
/// <summary> /// Show ghost gate when you hover near a shape. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void sketchPanel_StylusInAirMove(object sender, System.Windows.Input.StylusEventArgs e) { // Don't show gates when erasing, or if we don't have the right feedbacks turned on if ((!GatesOnHovering && !RotateGates) || e.StylusDevice.Inverted) { return; } // Get the shape we're looking for System.Windows.Point point = e.GetPosition(sketchPanel.InkCanvas); Shape shape = sketchPanel.Sketch.shapeAtPoint(point.X, point.Y, 100); //Don't allow rotation if anything is selected System.Windows.Ink.StrokeCollection selected = sketchPanel.InkCanvas.GetSelectedStrokes(); if (selected.Count != 0) { RotateGates = false; } // Remove the old hovergate if it's not the one we're going to draw anyways if (shape == null || (hoverGate != null && hoverGate.Shape != shape)) { RemoveGate(hoverGate); } // Draw the new hovergate, if possible and neccessary. Otherwise, grab it from the dictionary if (shape != null && !ShapeToGate.ContainsKey(shape)) { DrawFeedback(shape, true); } // Change the cursor if we need to if (RotateGates && shape != null && shape.AlreadyLabeled && ShapeToGate.ContainsKey(shape) && ShapeToGate[shape].canActivate(point)) { sketchPanel.UseCustomCursor = true; sketchPanel.Cursor = Cursors.Hand; } else { sketchPanel.UseCustomCursor = false; } }
// Touch down event handler. private void OnTouchDownHandler(object sender, StylusEventArgs e) { // If there exist stroke with this ID, finish it. Stroke stroke; if(_activeStrokes.TryGetValue(e.StylusDevice.Id, out stroke)) { FinishStroke(stroke); return; } // Create new stroke, add point and assign a color to it. Stroke newStroke = new Stroke (); newStroke.Color = _touchColor.GetColor(); newStroke.Id = e.StylusDevice.Id; // Add new stroke to the collection of strokes in drawing. _activeStrokes[newStroke.Id] = newStroke; }
internal RawMouseActions GetMouseActionsFromStylusEventAndPlaybackCachedDown(RoutedEvent stylusEvent, StylusEventArgs stylusArgs) { if (stylusEvent == Stylus.StylusSystemGestureEvent) { // See if this is an OK gesture to trigger a mouse event on. StylusSystemGestureEventArgs systemGestureArgs = (StylusSystemGestureEventArgs)stylusArgs; if (systemGestureArgs.SystemGesture == SystemGesture.Tap || systemGestureArgs.SystemGesture == SystemGesture.RightTap || systemGestureArgs.SystemGesture == SystemGesture.Drag || systemGestureArgs.SystemGesture == SystemGesture.RightDrag || systemGestureArgs.SystemGesture == SystemGesture.Flick) { // Usually UpdateStateForSystemGesture happens in the PreNotify. // And UpdateState for other stylus events happens during mouse promotion. // But with manipulations when events are stored for future promotion, // this difference in order could cause problems. Hence reexecute // UpdateStateForSystemGesture to fix the order. UpdateStateForSystemGesture(systemGestureArgs.SystemGesture, null); if (systemGestureArgs.SystemGesture == SystemGesture.Drag || systemGestureArgs.SystemGesture == SystemGesture.RightDrag || systemGestureArgs.SystemGesture == SystemGesture.Flick) { _fBlockMouseMoveChanges = false; TapCount = 1; // reset on a drag or flick. if (systemGestureArgs.SystemGesture == SystemGesture.Flick) { // Don't want to play down or cached moves. _needToSendMouseDown = false; } else { PlayBackCachedDownInputReport(systemGestureArgs.Timestamp); } } else //we have a Tap { PlayBackCachedDownInputReport(systemGestureArgs.Timestamp); } } } else if (stylusEvent == Stylus.StylusInAirMoveEvent) { return RawMouseActions.AbsoluteMove; } else if (stylusEvent == Stylus.StylusDownEvent) { _fLeftButtonDownTrigger = true; // Default to left click until system gesture says otherwise. _fBlockMouseMoveChanges = true; // See if we can promote the mouse button down right now. if (_seenDoubleTapGesture || _sawMouseButton1Down) { PlayBackCachedDownInputReport(stylusArgs.Timestamp); } } else if (stylusEvent == Stylus.StylusMoveEvent) { if (!_fBlockMouseMoveChanges) { return RawMouseActions.AbsoluteMove; } } else if (stylusEvent == Stylus.StylusUpEvent) { _fBlockMouseMoveChanges = false; _seenDoubleTapGesture = false; // reset this on Stylus Up. _sawMouseButton1Down = false; // reset to make sure we don't promote a mouse down on the next stylus down. if (_promotedMouseState == MouseButtonState.Pressed) { _promotedMouseState = MouseButtonState.Released; RawMouseActions actions = _fLeftButtonDownTrigger ? RawMouseActions.Button1Release : RawMouseActions.Button2Release; // Make sure we only promote a mouse up if the mouse is in the down // state (UpdateMousebuttonState returns true in that case)! if (_stylusLogic.UpdateMouseButtonState(actions)) { return actions; } // else - just return default of RawMouseActions.None since we don't want this // duplicate mouse up to be processed. } } // Default return return RawMouseActions.None; }
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; }
//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 new void PreviewStylusMove(object sender, StylusEventArgs e) { }
void button_StylusLeave(object sender, StylusEventArgs e) { Apple hoveredApple; var button = sender as KinectCircleButton; hoveredApple = myApple[(int)button.Content]; restoreAppleBackground(hoveredApple); }
protected override void OnStylusMove(StylusEventArgs e) { base.OnStylusMove(e); if(TouchEnabled) { // wpf generates to many events if mouse is over some visual // and OnMouseUp is fired, wtf, anyway... // http://greatmaps.codeplex.com/workitem/16013 if((e.Timestamp & Int32.MaxValue) - onMouseUpTimestamp < 55) { Debug.WriteLine("OnMouseMove skipped: " + ((e.Timestamp & Int32.MaxValue) - onMouseUpTimestamp) + "ms"); return; } if(!Core.IsDragging && !Core.mouseDown.IsEmpty) { Point p = e.GetPosition(this); if(MapScaleTransform != null) { p = MapScaleTransform.Inverse.Transform(p); } p = ApplyRotationInversion(p.X, p.Y); // cursor has moved beyond drag tolerance if(Math.Abs(p.X - Core.mouseDown.X) * 2 >= SystemParameters.MinimumHorizontalDragDistance || Math.Abs(p.Y - Core.mouseDown.Y) * 2 >= SystemParameters.MinimumVerticalDragDistance) { Core.BeginDrag(Core.mouseDown); } } if(Core.IsDragging) { if(!isDragging) { isDragging = true; Debug.WriteLine("IsDragging = " + isDragging); cursorBefore = Cursor; Cursor = Cursors.SizeAll; Mouse.Capture(this); } if(BoundsOfMap.HasValue && !BoundsOfMap.Value.Contains(Position)) { // ... } else { Point p = e.GetPosition(this); if(MapScaleTransform != null) { p = MapScaleTransform.Inverse.Transform(p); } p = ApplyRotationInversion(p.X, p.Y); Core.mouseCurrent.X = (int)p.X; Core.mouseCurrent.Y = (int)p.Y; { Core.Drag(Core.mouseCurrent); } if(IsRotated) { ForceUpdateOverlays(); } else { UpdateMarkersOffset(); } } InvalidateVisual(); } } }
void SuggestionCanvas_StylusEnter(object sender, StylusEventArgs e) { InkCanvas canvas = sender as InkCanvas; if (canvas != null) { canvas.Background = new SolidColorBrush(Colors.LightBlue); } }
/// <summary> /// Virtual method reporting the stylus is now out of range of the digitizer /// </summary> protected internal virtual void OnStylusOutOfRange(StylusEventArgs e) {}
/// <summary> /// Virtual method reporting that this element lost the stylus capture /// </summary> protected internal virtual void OnLostStylusCapture(StylusEventArgs e) {}
/// <summary> /// Virtual method reporting a stylus-in-air-move /// </summary> protected virtual void OnPreviewStylusInAirMove(StylusEventArgs e) {}
protected override void OnStylusUp(StylusEventArgs e) { base.OnStylusUp(e); if(TouchEnabled) { if(isSelected) { isSelected = false; } if(Core.IsDragging) { if(isDragging) { onMouseUpTimestamp = e.Timestamp & Int32.MaxValue; isDragging = false; Debug.WriteLine("IsDragging = " + isDragging); Cursor = cursorBefore; Mouse.Capture(null); } Core.EndDrag(); if(BoundsOfMap.HasValue && !BoundsOfMap.Value.Contains(Position)) { if(Core.LastLocationInBounds.HasValue) { Position = Core.LastLocationInBounds.Value; } } } else { Core.mouseDown = GPoint.Empty; InvalidateVisual(); } } }
/// <summary> /// Virtual method reporting the stylus entered this element /// </summary> protected virtual void OnStylusEnter(StylusEventArgs e) {}
void button_StylusEnter(object sender, StylusEventArgs e) { Apple hoveredApple; var button = sender as KinectCircleButton; hoveredApple = myApple[(int)button.Content]; appleHoverBackground(hoveredApple); }
/// <summary> /// Virtual method reporting the stylus is now in range of the digitizer /// </summary> protected virtual void OnStylusInRange(StylusEventArgs e) {}
public new void StylusUp(object sender, StylusEventArgs e) { }
/// <summary> /// Virtual method reporting the stylus is now out of range of the digitizer /// </summary> protected virtual void OnPreviewStylusOutOfRange(StylusEventArgs e) {}
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; } } } }
/// <summary> /// Virtual method reporting that this element got the stylus capture /// </summary> protected virtual void OnGotStylusCapture(StylusEventArgs e) {}
/* void circuitInkCanvas_StylusMove(object sender, StylusEventArgs e) { if (IsReadOnly) return; TimeSpan ts = _stopWatch.Elapsed; if (ts.TotalSeconds - _lastElapsedSecs> 2) { _stopWatch.Stop(); _stopWatch = Stopwatch.StartNew(); MessageBox.Show("Popup"); } Point mp2 = e.GetPosition(circuitInkCanvas); circuitInkCanvas.BringIntoView(new Rect(new Point(mp2.X - 10, mp2.Y - 10), new Point(mp2.X + 10, mp2.Y + 10))); switch (dragging) { case DragState.CONNECT_FROM: dragWire.Destination = mp2; break; case DragState.CONNECT_TO: dragWire.Origin = mp2; break; case DragState.MOVE: #region DragState is Move foreach (Gate g in selected) { //g.RenderTransform = new TranslateTransform(mp2.X, mp2.Y); //Direct Move double dx = mp2.X - mp.X; double dy = mp2.Y - mp.Y; ((GateLocation)g.Tag).x = ((GateLocation)g.Tag).x + dx; ((GateLocation)g.Tag).y = ((GateLocation)g.Tag).y + dy; double cx = ((GateLocation)g.Tag).x % GRID_SIZE; double cy = ((GateLocation)g.Tag).y % GRID_SIZE; Point op = new Point(g.Margin.Left, g.Margin.Top); if ((Math.Abs(cx) < DELTA_SNAP || Math.Abs(GRID_SIZE - cx) < DELTA_SNAP) && (Math.Abs(cy) < DELTA_SNAP || Math.Abs(GRID_SIZE - cy) < DELTA_SNAP)) { g.Margin = new Thickness(Math.Round(g.Margin.Left / GRID_SIZE) * GRID_SIZE, Math.Round(g.Margin.Top / GRID_SIZE) * GRID_SIZE, 0, 0); } else { g.Margin = new Thickness(((GateLocation)g.Tag).x, ((GateLocation)g.Tag).y, 0, 0); } Point np = new Point(g.Margin.Left, g.Margin.Top); if (op != np) moves.Add(new UndoRedo.MoveGate(g, this, op, np)); SizeCanvas(); g.BringIntoView(); // still needed because gate larger than 20px block } UpdateWireConnections(); break; #endregion case DragState.NONE: #region Drag State is None // not dragging // creating a selection rectangle if (ReadyToSelect) { double x1 = Math.Min(mp2.X, sp.X); double width = Math.Abs(mp2.X - sp.X); double y1 = Math.Min(mp2.Y, sp.Y); double height = Math.Abs(mp2.Y - sp.Y); dragSelect.Margin = new Thickness(x1, y1, 0, 0); dragSelect.Width = width; dragSelect.Height = height; dragSelect.Visibility = Visibility.Visible; // select any gates inside the rectangle Rect select = new Rect(x1, y1, width, height); foreach (Gate g in gates.Values) { Rect grect = new Rect(g.Margin.Left, g.Margin.Top, g.Width, g.Height); if (select.IntersectsWith(grect) && !g.Selected) { g.Selected = true; selected.Add(g); } // this is not the same as just "not" or else the above if (!select.IntersectsWith(grect) && g.Selected) { g.Selected = false; selected.Remove(g); } } } break; #endregion } mp = mp2; } * * */ /* void circuitInkCanvas_MouseMove(object sender, MouseEventArgs e) { if (IsReadOnly) return; TimeSpan ts = _stopWatch.Elapsed; if (ts.TotalSeconds - _lastElapsedSecs > 2) { MessageBox.Show("Popup"); } Point mp2 = e.GetPosition(circuitInkCanvas); circuitInkCanvas.BringIntoView(new Rect(new Point(mp2.X - 10, mp2.Y - 10), new Point(mp2.X + 10, mp2.Y + 10))); switch (dragging) { case DragState.CONNECT_FROM: dragWire.Destination = mp2; break; case DragState.CONNECT_TO: dragWire.Origin = mp2; break; case DragState.MOVE: #region DragState is Move foreach (Gate g in selected) { //g.RenderTransform = new TranslateTransform(mp2.X, mp2.Y); //Direct Move if (e.LeftButton == MouseButtonState.Pressed) { double dx = mp2.X - mp.X; double dy = mp2.Y - mp.Y; ((GateLocation)g.Tag).x = ((GateLocation)g.Tag).x + dx; ((GateLocation)g.Tag).y = ((GateLocation)g.Tag).y + dy; double cx = ((GateLocation)g.Tag).x % GRID_SIZE; double cy = ((GateLocation)g.Tag).y % GRID_SIZE; Point op = new Point(g.Margin.Left, g.Margin.Top); if ((Math.Abs(cx) < DELTA_SNAP || Math.Abs(GRID_SIZE - cx) < DELTA_SNAP) && (Math.Abs(cy) < DELTA_SNAP || Math.Abs(GRID_SIZE - cy) < DELTA_SNAP)) { g.Margin = new Thickness(Math.Round(g.Margin.Left / GRID_SIZE) * GRID_SIZE, Math.Round(g.Margin.Top / GRID_SIZE) * GRID_SIZE, 0, 0); } else { g.Margin = new Thickness(((GateLocation)g.Tag).x, ((GateLocation)g.Tag).y, 0, 0); } Point np = new Point(g.Margin.Left, g.Margin.Top); if (op != np) moves.Add(new UndoRedo.MoveGate(g, this, op, np)); SizeCanvas(); g.BringIntoView(); // still needed because gate larger than 20px block } } UpdateWireConnections(); break; #endregion case DragState.NONE: #region Drag State is None // not dragging // creating a selection rectangle if (ReadyToSelect) { double x1 = Math.Min(mp2.X, sp.X); double width = Math.Abs(mp2.X - sp.X); double y1 = Math.Min(mp2.Y, sp.Y); double height = Math.Abs(mp2.Y - sp.Y); dragSelect.Margin = new Thickness(x1, y1, 0, 0); dragSelect.Width = width; dragSelect.Height = height; dragSelect.Visibility = Visibility.Visible; // select any gates inside the rectangle Rect select = new Rect(x1, y1, width, height); foreach (Gate g in gates.Values) { Rect grect = new Rect(g.Margin.Left, g.Margin.Top, g.Width, g.Height); if (select.IntersectsWith(grect) && !g.Selected) { g.Selected = true; selected.Add(g); } // this is not the same as just "not" or else the above if (!select.IntersectsWith(grect) && g.Selected) { g.Selected = false; selected.Remove(g); } } } break; #endregion } mp = mp2; } * */ /* void circuitInkCanvas_PreviewStylusDown(object sender, StylusDownEventArgs e) { if (EditingMode.currentEditingMode != EditingMode.EditingModeType.SketchLogicGate) { MessageBox.Show("Please Check Sketch Logic Diagram Radio Button", "TIP"); return; } _lastElapsedSecs = _stopWatch.Elapsed.TotalSeconds; // only come here if the uigate doesn't handle it ClearSelection(); Point mp2 = e.GetPosition(circuitInkCanvas); sp = new Point(mp2.X, mp2.Y); ReadyToSelect = true; onGateStroke = false; foreach (UIElement gate in circuitInkCanvas.Children) { if (gate is Gate) { Gate g = gate as Gate; Rect grect = new Rect(g.Margin.Left, g.Margin.Top, g.Width, g.Height); if (mp2.X >= grect.Left && mp2.X <= grect.Right && mp2.Y >= grect.Top && mp2.Y <= grect.Bottom) { onGateStroke = true; uigate_MouseDown(g, e); if (dragging == DragState.MOVE) { if (g is UIGates.UserInput) { UIGates.UserInput temp = g as UIGates.UserInput; temp.r_MouseDown(this, e); } } break; } } } e.Handled = true; } */ #endregion public void circuitInkCanvas_PreviewStylusMove(object sender, StylusEventArgs e) { if (IsReadOnly) return; Point mp2 = e.GetPosition(circuitInkCanvas); if (sender is ConnectedWire) { #region connectedWire Object onWireMoveStroke = true; ConnectedWire myWire = sender as ConnectedWire; Gate.TerminalID tid = myWire.OriginTerminalID; // ok, so are we connecting to or from // is this an input or output? if (tid.isInput) { // can only connect from an input // if there is no other connection here //if (wires.ContainsKey(new Gates.Terminal(tid.ID, tid.abgate))) dragging = DragState.CONNECT_TO; dragWire.Value = false; // highlight all terminals which provide output foreach (Gates.AbstractGate ag in gates.Keys) { for (int i = 0; i < ag.Output.Length; i++) { gates[ag].FindTerminal(false, i).t.Highlight = true; } } } else { dragging = DragState.CONNECT_FROM; // TODO: if the value of the output changes // while being dragged, this won't update dragWire.Value = tid.abgate.Output[tid.ID]; // highlight all terminals which accept input // note this is all inputs NOT already connected foreach (Gates.AbstractGate ag in gates.Keys) { for (int i = 0; i < ag.NumberOfInputs; i++) { if (c.GetSource(new Gates.Terminal(i, ag)) == null) gates[ag].FindTerminal(true, i).t.Highlight = true; } } } beginTID = tid; dragWire.Destination = tid.t.TranslatePoint(new Point(5, 5), circuitInkCanvas); dragWire.Origin = tid.t.TranslatePoint(new Point(5, 5), circuitInkCanvas); //if (dragging == DragState.MOVE) //{ // if (g is UIGates.UserInput) // { // UIGates.UserInput temp = g as UIGates.UserInput; // temp.r_MouseDown(this, e); // } //} //break; return; #endregion } circuitInkCanvas.BringIntoView(new Rect(new Point(mp2.X - 10, mp2.Y - 10), new Point(mp2.X + 10, mp2.Y + 10))); switch (dragging) { case DragState.CONNECT_FROM: foreach (UIElement gate in circuitInkCanvas.Children) { if (gate is Gate) { Gate g = gate as Gate; foreach (Gate.TerminalID tid in g) { tid.t.Background = Brushes.Transparent; } } } // gate termination indication 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) { Rect gRect = new Rect(g.Margin.Left, g.Margin.Top, g.Width, g.Height); foreach (Gate.TerminalID tid in g) { Rect tRect = GetTerminalBounds(g, grect, tid); condition = tRect.Contains(mp2); if (condition) { tid.t.Background = Brushes.Yellow; }else { tid.t.Background = Brushes.Transparent; } } } } } dragWire.Destination = mp2; break; case DragState.CONNECT_TO: foreach (UIElement gate in circuitInkCanvas.Children) { if (gate is Gate) { Gate g = gate as Gate; foreach (Gate.TerminalID tid in g) { tid.t.Background = Brushes.Transparent; } } } // gate termination indication 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) { Rect gRect = new Rect(g.Margin.Left, g.Margin.Top, g.Width, g.Height); foreach (Gate.TerminalID tid in g) { Rect tRect = GetTerminalBounds(g, grect, tid); condition = tRect.Contains(mp2); if (condition) { tid.t.Background = Brushes.Yellow; }else { tid.t.Background = Brushes.Transparent; } } } } } dragWire.Origin = mp2; break; case DragState.MOVE: #region DragState is Move foreach (Gate g in selected) { //g.RenderTransform = new TranslateTransform(mp2.X, mp2.Y); //Direct Move double dx = mp2.X - mp.X; double dy = mp2.Y - mp.Y; ((GateLocation)g.Tag).x = ((GateLocation)g.Tag).x + dx; ((GateLocation)g.Tag).y = ((GateLocation)g.Tag).y + dy; double cx = ((GateLocation)g.Tag).x % GRID_SIZE; double cy = ((GateLocation)g.Tag).y % GRID_SIZE; Point op = new Point(g.Margin.Left, g.Margin.Top); if ((Math.Abs(cx) < DELTA_SNAP || Math.Abs(GRID_SIZE - cx) < DELTA_SNAP) && (Math.Abs(cy) < DELTA_SNAP || Math.Abs(GRID_SIZE - cy) < DELTA_SNAP)) { g.Margin = new Thickness(Math.Round(g.Margin.Left / GRID_SIZE) * GRID_SIZE, Math.Round(g.Margin.Top / GRID_SIZE) * GRID_SIZE, 0, 0); } else { g.Margin = new Thickness(((GateLocation)g.Tag).x, ((GateLocation)g.Tag).y, 0, 0); } Point np = new Point(g.Margin.Left, g.Margin.Top); if (op != np) moves.Add(new UndoRedo.MoveGate(g, this, op, np)); SizeCanvas(); g.BringIntoView(); // still needed because gate larger than 20px block } UpdateWireConnections(); break; #endregion case DragState.NONE: #region Drag State is None // not dragging // creating a selection rectangle if (ReadyToSelect) { double x1 = Math.Min(mp2.X, sp.X); double width = Math.Abs(mp2.X - sp.X); double y1 = Math.Min(mp2.Y, sp.Y); double height = Math.Abs(mp2.Y - sp.Y); //dragSelect.Margin = new Thickness(x1, y1, 0, 0); //dragSelect.Width = width; //dragSelect.Height = height; //dragSelect.Visibility = Visibility.Visible; // select any gates inside the rectangle Rect select = new Rect(x1, y1, width, height); foreach (Gate g in gates.Values) { Rect grect = new Rect(g.Margin.Left, g.Margin.Top, g.Width, g.Height); if (select.IntersectsWith(grect) && !g.Selected) { g.Selected = true; selected.Add(g); } // this is not the same as just "not" or else the above if (!select.IntersectsWith(grect) && g.Selected) { g.Selected = false; selected.Remove(g); } } } break; #endregion } mp = mp2; }
/// <summary> /// Virtual method reporting a stylus-in-air-move /// </summary> protected internal virtual void OnStylusInAirMove(StylusEventArgs e) {}
public PieMenuHitTestEventArgs(Point pt, StylusEventArgs eventArgs, EventType eventType) : base() { Pt = pt; EventArgs = eventArgs; DragAndDropEventType = eventType; if(eventType == EventType.Down) { PieMenuHitTestEventArgs.FinalPt = pt; } }
/// <summary> /// Virtual method reporting the stylus left this element /// </summary> protected internal virtual void OnStylusLeave(StylusEventArgs e) {}
internal void ChangeStylusCapture(IInputElement stylusCapture, CaptureMode captureMode, int timestamp) #endif { // if the capture changed... if(stylusCapture != _stylusCapture) { // Actually change the capture first. Invalidate the properties, // and then send the events. IInputElement oldStylusCapture = _stylusCapture; using(Dispatcher.DisableProcessing()) // Disable reentrancy due to locks taken { lock(_rtiCaptureChanged) { _stylusCapture = stylusCapture; _captureMode = captureMode; // We also need to figure out ahead of time if any plugincollections on this captured element (or a parent) // for the penthread hittesting code. _stylusCapturePlugInCollection = null; if (stylusCapture != null) { UIElement uiElement = InputElement.GetContainingUIElement(stylusCapture as DependencyObject) as UIElement; if (uiElement != null) { PresentationSource source = PresentationSource.CriticalFromVisual(uiElement as Visual); if (source != null) { PenContexts penContexts = _stylusLogic.GetPenContextsFromHwnd(source); _stylusCapturePlugInCollection = penContexts.FindPlugInCollection(uiElement); } } } } } #if MULTICAPTURE DetachFromPropertiesAffectingCapture(oldStylusCapture); AttachToPropertiesAffectingCapture(_stylusCapture); // Oddly enough, update the IsStylusCaptureWithin property first. This is // so any callbacks will see the more-common IsStylusCaptureWithin property // set correctly. UIElement.StylusCaptureWithinProperty.OnOriginValueChanged(oldStylusCapture as DependencyObject, _stylusCapture as DependencyObject, ref _stylusCaptureWithinTreeState); // Invalidate the IsStylusCaptured properties. if (oldStylusCapture != null) { var o = oldStylusCapture as DependencyObject; o.SetValue(UIElement.IsStylusCapturedPropertyKey, false); // Same property for ContentElements } if (_stylusCapture != null) { var o = _stylusCapture as DependencyObject; o.SetValue(UIElement.IsStylusCapturedPropertyKey, true); // Same property for ContentElements } #else _stylusLogic.UpdateStylusCapture(this, oldStylusCapture, _stylusCapture, timestamp); #endif // Send the LostStylusCapture and GotStylusCapture events. if(oldStylusCapture != null) { StylusEventArgs lostCapture = new StylusEventArgs(this, timestamp); lostCapture.RoutedEvent=Stylus.LostStylusCaptureEvent; lostCapture.Source= oldStylusCapture; _stylusLogic.InputManagerProcessInputEventArgs(lostCapture); } if(_stylusCapture != null) { StylusEventArgs gotCapture = new StylusEventArgs(this, timestamp); gotCapture.RoutedEvent=Stylus.GotStylusCaptureEvent; gotCapture.Source= _stylusCapture; _stylusLogic.InputManagerProcessInputEventArgs(gotCapture); } // Now update the stylus over state (only if this is the current stylus and // it is inrange). if (_stylusLogic.CurrentStylusDevice == this || InRange) { if (_stylusCapture != null) { IInputElement inputElementHit = _stylusCapture; // See if we need to update over for subtree mode. if (CapturedMode == CaptureMode.SubTree && _inputSource != null && _inputSource.Value != null) { Point pt = _stylusLogic.DeviceUnitsFromMeasureUnits(GetPosition(null)); inputElementHit = FindTarget(_inputSource.Value, pt); } ChangeStylusOver(inputElementHit); } else { // Only try to update over if we have a valid input source. if (_inputSource != null && _inputSource.Value != null) { Point pt = GetPosition(null); // relative to window (root element) pt = _stylusLogic.DeviceUnitsFromMeasureUnits(pt); // change back to device coords. IInputElement currentOver = GlobalHitTest(_inputSource.Value, pt); ChangeStylusOver(currentOver); } } } // For Mouse StylusDevice we want to make sure Mouse capture is set up the same. #if MULTICAPTURE if ((Mouse.PrimaryDevice.StylusDevice == this) && (Mouse.Captured != _stylusCapture || Mouse.CapturedMode != _captureMode)) #else if (Mouse.Captured != _stylusCapture || Mouse.CapturedMode != _captureMode) #endif { Mouse.Capture(_stylusCapture, _captureMode); } } }
/// <summary> /// Virtual method reporting the stylus is now in range of the digitizer /// </summary> protected internal virtual void OnPreviewStylusInRange(StylusEventArgs e) {}