Exemplo n.º 1
0
        public static void SaveDefToXml(Drawing drawing, string fileName)
        {
            MemoryStream stream = new MemoryStream();

            using (var writer = XmlWriter.Create(stream,
                                                 new XmlWriterSettings()
            {
                Indent = true,
                Encoding = new UTF8Encoding(false)
            }
                                                 ))
            {
                writer.WriteStartDocument();
                writer.WriteStartElement("Drawing");
                IEnumerable <Webb.Playbook.Geometry.Game.PBPlayer> defensivePlayers = drawing.Figures.OfType <Webb.Playbook.Geometry.Game.PBPlayer>().Where(p => p.ScoutType == 1);
                Webb.Playbook.Geometry.Game.PBBall pbball = drawing.Figures.OfType <Webb.Playbook.Geometry.Game.PBBall>().FirstOrDefault();
                writer.WriteStartElement("Figures");
                defensivePlayers.ForEach(p => SetWritePlayer(p, writer));
                if (pbball != null)
                {
                    writer.WriteStartElement(GetTagNameForFigure(pbball));
                    pbball.WriteXml(writer);
                    writer.WriteEndElement();
                }

                writer.WriteEndElement();

                writer.WriteEndElement();
                writer.WriteEndDocument();
            }
            File.WriteAllText(fileName, Encoding.UTF8.GetString(stream.ToArray()));
        }
Exemplo n.º 2
0
        public static void FillDocument(FixedDocument fixedDoc, List <string> files, int nStartPage)
        {
            if (files.Count > 0)
            {
                int nPageNum = nStartPage;

                foreach (string printFile in files)
                {
                    double space  = 20;
                    double width  = Webb.Playbook.Data.GameSetting.Instance.Landscape ? LocalPrinter.DefaultPageSettings.PrintableArea.Height : LocalPrinter.DefaultPageSettings.PrintableArea.Width;
                    double height = Webb.Playbook.Data.GameSetting.Instance.Landscape ? LocalPrinter.DefaultPageSettings.PrintableArea.Width : LocalPrinter.DefaultPageSettings.PrintableArea.Height;

                    FixedPage page = new FixedPage();
                    page.Margin = new Thickness(space);
                    //page.Width = fixedDoc.DocumentPaginator.PageSize.Width;
                    //page.Height = fixedDoc.DocumentPaginator.PageSize.Height;
                    page.Width  = width;
                    page.Height = height;

                    Grid grid = new Grid();
                    grid.Width  = page.Width - 2 * space;
                    grid.Height = page.Height - 2 * space;
                    Canvas canvas = new Canvas();
                    grid.Children.Add(canvas);
                    page.Children.Add(grid);

                    // add logo
                    Image imgLogo = new Image()
                    {
                        Stretch = Stretch.Fill,
                        Width   = 120,
                        Height  = 30,
                        Margin  = new Thickness(0, 0, width - 120, height - 30),
                    };

                    string strLogoPath = AppDomain.CurrentDomain.BaseDirectory + @"\Resource\logo.PNG";
                    imgLogo.Source = new BitmapImage(new Uri(strLogoPath, UriKind.RelativeOrAbsolute));
                    page.Children.Add(imgLogo);

                    FullScale(canvas);
                    TextBlock tbPageNumber = new TextBlock()
                    {
                        Text                = nPageNum.ToString(),
                        FontSize            = 30,
                        HorizontalAlignment = HorizontalAlignment.Right,
                        VerticalAlignment   = VerticalAlignment.Top,
                        Margin              = new Thickness(space),
                    };
                    grid.Children.Add(tbPageNumber);
                    Webb.Playbook.Geometry.Drawing draw = Webb.Playbook.Geometry.Drawing.Load(printFile, canvas);

                    draw.SetStartYard(width, draw.GetBallPoint().Y);   // 01-16-2012 Scott

                    // 04-11-2011 Scott
                    if (draw.Figures.Any(f => f is Webb.Playbook.Geometry.Game.PBBall))
                    {
                        Webb.Playbook.Geometry.Game.PBBall ball = draw.Figures.OfType <Webb.Playbook.Geometry.Game.PBBall>().First();

                        if (ball.Visible)
                        {
                            ball.Visible = false;
                        }
                    }

                    if (Webb.Playbook.Data.GameSetting.Instance.ShowPlayground)
                    {
                        draw.SetPlaygroundColor(Webb.Playbook.Data.GameSetting.Instance.EnableColor ? Webb.Playbook.Data.PlaygroundColors.Color : Webb.Playbook.Data.PlaygroundColors.BlackAndWhite);
                    }
                    else
                    {
                        if (draw.Canvas.Children.Contains(draw.Playground.UCPlayground))
                        {
                            draw.Canvas.Children.Remove(draw.Playground.UCPlayground);
                        }
                    }

                    draw.SetFiguresColor(Webb.Playbook.Data.GameSetting.Instance.EnableSymbolColor);

                    if (Webb.Playbook.Data.GameSetting.Instance.EnableTitle)
                    {
                        TextBlock tbTitle = new TextBlock()
                        {
                            Text                = System.IO.Path.GetFileNameWithoutExtension(printFile),
                            FontSize            = 30,
                            HorizontalAlignment = HorizontalAlignment.Center,
                            VerticalAlignment   = VerticalAlignment.Top,
                            Margin              = new Thickness(space, 2 * space, space, space),
                            TextWrapping        = TextWrapping.Wrap,
                            TextAlignment       = TextAlignment.Center,
                        };
                        Panel.SetZIndex(tbTitle, 10000);
                        grid.Children.Add(tbTitle);
                    }

                    PageContent pageContent = new PageContent();
                    ((IAddChild)pageContent).AddChild(page);
                    fixedDoc.Pages.Add(pageContent);

                    nPageNum++;
                }
            }
        }