예제 #1
0
 public void DrawFigure(object dc, ShapeRenderer renderer, FigureShape figure, ISelection selection, double dx, double dy)
 {
     foreach (var shape in figure.Shapes)
     {
         DrawShape(dc, renderer, shape, selection, dx, dy);
     }
 }
예제 #2
0
        private void StartInternal(IToolContext context, double x, double y, Modifier modifier)
        {
            Filters?.Any(f => f.Process(context, ref x, ref y));

            _path = new PathShape()
            {
                FillRule = Settings.FillRule,
                Style    = context.CurrentStyle
            };

            _figure = new FigureShape()
            {
                IsFilled = Settings.IsFilled,
                IsClosed = Settings.IsClosed
            };

            _path.Figures.Add(_figure);

            _previousPoint = new PointShape(x, y, context.PointShape);

            context.WorkingContainer.Shapes.Add(_path);

            context.Capture?.Invoke();
            context.Invalidate?.Invoke();

            CurrentState = State.Points;
        }
예제 #3
0
        /// <summary>
        /// 增加图元到绘图面板
        /// </summary>
        /// <param name="figure"></param>
        private void AddFigureToDiagram(FigureBase figure)
        {
            var shape = new FigureShape()
            {
                DataContext = figure
            };

            diagram.AddShape(shape);
        }
예제 #4
0
        private void PointsInternal(IToolContext context, double x, double y, Modifier modifier)
        {
            CurrentState = State.Start;

            if (Settings?.Simplify ?? true)
            {
                List <PointShape> points  = _path.GetPoints().Distinct().ToList();
                List <Vector2>    vectors = points.Select(p => new Vector2((float)p.X, (float)p.Y)).ToList();
                int      count            = vectors.Count;
                RDP      rdp      = new RDP();
                BitArray accepted = rdp.DouglasPeucker(vectors, 0, count - 1, Settings?.Epsilon ?? 1.0);
                int      removed  = 0;
                for (int i = 0; i <= count - 1; ++i)
                {
                    if (!accepted[i])
                    {
                        points.RemoveAt(i - removed);
                        ++removed;
                    }
                }

                _figure.Shapes.Clear();
                _figure.MarkAsDirty(true);

                if (points.Count >= 2)
                {
                    for (int i = 0; i < points.Count - 1; i++)
                    {
                        var line = new LineShape()
                        {
                            StartPoint = points[i],
                            Point      = points[i + 1],
                            Style      = context.CurrentStyle
                        };
                        _figure.Shapes.Add(line);
                    }
                }
            }

            context.WorkingContainer.Shapes.Remove(_path);

            if (_path.Validate(true) == true)
            {
                context.CurrentContainer.Shapes.Add(_path);
            }

            _path          = null;
            _figure        = null;
            _previousPoint = null;
            _nextPoint     = null;

            Filters?.ForEach(f => f.Clear(context));

            context.Release?.Invoke();
            context.Invalidate?.Invoke();
        }
예제 #5
0
        private void TryLoadFromSave()
        {
            if (Properties.Settings.Default.IsSaved)
            {
                Engine.Engine.Score = Properties.Settings.Default.SavedScore;
                Title = "Счёт: " + Engine.Engine.Score + " / " + Properties.Settings.Default.BestScore;

                if (Properties.Settings.Default.SavedShowcase0 != -1)
                {
                    var figure = new Figure((FigureShape)Properties.Settings.Default.SavedShowcase0);
                    Showcase.Pick(Showcase.Maps[0].Figure);
                    figure.TryPutOnMap(Showcase.Maps[0], new Location(0, 0));
                }
                else
                {
                    Showcase.Maps[0].Figure = null;
                }

                if (Properties.Settings.Default.SavedShowcase1 != -1)
                {
                    var figure = new Figure((FigureShape)Properties.Settings.Default.SavedShowcase1);
                    Showcase.Pick(Showcase.Maps[1].Figure);
                    figure.TryPutOnMap(Showcase.Maps[1], new Location(0, 0));
                }
                else
                {
                    Showcase.Maps[1].Figure = null;
                }

                if (Properties.Settings.Default.SavedShowcase2 != -1)
                {
                    var figure = new Figure((FigureShape)Properties.Settings.Default.SavedShowcase2);
                    Showcase.Pick(Showcase.Maps[2].Figure);
                    figure.TryPutOnMap(Showcase.Maps[2], new Location(0, 0));
                }
                else
                {
                    Showcase.Maps[2].Figure = null;
                }

                var savedMap = Properties.Settings.Default.SavedMap;
                for (int x = 0; x < GameMap.Size; ++x)
                {
                    for (int y = 0; y < GameMap.Size; ++y)
                    {
                        string tileStr = savedMap[x * 10 + y].ToString();
                        if (tileStr != "-")
                        {
                            FigureShape shape = (FigureShape)IntStringBaseConverter.BaseToLong(tileStr);
                            Tile        tile  = new Tile(new Location(x, y), new Figure(shape));
                            GameMap.SetTile(x, y, tile);
                        }
                    }
                }
            }
        }
예제 #6
0
        public void DrawFigure(object dc, IShapeRenderer renderer, FigureShape figure, ISelectionState selectionState, double dx, double dy, double scale)
        {
            if (selectionState.IsSelected(figure))
            {
                DrawBoxFromPoints(dc, renderer, figure, dx, dy, scale);
            }

            foreach (var shape in figure.Shapes)
            {
                DrawShape(dc, renderer, shape, selectionState, dx, dy, scale);
            }
        }
예제 #7
0
        public void Move()
        {
            _figure = new FigureShape()
            {
                IsFilled = Settings.IsFilled,
                IsClosed = Settings.IsClosed
            };
            _path.Figures.Add(_figure);

            if (Settings.PreviousTool != null)
            {
                Settings.CurrentTool = Settings.PreviousTool;
            }
        }
예제 #8
0
        private void CleanInternal(IToolContext context)
        {
            CurrentState = State.Start;

            Filters?.ForEach(f => f.Clear(context));

            if (_path != null)
            {
                context.WorkingContainer.Shapes.Remove(_path);
                _path          = null;
                _figure        = null;
                _previousPoint = null;
                _nextPoint     = null;
            }

            context.Release?.Invoke();
            context.Invalidate?.Invoke();
        }
예제 #9
0
        private void CleanInternal(IToolContext context)
        {
            CleanCurrentTool(context);

            Filters?.ForEach(f => f.Clear(context));

            if (_path != null)
            {
                context.WorkingContainer.Shapes.Remove(_path);
                context.Renderer.Selected.Remove(_path);

                if (_path.Validate(true) == true)
                {
                    context.CurrentContainer.Shapes.Add(_path);
                }

                Settings.PreviousTool = null;
                SetNextPoint(null);
                SetContext(null);

                _path   = null;
                _figure = null;
            }
        }
예제 #10
0
 public Figure(FigureShape shape, Location?location = null) : base()
 {
     Shape    = shape;
     Location = location;
     Color    = FigureShapes.FigureParams[shape].Color + 0xff000000;
 }
예제 #11
0
        internal static PathShape ToPathShape(IToolContext context, SKPath path, ShapeStyle style, IBaseShape pointTemplate)
        {
            var pathShape = new PathShape()
            {
                Points   = new ObservableCollection <IPointShape>(),
                Shapes   = new ObservableCollection <IBaseShape>(),
                FillType = ToPathFillType(path.FillType),
                Text     = new Text(),
                StyleId  = style.Title
            };

            var figureShape = default(FigureShape);

            using (var iterator = path.CreateRawIterator())
            {
                var points     = new SKPoint[4];
                var pathVerb   = SKPathVerb.Move;
                var firstPoint = new SKPoint();
                var lastPoint  = new SKPoint();

                while ((pathVerb = iterator.Next(points)) != SKPathVerb.Done)
                {
                    switch (pathVerb)
                    {
                    case SKPathVerb.Move:
                    {
                        figureShape = new FigureShape()
                        {
                            Points   = new ObservableCollection <IPointShape>(),
                            Shapes   = new ObservableCollection <IBaseShape>(),
                            IsFilled = true,
                            IsClosed = false
                        };
                        figureShape.Owner = pathShape;
                        pathShape.Shapes.Add(figureShape);
                        firstPoint = lastPoint = points[0];
                    }
                    break;

                    case SKPathVerb.Line:
                    {
                        var lastPointShape = pathShape.GetLastPoint();
                        if (lastPointShape == null)
                        {
                            lastPointShape = new PointShape(points[0].X, points[0].Y, pointTemplate);
                        }
                        var lineShape = new LineShape()
                        {
                            Points     = new ObservableCollection <IPointShape>(),
                            StartPoint = lastPointShape,
                            Point      = new PointShape(points[1].X, points[1].Y, pointTemplate),
                            Text       = new Text(),
                            StyleId    = style.Title
                        };
                        lineShape.Owner            = figureShape;
                        lineShape.StartPoint.Owner = lineShape;
                        lineShape.Point.Owner      = lineShape;
                        figureShape.Shapes.Add(lineShape);
                        lastPoint = points[1];
                    }
                    break;

                    case SKPathVerb.Cubic:
                    {
                        var lastPointShape = pathShape.GetLastPoint();
                        if (lastPointShape == null)
                        {
                            lastPointShape = new PointShape(points[0].X, points[0].Y, pointTemplate);
                        }
                        var cubicBezierShape = new CubicBezierShape()
                        {
                            Points     = new ObservableCollection <IPointShape>(),
                            StartPoint = lastPointShape,
                            Point1     = new PointShape(points[1].X, points[1].Y, pointTemplate),
                            Point2     = new PointShape(points[2].X, points[2].Y, pointTemplate),
                            Point3     = new PointShape(points[3].X, points[3].Y, pointTemplate),
                            Text       = new Text(),
                            StyleId    = style.Title
                        };
                        cubicBezierShape.Owner            = figureShape;
                        cubicBezierShape.StartPoint.Owner = cubicBezierShape;
                        cubicBezierShape.Point1.Owner     = cubicBezierShape;
                        cubicBezierShape.Point2.Owner     = cubicBezierShape;
                        cubicBezierShape.Point3.Owner     = cubicBezierShape;
                        figureShape.Shapes.Add(cubicBezierShape);
                        lastPoint = points[3];
                    }
                    break;

                    case SKPathVerb.Quad:
                    {
                        var lastPointShape = pathShape.GetLastPoint();
                        if (lastPointShape == null)
                        {
                            lastPointShape = new PointShape(points[0].X, points[0].Y, pointTemplate);
                        }
                        var quadraticBezierShape = new QuadraticBezierShape()
                        {
                            Points     = new ObservableCollection <IPointShape>(),
                            StartPoint = lastPointShape,
                            Point1     = new PointShape(points[1].X, points[1].Y, pointTemplate),
                            Point2     = new PointShape(points[2].X, points[2].Y, pointTemplate),
                            Text       = new Text(),
                            StyleId    = style.Title
                        };
                        quadraticBezierShape.Owner            = figureShape;
                        quadraticBezierShape.StartPoint.Owner = quadraticBezierShape;
                        quadraticBezierShape.Point1.Owner     = quadraticBezierShape;
                        quadraticBezierShape.Point2.Owner     = quadraticBezierShape;
                        figureShape.Shapes.Add(quadraticBezierShape);
                        lastPoint = points[2];
                    }
                    break;

                    case SKPathVerb.Conic:
                    {
                        var lastPointShape = pathShape.GetLastPoint();
                        if (lastPointShape == null)
                        {
                            lastPointShape = new PointShape(points[0].X, points[0].Y, pointTemplate);
                        }
                        var conicShape = new ConicShape()
                        {
                            Points     = new ObservableCollection <IPointShape>(),
                            StartPoint = lastPointShape,
                            Point1     = new PointShape(points[1].X, points[1].Y, pointTemplate),
                            Point2     = new PointShape(points[2].X, points[2].Y, pointTemplate),
                            Weight     = iterator.ConicWeight(),
                            Text       = new Text(),
                            StyleId    = style.Title
                        };
                        conicShape.Owner            = figureShape;
                        conicShape.StartPoint.Owner = conicShape;
                        conicShape.Point1.Owner     = conicShape;
                        conicShape.Point2.Owner     = conicShape;
                        figureShape.Shapes.Add(conicShape);
                        lastPoint = points[2];
                    }
                    break;

                    case SKPathVerb.Close:
                    {
#if USE_CLOSE_SHAPE
                        var line = new LineShape()
                        {
                            Points     = new ObservableCollection <IPointShape>(),
                            StartPoint = pathShape.GetLastPoint(),
                            Point      = pathShape.GetFirstPoint(),
                            Text       = new Text(),
                            StyleId    = style.Title
                        };
                        line.Owner            = figureShape;
                        line.StartPoint.Owner = line;
                        line.Point.Owner      = line;
                        figureShape.Shapes.Add(line);
#else
                        figureShape.IsClosed = true;
                        firstPoint           = lastPoint = new SKPoint(0, 0);
#endif
                    }
                    break;
                    }
                }
            }

            return(pathShape);
        }
예제 #12
0
 internal static void AddFigure(IToolContext context, FigureShape figure, double dx, double dy, SKPath geometry)
 {
     AddFigure(context, figure.Shapes, figure.IsClosed, dx, dy, geometry);
 }