예제 #1
0
        private void OnKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            switch (e.Key)
            {
            case Key.Escape:
            {
                if (drawMode == DrawMode.POLYLINE && formingPoints.Count >= 2)
                {
                    ReleaseFigure(formingFigure, directXRenderer);
                    formingFigure = null;
                    PolyLine polyLine = new PolyLine(formingPoints, CurrentColor, CurrentBorderWidth);
                    InitializeFigure(polyLine, directXRenderer);
                    figures.Add(polyLine);
                    drawMode = DrawMode.NONE;
                    polyLineButton.IsChecked = false;

                    directXControl.Invalidate();
                }
                break;
            }
            }
        }
예제 #2
0
        private void OnMouseDown(MouseButton button, int xMouse, int yMouse)
        {
            float x = (float)cameraCoords.X + (xMouse - directXControl.Size.Width / 2.0f) / CurrentZoom;
            float y = (float)cameraCoords.Y + (directXControl.Size.Height / 2.0f - yMouse) / CurrentZoom;

            switch (button)
            {
            case MouseButton.Left:
            {
                leftMouseClickCoords     = new Point(xMouse, yMouse);
                leftMouseButtonIsPressed = true;

                switch (drawMode)
                {
                case DrawMode.NONE:
                {
                    if (currentFigure != null)
                    {
                        upscalingBoundary = boundingBox.PointIsOnBoundary(new Point(x, y), CurrentZoom);
                        lastScalingPoint  = new Point(x, y);
                    }

                    if (upscalingBoundary == Boundary.NONE)
                    {
                        int i = figures.Count - 1;
                        for (; i >= 0; i--)
                        {
                            if (figures[i].PointIsInside(new Point(x, y)))
                            {
                                currentFigure = figures[i];

                                CurrentColor       = (currentFigure as Figure).color;
                                CurrentBorderColor = (currentFigure as Figure).borderColor;
                                CurrentBorderWidth = (currentFigure as Figure).borderWidth;

                                List <Point> boundingBoxPoints = (currentFigure as Figure).BoundingBoxPoints;
                                boundingBox = new BoundingBox(boundingBoxPoints[0], boundingBoxPoints[1]);
                                ModifyFigure(boundingBox, directXRenderer);

                                isTranslating = true;
                                directXControl.Invalidate();

                                break;
                            }
                        }

                        if (i < 0)
                        {
                            currentFigure = null;
                            boundingBox   = null;
                            directXControl.Invalidate();
                        }
                    }
                    break;
                }

                case DrawMode.POLYLINE:
                {
                    formingPoints.Add(new Point(x, y));
                    if (formingPoints.Count == 1)
                    {
                        List <Point> currentPoints = new List <Point>(formingPoints);
                        currentPoints.Add(new Point(x, y));
                        formingFigure = new PolyLine(currentPoints, CurrentBorderColor, CurrentBorderWidth);
                        InitializeFigure(formingFigure, directXRenderer);
                    }
                    else if (formingPoints.Count >= 6)
                    {
                        ReleaseFigure(formingFigure, directXRenderer);
                        formingFigure = null;
                        PolyLine polyLine = new PolyLine(formingPoints, CurrentColor, CurrentBorderWidth);
                        InitializeFigure(polyLine, directXRenderer);
                        figures.Add(polyLine);
                        drawMode = DrawMode.NONE;

                        polyLineButton.IsChecked = false;
                        directXControl.Invalidate();
                    }
                    break;
                }

                case DrawMode.TRIANGLE:
                {
                    formingPoints.Add(new Point(x, y));
                    if (formingPoints.Count == 1)
                    {
                        List <Point> currentPoints = new List <Point>(formingPoints);
                        currentPoints.Add(new Point(x, y));
                        formingFigure = new PolyLine(currentPoints, CurrentColor, CurrentBorderWidth);
                        InitializeFigure(formingFigure, directXRenderer);
                    }
                    else if (formingPoints.Count == 2)
                    {
                        ReleaseFigure(formingFigure, directXRenderer);
                        formingFigure = new Triangle(formingPoints[0], formingPoints[1], formingPoints[1], CurrentColor, CurrentBorderColor, CurrentBorderWidth);
                        InitializeFigure(formingFigure, directXRenderer);
                    }
                    else if (formingPoints.Count >= 3)
                    {
                        ReleaseFigure(formingFigure, directXRenderer);
                        formingFigure = null;
                        Triangle triangle = new Triangle(formingPoints[0], formingPoints[1], formingPoints[2], CurrentColor, CurrentBorderColor, CurrentBorderWidth);
                        InitializeFigure(triangle, directXRenderer);
                        figures.Add(triangle);
                        drawMode = DrawMode.NONE;

                        triangleButton.IsChecked = false;
                        directXControl.Invalidate();
                    }
                    break;
                }

                case DrawMode.QUAD:
                {
                    formingPoints.Add(new Point(x, y));
                    if (formingPoints.Count == 1)
                    {
                        List <Point> currentPoints = new List <Point>(formingPoints);
                        currentPoints.Add(new Point(x, y));
                        formingFigure = new PolyLine(currentPoints, CurrentColor, CurrentBorderWidth);
                        InitializeFigure(formingFigure, directXRenderer);
                    }
                    else if (formingPoints.Count == 2)
                    {
                        ReleaseFigure(formingFigure, directXRenderer);
                        formingFigure = new Triangle(formingPoints[0], formingPoints[1], formingPoints[1], CurrentColor, CurrentBorderColor, CurrentBorderWidth);
                        InitializeFigure(formingFigure, directXRenderer);
                    }
                    else if (formingPoints.Count == 3)
                    {
                        ReleaseFigure(formingFigure, directXRenderer);
                        formingFigure = new Quad(formingPoints[0], formingPoints[1], formingPoints[2], formingPoints[2], CurrentColor, CurrentBorderColor, CurrentBorderWidth);
                        InitializeFigure(formingFigure, directXRenderer);
                    }
                    else if (formingPoints.Count >= 4)
                    {
                        if ((formingFigure as Quad).IsConvex())
                        {
                            Quad quad = new Quad(formingPoints[0], formingPoints[1], formingPoints[2], formingPoints[3], CurrentColor, CurrentBorderColor, CurrentBorderWidth);
                            InitializeFigure(quad, directXRenderer);
                            figures.Add(quad);
                        }

                        ReleaseFigure(formingFigure, directXRenderer);
                        formingFigure = null;
                        drawMode      = DrawMode.NONE;

                        quadButton.IsChecked = false;
                        directXControl.Invalidate();
                    }
                    break;
                }

                case DrawMode.ELLIPSE:
                {
                    formingPoints.Add(new Point(x, y));
                    if (formingPoints.Count == 1)
                    {
                        List <Point> currentPoints = new List <Point>(formingPoints);
                        currentPoints.Add(new Point(x, y));
                        formingFigure = new PolyLine(currentPoints, CurrentColor, CurrentBorderWidth);
                        InitializeFigure(formingFigure, directXRenderer);
                    }
                    else if (formingPoints.Count == 2)
                    {
                        ReleaseFigure(formingFigure, directXRenderer);
                        formingFigure = new Ellipse(formingPoints[0], formingPoints[1], formingPoints[1], CurrentColor, CurrentBorderColor, CurrentBorderWidth);
                        InitializeFigure(formingFigure, directXRenderer);
                    }
                    else if (formingPoints.Count >= 3)
                    {
                        ReleaseFigure(formingFigure, directXRenderer);
                        formingFigure = null;
                        Ellipse ellipse = new Ellipse(formingPoints[0], formingPoints[1], formingPoints[2], CurrentColor, CurrentBorderColor, CurrentBorderWidth);
                        InitializeFigure(ellipse, directXRenderer);
                        figures.Add(ellipse);
                        drawMode = DrawMode.NONE;

                        ellipseButton.IsChecked = false;
                        directXControl.Invalidate();
                    }
                    break;
                }
                }
                break;
            }

            case MouseButton.Middle:
            {
                middleMouseClickCoords     = new Point(xMouse, yMouse);
                middleMouseButtonIsPressed = true;

                break;
            }

            case MouseButton.Right:
            {
                rightMouseClickCoords     = new Point(xMouse, yMouse);
                rightMouseButtonIsPressed = true;

                break;
            }
            }
        }