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); } } } }
private void SetSelectionValuesAndMode() { PinboardFileV1.RectangleInfo rectInfo = pinboardControl.Selection; if (rectInfo != null) { this.nameTextBox.Text = rectInfo.Name; this.xTextBox.Text = rectInfo.Rectangle.X.ToString(); this.yTextBox.Text = rectInfo.Rectangle.Y.ToString(); this.widthTextBox.Text = rectInfo.Rectangle.Width.ToString(); this.heightTextBox.Text = rectInfo.Rectangle.Height.ToString(); this.depthTextBox.Text = pinboardControl.SelectionIndex.ToString(); this.redColorPicker.Value = rectInfo.Color.R; this.greenColorPicker.Value = rectInfo.Color.G; this.blueColorPicker.Value = rectInfo.Color.B; this.alphaColorPicker.Value = rectInfo.Color.A; } PropertiesFormMode mode; if (pinboardControl.SelectionIndex == -1) { mode = PropertiesFormMode.PartialEdit; } else { mode = PropertiesFormMode.FullEdit; } if (this.Mode != mode) { this.Mode = mode; } }
public void SetRectanglePositionFromPoint(Point point) { PinboardFileV1.RectangleInfo selection = Data.RectInfos[selectedIndex]; int x = point.X - dragOffset.X; int y = point.Y - dragOffset.Y; if (x < Data.ScreenRectInfo.X) { x = Data.ScreenRectInfo.X; } else if (x + selection.Width > Data.ScreenRectInfo.Width) { x = Data.ScreenRectInfo.Width - selection.Width; } Selection.X = x; if (y < Data.ScreenRectInfo.Y) { y = Data.ScreenRectInfo.Y; } else if (y + selection.Height > Data.ScreenRectInfo.Height) { y = Data.ScreenRectInfo.Height - selection.Height; } Selection.Y = y; }
public void DuplicateSelection() { if (selectedIndex != -1) { PinboardFileV1.RectangleInfo rectInfo = new PinboardFileV1.RectangleInfo(Data.RectInfos[selectedIndex]); rectInfo.Name += "_Copy"; Data.RectInfos.Insert(selectedIndex, rectInfo); Data.RectInfos.Reverse(selectedIndex, 2); DataDirty = true; selectedIndex++; RaiseSelectionChangedEvent(); } }
public void SetRectangleSizeFromPoint(Point point) { PinboardFileV1.RectangleInfo selection = Data.RectInfos[selectedIndex]; int x = point.X + dragOffset.X; int y = point.Y + dragOffset.Y; if (point.X > Data.ScreenRectInfo.Width) { x = Data.ScreenRectInfo.Width; } selection.Width = Math.Max(minRectSize.Width, x - selection.X); if (point.Y > Data.ScreenRectInfo.Height) { y = Data.ScreenRectInfo.Height; } selection.Height = Math.Max(minRectSize.Height, y - selection.Y); }
private void PinboardControl_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { int index = FindRectangle(e.Location); if (index == -1) { selectedIndex = -1; RaiseSelectionChangedEvent(); this.DisplayDirty = true; return; } this.Capture = true; PinboardFileV1.RectangleInfo dragRectInfo = Data.RectInfos[index]; Point[] points = this.GetCornerPoints(dragRectInfo.Rectangle); if (Vector.IsPointInTriangle(e.Location, points[0], points[1], points[2])) { this.dragOffset = new Point( dragRectInfo.X + dragRectInfo.Width - e.Location.X, dragRectInfo.Y + dragRectInfo.Height - e.Location.Y); dragOp = DragOperation.Sizing; this.Cursor = Cursors.SizeNWSE; } else { this.dragOffset = new Point( e.Location.X - dragRectInfo.Rectangle.X, e.Location.Y - dragRectInfo.Rectangle.Y); dragOp = DragOperation.Moving; this.Cursor = Cursors.Hand; } selectedIndex = index; RaiseSelectionChangedEvent(); this.DisplayDirty = true; } }
private void Draw(Graphics g) { if (bufferRect.IsEmpty) { return; } if (Data == null || Data.ScreenRectInfo == null) { g.FillRectangle(Brushes.White, bufferRect); return; } DrawPinboardFile(g, Data.ScreenRectInfo, selectedIndex == -1); for (int i = 0; i < Data.RectInfos.Count; i++) { PinboardFileV1.RectangleInfo rectInfo = Data.RectInfos[i]; DrawPinboardFile(g, rectInfo, i == selectedIndex); } }
public void Compile() { IEnumerable <ParsedPath> svgFileNames = Target.InputFiles.Where(f => f.Extension == ".svg"); ParsedPath pinboardFileName = Target.InputFiles.Where(f => f.Extension == ".pinboard").First(); ParsedPath xnbFileName = Target.OutputFiles.Where(f => f.Extension == ".xnb").First(); PinboardFileV1 pinboardFile = PinboardFileCache.Load(pinboardFileName); List <ImagePlacement> placements = new List <ImagePlacement>(); string rectangleName = this.Target.Properties.GetRequiredValue("Rectangle"); PinboardFileV1.RectangleInfo rectInfo = pinboardFile.GetRectangleInfoByName(rectangleName); if (rectInfo == null) { throw new ContentFileException("Rectangle {0} not found in pinboard file {1}".CultureFormat(rectangleName, pinboardFileName)); } string converterName = Target.Properties.GetOptionalValue("Converter", "Inkscape").ToLower(); if (converterName != "inkscape" && converterName != "rsvg") { throw new ContentFileException("Unknown SVG converter '{0}'".CultureFormat(converterName)); } ParsedPath combinedPngPathName = xnbFileName.WithExtension(".png"); try { int row = 0; foreach (var svgFileName in svgFileNames) { int col = 0; if (rectInfo == null) { throw new InvalidOperationException( "Rectangle '{0}' not found in pinboard '{1}'".CultureFormat(rectangleName, pinboardFileName)); } // TODO-johnls: This should probably go in an intermediate file directory ParsedPath pngFile = xnbFileName.WithFileAndExtension(String.Format("{0}_{1}_{2}.png", svgFileName.File, row, col)); placements.Add(new ImagePlacement(pngFile, new Rectangle(col * rectInfo.Width, row * rectInfo.Height, rectInfo.Width, rectInfo.Height))); switch (converterName) { default: case "rsvg": ImageTools.SvgToPngWithRSvg(svgFileName, pngFile, rectInfo.Width, rectInfo.Height); break; case "inkscape": ImageTools.SvgToPngWithInkscape(svgFileName, pngFile, rectInfo.Width, rectInfo.Height); break; } } ImageTools.CombinePngs(placements, combinedPngPathName); Texture2DContent textureContent; ImageTools.CompressPngToTexture2DContent( combinedPngPathName, this.Target.Properties.GetOptionalValue("CompressionType", "None"), out textureContent); XnbFileWriterV5.WriteFile(textureContent, xnbFileName); } finally { foreach (var placement in placements) { if (File.Exists(placement.ImageFile)) { File.Delete(placement.ImageFile); } } if (File.Exists(combinedPngPathName)) { File.Delete(combinedPngPathName); } } }
public void Compile() { IEnumerable <ParsedPath> svgPaths = Target.InputFiles.Where(f => f.Extension == ".svg"); ParsedPath pinboardPath = Target.InputFiles.Where(f => f.Extension == ".pinboard").First(); ParsedPath pngPath = Target.OutputFiles.Where(f => f.Extension == ".png").First(); PinboardFileV1 pinboardFile = PinboardFileCache.Load(pinboardPath); List <ImagePlacement> placements = new List <ImagePlacement>(); string[] rectangleNames; Target.Properties.GetRequiredValue("Rectangles", out rectangleNames); if (svgPaths.Count() != rectangleNames.Length) { throw new ContentFileException("Number of .svg files ({0}) does match number of RectangleNames ({1})" .CultureFormat(svgPaths.Count(), rectangleNames.Length)); } string s = Target.Properties.GetOptionalValue("Rotation", "None"); ImageRotation rotation; if (!Enum.TryParse(s, out rotation)) { throw new ContentFileException("Invalid value '{0}' for given for rotation. Valid are None, Left, Right, UpsideDown".CultureFormat(s)); } 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); } } } }
private void ApplyButton_Click(object sender, EventArgs e) { applyButton.Focus(); if (inErrorState) { ResetColors(); } inErrorState = true; PinboardFileV1 data = pinboardControl.Data; PinboardFileV1.RectangleInfo selection = pinboardControl.Selection; int selectionIndex = pinboardControl.SelectionIndex; if (pinboardControl.SelectionIndex == -1) { Size savedSize = selection.Size; int width; if (!int.TryParse(widthTextBox.Text, out width) || width < 128 || width > 2048) { widthTextBox.ForeColor = Color.Red; widthTextBox.Focus(); return; } selection.Width = width; int height; if (!int.TryParse(heightTextBox.Text, out height) || height < 128 || height > 2048) { heightTextBox.ForeColor = Color.Red; heightTextBox.Focus(); return; } selection.Height = height; RaiseScreenSizeChangedEvent(savedSize); } else { string name = nameTextBox.Text; bool duplicate = false; if (name != selection.Name) { if (name == data.ScreenRectInfo.Name) { duplicate = true; } else { for (int i = 0; i < data.RectInfos.Count; i++) { if (i == selectionIndex) { continue; } PinboardFileV1.RectangleInfo rectInfo = data.RectInfos[i]; if (name == rectInfo.Name) { duplicate = true; break; } } } } if (name.Length == 0 || duplicate) { nameTextBox.ForeColor = Color.Red; nameTextBox.Focus(); return; } selection.Name = name; int x; if (!int.TryParse(xTextBox.Text, out x) || x < 0 || x > data.ScreenRectInfo.Width - selection.Width) { xTextBox.ForeColor = Color.Red; xTextBox.Focus(); return; } selection.X = x; int y; if (!int.TryParse(yTextBox.Text, out y) || y < 0 || y > data.ScreenRectInfo.Height - selection.Height) { yTextBox.ForeColor = Color.Red; yTextBox.Focus(); return; } selection.Y = y; int width; if (!int.TryParse(widthTextBox.Text, out width) || width < 1 || width > data.ScreenRectInfo.Width - selection.X) { widthTextBox.ForeColor = Color.Red; widthTextBox.Focus(); return; } selection.Width = width; int height; if (!int.TryParse(heightTextBox.Text, out height) || height < 1 || height > data.ScreenRectInfo.Height - selection.Y) { heightTextBox.ForeColor = Color.Red; heightTextBox.Focus(); return; } selection.Height = height; } inErrorState = false; pinboardControl.DataDirty = true; }
private void PinboardControl_KeyDown(object sender, KeyEventArgs e) { if (selectedIndex != -1 && dragOp == DragOperation.None) { switch (e.KeyCode) { case Keys.PageUp: if (e.Modifiers == Keys.None && selectedIndex < Data.RectInfos.Count - 1) { PinboardFileV1.RectangleInfo rectInfo = Data.RectInfos[selectedIndex]; Data.RectInfos[selectedIndex] = Data.RectInfos[selectedIndex + 1]; selectedIndex++; Data.RectInfos[selectedIndex] = rectInfo; DataDirty = true; } break; case Keys.PageDown: if (e.Modifiers == Keys.None && selectedIndex > 0) { PinboardFileV1.RectangleInfo rectInfo = Data.RectInfos[selectedIndex]; Data.RectInfos[selectedIndex] = Data.RectInfos[selectedIndex - 1]; selectedIndex--; Data.RectInfos[selectedIndex] = rectInfo; DataDirty = true; } break; case Keys.Right: if (e.Modifiers == Keys.None && Selection.X + Selection.Width < Data.ScreenRectInfo.Width) { Selection.X++; DataDirty = true; } else if ((e.Modifiers & Keys.Control) != 0 && Selection.Width < Data.ScreenRectInfo.Width - Selection.X) { Selection.Width++; DataDirty = true; } break; case Keys.Left: if (e.Modifiers == Keys.None && Selection.X > Data.ScreenRectInfo.X) { Selection.X--; DataDirty = true; } else if ((e.Modifiers & Keys.Control) != 0 && Selection.Width > 1) { Selection.Width--; DataDirty = true; } break; case Keys.Up: if (e.Modifiers == Keys.None && Selection.Y > Data.ScreenRectInfo.Y) { Selection.Y--; DataDirty = true; } else if ((e.Modifiers & Keys.Control) != 0 && Selection.Height > 1) { Selection.Height--; DataDirty = true; } break; case Keys.Down: if (e.Modifiers == Keys.None && Selection.Y + Selection.Height < Data.ScreenRectInfo.Height) { Selection.Y++; DataDirty = true; } else if ((e.Modifiers & Keys.Control) != 0 && Selection.Height < Data.ScreenRectInfo.Height - Selection.Y) { Selection.Height++; DataDirty = true; } break; } } }