Esempio n. 1
0
 /// <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);
     }
 }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
 /// <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();
     }
 }
Esempio n. 4
0
        /// <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;
            }
        }
Esempio n. 5
0
        public void DragSourcePieMenuPreviewMouseMove(object sender, StylusEventArgs e)
        {
            if (e.InAir)
                _draggedData = null;

            if (_draggedData != null)
            {
                //release the stylus like up event
                _draggedData = null;
                _stylusCaptured = false;
                if (_adorner != null)
                {
                    //_adorner.ReleaseStylusCapture();
                    _adornerLayer.Children.Remove(_adorner);
                }
            }

            _draggedData = (sender as FrameworkElement).DataContext;


            if (!_stylusCaptured && _draggedData != null)
            {
                // Only drag when user moved the mouse by a reasonable amount.
                if (DragDropHelper.IsMovementBigEnough(_initialMousePosition, e.GetPosition(_topUserControl)))
                {
                    try
                    {
                        _adorner = (DragDropAdornerBase)GetDragDropControl(sender as DependencyObject);
                        _adorner.DataContext = _draggedData;

                        _adorner.Opacity = 0.7;

                        _adornerLayer.Visibility = Visibility.Collapsed;

                        _adornerLayer.Children.Add(_adorner);

                        //_stylusCaptured = Stylus.Capture(_adorner);

                        Canvas.SetLeft(_adorner, _initialMousePosition.X - 20);
                        Canvas.SetTop(_adorner, _initialMousePosition.Y - 15);

                        //_adornerLayer.PreviewMouseMove += new MouseEventHandler(_adorner_MouseMove);
                        //_adornerLayer.PreviewMouseUp += new MouseButtonEventHandler(_adorner_MouseUp);
                        //_adornerLayer.StylusUp += new StylusEventHandler(_adornerLayer_StylusUp);
                    }
                    catch (Exception eee)
                    {
                        System.Diagnostics.Debug.Print(eee.ToString());
                        // bummer
                    }
                }
            }

        }
Esempio n. 6
0
        public void DragSourcePieMenuPreviewMouseLeftButtonDown(UserControl diagramUserControl, StylusEventArgs e)
        {
            try
            {
                _topUserControl = diagramUserControl;

                _initialMousePosition = e.GetPosition(_topUserControl);

                _adornerLayer = (Canvas)_topUserControl.FindName("adornerLayer");

                _dropTarget = (UIElement)_topUserControl.FindName("inkCanvas");

            }
            catch (Exception exc)
            {
                Console.WriteLine("Exception in DragDropHelper: " + exc.InnerException.ToString());
            }
        }
        protected override void OnStylusMove(StylusEventArgs args)
        {
            base.OnStylusMove(args);

            if (isDrawing)
            {
                Point ptStylus = args.GetPosition(canv);
                polyStylus.Points.Add(ptStylus);
                polyShadow.Points.Add(ptStylus + vectShadow);
                args.Handled = true;
            }
        }
Esempio n. 8
0
 private void Grid_StylusMove(object sender, StylusEventArgs e)
 {
     Point currentPosition = e.GetPosition(Grid1);
     DrawProcessing(currentPosition);
 }
 void Emitter_StylusMove(object sender, StylusEventArgs e)
 {
     Emitter.EmitLocation = e.GetPosition(Emitter);
 }
        private void AddPenPointerEvent(PointerEventType eventType, PointerUpdateKind updateKind, bool isPress, StylusEventArgs e)
        {
            var p = e.GetPosition(element);

            var point = new PointerPoint();

            FillPointInformation(ref point,
                                 eventType,
                                 PointerDeviceType.Pen,
                                 updateKind,
                                 p);

            // if this was a press - try to determine which button was pressed
            if (isPress)
            {
                if (e.Inverted)
                    point.IsRightButtonPressed = true;
                else
                    point.IsLeftButtonPressed = true;
            }

            manager.AddPointerEvent(ref point);
        }
Esempio n. 11
0
 // Touch move event handler.
 private void OnTouchMoveHandler(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))
     {
         // Add contact point to the stroke
         stroke.Add(e.GetPosition(_canvas));
         stroke.AddToCanvas(_canvas);
     }
 }
Esempio n. 12
0
        /*
        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;
        }
Esempio n. 13
0
        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;
                    }
                }
            }
        }
 public Point GetPositionReletiveToContainer(StylusEventArgs e, Window win)
 {
     return e.GetPosition(win);
 }
Esempio n. 15
0
        /*
        * Expression User Control: No
        * TruthTable User Control: No
        * Diagram User Control: Yes
        * 
        */
        protected override void OnStylusUp(StylusEventArgs e)
        {
            base.OnStylusUp(e);
        
            InkQueryRegionStruct removedRegion = null;

            foreach (UIElement child in Children)
            {
                if (child is IPassable)
                {
                    if (child is LogicPad2.TruthTable.UserControl1)
                    {
                        #region TruthTable User Control
                        LogicPad2.TruthTable.UserControl1 truthTableUserControl = child as LogicPad2.TruthTable.UserControl1;

                        //HitTest
                        Point pt = e.GetPosition(this);

                        if (truthTableUserControl.UserControlStatus != UserControlStatus.None)
                        {
                            //Check HitTest With Other InkCanvas InkQueryRegionStruct
                            removedRegion = HitTestInkQueryRegionStruct(truthTableUserControl);

                            truthTableUserControl.UserControlStatus = UserControlStatus.None;
                        }

                        truthTableUserControl.ReleaseStylusCapture();

                        #endregion
                    }
                    else if (child is LogicPad2.Diagram.UserControl1)
                    {
                        #region Diagram User Control

                        LogicPad2.Diagram.UserControl1 diagramUserControl = child as LogicPad2.Diagram.UserControl1;

                        //HitTest
                        Point pt = e.GetPosition(this);

                        if (diagramUserControl.UserControlStatus == UserControlStatus.Scale
                            || diagramUserControl.UserControlStatus == UserControlStatus.Transform)
                        {
                            //HitTest With Other InkCanvas InkQueryRegionStruct
                            removedRegion = HitTestInkQueryRegionStruct(diagramUserControl);
                        }
                        else if (diagramUserControl.UserControlStatus == UserControlStatus.Inking)
                        {
                            //Check HitTest Result on InkCanvas
                            HitTestResult result = VisualTreeHelper.HitTest(diagramUserControl.DiagramInkCanvas, this.TransformToDescendant(diagramUserControl.DiagramInkCanvas).Transform(pt));
                            if (result != null)
                            {
                                (child as IPassable).StylusUp(this, e);
                                return;
                            }
                        }

                        diagramUserControl.UserControlStatus = UserControlStatus.None;

                        diagramUserControl.ReleaseStylusCapture();

                        #endregion
                    }
                    else if (child is LogicPad2.Expression.UserControl1)
                    {
                        #region Expression User Control

                        LogicPad2.Expression.UserControl1 expressionUserControl = child as LogicPad2.Expression.UserControl1;

                        //HitTest
                        Point pt = e.GetPosition(this);

                        if (expressionUserControl.UserControlStatus != UserControlStatus.None)
                        {
                            //Check HitTest With Other InkCanvas InkQueryRegionStruct
                            removedRegion = HitTestInkQueryRegionStruct(expressionUserControl);

                            expressionUserControl.UserControlStatus = UserControlStatus.None;
                        }

                        expressionUserControl.ReleaseStylusCapture();

                        #endregion
                    }
                    else if (child is ExpressionWindow.ExpressionRepresentation)
                    {
                        #region Expression Representation
                        ExpressionWindow.ExpressionRepresentation expressionRepr = child as ExpressionWindow.ExpressionRepresentation;

                        //HitTest
                        Point pt = e.GetPosition(this);

                        if (expressionRepr.UserControlStatus != UserControlStatus.None)
                        {
                            expressionRepr.UserControlStatus = UserControlStatus.None;
                        }

                        expressionRepr.ReleaseStylusCapture();

                        #endregion
                    }
                    else if (child is TruthTableWindow.TruthTableRepresentation)
                    {
                        #region TruthTable Representation
                        TruthTableWindow.TruthTableRepresentation truthTableRepr = child as TruthTableWindow.TruthTableRepresentation;

                        //HitTest
                        Point pt = e.GetPosition(this);

                        if (truthTableRepr.UserControlStatus != UserControlStatus.None)
                        {
                            truthTableRepr.UserControlStatus = UserControlStatus.None;
                        }

                        truthTableRepr.ReleaseStylusCapture();

                        #endregion
                    }
                    else if (child is GatesWpf.DiagramRepresentation)
                    {
                        #region Diagram Representation
                        GatesWpf.DiagramRepresentation diagramRepr = child as GatesWpf.DiagramRepresentation;

                        //HitTest
                        Point pt = e.GetPosition(this);
                        if (diagramRepr.UserControlStatus != UserControlStatus.None)
                        {
                            diagramRepr.UserControlStatus = UserControlStatus.None;
                        }
                        diagramRepr.ReleaseStylusCapture();

                        #endregion
                    }
                }
            }

            if (removedRegion != null)
            {
                this.Children.Remove(removedRegion);
            }
        }
Esempio n. 16
0
        /*
        * Expression User Control: No
        * TruthTable User Control: No
        * Diagram User Control: Yes
        * 
        */
        protected override void OnStylusMove(StylusEventArgs e)
        {
            base.OnStylusMove(e);

            foreach (UIElement child in Children)
            {
                if (child is IPassable)
                {
                    if (child is LogicPad2.Expression.UserControl1)
                    {
                        #region Expression User Control
                        Point pt = e.GetPosition(this);

                        LogicPad2.Expression.UserControl1 expressionUserControl = child as LogicPad2.Expression.UserControl1;

                        //Scale User Control Operation
                        if (expressionUserControl.UserControlStatus == UserControlStatus.Scale)
                        {
                            double newBtmX = pt.X;
                            expressionUserControl.CaptureStylus();
                            double scaler = -(expressionUserControl.InitBtmX - newBtmX) / expressionUserControl.ActualWidth;
                            expressionUserControl.InitBtmX = newBtmX;
                            expressionUserControl.UserControlScaleX += scaler;
                            expressionUserControl.UserControlScaleY += scaler;
                            return;
                        }
                        else if (expressionUserControl.UserControlStatus == UserControlStatus.Transform)
                        {
                            expressionUserControl.CaptureStylus();
                            expressionUserControl.UserControlX = e.GetPosition(this).X - expressionUserControl.ActualWidth * expressionUserControl.UserControlScaleX;
                            expressionUserControl.UserControlY = e.GetPosition(this).Y - expressionUserControl.ActualHeight * expressionUserControl.UserControlScaleY;
                          
                            return;
                        }

                        #endregion
                    }
                    else if (child is LogicPad2.TruthTable.UserControl1)
                    {
                        #region Truth Table User Control

                        Point pt = e.GetPosition(this);

                        LogicPad2.TruthTable.UserControl1 truthTableUserControl = child as LogicPad2.TruthTable.UserControl1;

                        //Scale User Control Operation
                        if (truthTableUserControl.UserControlStatus == UserControlStatus.Scale)
                        {
                            double newBtmX = pt.X;
                            truthTableUserControl.CaptureStylus();
                            double scaler = -(truthTableUserControl.InitBtmX - newBtmX) / truthTableUserControl.ActualWidth;
                            truthTableUserControl.InitBtmX = newBtmX;
                            truthTableUserControl.UserControlScaleX += scaler;
                            truthTableUserControl.UserControlScaleY += scaler;
                            
                            return;
                        }
                        else if (truthTableUserControl.UserControlStatus == UserControlStatus.Transform)
                        {
                            truthTableUserControl.CaptureStylus();
                            truthTableUserControl.UserControlX = e.GetPosition(this).X - truthTableUserControl.ActualWidth * truthTableUserControl.UserControlScaleX;
                            truthTableUserControl.UserControlY = e.GetPosition(this).Y - truthTableUserControl.ActualHeight * truthTableUserControl.UserControlScaleY;
                            return;
                        }
                        #endregion
                    }
                    else if (child is LogicPad2.Diagram.UserControl1)
                    { 
                        #region Diagram User Control

                        Point pt = e.GetPosition(this);

                        LogicPad2.Diagram.UserControl1 diagramUserControl = child as LogicPad2.Diagram.UserControl1;

                        double newBtmX = pt.X;
                        double newBtmY = pt.Y;

                        //Scale User Control Operation
                        if (diagramUserControl.UserControlStatus == UserControlStatus.Scale)
                        {
                            diagramUserControl.CaptureStylus();
                            double scaler = -(diagramUserControl.InitBtmX - newBtmX) / diagramUserControl.ActualWidth;
                            diagramUserControl.InitBtmX = newBtmX;
                            diagramUserControl.UserControlScaleX += scaler;
                            diagramUserControl.UserControlScaleY += scaler;
                            return;
                        }
                        else if (diagramUserControl.UserControlStatus == UserControlStatus.Transform)
                        {
                            diagramUserControl.CaptureStylus();

                            double deltax = -(diagramUserControl.InitBtmX - newBtmX);
                            double deltay = -(diagramUserControl.InitBtmY - newBtmY);
                            //diagramUserControl.UserControlX = e.GetPosition(this).X - diagramUserControl.ActualWidth * diagramUserControl.UserControlScaleX;
                            diagramUserControl.UserControlX += deltax; 
                            //diagramUserControl.UserControlY = e.GetPosition(this).Y - diagramUserControl.ActualHeight * diagramUserControl.UserControlScaleY;
                            diagramUserControl.UserControlY += deltay;
                            diagramUserControl.InitBtmX = newBtmX;
                            diagramUserControl.InitBtmY = newBtmY;
                            return;
                        }else if(diagramUserControl.UserControlStatus == UserControlStatus.Inking)
                        {
                            //Check HitTest Result on InkCanvas
                            HitTestResult result = VisualTreeHelper.HitTest(diagramUserControl.DiagramInkCanvas, this.TransformToDescendant(diagramUserControl.DiagramInkCanvas).Transform(pt));
                            if (result != null)
                            {
                                diagramUserControl.UserControlStatus = UserControlStatus.Inking;
                                (child as IPassable).StylusMove(this, e);
                                return;
                            }
                        }
                        #endregion
                    }
                    else if (child is ExpressionWindow.ExpressionRepresentation)
                    {
                        #region Expression Representation
                        Point pt = e.GetPosition(this);

                        ExpressionWindow.ExpressionRepresentation expressionRepr = child as ExpressionWindow.ExpressionRepresentation;

                        //Scale User Control Operation
                        if (expressionRepr.UserControlStatus == UserControlStatus.Scale)
                        {
                            double newBtmX = pt.X;
                            expressionRepr.CaptureStylus();
                            double scaler = -(expressionRepr.InitBtmX - newBtmX) / expressionRepr.ActualWidth;
                            expressionRepr.InitBtmX = newBtmX;
                            expressionRepr.UserControlScaleX += scaler;
                            expressionRepr.UserControlScaleY += scaler;
                            return;
                        }
                        else if (expressionRepr.UserControlStatus == UserControlStatus.Transform)
                        {
                            expressionRepr.CaptureStylus();
                            expressionRepr.UserControlX = e.GetPosition(this).X - expressionRepr.ActualWidth * expressionRepr.UserControlScaleX;
                            expressionRepr.UserControlY = e.GetPosition(this).Y - expressionRepr.ActualHeight * expressionRepr.UserControlScaleY;

                            return;
                        }

                        #endregion
                    }
                    else if (child is TruthTableWindow.TruthTableRepresentation)
                    {
                        #region TruthTable Representation
                        Point pt = e.GetPosition(this);

                        TruthTableWindow.TruthTableRepresentation truthTableRepr = child as TruthTableWindow.TruthTableRepresentation;

                        //Scale User Control Operation
                        if (truthTableRepr.UserControlStatus == UserControlStatus.Scale)
                        {
                            double newBtmX = pt.X;
                            truthTableRepr.CaptureStylus();
                            double scaler = -(truthTableRepr.InitBtmX - newBtmX) / truthTableRepr.ActualWidth;
                            truthTableRepr.InitBtmX = newBtmX;
                            truthTableRepr.UserControlScaleX += scaler;
                            truthTableRepr.UserControlScaleY += scaler;
                            return;
                        }
                        else if (truthTableRepr.UserControlStatus == UserControlStatus.Transform)
                        {
                            truthTableRepr.CaptureStylus();
                            truthTableRepr.UserControlX = e.GetPosition(this).X - truthTableRepr.ActualWidth * truthTableRepr.UserControlScaleX;
                            truthTableRepr.UserControlY = e.GetPosition(this).Y - truthTableRepr.ActualHeight * truthTableRepr.UserControlScaleY;

                            return;
                        }

                        #endregion    
                    }
                    else if (child is GatesWpf.DiagramRepresentation)
                    {
                        #region Diagram Representation

                        Point pt = e.GetPosition(this);

                        GatesWpf.DiagramRepresentation diagramRepr = child as GatesWpf.DiagramRepresentation;

                        //Scale User Control Operation
                        if (diagramRepr.UserControlStatus == UserControlStatus.Scale)
                        {
                            double newBtmX = pt.X;
                            diagramRepr.CaptureStylus();
                            double scaler = -(diagramRepr.InitBtmX - newBtmX) / diagramRepr.ActualWidth;
                            diagramRepr.InitBtmX = newBtmX;
                            diagramRepr.UserControlScaleX += scaler;
                            diagramRepr.UserControlScaleY += scaler;
                            return;
                        }
                        else if (diagramRepr.UserControlStatus == UserControlStatus.Transform)
                        {
                            diagramRepr.CaptureStylus();
                            diagramRepr.UserControlX = e.GetPosition(this).X - diagramRepr.ActualWidth * diagramRepr.UserControlScaleX;
                            diagramRepr.UserControlY = e.GetPosition(this).Y - diagramRepr.ActualHeight * diagramRepr.UserControlScaleY;

                            return;
                        }

                        #endregion
                    }
                  }
              }
        }
Esempio n. 17
0
        /*
         * Expression User Control: No
         * TruthTable User Control: No
         * Diagram User Control: Yes
         * 
         */

        protected override void OnPreviewStylusMove(StylusEventArgs e)
        {
            base.OnPreviewStylusMove(e);

            foreach (UIElement child in Children)
            {
                if (child is IPassable)
                {
                    if (child is LogicPad2.Diagram.UserControl1)
                    {
                        #region Diagram User Control

                        Point pt = e.GetPosition(this);
                        HitTestResult result = VisualTreeHelper.HitTest(child, this.TransformToDescendant(child).Transform(pt));

                        if (result != null)
                        {
                            LogicPad2.Diagram.UserControl1 diagramUserControl = child as LogicPad2.Diagram.UserControl1;

                            if (diagramUserControl.UserControlStatus == UserControlStatus.Inking)
                            {
                                #region obsolete code
                                /* 
                                //Adhoc to hittest
                                for (int i = 0; i < diagramUserControl.DiagramInkCanvas.Children.Count; i++)
                                {
                                    UIElement uie = diagramUserControl.DiagramInkCanvas.Children[i];

                                    if (uie is ConnectedWire)
                                    {
                                        result = VisualTreeHelper.HitTest(uie, this.TransformToDescendant(diagramUserControl.DiagramInkCanvas).Transform(pt));
                                        if (result != null)
                                        {
                                            ConnectedWire myWire = uie as ConnectedWire;

                                            if (HitTestWireDict.ContainsKey(myWire))
                                            {
                                                HitTestWireDict[myWire]++;
                                            }
                                            else
                                            {
                                                HitTestWireDict.Add(myWire, 1);
                                            }

                                            
                                            if(HitTestWireDict[myWire] == 3)
                                            {
                                                HitTestWireDict.Clear();

                                                Debug.WriteLine("This wire is " + myWire.ToString());

                                                (child as IPassable).PreviewStylusMove(uie, e);
                                            }
                                            

                                            Debug.WriteLine("HitTest count " + HitTestWireDict[myWire].ToString());
                                        }
                                    }
                                }

                                */
                                #endregion

                                //Check HitTest Result on InkCanvas
                                result = VisualTreeHelper.HitTest(diagramUserControl.DiagramInkCanvas, this.TransformToDescendant(diagramUserControl.DiagramInkCanvas).Transform(pt));
                                if (result != null)
                                {
                                    diagramUserControl.UserControlStatus = UserControlStatus.Inking;
                                    (child as IPassable).PreviewStylusMove(this, e);
                                    return;
                                }
                            }
                        }
                        #endregion
                    }
                }
            }
        }
Esempio n. 18
0
        void _adornerLayer_StylusUp(object sender, StylusEventArgs e)
        {
            Debug.WriteLine(_adorner.AdornerDropState.ToString());
            switch (_adorner.AdornerDropState)
            {
                case DropState.CanDrop:
                    try
                    {
                        ((Storyboard)_adorner.Resources["canDrop"]).Completed += (s, args) =>
                        {
                            _adornerLayer.Children.Clear();
                            _adornerLayer.Visibility = Visibility.Collapsed;
                        };
                        ((Storyboard)_adorner.Resources["canDrop"]).Begin(_adorner);

                        // Added position in drop target
                        Point pos = e.GetPosition((IInputElement)_dropTarget);
                        if (ItemDropped != null)
                            ItemDropped(_adorner, new DragDropEventArgs(_draggedData, pos, _dropTarget));
                    }
                    catch (Exception)
                    { }
                    break;
                case DropState.CannotDrop:
                    try
                    {
                        Storyboard sb = _adorner.Resources["cannotDrop"] as Storyboard;
                        DoubleAnimation aniX = sb.Children[0] as DoubleAnimation;
                        aniX.To = _delta.X;
                        DoubleAnimation aniY = sb.Children[1] as DoubleAnimation;
                        aniY.To = _delta.Y;
                        sb.Completed += (s, args) =>
                        {
                            _adornerLayer.Children.Clear();
                            _adornerLayer.Visibility = Visibility.Collapsed;
                        };
                        sb.Begin(_adorner);
                    }
                    catch (Exception) { }
                    break;
            }

            _draggedData = null;
            //_adornerLayer.PreviewMouseMove -= new MouseEventHandler(_adorner_MouseMove);
            //_adornerLayer.PreviewMouseUp -= new MouseButtonEventHandler(_adorner_MouseUp);
            _adornerLayer.StylusUp -= new StylusEventHandler(_adornerLayer_StylusUp);

            if (_adorner != null)
            {
                _adorner.ReleaseMouseCapture();
            }
            _adorner = null;
            //_mouseCaptured = false;
            _stylusCaptured = false;
        }
Esempio n. 19
0
 void MainInkCanvas_StylusMove(object sender, StylusEventArgs e)
 {
     if (e.GetPosition(MainInkCanvas).X <= 10)
     {
         openSidebar();
     }
     else
     {
         hideSidebar();
     }
 }
Esempio n. 20
0
      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();
            }
         }         
      }
Esempio n. 21
0
      protected override void OnStylusMove(StylusEventArgs e)
      {
         if(TouchEnabled && Core.IsDragging)
         {
            if(!isDragging)
            {
               isDragging = true;
               Debug.WriteLine("IsDragging = " + isDragging);
            }

            if(BoundsOfMap.HasValue && !BoundsOfMap.Value.Contains(Position))
            {
               // ...
            }
            else
            {
               System.Windows.Point p = e.GetPosition(this);

               if(MapRenderTransform != null)
               {
                  p = MapRenderTransform.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)
               {
                  Core_OnMapZoomChanged();
               }
               else
               {
                  UpdateMarkersOffset();
               }
            }
            InvalidateVisual();
         }

         base.OnStylusMove(e);
      }
Esempio n. 22
0
        //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);
            }
           
        }     
Esempio n. 23
0
        /** @} */
        #endregion

        #region Stylus
        /** @name Stylus Overrides
         * Stylus event triggers overriden from <see cref="UIElement"/>.
         */
        /** @{ */

        /// @internal
        /// <inheritdoc />
        protected override void OnPreviewStylusMove( StylusEventArgs e )
        {
            if ( !IsLive )
                return;

            var pos = e.GetPosition( this );
            var x = (int)( pos.X * deviceTransform.M11 );
            var y = (int)( pos.Y * deviceTransform.M22 );

            awe_webview_inject_mouse_move( Instance, x, y );
            base.OnPreviewStylusMove( e );
        }
Esempio n. 24
0
        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;
        }
Esempio n. 25
0
 void SideInkCanvas_StylusUp(object sender, StylusEventArgs e)
 {
     headings.click(e.GetPosition(SideInkCanvas));
 }