Beispiel #1
0
        public static void CreateEdge(DrawingState state)
        {
            if (state.firstCircle == null || state.secondCircle == null)
                return;
            if (!state.controller.ContainsEdge(state.firstCircle, state.secondCircle) &&
                state.firstCircle != state.secondCircle)
            {
                Line line = new Line()
                {
                    X1 = state.firstCircle.Position.X,
                    Y1 = state.firstCircle.Position.Y,
                    X2 = state.secondCircle.Position.X,
                    Y2 = state.secondCircle.Position.Y
                };
                state.controller.AddEdge(line, state.firstCircle, state.secondCircle);
                line.Stroke = System.Windows.Media.Brushes.LightSteelBlue;
                line.StrokeThickness = 2;
                state.canvas.Children.Add(line);

                line.MouseDown += (object a, MouseButtonEventArgs b) =>
                {
                    if (state.currentTool == DrawingState.Tool.REMOVE_EDGE)
                    {
                        state.controller.RemoveEdge(a as Line, state.mainWindow);
                    }
                };
            }
            state.firstCircle = null;
            state.secondCircle = null;
        }
Beispiel #2
0
        public static Circle CreateVertex(Point position, DrawingState state)
        {
            Circle circle = new Circle(position);
            state.controller.AddVertex(circle);
            Ellipse ellipse = circle.ellipse;

            ellipse.MouseDown += (object a, MouseButtonEventArgs b) =>
            {
                if (state.currentTool == DrawingState.Tool.DRAW_EDGE)
                {
                    if (state.firstCircle == null)
                        state.firstCircle = circle;
                    else if (state.secondCircle != null)
                        state.firstCircle = circle;
                    else
                        state.secondCircle = circle;
                }
                else
                {
                    state.firstCircle = state.secondCircle = null;
                }
            };
            //TODO - choose hover effect, do when styling
            ellipse.MouseEnter += (object o, MouseEventArgs e) =>
            {
                if (state.currentTool == DrawingState.Tool.DRAW_EDGE)
                {
                    ellipse.Fill = new SolidColorBrush(Color.FromRgb(0, 0, 0));
                }
            };
            ellipse.MouseLeave += (object o, MouseEventArgs e) =>
            {
                ellipse.Fill = new SolidColorBrush(Color.FromArgb(255, 0, 150, 0));
            };

            state.canvas.Children.Add(ellipse);
            return circle;
        }
Beispiel #3
0
 public LineDrawer(DrawingState state)
     : base(state)
 {
 }
Beispiel #4
0
 public MainWindow()
 {
     controller = new Controller();
     state = new DrawingState(controller, paintSurface, this);
     InitializeComponent();
 }
Beispiel #5
0
 public VertexDrawer(DrawingState state)
     : base(state)
 {
 }