Esempio n. 1
0
        public void LinesToListOfStrokes()
        {
            var result = new List <Models.Game.Path>();

            foreach (var stroke in Editor.lines)
            {
                var tempStroke = new Models.Game.Path(Guid.NewGuid().ToString(), GameService.Instance.CurrentGame.CurrentRound.Canvas.ID,
                                                      Editor.LineSize, Editor.SelectedColor, false, Editor.SelectedDrawingShape)
                {
                    Coordinates = new List <Models.Game.Coordinate>()
                };

                foreach (var point in stroke.StylusPoints)
                {
                    tempStroke.Coordinates.Add(new Models.Game.Coordinate()
                    {
                        X = point.X, Y = point.Y
                    });
                }

                result.Add(tempStroke);
            }

            ListOfStrokes = result;
        }
Esempio n. 2
0
        private void AddNewStroke(StrokeCollection newStroke)
        {
            if (IsCreatingGame)
            {
                return;
            }

            foreach (var stroke in newStroke)
            {
                var tempStroke = new Models.Game.Path(Guid.NewGuid().ToString(),
                                                      GameService.Instance.CurrentGame.CurrentRound.Canvas.ID,
                                                      Editor.LineSize, Editor.SelectedColor, false, Editor.SelectedDrawingShape)
                {
                    Coordinates = new List <Models.Game.Coordinate>()
                };

                foreach (var point in stroke.StylusPoints)
                {
                    tempStroke.Coordinates.Add(new Models.Game.Coordinate()
                    {
                        X = point.X, Y = point.Y
                    });
                }

                WebSocket.Instance.CreateStroke(tempStroke);
                _strokeByStroke.Add(stroke, tempStroke);
            }
        }
Esempio n. 3
0
        public void Down(Point point, string selectedTool)
        {
            if (selectedTool != "crayon")
            {
                return;
            }

            CurrentPath = new Models.Game.Path();

            _isPressingDown = true;
            CurrentPath     = new Models.Game.Path(Guid.NewGuid().ToString(), GameService.Instance.CurrentGame.CurrentRound.Canvas.ID,
                                                   Editor.LineSize, Editor.SelectedColor, false, Editor.SelectedDrawingShape)
            {
                Coordinates = new List <Models.Game.Coordinate>()
                {
                    new Models.Game.Coordinate()
                    {
                        X = point.X,
                        Y = point.Y
                    }
                }
            };

            if (!IsCreatingGame)
            {
                _timer.Enabled = true;
            }
        }
        private int SortPredicatCenterDirection(List <Models.Game.Path> strokes, Models.Game.Path pathOne, Models.Game.Path pathTwo, CENTER_DRAWING_DIRECTION direction)
        {
            //find the center point of coordinates
            double totalX = 0, totalY = 0, countCoordinate = 0;

            foreach (var stroke in strokes)
            {
                foreach (var coodinate in stroke.Coordinates)
                {
                    totalX += coodinate.X;
                    totalY += coodinate.Y;
                    countCoordinate++;
                }
            }
            double centerX = totalX / countCoordinate;
            double centerY = totalY / countCoordinate;

            var    originineOne      = pathOne.Coordinates[0];
            var    originineTwo      = pathTwo.Coordinates[0];
            double distanceStrokeOne = Math.Sqrt(Math.Pow(originineOne.X - centerX, 2) + Math.Pow(originineOne.Y - centerY, 2));
            double distanceStrokeTwo = Math.Sqrt(Math.Pow(originineTwo.X - centerX, 2) + Math.Pow(originineTwo.Y - centerY, 2));

            switch (direction)
            {
            case CENTER_DRAWING_DIRECTION.INSIDE_TO_OUTSIDE:
                return(distanceStrokeOne.CompareTo(distanceStrokeTwo));

            case CENTER_DRAWING_DIRECTION.OUTSIDE_TO_INSIDE:
                return(distanceStrokeTwo.CompareTo(distanceStrokeOne));

            default: return(0);
            }
        }
        private List <Models.Game.Path> ConvertBitmapToStrokes(Bitmap bitmap)
        {
            bool[,] Matrix;
            ArrayList ListOfCurveArray; ListOfCurveArray = new ArrayList();

            Matrix = Potrace.BitMapToBinary(bitmap, 150);
            Potrace.potrace_trace(Matrix, ListOfCurveArray);

            string selectedColor = "Black";
            int    lineSize      = 11;
            string shape         = "rond";
            var    listOfStrokes = new List <Models.Game.Path>();
            var    canvasId      = Guid.NewGuid().ToString();

            for (int i = 0; i < ListOfCurveArray.Count; i++)
            {
                ArrayList CurveArray = (ArrayList)ListOfCurveArray[i];
                for (int j = 0; j < CurveArray.Count; j++)
                {
                    Potrace.Curve[] Curves = (Potrace.Curve[])CurveArray[j];
                    var             stroke = new Models.Game.Path(Guid.NewGuid().ToString(), canvasId, lineSize, selectedColor, false, shape);
                    for (int k = 0; k < Curves.Length; k++)
                    {
                        if (Curves[k].Kind == Potrace.CurveKind.Bezier)
                        {
                            stroke.Coordinates.Add(new Coordinate()
                            {
                                X = Curves[k].A.X, Y = Curves[k].A.Y
                            });
                            stroke.Coordinates.Add(new Coordinate()
                            {
                                X = Curves[k].ControlPointA.X, Y = Curves[k].ControlPointA.Y
                            });
                            stroke.Coordinates.Add(new Coordinate()
                            {
                                X = Curves[k].ControlPointB.X, Y = Curves[k].ControlPointB.Y
                            });
                            stroke.Coordinates.Add(new Coordinate()
                            {
                                X = Curves[k].B.X, Y = Curves[k].B.Y
                            });
                        }
                        else
                        {
                            stroke.Coordinates.Add(new Coordinate()
                            {
                                X = Curves[k].A.X, Y = Curves[k].A.Y
                            });
                            stroke.Coordinates.Add(new Coordinate()
                            {
                                X = Curves[k].B.X, Y = Curves[k].B.Y
                            });
                        }
                    }
                    listOfStrokes.Add(stroke);
                }
            }

            return(listOfStrokes);
        }
Esempio n. 6
0
        public DrawingService()
        {
            _timer          = new Timer();
            _timer.Elapsed += SendCoordinateAfterTime;
            _timer.Interval = 3;
            _timer.Enabled  = false;
            _strokeById     = new Dictionary <string, Stroke>();
            IsCreatingGame  = false;
            _strokeByStroke = new Dictionary <Stroke, Models.Game.Path>();

            CurrentPath   = new Models.Game.Path();
            Editor        = new Editor();
            Lines         = Editor.lines;
            ListOfStrokes = new List <Models.Game.Path>();
        }
Esempio n. 7
0
        public void Redraw(Models.Game.Path path)
        {
            App.Current.Dispatcher.Invoke((Action) delegate
            {
                if (path.ToDelete)
                {
                    var str = _strokeById[path.ID];
                    Lines.Remove(str);
                    _strokeById.Remove(path.ID);

                    return;
                }

                if (path.Coordinates.Count == 0)
                {
                    return;
                }

                var points = new StylusPointCollection();

                foreach (var coordinate in path.Coordinates)
                {
                    points.Add(new StylusPoint(coordinate.X, coordinate.Y));
                }


                if (!_strokeById.ContainsKey(path.ID))
                {
                    _strokeById.Add(path.ID, new Stroke(points));
                    _strokeById[path.ID].DrawingAttributes.Width     = path.Size;
                    _strokeById[path.ID].DrawingAttributes.StylusTip = path.DrawingShape == Models.Game.Cap.Round ? StylusTip.Ellipse : StylusTip.Rectangle;
                    _strokeById[path.ID].DrawingAttributes.Height    = path.Size;
                    _strokeById[path.ID].DrawingAttributes.Color     = (Color)ColorConverter.ConvertFromString(path.Color);
                }
                else
                {
                    _strokeById[path.ID].StylusPoints.Add(points);
                }

                var tempStroke = _strokeById[path.ID];
                if (!Lines.Contains(tempStroke))
                {
                    Lines.Add(tempStroke);
                }
            });
        }
        private int SortPredicatForPanoramicDirection(Models.Game.Path pathOne, Models.Game.Path pathTwo, PANORAMIC_DRAWING_DIRECTION direction)
        {
            var originineOne = pathOne.Coordinates[0];
            var originineTwo = pathTwo.Coordinates[0];

            switch (direction)
            {
            case PANORAMIC_DRAWING_DIRECTION.FROM_LEFT_TO_RIGHT:
                return(originineOne.X.CompareTo(originineTwo.X));

            case PANORAMIC_DRAWING_DIRECTION.FROM_RIGHT_TO_LEFT:
                return(originineTwo.X.CompareTo(originineOne.X));

            case PANORAMIC_DRAWING_DIRECTION.FROM_TOP_TO_BOTTOM:
                return(originineOne.Y.CompareTo(originineTwo.Y));

            case PANORAMIC_DRAWING_DIRECTION.FROM_BOTTOM_TO_TOP:
                return(originineTwo.Y.CompareTo(originineOne.Y));

            default: return(0);
            }
        }