예제 #1
0
        public static PinboardFileV1 Load(ParsedPath pinboardFileName)
        {
            PinboardFileV1 data = null;

            if (pinboardFiles == null)
            {
                pinboardFiles = new Dictionary <ParsedPath, PinboardFileV1>();
            }

            if (pinboardFiles.TryGetValue(pinboardFileName, out data))
            {
                return(data);
            }

            try
            {
                data = PinboardFileReaderV1.ReadFile(pinboardFileName);
            }
            catch
            {
                throw new ContentFileException("Unable to read pinboard file '{0}'".CultureFormat(pinboardFileName));
            }

            pinboardFiles.Add(pinboardFileName, data);

            return(data);
        }
        private RectanglesContent CreateRectangleData(IEnumerable <ParsedPath> distinctPinboardFiles, Dictionary <ParsedPath, PinboardFileV1> pinboards)
        {
            RectanglesContent rectData = new RectanglesContent();

            rectData.Namespace = this.Namespace;
            rectData.Classes   = new List <RectanglesContent.Class>();

            foreach (var pinboardFile in distinctPinboardFiles)
            {
                PinboardFileV1 pinboard = pinboards[pinboardFile];

                RectanglesContent.Class rectClass = new RectanglesContent.Class();

                rectClass.ClassNamePrefix = pinboardFile.File;

                List <string> names = new List <string>();

                names.Add("Screen");

                foreach (var rectInfo in pinboard.RectInfos)
                {
                    names.Add(rectInfo.Name);
                }

                rectClass.RectangleNames = names;

                rectData.Classes.Add(rectClass);
            }

            return(rectData);
        }
예제 #3
0
        private static void WritePinboardXml(XmlWriter writer, PinboardFileV1 data)
        {
            writer.WriteStartElement("Pinboard");
            writer.WriteAttributeString("Format", "1");

            WriteRectangleXml(writer, data.ScreenRectInfo);

            WriteRectanglesXml(writer, data);
            writer.WriteEndElement();
        }
예제 #4
0
        private static void WriteRectanglesXml(XmlWriter writer, PinboardFileV1 data)
        {
            writer.WriteStartElement("Rectangles");

            foreach (var rectInfo in data.RectInfos)
            {
                WriteRectangleXml(writer, rectInfo);
            }

            writer.WriteEndElement();
        }
예제 #5
0
        private PinboardFileV1 ReadPinboardXml()
        {
            PinboardFileV1 data = new PinboardFileV1();

            reader.ReadStartElement("Pinboard");
            reader.MoveToContent();
            data.ScreenRectInfo = ReadRectangleXml();

            data.RectInfos = ReadRectanglesXml();

            reader.ReadEndElement();
            reader.MoveToContent();

            return(data);
        }
예제 #6
0
        private PinboardFileV1 ReadPinboardXml()
        {
            PinboardFileV1 data = new PinboardFileV1();

            reader.ReadStartElement("Pinboard");
            reader.MoveToContent();
            data.ScreenRectInfo = ReadRectangleXml();

            data.RectInfos = ReadRectanglesXml();

            reader.ReadEndElement();
            reader.MoveToContent();

            return data;
        }
        private void ReconcilePinboards(
            IEnumerable <ParsedPath> pinboardFiles,
            IEnumerable <ParsedPath> distinctPinboardFiles,
            Dictionary <ParsedPath, PinboardFileV1> pinboards)
        {
            foreach (var distinctPinboardFile in distinctPinboardFiles)
            {
                PinboardFileV1 goldPinboard     = null;
                ParsedPath     goldPinboardFile = null;

                foreach (var pinboardFile in pinboardFiles.Where(p => p.File == distinctPinboardFile.File))
                {
                    if (goldPinboard == null)
                    {
                        goldPinboard     = pinboards[pinboardFile];
                        goldPinboardFile = pinboardFile;
                    }
                    else
                    {
                        PinboardFileV1 pinboard = pinboards[pinboardFile];

                        if (goldPinboard.RectInfos.Count != pinboard.RectInfos.Count)
                        {
                            throw new ContentFileException("Pinboard '{0}' and '{1}' have a different number of rectangles".CultureFormat(
                                                               goldPinboardFile, pinboardFile));
                        }

                        for (int i = 0; i < goldPinboard.RectInfos.Count; i++)
                        {
                            if (goldPinboard.RectInfos[i].Name != pinboard.RectInfos[i].Name)
                            {
                                throw new ContentFileException("RectangleInfo named {0} at depth {1} in pinboard '{2}' is different from pinboard '{3}'".CultureFormat(
                                                                   goldPinboard.RectInfos[i].Name, i, goldPinboardFile, pinboardFile));
                            }
                        }
                    }
                }
            }
        }
        private Dictionary <ParsedPath, PinboardFileV1> ReadPinboardFiles(IEnumerable <ParsedPath> pinboardFiles)
        {
            Dictionary <ParsedPath, PinboardFileV1> pinboards = new Dictionary <ParsedPath, PinboardFileV1>();

            foreach (var pinboardFile in pinboardFiles)
            {
                Context.WriteMessage("Reading pinboard file '{0}'", pinboardFile);

                PinboardFileV1 pinboard = null;

                try
                {
                    pinboard = PinboardFileReaderV1.ReadFile(pinboardFile);
                }
                catch (Exception e)
                {
                    throw new ContentFileException("Unable to read pinboard file '{0}'".CultureFormat(pinboardFile), e);
                }

                pinboards.Add(pinboardFile, pinboard);
            }

            return(pinboards);
        }
예제 #9
0
        private void SetPinboardData(PinboardFileV1 data)
        {
            this.data = data;

            this.pinboardControl.Data = data;
            this.pinboardControl.Visible = true;

            if (!this.propertiesForm.Visible)
                this.propertiesForm.Show(this);
        }
예제 #10
0
        private void OpenFile(string fileName)
        {
            PinboardFileV1 data = null;

            try
            {
                data = PinboardFileReaderV1.ReadFile(new ParsedPath(fileName, PathType.File));
            }
            catch
            {
                MessageBox.Show("Unable to load pinboard file", "Error Loading File",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            this.fileName = fileName;
            SetPinboardData(data);
            SetPinboardSize();
        }
        public void Compile()
        {
            IEnumerable <ParsedPath> svgPaths  = Target.InputPaths.Where(f => f.Extension == ".svg");
            ParsedPath            pinboardPath = Target.InputPaths.Where(f => f.Extension == ".pinboard").First();
            ParsedPath            pngPath      = Target.OutputPaths.Where(f => f.Extension == ".png").First();
            PinboardFileV1        pinboardFile = PinboardFileCache.Load(pinboardPath);
            List <ImagePlacement> placements   = new List <ImagePlacement>();

            string[] rectangleNames = this.Rectangle.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            if (svgPaths.Count() != rectangleNames.Length)
            {
                throw new ContentFileException("Number of .svg files ({0}) does match number of RectangleNames ({1})"
                                               .CultureFormat(svgPaths.Count(), rectangleNames.Length));
            }

            ImageRotation rotation;

            if (!Enum.TryParse(this.Rotation, out rotation))
            {
                throw new ContentFileException("Invalid value '{0}' for given for rotation.  Valid are None, Left, Right, UpsideDown".CultureFormat(this.Rotation));
            }

            int i = 0;

            try
            {
                if (!Directory.Exists(pngPath.VolumeAndDirectory))
                {
                    Directory.CreateDirectory(pngPath.VolumeAndDirectory);
                }

                foreach (var svgPath in svgPaths)
                {
                    PinboardFileV1.RectangleInfo rectInfo = pinboardFile.GetRectangleInfoByName(rectangleNames[i]);
                    ParsedPath tempPngPath = pngPath.WithFileAndExtension(String.Format("{0}_{1}.png", pngPath.File, i));

                    if (rectInfo == null)
                    {
                        throw new ContentFileException("Rectangle '{0}' not found in pinboard file '{1}'"
                                                       .CultureFormat(rectangleNames[i], pinboardFile));
                    }

                    ImageTools.SvgToPngWithInkscape(svgPath, tempPngPath, rectInfo.Width, rectInfo.Height);

                    placements.Add(new ImagePlacement(
                                       tempPngPath, new Cairo.Rectangle(rectInfo.X, rectInfo.Y, rectInfo.Width, rectInfo.Height)));

                    i++;
                }

                ImageTools.CombinePngs(placements, pngPath);
                ImageTools.RotatePng(pngPath, rotation);
            }
            finally
            {
                foreach (var placement in placements)
                {
                    if (File.Exists(placement.ImageFile))
                    {
                        File.Delete(placement.ImageFile);
                    }
                }
            }
        }
예제 #12
0
 public static void WriteXml(XmlWriter writer, PinboardFileV1 data)
 {
     WritePinboardXml(writer, data);
 }
예제 #13
0
        private void DrawPinboardFile(Graphics g, PinboardFileV1.RectangleInfo rectInfo, bool selected)
        {
            using (SolidBrush brush = new SolidBrush(rectInfo.Color))
            {
                g.FillRectangle(brush, rectInfo.Rectangle);
            }

            float penWidth = 1.0f;
            using (Pen blackPen = new Pen(Color.FromArgb(rectInfo.Color.A, Color.Black), penWidth))
            {
                Rectangle rect = rectInfo.Rectangle;

                if (selected)
                {
                    using (Pen whitePen = new Pen(Color.FromArgb(rectInfo.Color.A, Color.White), penWidth))
                    {
                        using (Pen blackDottedPen = new Pen(Color.FromArgb(rectInfo.Color.A, Color.Black), penWidth))
                        {
                            DrawExactRectangle(g, whitePen, ref rect);

                            blackDottedPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;

                            DrawExactRectangle(g, blackDottedPen, ref rect);

                            Rectangle expandedRect = rectInfo.Rectangle;

                            expandedRect.Inflate(2, 2);

                            DrawExactRectangle(g, blackDottedPen, ref expandedRect);

                            if (selectedIndex != -1)
                            {
                                Point[] points = GetCornerPoints(rect);

                                g.FillPolygon(Brushes.White, points);
                                g.DrawPolygon(Pens.Black, points);
                            }
                        }
                    }
                }
                else
                {
                    DrawExactRectangle(g, blackPen, ref rect);
                }

                int margin = 5;
                RectangleF textRect = new Rectangle(
                    rectInfo.X + margin, rectInfo.Y + margin,
                    Math.Max(rectInfo.Width - margin, 0), Math.Max(rectInfo.Height - margin, 0));

                if (!textRect.IsEmpty)
                {
                    using (StringFormat format = new StringFormat(StringFormatFlags.NoWrap))
                    {
                        g.DrawString(rectInfo.Name, this.Font, Brushes.Black, textRect, format);
                    }
                }
            }
        }