Exemple #1
0
 private void ClassBox_MouseEnter(object sender, MouseEventArgs e)
 {
     if (sender is ClassBox)
     {
         classBox = (ClassBox)sender;
     }
 }
Exemple #2
0
        private void MouseLeftButtonDown_groupClassBox(object sender, MouseButtonEventArgs e)
        {
            if ((sender is ClassBox))
            {
                ClassBox moveObject = (ClassBox)sender;

                if (moveObject.Parent is Canvas)
                {
                    beginTop  = Canvas.GetTop(moveObject);
                    beginLeft = Canvas.GetLeft(moveObject);

                    mouseMaxX = canvas.Width - moveObject.Width;
                    mouseMaxY = canvas.Height - moveObject.Height;

                    Point point = e.GetPosition(moveObject);
                    mouseMaxX += point.X;
                    mouseMaxY += point.Y;

                    point      = e.GetPosition(canvas);
                    beginLeft -= point.X;
                    beginTop  -= point.Y;

                    moveObject.MouseMove += MouseMove_groupClassBox;
                }
            }
        }
Exemple #3
0
        public void MouseLeftButtonUp_CreateArrow(object sender, MouseButtonEventArgs e)
        {
            canvas.MouseMove -= MouseMove_ArrowDrawing;

            if (classBox is ClassBox)
            {
                Point classBoxPoint = classBox.TransformToAncestor(canvas).Transform(new Point(0, 0));
                Point pt            = new Point(classBoxPoint.X + classBox.ActualWidth / 2, classBoxPoint.Y + classBox.ActualHeight / 2);
                classBox.linkPoint = pt;
                arrow.X2           = pt.X;
                arrow.Y2           = pt.Y;
                classBox.arrowLinesTo.Add(arrow);
            }
            else
            {
                canvas.Children.Remove(arrow);
                arrow = null;
            }

            foreach (object obj in canvas.Children)
            {
                if (obj is ClassBox)
                {
                    ClassBox cb = (ClassBox)obj;
                    cb.MouseLeftButtonDown -= MouseLeftButtonDown_CreateArrow;
                    cb.MouseLeftButtonDown += MouseLeftButtonDown_groupClassBox;
                    cb.MouseLeftButtonUp   -= MouseLeftButtonUp_CreateArrow;
                }
            }

            canvas.MouseLeftButtonUp -= MouseLeftButtonUp_CreateArrow;
        }
Exemple #4
0
 private void MouseLeftButtonUp_GroupBoxMove(object sender, MouseButtonEventArgs e)
 {
     if (sender is ClassBox)
     {
         ClassBox moveObject = (ClassBox)sender;
         moveObject.MouseMove -= MouseMove_groupClassBox;
     }
 }
Exemple #5
0
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            ClassBox cl = new ClassBox();

            cl.MouseLeftButtonDown += MouseLeftButtonDown_groupClassBox;
            cl.MouseLeftButtonUp   += MouseLeftButtonUp_GroupBoxMove;
            cl.MouseEnter          += ClassBox_MouseEnter;
            canvas.Children.Add(cl);
        }
Exemple #6
0
        private void MouseMove_groupClassBox(object sender, MouseEventArgs e)
        {
            if (sender is ClassBox)
            {
                ClassBox moveObject = (ClassBox)sender;

                Point  point = e.GetPosition(canvas);
                double x     = point.X;
                double y     = point.Y;

                if (x < mouseMinX)
                {
                    x = mouseMinX;
                }
                else if (x > mouseMaxX)
                {
                    x = mouseMaxX;
                }
                if (y < mouseMinY)
                {
                    y = mouseMinY;
                }
                else if (y > mouseMaxY)
                {
                    y = mouseMaxY;
                }

                Point classBoxPoint = moveObject.TransformToAncestor(canvas).Transform(new Point(0, 0));
                Point pt            = new Point(classBoxPoint.X + moveObject.ActualWidth / 2, classBoxPoint.Y + moveObject.ActualHeight / 2);

                moveObject.linkPoint = pt;
                foreach (ArrowLine arrow in moveObject.arrowLinesTo)
                {
                    arrow.X2 = moveObject.linkPoint.X;
                    arrow.Y2 = moveObject.linkPoint.Y;
                }

                foreach (ArrowLine arrow in moveObject.arrowLinesFrom)
                {
                    arrow.X1 = moveObject.linkPoint.X;
                    arrow.Y1 = moveObject.linkPoint.Y;
                }

                double top  = beginTop + y;
                double left = beginLeft + x;

                Canvas.SetLeft(moveObject, left);
                Canvas.SetTop(moveObject, top);
            }
        }
Exemple #7
0
        private void CreateLinkBetweenClassBoxes()
        {
            arrow                 = new ArrowLine();
            arrow.Stroke          = Brushes.White;
            arrow.StrokeThickness = 5;

            foreach (object obj in canvas.Children)
            {
                if (obj is ClassBox)
                {
                    ClassBox classBox = (ClassBox)obj;
                    classBox.MouseLeftButtonDown -= MouseLeftButtonDown_groupClassBox;
                    classBox.MouseLeftButtonDown += MouseLeftButtonDown_CreateArrow;
                    classBox.MouseLeftButtonUp   += MouseLeftButtonUp_CreateArrow;
                }
            }

            canvas.MouseLeftButtonUp += MouseLeftButtonUp_CreateArrow;
        }
Exemple #8
0
        private void MouseLeftButtonDown_CreateArrow(object sender, MouseButtonEventArgs e)
        {
            if (sender is ClassBox)
            {
                ClassBox classBox = (ClassBox)sender;
                if (arrow.X1 == 0 && arrow.X2 == 0)
                {
                    Point classBoxPoint = classBox.TransformToAncestor(canvas).Transform(new Point(0, 0));
                    Point pt            = new Point(classBoxPoint.X + classBox.ActualWidth / 2, classBoxPoint.Y + classBox.ActualHeight / 2);

                    arrow.X1          = pt.X;
                    arrow.Y1          = pt.Y;
                    arrow.X2          = pt.X;
                    arrow.Y2          = pt.Y;
                    canvas.MouseMove += MouseMove_ArrowDrawing;
                    canvas.Children.Add(arrow);
                    classBox.arrowLinesFrom.Add(arrow);
                }
            }
        }