Пример #1
0
        private List <IDrawnShape> DecodeBRSText(string[] text)
        {
            List <IDrawnShape> drawnShapes = new List <IDrawnShape>();

            try {
                foreach (string dataPoint in text)
                {
                    //Get individual arguments from line
                    string[] arguments = dataPoint.Split(' ');
                    //2nd and 3rd arguments are always cords of the startPoint
                    Point startPoint = new Point(int.Parse(arguments[1]), int.Parse(arguments[2]));
                    if (arguments[0] == "SchetsEditor.DrawnLetter")
                    {
                        //Letter only has startpoint
                        Color col    = Color.FromArgb(int.Parse(arguments[3]), int.Parse(arguments[4]), int.Parse(arguments[5]), int.Parse(arguments[6]));
                        char  letter = arguments[7].ToCharArray()[0];
                        drawnShapes.Add(new DrawnLetter(startPoint, col, letter));
                    }
                    else if (arguments[0] == "▲")
                    {
                        Size sz = new Size(int.Parse(arguments[1]), int.Parse(arguments[2]));
                        schetscontrol.veranderAfmeting(sz);
                        this.changeSizeFromSketchSize(sz);
                    }
                    else
                    {
                        //Other options also have a end point
                        Point endPoint = new Point(int.Parse(arguments[3]), int.Parse(arguments[4]));
                        Color col      = Color.FromArgb(int.Parse(arguments[5]), int.Parse(arguments[6]), int.Parse(arguments[7]), int.Parse(arguments[8]));
                        switch (arguments[0])
                        {
                        case "SchetsEditor.DrawnLine":
                            drawnShapes.Add(new DrawnLine(startPoint, endPoint, int.Parse(arguments[9]), col));
                            break;

                        case "SchetsEditor.DrawnRectangle":
                            drawnShapes.Add(new DrawnRectangle(startPoint, endPoint, int.Parse(arguments[9]), col));
                            break;

                        case "SchetsEditor.DrawnFilledRectangle":
                            drawnShapes.Add(new DrawnFilledRectangle(startPoint, endPoint, col));
                            break;

                        case "SchetsEditor.DrawnEllipse":
                            drawnShapes.Add(new DrawnEllipse(startPoint, endPoint, int.Parse(arguments[9]), col));
                            break;

                        case "SchetsEditor.DrawnFilledEllipse":
                            drawnShapes.Add(new DrawnFilledEllipse(startPoint, endPoint, col));
                            break;

                        default:
                            MessageBox.Show("Tried to load invalid shape type (" + arguments[0] + ")");
                            break;
                        }
                    }
                }
                return(drawnShapes);
            } catch {
                MessageBox.Show("This File is Corrupted or not in Bob Ross Format!");
                return(drawnShapes);
            }
        }