コード例 #1
0
        //マウスで線を引いていたのを止める
        private void EndDraw()
        {
            IsDrawing = false;
            MyCanvas.ReleaseMouseCapture();//Canvasからマウス開放
            if (TempPolyline == null)
            {
                return;
            }
            //polyline
            if (TempPolyline.Points.Count > 1)
            {
                //PolylinePathからベジェ曲線Pathを作成してリストに追加
                Visibility visibility = (bool)(CheckBoxVisible.IsChecked) ? Visibility.Visible : Visibility.Hidden;
                var        myBezier   = new MyBezier(TempPolyline.Points, SliderCurve.Value, (int)SliderInterval.Value,
                                                     (DistanceType)ComboBoxDistanceType.SelectedItem,
                                                     (RadianType)ComboBoxRadianType.SelectedItem,
                                                     visibility);
                MyListBezierPaths.Add(myBezier);
                MyCanvas.Children.Add(myBezier.BezierPath);
                MyCanvas.Children.Add(myBezier.VertexPath);
                MyCanvas.Children.Add(myBezier.DirectionLinePath);

                MyCanvas.Children.Remove(TempPolyline);
            }
            TempPolyline = null;
        }
コード例 #2
0
        private void OnLeftUp(object sender, MouseButtonEventArgs e)
        {
            if (MyCanvas.IsMouseCaptured)
            {
                maskDrawer.DoneDrawingFreehandPath();

                AllPoints.Add(maskDrawer.RawPathPoints);

                MyCanvas.ReleaseMouseCapture();
            }
        }
コード例 #3
0
 //左クリック離したとき、描画の終了処理
 private void MyCanvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
 {
     if (IsDrawing == true)
     {
         IsDrawing = false;
         MyCanvas.ReleaseMouseCapture();//マウスキャプチャ開放
         //Tagに入れたPointsはもとに戻すときに使う
         MyPolyline.Tag = MyPolyline.Points;
         //クリックのみでドラッグ移動しなかったときは
         //作成したPolylineを削除
         if (MyPolyline.Points.Count == 0)
         {
             ClearEllipsePoints();
             MyListPolyline.Remove(MyPolyline);
             MyCanvas.Children.Remove(MyPolyline);
         }
         //●を表示
         ClearEllipsePoints();
         AddEllipsePoints2();
     }
 }
コード例 #4
0
 private void MyCanvas_OnMouseUp(object sender, MouseButtonEventArgs e)
 {
     if (e.LeftButton == MouseButtonState.Released)
     {
         if (MyCanvas.IsMouseCaptured)
         {
             var currentPosition = Mouse.GetPosition(MyCanvas);
             if (currentPosition.X < _startPoint.X || currentPosition.Y < _startPoint.Y)
             {
                 MyCanvas.Children.Remove(_lastRectangle);
             }
             else
             {
                 ResizeRectangle(currentPosition);
             }
             _isDragging = false;
             MyCanvas.ReleaseMouseCapture();
             e.Handled = true;
         }
     }
 }
コード例 #5
0
        private void MyCanvas_MouseUp(object sender, MouseButtonEventArgs e)
        {
            try
            {
                Point point = e.GetPosition((UIElement)sender);

                // Perform the hit test against a given portion of the visual object tree.
                HitTestResult result = VisualTreeHelper.HitTest(MyCanvas, point);

                if (action.Equals("connect"))
                {
                    Console.WriteLine(point.X);
                    Console.WriteLine(point.Y);

                    if (result != null)
                    {
                        // Get the label for the result
                        Label label = FindParent <Label>(result.VisualHit);

                        // Search the state that has the specific label
                        foreach (var state in States)
                        {
                            if (state.Content.Equals(label.Content))
                            {
                                // set the second state
                                state2 = state;
                            }
                        }

                        // delete the line
                        if (line != null)
                        {
                            MyCanvas.Children.Remove(line);
                            line = null;
                        }

                        if (state1 != state2)
                        {
                            if (state1.X < state2.X)
                            {
                                // create a new line
                                line = new Line
                                {
                                    /* set the coordonates for the new line(this is the final line,
                                     *  it will connect the states)*/
                                    X1 = state1.X + 50,
                                    Y1 = state1.Y + 25
                                };

                                line.X2 = Math.Abs(state2.X);
                                line.Y2 = Math.Abs(state2.Y + state2.Height / 2);
                            }
                            else
                            {
                                Console.WriteLine("state 1: " + state1.ToString());
                                Console.WriteLine("state 2: " + state2.ToString());
                                // create a new line
                                line = new Line
                                {
                                    Name = state1.Content.Concat(state2.Content).ToString(),

                                    /* set the coordonates for the new line(this is the final line,
                                     *  it will connect the states)*/
                                    X1 = state1.X,
                                    Y1 = state1.Y + state1.Height / 2
                                };

                                line.X2 = state2.X + state2.Width / 2;
                                line.Y2 = state2.Y;
                            }


                            line.StrokeThickness = 2;
                            line.Stroke          = Brushes.Black;
                            line.Cursor          = Cursors.Cross;
                            MyCanvas.Children.Add(line);
                            Tuple <UIElement, string> t = new Tuple <UIElement, string>(line, action);
                            Console.WriteLine("Before: " + UndoStack.Count);
                            UndoStack.Add(t);
                            TextBox txt = new TextBox
                            {
                                Text = "Transition",
                                Name = line.Name
                            };

                            Canvas.SetLeft(txt, state1.X + (state2.X - state1.X) / 2);
                            Canvas.SetTop(txt, state1.Y + (state2.Y - state1.Y) / 2 + 5);
                            MyCanvas.Children.Add(txt);
                            Tuple <UIElement, string> t2 = new Tuple <UIElement, string>(txt, action);
                            UndoStack.Add(t2);
                            Console.WriteLine("After: " + UndoStack.Count);
                            Arrow newArrow = new Arrow
                            {
                                Label = txt,
                                Line  = line
                            };
                            Arrows.Add(newArrow);
                            line = null;
                        }
                        else
                        {
                            // draw an arc from a state to the same state
                            var g = new StreamGeometry();

                            using (var gc = g.Open())
                            {
                                gc.BeginFigure(
                                    startPoint: new Point(state1.X + 20, state1.Y),
                                    isFilled: false,
                                    isClosed: false);

                                gc.ArcTo(
                                    point: new Point(state1.X + 30, state1.Y),
                                    size: new Size(3, 10),
                                    rotationAngle: 0d,
                                    isLargeArc: false,
                                    sweepDirection: SweepDirection.Clockwise,
                                    isStroked: true,
                                    isSmoothJoin: true);
                            }

                            var path = new Path
                            {
                                Stroke          = Brushes.Black,
                                StrokeThickness = 2,
                                Data            = g
                            };

                            MyCanvas.Children.Add(path);
                            Tuple <UIElement, string> t = new Tuple <UIElement, string>(path, action);
                            UndoStack.Add(t);
                            TextBox txt = new TextBox
                            {
                                Text = "Transition"
                            };
                            Canvas.SetLeft(txt, state1.X);
                            Canvas.SetTop(txt, state1.Y - state1.Height * 3 / 4);
                            MyCanvas.Children.Add(txt);
                            Tuple <UIElement, string> t2 = new Tuple <UIElement, string>(txt, action);
                            UndoStack.Add(t2);
                        }

                        state1    = null;
                        state2    = null;
                        _isMoving = false;
                        MyCanvas.ReleaseMouseCapture();
                    }
                }
                else if (action.Equals("select"))
                {
                    MyCanvas.Children.Remove(movingGrid as UIElement);
                    Point mousePos = Mouse.GetPosition(MyCanvas);
                    Console.WriteLine("Position: " + mousePos.ToString());
                    State state = new State
                    {
                        X      = mousePos.X - 25,
                        Y      = mousePos.Y - 25,
                        Width  = 50,
                        Height = 50,
                        Id     = Int32.Parse(movingState.Content.Substring(1))
                    };

                    States.Add(state);

                    Ellipse stateel = new Ellipse
                    {
                        Height = 50,
                        Width  = 50,
                        Fill   = Brushes.LightBlue,
                        Stroke = Brushes.Black
                    };

                    Label lbl = new Label
                    {
                        Content = "S" + Int32.Parse(movingState.Content.Substring(1)),
                        Height  = 50,
                        Width   = 50,
                        HorizontalContentAlignment = HorizontalAlignment.Center,
                        VerticalContentAlignment   = VerticalAlignment.Center
                    };

                    Grid stateGrid = new Grid();
                    stateGrid.Children.Add(stateel);
                    stateGrid.Children.Add(lbl);
                    stateGrid.Width  = 50;
                    stateGrid.Height = 50;
                    stateGrid.Cursor = Cursors.Hand;
                    Canvas.SetLeft(stateGrid, state.X);
                    Canvas.SetTop(stateGrid, state.Y);

                    movingState = null;
                    movingGrid  = null;
                    _isMoving   = false;
                    MyCanvas.ReleaseMouseCapture();
                    MyCanvas.Children.Add(stateGrid);
                    foreach (var el in UndoStack)
                    {
                        if (el.GetType().Equals(typeof(Grid)) && ((el.Item1 as Grid).Children[1] as Label).Content.Equals(lbl.Content))
                        {
                            UndoStack.Remove(el);
                            RedoStack.Add(el);
                        }
                    }

                    for (var index = MyCanvas.Children.Count - 1; index >= 0; index--)
                    {
                        if (MyCanvas.Children[index].GetType().Equals(typeof(Line)) && (MyCanvas.Children[index] as Line).Name.Contains((stateGrid.Children[1] as Label).Content.ToString()))
                        {
                            //MyCanvas.Children[1]
                            //Console.WriteLine("fjsdhfd");
                        }
                    }

                    Tuple <UIElement, string> t = new Tuple <UIElement, string>(stateGrid, action);
                    UndoStack.Add(t);
                }
            }
            catch (Exception)
            {
                Console.WriteLine("Something is wrong...");
            }
        }