Ejemplo n.º 1
0
        private void CanvasWithImage_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            Point clickCoords   = new Point(e.GetPosition(BottomImage).X, e.GetPosition(BottomImage).Y);
            bool  figureClicked = false;

            foreach (var fig in DrawnFigureList)
            {
                if (fig.WasClicked(clickCoords))
                {
                    figureClicked = true;
                    if (candidateToMark == fig)
                    {
                        MarkedFigures.Add(fig);
                        fig.MarkUnmark();
                        RefreshAndDrawFigures();
                    }
                    candidateToMark = null;
                    break;
                }
            }
            if (!figureClicked)
            {
                if (IsDrawingInProgress)
                {
                    Polygon figure         = currentlyEditedFigure as Polygon;
                    Segment currentSegment = figure.getSegmentByIdx(figure.getSegmentsNumber() - 1);
                    Point   lastPointDrawn = currentSegment.pointB;
                    Point   firstPoint     = figure.getSegmentByIdx(0).pointA;
                    if (firstPoint.WasClicked(lastPointDrawn))
                    {
                        currentSegment.SetPoint("B", firstPoint);
                        //RefreshAndDrawFigures(currentlyEditedFigure);
                        DrawnFigureList.Add(currentlyEditedFigure);
                        foreach (var seg in figure.segmentList)
                        {
                            seg.pointA.Tag.adherentSegments.Add(seg);
                            seg.pointB.Tag.adherentSegments.Add(seg);
                        }
                        figure.UpdateFigureColor();
                        AddFiguresToBottomBitmap(currentlyEditedFigure);
                        currentlyEditedFigure = null;
                        IsDrawingInProgress   = false;
                    }
                    else
                    {
                        currentSegment.SetPoint("B", clickCoords);
                        UpdateCurrentBitmap();
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void MainWindow_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            switch (e.Key)
            {
            case Key.D:
                foreach (var fig in MarkedFigures)
                {
                    DrawnFigureList.Remove(fig);
                }
                MarkedFigures = new List <Figure>();
                RefreshAndDrawFigures();
                break;

            case Key.M:
                Polygon newRandom = Quickhull.CreateConvexPolygon(0, bottomBitmap.Width, 0, bottomBitmap.Height);
                newRandom.FillColor   = System.Drawing.Color.FromArgb(100, 255, 0, 0);
                newRandom.FillTexture = RandomFiguresFillTexture;
                newRandom.BumpMap     = RandomFiguresBumpMap;
                newRandom             = new RandomPolygon(newRandom);
                (newRandom as RandomPolygon).Speed = ReturnRandomSpeed();
                RandomFigureList.Add(newRandom);
                DrawRandomFigures();
                break;

            case Key.K:
                Polygon[] temp = WeilerAtherton.PerformAlgorithm(DrawnFigureList[0] as Polygon, DrawnFigureList[1] as Polygon);
                DrawnFigureList = new List <Figure>();
                DrawnFigureList.AddRange(temp);
                RefreshAndDrawFigures();
                break;

            case Key.Y:
                foreach (var fig in DrawnFigureList)
                {
                    fig.Fill(CurrentBitmap, LightColor, new Vector3D(XLightCoord, YLightCoord, LightHeight));
                    fig.Draw(CurrentBitmap);
                    BottomImage.Source = loadBitmap(CurrentBitmap);
                }
                break;
            }
        }