/// <summary> /// Draws a sample box. /// </summary> public void BeginBox(XGraphics gfx, int number) { //obracene XY gfx.RotateAtTransform(90.0, new XPoint(height / 4, width / 4)); gfx.TranslateTransform(+62, +63); //const int dEllipse = 15; XRect rect = new XRect(0, 0, height /2 -2, width/2 -2); if (number % 2 == 0) rect.X += height/2 +2; rect.Y = ((number - 1) / 2) * (-width/2 - 3); //rect.Inflate(-10, -10); //XRect rect2 = rect; XPen pen = new XPen(XColors.Black, 1); gfx.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height); //rect2.Offset(this.borderWidth, this.borderWidth); //gfx.DrawRoundedRectangle(new XSolidBrush(this.shadowColor), rect2, new XSize(dEllipse + 8, dEllipse + 8)); //XLinearGradientBrush brush = new XLinearGradientBrush(rect, this.backColor, this.backColor2, XLinearGradientMode.Vertical); //gfx.DrawRoundedRectangle(this.borderPen, brush, rect, new XSize(dEllipse, dEllipse)); //rect.Inflate(-5, -5); //rect.Inflate(-10, -5); //rect.Y += 20; //rect.Height -= 20; ////gfx.DrawRectangle(XPens.Red, rect); // gfx.TranslateTransform(rect.X, rect.Y); this.state = gfx.Save(); }
/// <summary> /// Demonstrates the use of XGraphics.Transform. /// </summary> public override void RenderPage(XGraphics gfx) { base.RenderPage(gfx); //XGraphicsState state = gfx.Save(); gfx.Save(); gfx.IntersectClip(new XRect(20, 20, 300, 500)); gfx.DrawRectangle(XBrushes.Yellow, 0, 0, gfx.PageSize.Width, gfx.PageSize.Height); gfx.Restore(); gfx.Save(); gfx.IntersectClip(new XRect(100, 200, 300, 500)); gfx.DrawRectangle(XBrushes.LightBlue, 0, 0, gfx.PageSize.Width, gfx.PageSize.Height); gfx.DrawLine(XPens.MediumSlateBlue, 0, 0, 150, 200); gfx.DrawPolygon(properties.Pen1.Pen, GetPentagram(75, new PointF(150, 200))); Matrix matrix = new Matrix(); //matrix.Scale(2f, 1.5f); //matrix.Translate(-200, -400); //matrix.Rotate(45); //matrix.Translate(200, 400); //gfx.Transform = matrix; //gfx.TranslateTransform(50, 30); #if true gfx.TranslateTransform(30, 40, XMatrixOrder.Prepend); gfx.ScaleTransform(2.0f, 2.0f, XMatrixOrder.Prepend); gfx.RotateTransform(15, XMatrixOrder.Prepend); #else gfx.TranslateTransform(30, 40, XMatrixOrder.Append); gfx.ScaleTransform(2.0f, 2.0f, XMatrixOrder.Append); gfx.RotateTransform(15, XMatrixOrder.Append); #endif bool id = matrix.IsIdentity; matrix.Scale(2.0f, 2.0f, MatrixOrder.Prepend); //matrix.Translate(30, -50); matrix.Rotate(15, MatrixOrder.Prepend); //Matrix mtx = gfx.Transform.ToGdiMatrix(); //gfx.Transform = matrix; gfx.DrawLine(XPens.MediumSlateBlue, 0, 0, 150, 200); gfx.DrawPolygon(properties.Pen2.Pen, GetPentagram(75, new PointF(150, 200))); gfx.Restore(); gfx.DrawLine(XPens.Red, 0, 0, 1000, 1000); gfx.DrawPolygon(XPens.SandyBrown, GetPentagram(75, new PointF(150, 200))); }
void Box(XGraphics gfx, XRect rect, double startAngle, double sweepAngle) { double xc = rect.X + rect.Width / 2; double yc = rect.Y + rect.Height / 2; double a = startAngle * 0.0174532925199433; double b = (startAngle + sweepAngle) * 0.0174532925199433; XGraphicsState state = gfx.Save(); gfx.IntersectClip(rect); #if true #if true_ for (double deg = 0; deg < 360; deg += 10) gfx.DrawLine(XPens.Yellow, xc, yc, (xc + rect.Width / 2 * Math.Cos(deg * 0.0174532925199433)), (yc + rect.Height / 2 * Math.Sin(deg * 0.0174532925199433))); #endif double f = Math.Max(rect.Width / 2, rect.Height / 2); for (double deg = 0; deg < 360; deg += 10) gfx.DrawLine(XPens.Goldenrod, xc, yc, (xc + f * Math.Cos(deg * 0.0174532925199433)), (yc + f * Math.Sin(deg * 0.0174532925199433))); gfx.DrawLine(XPens.PaleGreen, xc, rect.Y, xc, rect.Y + rect.Height); gfx.DrawLine(XPens.PaleGreen, rect.X, yc, rect.X + rect.Width, yc); //gfx.DrawLine(XPens.DarkGray, xc, yc, (xc + rect.Width / 2 * Math.Cos(a)), (yc + rect.Height / 2 * Math.Sin(a))); //gfx.DrawLine(XPens.DarkGray, xc, yc, (xc + rect.Width / 2 * Math.Cos(b)), (yc + rect.Height / 2 * Math.Sin(b))); #endif gfx.Restore(state); gfx.DrawRectangle(properties.Pen1.Pen, rect); }
public void DrawTo(XGraphics context) { var state = context.Save(); layout.Transform(context, form.Size); form.PageIndex = sourcePageIndex; context.DrawImage(form, 0, 0); context.Restore(state); }
/// <summary> /// Demonstrates the use of XGraphics.SetClip. /// </summary> public override void RenderPage(XGraphics gfx) { base.RenderPage(gfx); gfx.Save(); gfx.TranslateTransform(50, 50); gfx.IntersectClip(new Rectangle(0, 0, 400, 250)); gfx.TranslateTransform(50, 50); //gfx.Clear(XColor.GhostWhite); gfx.DrawEllipse(XPens.Green, XBrushes.Yellow, 40, 40, 500, 500); gfx.Restore(); gfx.Save(); //gfx.Transform = new XMatrix(); //XMatrix.Identity; gfx.TranslateTransform(200, 200); gfx.IntersectClip(new Rectangle(0, 0, 400, 250)); gfx.DrawEllipse(XPens.Green, XBrushes.Yellow, 40, 40, 500, 500); gfx.Restore(); }
/// <summary> /// Renders the OMR code. /// </summary> protected internal override void Render(XGraphics gfx, XBrush brush, XFont font, XPoint position) { XGraphicsState state = gfx.Save(); switch (this.direction) { case CodeDirection.RightToLeft: gfx.RotateAtTransform(180, position); break; case CodeDirection.TopToBottom: gfx.RotateAtTransform(90, position); break; case CodeDirection.BottomToTop: gfx.RotateAtTransform(-90, position); break; } //XPoint pt = center - this.size / 2; XPoint pt = position - CodeBase.CalcDistance(AnchorType.TopLeft, this.anchor, this.size); uint value; uint.TryParse(this.text, out value); #if true // HACK: Project Wallenwein: set LK value |= 1; this.synchronizeCode = true; #endif if (this.synchronizeCode) { XRect rect = new XRect(pt.x, pt.y, this.makerThickness, this.size.height); gfx.DrawRectangle(brush, rect); pt.x += 2 * this.makerDistance; } for (int idx = 0; idx < 32; idx++) { if ((value & 1) == 1) { XRect rect = new XRect(pt.x + idx * this.makerDistance, pt.y, this.makerThickness, this.size.height); gfx.DrawRectangle(brush, rect); } value = value >> 1; } gfx.Restore(state); }
/// <summary> /// Renders the content of the page. /// </summary> public void Render(XGraphics xGraphics) { const double textPossitionX = 50; double textPossitionY = 100; const string fontFamilyName = "Times"; const int fontSizeHeader = 18; const int fontSizeText = 12; XFont fontHeader = new XFont(fontFamilyName, fontSizeHeader, XFontStyle.Bold); XFont fontText = new XFont(fontFamilyName, fontSizeText); XFont fontItalic = new XFont(fontFamilyName, fontSizeText, XFontStyle.BoldItalic); double lineSpacing = fontText.GetHeight(xGraphics); xGraphics.DrawString("This is Header", fontHeader, XBrushes.Black, textPossitionX, textPossitionX); textPossitionY += lineSpacing; xGraphics.DrawString("This is normal.", fontText, XBrushes.Black, textPossitionX, textPossitionY); textPossitionY += lineSpacing; xGraphics.DrawString("This is Italic.", fontItalic, XBrushes.Black, textPossitionX, textPossitionY); textPossitionY += lineSpacing*3; //Bitmap bitmap = (Bitmap)Image.FromFile(@"E:\temp\klicaj.jpeg"); XImage xImage = null; if (item != null) { if (item.Image != null) { MemoryStream memoryStream = new MemoryStream(item.Image); Bitmap bitmap = (Bitmap) Image.FromStream(memoryStream, true, true); xImage = XImage.FromGdiPlusImage(bitmap); } } if (xImage != null) { XRect rcImage = new XRect(100, textPossitionY, 100, 100*Math.Sqrt(2)); xGraphics.DrawImage(xImage, rcImage); } XGraphicsState state = xGraphics.Save(); xGraphics.Restore(state); }
/// <summary> /// Draw the texture image in the given graphics at the given location. /// </summary> public void DrawRectangle(XGraphics g, double x, double y, double width, double height) { var prevState = g.Save(); g.IntersectClip(new XRect(x, y, width, height)); double rx = _translateTransformLocation.X; double w = _image.PixelWidth, h = _image.PixelHeight; while (rx < x + width) { double ry = _translateTransformLocation.Y; while (ry < y + height) { g.DrawImage(_image, rx, ry, w, h); ry += h; } rx += w; } g.Restore(prevState); }
public override void RenderPage(XGraphics gfx) { //base.RenderPage(gfx); XPoint[] origins = new XPoint[] { new XPoint(100, 200), new XPoint(300, 200), new XPoint(100, 400), new XPoint(300, 400), new XPoint(100, 600), new XPoint(350, 600), }; XPoint origin; XGraphicsState state; float length = 100; // Not transformed origin = origins[0]; DrawAxes(gfx, XPens.Black, origin, length); gfx.DrawString(this.properties.Font1.Text, this.properties.Font1.Font, this.properties.Font1.Brush, origin); // Translation state = gfx.Save(); origin = origins[1]; DrawAxes(gfx, XPens.Black, origin, length); gfx.TranslateTransform(20, -30); DrawAxes(gfx, XPens.DarkGray, origin, length); gfx.DrawString(this.properties.Font1.Text, this.properties.Font1.Font, this.properties.Font1.Brush, origin); gfx.Restore(state); // Translation state = gfx.Save(); origin = origins[2]; DrawAxes(gfx, XPens.Black, origin, length); gfx.TranslateTransform(20, -30); DrawAxes(gfx, XPens.DarkGray, origin, length); gfx.DrawString(this.properties.Font1.Text, this.properties.Font1.Font, this.properties.Font1.Brush, origin); gfx.Restore(state); //// Scaling //state = gfx.Save(); //origin = origins[2]; //DrawAxes(gfx, XPens.Black, origin, length); //gfx.TranslateTransform(origin.X, origin.Y); //gfx.ScaleTransform(1.3, 1.5); //DrawAxes(gfx, XPens.DarkGray, new XPoint(), length); //gfx.DrawString(this.properties.Font1.Text, this.properties.Font1.Font, this.properties.Font1.Brush, 0, 0); //gfx.Restore(state); // Rotation state = gfx.Save(); origin = origins[3]; DrawAxes(gfx, XPens.Black, origin, length); gfx.TranslateTransform(origin.X, origin.Y); gfx.RotateTransform(-45); DrawAxes(gfx, XPens.DarkGray, new XPoint(), length); gfx.DrawString(this.properties.Font1.Text, this.properties.Font1.Font, this.properties.Font1.Brush, 0 , 0); gfx.Restore(state); // Skewing (or shearing) state = gfx.Save(); origin = origins[4]; DrawAxes(gfx, XPens.Black, origin, length); gfx.TranslateTransform(origin.X, origin.Y); gfx.MultiplyTransform(new Matrix(1, -0.3f, -0.4f, 1, 0, 0)); DrawAxes(gfx, XPens.DarkGray, new XPoint(), length); gfx.DrawString(this.properties.Font1.Text, this.properties.Font1.Font, this.properties.Font1.Brush, 0 , 0); gfx.Restore(state); // Reflection state = gfx.Save(); origin = origins[5]; DrawAxes(gfx, XPens.Black, origin, length); gfx.TranslateTransform(origin.X, origin.Y); gfx.MultiplyTransform(new Matrix(-1, 0, 0, -1, 0, 0)); DrawAxes(gfx, XPens.DarkGray, new XPoint(), length); gfx.DrawString(this.properties.Font1.Text, this.properties.Font1.Font, this.properties.Font1.Brush, 0 , 0); gfx.Restore(state); }
void DrawHourHand(XGraphics gfx, XPen pen, XBrush brush) { XGraphicsState gs = gfx.Save(); gfx.RotateTransform(360 * Time.Hour / 12 + 30 * Time.Minute / 60); gfx.DrawPolygon(pen, brush, new XPoint[]{new XPoint(0, 150), new XPoint(100, 0), new XPoint(0, -600), new XPoint(-100, 0)}, XFillMode.Winding); gfx.Restore(gs); }
void DrawIcon(XGraphics gfx, string iconName, XPoint position, double width, double height) { var iconPath = Server.MapPath("~/Content/icons/" + iconName + ".png"); if (System.IO.File.Exists(iconPath)) { using (XImage image = XImage.FromFile(iconPath)) { var state = gfx.Save(); gfx.DrawImage(image, position.X, position.Y, width, height); gfx.Restore(state); } } }
/// <summary> /// Renders the matrix code. /// </summary> protected internal override void Render(XGraphics gfx, XBrush brush, XPoint position) { XGraphicsState state = gfx.Save(); switch (this.direction) { case CodeDirection.RightToLeft: gfx.RotateAtTransform(180, position); break; case CodeDirection.TopToBottom: gfx.RotateAtTransform(90, position); break; case CodeDirection.BottomToTop: gfx.RotateAtTransform(-90, position); break; } XPoint pos = position + CodeBase.CalcDistance(this.anchor, AnchorType.TopLeft, this.size); if (this.matrixImage == null) this.matrixImage = DataMatrixImage.GenerateMatrixImage(Text, Encoding, Rows, Columns); if (QuietZone > 0) { XSize sizeWithZone = new XSize(this.size.width, this.size.height); sizeWithZone.width = sizeWithZone.width / (Columns + 2 * QuietZone) * Columns; sizeWithZone.height = sizeWithZone.height / (Rows + 2 * QuietZone) * Rows; XPoint posWithZone = new XPoint(pos.X, pos.Y); posWithZone.X += size.width / (Columns + 2 * QuietZone) * QuietZone; posWithZone.Y += size.height / (Rows + 2 * QuietZone) * QuietZone; gfx.DrawRectangle(XBrushes.White, pos.x, pos.y, size.width, size.height); gfx.DrawImage(matrixImage, posWithZone.x, posWithZone.y, sizeWithZone.width, sizeWithZone.height); } else gfx.DrawImage(matrixImage, pos.x, pos.y, this.size.width, this.size.height); gfx.Restore(state); }
public SaveGraphicsState(XGraphics graphics) { g = graphics; gs = graphics.Save(); }
public SaveGraphicsState(XGraphics g) { this.g = g; this.gs = g.Save(); }
/// <summary> /// Renders the content of the page. /// </summary> public void Render(XGraphics gfx) { XRect rect; XPen pen; double x = 50, y = 100; XFont fontH1 = new XFont("Times", 18, XFontStyle.Bold); XFont font = new XFont("Times", 12); XFont fontItalic = new XFont("Times", 12, XFontStyle.BoldItalic); double ls = font.GetHeight(gfx); // Draw some text gfx.DrawString("Create PDF on the fly with PDFsharp", fontH1, XBrushes.Black, x, x); gfx.DrawString("With PDFsharp you can use the same code to draw graphic, " + "text and images on different targets.", font, XBrushes.Black, x, y); y += ls; gfx.DrawString("The object used for drawing is the XGraphics object.", font, XBrushes.Black, x, y); y += 2 * ls; // Draw an arc pen = new XPen(XColors.Red, 4); pen.DashStyle = XDashStyle.Dash; gfx.DrawArc(pen, x + 20, y, 100, 60, 150, 120); // Draw a star XGraphicsState gs = gfx.Save(); gfx.TranslateTransform(x + 140, y + 30); for (int idx = 0; idx < 360; idx += 10) { gfx.RotateTransform(10); gfx.DrawLine(XPens.DarkGreen, 0, 0, 30, 0); } gfx.Restore(gs); // Draw a rounded rectangle rect = new XRect(x + 230, y, 100, 60); pen = new XPen(XColors.DarkBlue, 2.5); XColor color1 = XColor.FromKnownColor(KnownColor.DarkBlue); XColor color2 = XColors.Red; XLinearGradientBrush lbrush = new XLinearGradientBrush(rect, color1, color2, XLinearGradientMode.Vertical); gfx.DrawRoundedRectangle(pen, lbrush, rect, new XSize(10, 10)); // Draw a pie pen = new XPen(XColors.DarkOrange, 1.5); pen.DashStyle = XDashStyle.Dot; gfx.DrawPie(pen, XBrushes.Blue, x + 360, y, 100, 60, -130, 135); // Draw some more text y += 60 + 2 * ls; gfx.DrawString("With XGraphics you can draw on a PDF page as well as " + "on any System.Drawing.Graphics object.", font, XBrushes.Black, x, y); y += ls * 1.1; gfx.DrawString("Use the same code to", font, XBrushes.Black, x, y); x += 10; y += ls * 1.1; gfx.DrawString("• draw on a newly created PDF page", font, XBrushes.Black, x, y); y += ls; gfx.DrawString("• draw above or beneath of the content of an existing PDF page", font, XBrushes.Black, x, y); y += ls; gfx.DrawString("• draw in a window", font, XBrushes.Black, x, y); y += ls; gfx.DrawString("• draw on a printer", font, XBrushes.Black, x, y); y += ls; gfx.DrawString("• draw in a bitmap image", font, XBrushes.Black, x, y); x -= 10; y += ls * 1.1; gfx.DrawString("You can also import an existing PDF page and use it like " + "an image, e.g. draw it on another PDF page.", font, XBrushes.Black, x, y); y += ls * 1.1 * 2; gfx.DrawString("Imported PDF pages are neither drawn nor printed; create a " + "PDF file to see or print them!", fontItalic, XBrushes.Firebrick, x, y); y += ls * 1.1; gfx.DrawString("Below this text is a PDF form that will be visible when " + "viewed or printed with a PDF viewer.", fontItalic, XBrushes.Firebrick, x, y); y += ls * 1.1; XGraphicsState state = gfx.Save(); XRect rcImage = new XRect(100, y, 100, 100 * Math.Sqrt(2)); gfx.DrawRectangle(XBrushes.Snow, rcImage); gfx.DrawImage(XPdfForm.FromFile("../../../../../PDFs/SomeLayout.pdf"), rcImage); gfx.Restore(state); }
public override void Draw(XGraphics graphics, Palette palette, DrawingContext context) { Random random = new Random(Name.GetHashCode()); var topLeft = InnerBounds.GetCorner(CompassPoint.NorthWest); var topRight = InnerBounds.GetCorner(CompassPoint.NorthEast); var bottomLeft = InnerBounds.GetCorner(CompassPoint.SouthWest); var bottomRight = InnerBounds.GetCorner(CompassPoint.SouthEast); var top = new LineSegment(topLeft, topRight); var right = new LineSegment(topRight, bottomRight); var bottom = new LineSegment(bottomRight, bottomLeft); var left = new LineSegment(bottomLeft, topLeft); context.LinesDrawn.Add(top); context.LinesDrawn.Add(right); context.LinesDrawn.Add(bottom); context.LinesDrawn.Add(left); var brush = context.Selected ? palette.BorderBrush : palette.FillBrush; if (!Settings.DebugDisableLineRendering) { var path = palette.Path(); Drawing.AddLine(path, top, random); Drawing.AddLine(path, right, random); Drawing.AddLine(path, bottom, random); Drawing.AddLine(path, left, random); graphics.DrawPath(brush, path); if (IsDark) { var state = graphics.Save(); graphics.IntersectClip(path); brush = context.Selected ? palette.FillBrush : palette.BorderBrush; graphics.DrawPolygon(brush, new PointF[] { topRight.ToPointF(), new PointF(topRight.X - Settings.DarknessStripeSize, topRight.Y), new PointF(topRight.X, topRight.Y + Settings.DarknessStripeSize) }, XFillMode.Alternate); graphics.Restore(state); } graphics.DrawPath(palette.BorderPen, path); } var font = Settings.LargeFont; brush = context.Selected ? palette.FillBrush : palette.LargeTextBrush; Rect textBounds = InnerBounds; textBounds.Inflate(-5, -5); if (textBounds.Width > 0 && textBounds.Height > 0) { m_name.Draw(graphics, font, brush, textBounds.Position, textBounds.Size, XStringFormats.Center); } var expandedBounds = InnerBounds; expandedBounds.Inflate(Settings.ObjectListOffsetFromRoom, Settings.ObjectListOffsetFromRoom); var drawnObjectList = false; font = Settings.SmallFont; brush = palette.SmallTextBrush; if (!string.IsNullOrEmpty(Objects)) { XStringFormat format = new XStringFormat(); Vector pos = expandedBounds.GetCorner(m_objectsPosition); if (!Drawing.SetAlignmentFromCardinalOrOrdinalDirection(format, m_objectsPosition)) { // object list appears inside the room below its name format.LineAlignment = XLineAlignment.Far; format.Alignment = XStringAlignment.Near; //format.Trimming = StringTrimming.EllipsisCharacter; //format.FormatFlags = StringFormatFlags.LineLimit; var height = InnerBounds.Height / 2 - font.Height / 2; var bounds = new Rect(InnerBounds.Left + Settings.ObjectListOffsetFromRoom, InnerBounds.Bottom - height, InnerBounds.Width - Settings.ObjectListOffsetFromRoom, height - Settings.ObjectListOffsetFromRoom); brush = context.Selected ? palette.FillBrush : brush; if (bounds.Width > 0 && bounds.Height > 0) { m_objects.Draw(graphics, font, brush, bounds.Position, bounds.Size, format); } drawnObjectList = true; } else if (m_objectsPosition == CompassPoint.North || m_objectsPosition == CompassPoint.South) { pos.X += Settings.ObjectListOffsetFromRoom; } if (!drawnObjectList) { m_objects.Draw(graphics, font, brush, pos, Vector.Zero, format); } } }
/// <summary> /// Renders the bar code. /// </summary> protected internal override void Render(XGraphics gfx, XBrush brush, XFont font, XPoint position) { XGraphicsState state = gfx.Save(); BarCodeRenderInfo info = new BarCodeRenderInfo(gfx, brush, font, position); InitRendering(info); info.CurrPosInString = 0; //info.CurrPos = info.Center - this.size / 2; info.CurrPos = position - CodeBase.CalcDistance(AnchorType.TopLeft, this.anchor, this.size); if (TurboBit) RenderTurboBit(info, true); RenderStart(info); while (info.CurrPosInString < this.text.Length) RenderNextPair(info); RenderStop(info); if (TurboBit) RenderTurboBit(info, false); if (this.TextLocation != TextLocation.None) RenderText(info); gfx.Restore(state); }
/// <summary> /// Demonstrates the use of XGraphics.Transform. /// </summary> public override void RenderPage(XGraphics gfx) { XGraphicsState state1, state2; base.RenderPage(gfx); state1 = gfx.Save(); // Level 1 gfx.TranslateTransform(20, 50); gfx.DrawLine(XPens.Blue, 0, 0, 10, 10); gfx.Restore(state1); state1 = gfx.Save(); // Level 2 gfx.TranslateTransform(220, 50); gfx.DrawLine(XPens.Blue, 0, 0, 10, 10); XGraphicsPath clipPath = new XGraphicsPath(); clipPath.AddPie(0, 10, 150, 100, -50, 100); gfx.IntersectClip(clipPath); gfx.DrawRectangle(XBrushes.LightYellow, 0, 0, 1000, 1000); state2 = gfx.Save(); // Level 3 gfx.ScaleTransform(10); gfx.DrawLine(XPens.Red, 1, 1, 10, 10); //gfx.ResetClip(); gfx.Restore(state2); // Level 2 gfx.DrawLine(XPens.Red, 1, 1, 10, 10); gfx.Restore(state1); #if true_ gfx.SetClip(new XRect(20, 20, 300, 500)); gfx.DrawRectangle(XBrushes.Yellow, 0, 0, gfx.PageSize.Width, gfx.PageSize.Height); gfx.SetClip(new XRect(100, 200, 300, 500), XCombineMode.Intersect); gfx.DrawRectangle(XBrushes.LightBlue, 0, 0, gfx.PageSize.Width, gfx.PageSize.Height); gfx.DrawLine(XPens.MediumSlateBlue, 0, 0, 150, 200); gfx.DrawPolygon(properties.Pen1.Pen, GetPentagram(75, new PointF(150, 200))); Matrix matrix = new Matrix(); //matrix.Scale(2f, 1.5f); //matrix.Translate(-200, -400); //matrix.Rotate(45); //matrix.Translate(200, 400); //gfx.Transform = matrix; //gfx.TranslateTransform(50, 30); #if true gfx.TranslateTransform(30, 40, XMatrixOrder.Prepend); gfx.ScaleTransform(2.0f, 2.0f, XMatrixOrder.Prepend); gfx.RotateTransform(15, XMatrixOrder.Prepend); #else gfx.TranslateTransform(30, 40, XMatrixOrder.Append); gfx.ScaleTransform(2.0f, 2.0f, XMatrixOrder.Append); gfx.RotateTransform(15, XMatrixOrder.Append); #endif bool id = matrix.IsIdentity; matrix.Scale(2.0f, 2.0f, MatrixOrder.Prepend); //matrix.Translate(30, -50); matrix.Rotate(15, MatrixOrder.Prepend); Matrix mtx = gfx.Transform.ToMatrix(); //gfx.Transform = matrix; gfx.DrawLine(XPens.MediumSlateBlue, 0, 0, 150, 200); gfx.DrawPolygon(properties.Pen2.Pen, GetPentagram(75, new PointF(150, 200))); gfx.ResetClip(); gfx.DrawLine(XPens.Red, 0, 0, 1000, 1000); gfx.DrawPolygon(XPens.SandyBrown, GetPentagram(75, new PointF(150, 200))); #endif }
/// <summary> /// Draws first chart only. /// </summary> public void DrawChart(XGraphics gfx) { XGraphicsState state = gfx.Save(); gfx.TranslateTransform(this.location.X, this.location.Y); if (this.chartList.Count > 0) { XRect chartRect = new XRect(0, 0, this.size.Width, this.size.Height); Chart chart = (Chart)this.chartList[0]; RendererParameters parms = new RendererParameters(gfx, chartRect); parms.DrawingItem = chart; ChartRenderer renderer = GetChartRenderer(chart, parms); renderer.Init(); renderer.Format(); renderer.Draw(); } gfx.Restore(state); }
/// <summary> /// Draws all charts inside the ChartFrame. /// </summary> public void Draw(XGraphics gfx) { // Draw frame of ChartFrame. First shadow frame. int dx = 5; int dy = 5; gfx.DrawRoundedRectangle(XBrushes.Gainsboro, this.location.X + dx, this.location.Y + dy, this.size.Width, this.size.Height, 20, 20); XRect chartRect = new XRect(this.location.X, this.location.Y, this.size.Width, this.size.Height); XLinearGradientBrush brush = new XLinearGradientBrush(chartRect, XColor.FromArgb(0xFFD0DEEF), XColors.White, XLinearGradientMode.Vertical); XPen penBorder = new XPen(XColors.SteelBlue, 2.5); gfx.DrawRoundedRectangle(penBorder, brush, this.location.X, this.location.Y, this.size.Width, this.size.Height, 15, 15); XGraphicsState state = gfx.Save(); gfx.TranslateTransform(this.location.X, this.location.Y); // Calculate rectangle for all charts. Y-Position will be moved for each chart. int charts = this.chartList.Count; uint dxChart = 20; uint dyChart = 20; uint dyBetweenCharts = 30; XRect rect = new XRect(dxChart, dyChart, this.size.Width - 2 * dxChart, (this.size.Height - (charts - 1) * dyBetweenCharts - 2 * dyChart) / charts); // draw each chart in list foreach (Chart chart in this.chartList) { RendererParameters parms = new RendererParameters(gfx, rect); parms.DrawingItem = chart; ChartRenderer renderer = GetChartRenderer(chart, parms); renderer.Init(); renderer.Format(); renderer.Draw(); rect.Y += rect.Height + dyBetweenCharts; } gfx.Restore(state); // // Calculate rectangle for all charts. Y-Position will be moved for each chart. // int charts = this.chartList.Count; // uint dxChart = 0; // uint dyChart = 0; // uint dyBetweenCharts = 0; // XRect rect = new XRect(dxChart, dyChart, // this.size.Width - 2 * dxChart, // (this.size.Height - (charts - 1) * dyBetweenCharts - 2 * dyChart) / charts); // // // draw each chart in list // foreach (Chart chart in this.chartList) // { // RendererParameters parms = new RendererParameters(gfx, rect); // parms.DrawingItem = chart; // // ChartRenderer renderer = GetChartRenderer(chart, parms); // renderer.Init(); // renderer.Format(); // renderer.Draw(); // // rect.Y += rect.Height + dyBetweenCharts; // } }
public static void DrawChevron(XGraphics graphics, PointF pos, float angle, float size, Brush fillBrush) { if (m_chevronPath == null) { var apex = new PointF(0.5f, 0); var leftCorner = new PointF(-0.5f, 0.5f); var rightCorner = new PointF(-0.5f, -0.5f); m_chevronPath = new XGraphicsPath(); m_chevronPath.AddLine(apex, rightCorner); m_chevronPath.AddLine(rightCorner, leftCorner); m_chevronPath.AddLine(leftCorner, apex); } var state = graphics.Save(); graphics.TranslateTransform(pos.X, pos.Y); graphics.RotateTransform(angle); graphics.ScaleTransform(size, size); graphics.DrawPath(fillBrush, m_chevronPath); graphics.Restore(state); }
void DrawMinuteHand(XGraphics gfx, XPen pen, XBrush brush) { XGraphicsState gs = gfx.Save(); gfx.RotateTransform(360 * Time.Minute / 60 + 6 * Time.Second / 60); gfx.DrawPolygon(pen, brush, new XPoint[]{new XPoint(0, 200), new XPoint(50, 0), new XPoint(0, -800), new XPoint(-50, 0)}, XFillMode.Winding); gfx.Restore(gs); }
private static XPoint DrawLineArrowInternal(XGraphics gfx, XPen pen, XSolidBrush brush, double x, double y, double angle, Core2D.Style.ArrowStyle style) { XPoint pt; var rt = new XMatrix(); var c = new XPoint(x, y); rt.RotateAtPrepend(angle, c); double rx = style.RadiusX; double ry = style.RadiusY; double sx = 2.0 * rx; double sy = 2.0 * ry; switch (style.ArrowType) { default: case Core2D.Style.ArrowType.None: { pt = new XPoint(x, y); } break; case Core2D.Style.ArrowType.Rectangle: { pt = rt.Transform(new XPoint(x - sx, y)); var rect = new XRect(x - sx, y - ry, sx, sy); gfx.Save(); gfx.RotateAtTransform(angle, c); DrawRectangleInternal(gfx, brush, pen, style.IsStroked, style.IsFilled, ref rect); gfx.Restore(); } break; case Core2D.Style.ArrowType.Ellipse: { pt = rt.Transform(new XPoint(x - sx, y)); gfx.Save(); gfx.RotateAtTransform(angle, c); var rect = new XRect(x - sx, y - ry, sx, sy); DrawEllipseInternal(gfx, brush, pen, style.IsStroked, style.IsFilled, ref rect); gfx.Restore(); } break; case Core2D.Style.ArrowType.Arrow: { pt = rt.Transform(new XPoint(x, y)); var p11 = rt.Transform(new XPoint(x - sx, y + sy)); var p21 = rt.Transform(new XPoint(x, y)); var p12 = rt.Transform(new XPoint(x - sx, y - sy)); var p22 = rt.Transform(new XPoint(x, y)); DrawLineInternal(gfx, pen, style.IsStroked, ref p11, ref p21); DrawLineInternal(gfx, pen, style.IsStroked, ref p12, ref p22); } break; } return pt; }
void DrawSecondHand(XGraphics gfx, XPen pen) { XGraphicsState gs = gfx.Save(); gfx.RotateTransform(360 * Time.Second / 60 + 6 * Time.Millisecond / 1000); gfx.DrawEllipse(new XSolidBrush(pen.Color), -15, -15, 30, 30); gfx.DrawLine(pen, 0, 40, 0, -800); gfx.Restore(gs); }
public static void Test(PdfSharp.Drawing.XGraphics gfx) { XRect rect; XPen pen; double x = 50, y = 100; XFont fontH1 = new XFont("Times", 18, XFontStyle.Bold); XFont font = new XFont("Times", 12); XFont fontItalic = new XFont("Times", 12, XFontStyle.BoldItalic); double ls = font.GetHeight(gfx); // Draw some text gfx.DrawString("Create PDF on the fly with PDFsharp", fontH1, XBrushes.Black, x, x); gfx.DrawString("With PDFsharp you can use the same code to draw graphic, " + "text and images on different targets.", font, XBrushes.Black, x, y); y += ls; gfx.DrawString("The object used for drawing is the XGraphics object.", font, XBrushes.Black, x, y); y += 2 * ls; // Draw an arc pen = new XPen(XColors.Red, 4); pen.DashStyle = XDashStyle.Dash; gfx.DrawArc(pen, x + 20, y, 100, 60, 150, 120); // Draw a star XGraphicsState gs = gfx.Save(); gfx.TranslateTransform(x + 140, y + 30); for (int idx = 0; idx < 360; idx += 10) { gfx.RotateTransform(10); gfx.DrawLine(XPens.DarkGreen, 0, 0, 30, 0); } gfx.Restore(gs); // Draw a rounded rectangle rect = new XRect(x + 230, y, 100, 60); pen = new XPen(XColors.DarkBlue, 2.5); XColor color1 = XColor.FromKnownColor(System.Drawing.KnownColor.DarkBlue); XColor color2 = XColors.Red; XLinearGradientBrush lbrush = new XLinearGradientBrush(rect, color1, color2, XLinearGradientMode.Vertical); gfx.DrawRoundedRectangle(pen, lbrush, rect, new XSize(10, 10)); // Draw a pie pen = new XPen(XColors.DarkOrange, 1.5); pen.DashStyle = XDashStyle.Dot; gfx.DrawPie(pen, XBrushes.Blue, x + 360, y, 100, 60, -130, 135); // Draw some more text y += 60 + 2 * ls; gfx.DrawString("With XGraphics you can draw on a PDF page as well as " + "on any System.Drawing.Graphics object.", font, XBrushes.Black, x, y); y += ls * 1.1; gfx.DrawString("Use the same code to", font, XBrushes.Black, x, y); x += 10; y += ls * 1.1; gfx.DrawString("• draw on a newly created PDF page", font, XBrushes.Black, x, y); y += ls; gfx.DrawString("• draw above or beneath of the content of an existing PDF page", font, XBrushes.Black, x, y); y += ls; gfx.DrawString("• draw in a window", font, XBrushes.Black, x, y); y += ls; gfx.DrawString("• draw on a printer", font, XBrushes.Black, x, y); y += ls; gfx.DrawString("• draw in a bitmap image", font, XBrushes.Black, x, y); x -= 10; y += ls * 1.1; gfx.DrawString("You can also import an existing PDF page and use it like " + "an image, e.g. draw it on another PDF page.", font, XBrushes.Black, x, y); y += ls * 1.1 * 2; gfx.DrawString("Imported PDF pages are neither drawn nor printed; create a " + "PDF file to see or print them!", fontItalic, XBrushes.Firebrick, x, y); y += ls * 1.1; gfx.DrawString("Below this text is a PDF form that will be visible when " + "viewed or printed with a PDF viewer.", fontItalic, XBrushes.Firebrick, x, y); y += ls * 1.1; XGraphicsState state = gfx.Save(); XRect rcImage = new XRect(100, y, 100, 100 * System.Math.Sqrt(2)); gfx.DrawRectangle(XBrushes.Snow, rcImage); gfx.DrawImage(XPdfForm.FromFile("../../../../../PDFs/SomeLayout.pdf"), rcImage); gfx.Restore(state); }
private static void PrepareInvoiceTop(XGraphics formGfx, XGraphicsState state, string InvoiceNumber) { string Headline = "Service Invoice " + InvoiceNumber + ""; string MyName = TimeConnector.Data.Variables.SelectedContractor["CmpName"]; string Phone = TimeConnector.Data.Variables.SelectedContractorContact["ConPhone"]; string MyPhone = "Phone (" + Phone.Substring(0, 3) + ") " + Phone.Substring(4, 3) + "-" + Phone.Substring(7, 4) + ""; string MyEmail = "Email: " + TimeConnector.Data.Variables.SelectedContractorContact["ConEmail"] + ""; string MyAddress = TimeConnector.Data.Variables.SelectedContractor["CmpAddress"]; string MyCityStateZip = "" + TimeConnector.Data.Variables.SelectedContractor["CmpCity"] + ", " + TimeConnector.Data.Variables.SelectedContractor["CmpState"] + " " + TimeConnector.Data.Variables.SelectedContractor["CmpZip"] + ""; string WeekEnding = TimeConnector.Data.Variables.SelectedPaydate["WeekEnd"]; string PayDate = TimeConnector.Data.Variables.SelectedPaydate["PayDate"]; string CompanyName = TimeConnector.Data.Variables.SelectedCompany["CmpName"]; string CompanyContact = "c/o " + TimeConnector.Data.Variables.SelectedContact["ConName"] + ""; string CompanyContactPhone = "" + TimeConnector.Data.Variables.SelectedContact["ConPhone"] + ""; string CompanyContactEmail = "" + TimeConnector.Data.Variables.SelectedContact["ConEmail"] + ""; string CompanyAddress = TimeConnector.Data.Variables.SelectedCompany["CmpAddress"]; string CompanyCityStateZip = "" + TimeConnector.Data.Variables.SelectedCompany["CmpCity"] + ", " + TimeConnector.Data.Variables.SelectedCompany["CmpState"] + " " + TimeConnector.Data.Variables.SelectedCompany["CmpZip"] + ""; //----- Invoice Header XFont HeaderFont = new XFont("Imprint MT Shadow", 30, XFontStyle.Bold); string HeaderText = "I N V O I C E"; XStringFormat format = new XStringFormat(); format.Alignment = XStringAlignment.Near; format.LineAlignment = XLineAlignment.Near; XColor color = default(XColor); color = XColor.FromName("SteelBlue"); color.A = 0.5; XBrush brush = default(XBrush); brush = new XSolidBrush(color); XPoint point = new XPoint(410, 20); formGfx.DrawString(HeaderText, HeaderFont, brush, point, format); //..... My Company Icon state = formGfx.Save(); formGfx.DrawImage(XImage.FromFile("Images\\logo.png"), 20, 20, 65, 65); formGfx.Restore(state); //..... My Company Information DrawText(MyName, formGfx, new XFont(PdfFontMyInfo, 15, XFontStyle.Bold), XBrushes.SteelBlue, 95, 20); DrawText(MyAddress, formGfx, new XFont(PdfFontMyInfo, 7, XFontStyle.Regular), XBrushes.Black, 95, 45); DrawText(MyCityStateZip, formGfx, new XFont(PdfFontMyInfo, 7, XFontStyle.Regular), XBrushes.Black, 95, 55); DrawText(MyPhone, formGfx, new XFont(PdfFontMyInfo, 7, XFontStyle.Regular), XBrushes.Black, 95, 65); DrawText(MyEmail, formGfx, new XFont(PdfFontMyInfo, 7, XFontStyle.Regular), XBrushes.Black, 95, 75); XPen pen1 = new XPen(XColors.Maroon); pen1.Width = 1; //Dim pen2 As New XPen(XColors.Maroon) XPen pen2 = new XPen(XColors.SteelBlue); pen2.Width = 2; //Dim pen3 As New XPen(XColors.SteelBlue) XPen pen3 = new XPen(XColors.Maroon); pen3.Width = 1; formGfx.DrawBeziers(pen1, XPoint.ParsePoints("20,95 80,140 190,70 250,110")); DrawSignature(formGfx, 531, 696, "LightGray", 1); DrawSignature(formGfx, 530, 695, "Black", 1.5); DrawSignature(formGfx, 530, 695, "SteelBlue", 1); //formGfx.DrawBeziers(pen2, XPoint.ParsePoints("300,100 310,110 340,90 350,100")) 'Top //formGfx.DrawBeziers(pen2, XPoint.ParsePoints("312,108 322,118 332,99 342,110")) 'Top Center //formGfx.DrawBeziers(pen2, XPoint.ParsePoints("314,118 324,128 334,109 344,120")) 'Bottom Center //formGfx.DrawBeziers(pen2, XPoint.ParsePoints("310,130 315,140 330,120 335,130")) 'Bottom //formGfx.DrawBeziers(pen2, XPoint.ParsePoints("325,100 335,110 325,120 335,130")) 'Center //formGfx.DrawBeziers(pen3, XPoint.ParsePoints("300,100 310,110 340,90 350,100")) 'Top //formGfx.DrawBeziers(pen3, XPoint.ParsePoints("312,108 322,118 332,99 342,110")) 'Top Center //formGfx.DrawBeziers(pen3, XPoint.ParsePoints("314,118 324,128 334,109 344,120")) 'Bottom Center //formGfx.DrawBeziers(pen3, XPoint.ParsePoints("310,130 315,140 330,120 335,130")) 'Bottom //formGfx.DrawBeziers(pen3, XPoint.ParsePoints("325,100 335,110 325,120 335,130")) 'Center //..... ACS Company Icon DrawText("B I L L T O :", formGfx, new XFont(PdfFont, 9, XFontStyle.Bold), XBrushes.Black, 60, 95); state = formGfx.Save(); formGfx.DrawImage(XImage.FromFile("Images\\ACSIcon.jpg"), 20, 115, 65, 65); formGfx.Restore(state); //..... ACS Company Information DrawText(CompanyName, formGfx, new XFont(PdfFontMyInfo, 15, XFontStyle.Bold), XBrushes.Green, 95, 115); DrawText(CompanyContact, formGfx, new XFont(PdfFontMyInfo, 7, XFontStyle.Regular), XBrushes.Black, 95, 135); DrawText(CompanyAddress, formGfx, new XFont(PdfFontMyInfo, 7, XFontStyle.Regular), XBrushes.Black, 95, 145); DrawText(CompanyCityStateZip, formGfx, new XFont(PdfFontMyInfo, 7, XFontStyle.Regular), XBrushes.Black, 95, 155); DrawText(CompanyContactPhone, formGfx, new XFont(PdfFontMyInfo, 7, XFontStyle.Regular), XBrushes.Black, 95, 165); DrawText(CompanyContactEmail, formGfx, new XFont(PdfFontMyInfo, 7, XFontStyle.Regular), XBrushes.Black, 95, 175); //..... Invoice Information DrawLine(formGfx, 450, 590, 80, "SteelBlue", 0.5); DrawText("Invoice #:", formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Black, 452, 71); DrawText(InvoiceNumber, formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Maroon, 530, 71); DrawLine(formGfx, 450, 590, 90, "SteelBlue", 0.5); DrawText("Week Ending:", formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Black, 452, 81); DrawText(WeekEnding, formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Black, 530, 81); DrawLine(formGfx, 450, 590, 100, "SteelBlue", 0.5); DrawText("Pay Date:", formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Black, 452, 91); DrawText(PayDate, formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Black, 530, 91); DrawLine(formGfx, 450, 590, 110, "SteelBlue", 0.5); DrawText("Hours Worked:", formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Black, 452, 101); DrawText(TimeConnector.Data.Invoice.FinHour, formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Black, 530, 101); DrawLine(formGfx, 450, 590, 120, "SteelBlue", 0.5); DrawText("Balance Due:", formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Black, 452, 111); DrawText(TimeConnector.Data.Invoice.FinCost, formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Black, 530, 111); }
/// <summary> /// Draw a multi-line string as it would be drawn by GDI+. /// Compensates for issues and draw-vs-PDF differences in PDFsharp. /// </summary> /// <param name="graphics">The graphics with which to draw.</param> /// <param name="text">The text to draw, which may contain line breaks.</param> /// <param name="font">The font with which to draw.</param> /// <param name="brush">The brush with which to draw.</param> /// <param name="pos">The position at which to draw.</param> /// <param name="size">The size to which to limit the drawn text; or Vector.Zero for no limit.</param> /// <param name="format">The string format to use.</param> /// <remarks> /// PDFsharp cannot currently render multi-line text to PDF files; it comes out as single line. /// This method simulates standard Graphics.DrawString() over PDFsharp. /// It always has the effect of StringFormatFlags.LineLimit (which PDFsharp does not support). /// </remarks> public void Draw(XGraphics graphics, Font font, Brush brush, Vector pos, Vector size, XStringFormat format) { // do a quick test to see if text is going to get drawn at the same size as last time; // if so, assume we don't need to recompute our layout for that reason. var sizeChecker = graphics.MeasureString("M q", font); if (sizeChecker != m_sizeChecker || pos != m_pos || m_size != size || m_requestedFormat.Alignment != format.Alignment || m_requestedFormat.LineAlignment != format.LineAlignment || m_requestedFormat.FormatFlags != format.FormatFlags) { m_invalidLayout = true; } m_sizeChecker = sizeChecker; if (m_invalidLayout) { // something vital has changed; rebuild our cached layout data RebuildCachedLayout(graphics, font, ref pos, ref size, format); m_invalidLayout = false; } var state = graphics.Save(); if (size != Vector.Zero) { graphics.IntersectClip(new RectangleF(pos.X, pos.Y, size.X, size.Y)); } // disable smoothing whilst rendering text; // visually this is no different, but is faster var smoothingMode = graphics.SmoothingMode; graphics.SmoothingMode = XSmoothingMode.HighSpeed; var origin = m_origin; for (var index=0; index<m_lines.Count; ++index) { if (size.Y > 0 && size.Y < m_lineHeight) break; // not enough remaining vertical space for a whole line var line = m_lines[index]; graphics.DrawString(line, font, brush, origin.X, origin.Y, m_actualFormat); origin += m_delta; size.Y -= m_lineHeight; } graphics.SmoothingMode = smoothingMode; graphics.Restore(state); }
public override void Draw(XGraphics graphics, Palette palette, DrawingContext context) { Random random = new Random(Name.GetHashCode()); var topLeft = InnerBounds.GetCorner(CompassPoint.NorthWest); var topRight = InnerBounds.GetCorner(CompassPoint.NorthEast); var bottomLeft = InnerBounds.GetCorner(CompassPoint.SouthWest); var bottomRight = InnerBounds.GetCorner(CompassPoint.SouthEast); var topCenter = InnerBounds.GetCorner(CompassPoint.North); var rightCenter = InnerBounds.GetCorner(CompassPoint.East); var bottomCenter = InnerBounds.GetCorner(CompassPoint.South); var leftCenter = InnerBounds.GetCorner(CompassPoint.West); var top = new LineSegment(topLeft, topRight); var right = new LineSegment(topRight, bottomRight); var bottom = new LineSegment(bottomRight, bottomLeft); var left = new LineSegment(bottomLeft, topLeft); var halfTopRight = new LineSegment(topCenter, topRight); var halfBottomRight = new LineSegment(bottomRight, bottomCenter); var centerVertical = new LineSegment(bottomCenter, topCenter); var centerHorizontal = new LineSegment(leftCenter, rightCenter); var halfRightBottom = new LineSegment(rightCenter, bottomRight); var halfLeftBottom = new LineSegment(bottomLeft, leftCenter); var slantUp = new LineSegment(bottomLeft, topRight); var slantDown = new LineSegment(bottomRight, topLeft); context.LinesDrawn.Add(top); context.LinesDrawn.Add(right); context.LinesDrawn.Add(bottom); context.LinesDrawn.Add(left); var brush = context.Selected ? palette.BorderBrush : palette.FillBrush; // Room specific fill brush (White shows global color) if (RoomFill != ColorTranslator.FromHtml("White") && RoomFill != ColorTranslator.FromHtml("#FFFFFF")) { brush = new SolidBrush(RoomFill); } if (!Settings.DebugDisableLineRendering) { var path = palette.Path(); Drawing.AddLine(path, top, random); Drawing.AddLine(path, right, random); Drawing.AddLine(path, bottom, random); Drawing.AddLine(path, left, random); graphics.DrawPath(brush, path); // Second fill for room specific colors with a split option if (SecondFill != ColorTranslator.FromHtml("White") && SecondFill != ColorTranslator.FromHtml("#FFFFFF")) { // Set the second fill color brush = new SolidBrush(SecondFill); // Define the second path based on the second fill location var secondPath = palette.Path(); switch (SecondFillLocation) { case "Bottom": Drawing.AddLine(secondPath, centerHorizontal, random); Drawing.AddLine(secondPath, halfRightBottom, random); Drawing.AddLine(secondPath, bottom, random); Drawing.AddLine(secondPath, halfLeftBottom, random); break; case "BottomRight": Drawing.AddLine(secondPath, slantUp, random); Drawing.AddLine(secondPath, right, random); Drawing.AddLine(secondPath, bottom, random); break; case "Right": Drawing.AddLine(secondPath, halfTopRight, random); Drawing.AddLine(secondPath, right, random); Drawing.AddLine(secondPath, halfBottomRight, random); Drawing.AddLine(secondPath, centerVertical, random); break; case "TopRight": Drawing.AddLine(secondPath, top, random); Drawing.AddLine(secondPath, right, random); Drawing.AddLine(secondPath, slantDown, random); break; default: break; } // Draw the second fill over the first graphics.DrawPath(brush, secondPath); } if (IsDark) { var state = graphics.Save(); graphics.IntersectClip(path); brush = context.Selected ? palette.FillBrush : palette.BorderBrush; // Room specific fill brush (White shows global color) if (RoomBorder != ColorTranslator.FromHtml("White") && RoomBorder != ColorTranslator.FromHtml("#FFFFFF")) { brush = new SolidBrush(RoomBorder); } graphics.DrawPolygon(brush, new PointF[] { topRight.ToPointF(), new PointF(topRight.X - Settings.DarknessStripeSize, topRight.Y), new PointF(topRight.X, topRight.Y + Settings.DarknessStripeSize) }, XFillMode.Alternate); graphics.Restore(state); } if (RoomBorder == ColorTranslator.FromHtml("White") || RoomBorder == ColorTranslator.FromHtml("#FFFFFF")) { graphics.DrawPath(palette.BorderPen, path); } else { var RoomBorderPen = new Pen(RoomBorder, Settings.LineWidth); RoomBorderPen.StartCap = LineCap.Round; RoomBorderPen.EndCap = LineCap.Round; graphics.DrawPath(RoomBorderPen, path); } } var font = Settings.LargeFont; brush = context.Selected ? palette.FillBrush : palette.LargeTextBrush; // Room specific fill brush (White shows global color) if (RoomLargeText != ColorTranslator.FromHtml("White") && RoomLargeText != ColorTranslator.FromHtml("#FFFFFF")) { brush = new SolidBrush(RoomLargeText); } Rect textBounds = InnerBounds; textBounds.Inflate(-5, -5); if (textBounds.Width > 0 && textBounds.Height > 0) { m_name.Draw(graphics, font, brush, textBounds.Position, textBounds.Size, XStringFormats.Center); } var expandedBounds = InnerBounds; expandedBounds.Inflate(Settings.ObjectListOffsetFromRoom, Settings.ObjectListOffsetFromRoom); var drawnObjectList = false; font = Settings.SmallFont; brush = palette.SmallTextBrush; // Room specific fill brush (White shows global color) if (RoomSmallText != ColorTranslator.FromHtml("White") && RoomSmallText != ColorTranslator.FromHtml("#FFFFFF")) { brush = new SolidBrush(RoomSmallText); } if (!string.IsNullOrEmpty(Objects)) { XStringFormat format = new XStringFormat(); Vector pos = expandedBounds.GetCorner(m_objectsPosition); if (!Drawing.SetAlignmentFromCardinalOrOrdinalDirection(format, m_objectsPosition)) { // object list appears inside the room below its name format.LineAlignment = XLineAlignment.Far; format.Alignment = XStringAlignment.Near; //format.Trimming = StringTrimming.EllipsisCharacter; //format.FormatFlags = StringFormatFlags.LineLimit; var height = InnerBounds.Height / 2 - font.Height / 2; var bounds = new Rect(InnerBounds.Left + Settings.ObjectListOffsetFromRoom, InnerBounds.Bottom - height, InnerBounds.Width - Settings.ObjectListOffsetFromRoom, height - Settings.ObjectListOffsetFromRoom); brush = context.Selected ? palette.FillBrush : brush; if (bounds.Width > 0 && bounds.Height > 0) { m_objects.Draw(graphics, font, brush, bounds.Position, bounds.Size, format); } drawnObjectList = true; } else if (m_objectsPosition == CompassPoint.North || m_objectsPosition == CompassPoint.South) { pos.X += Settings.ObjectListOffsetFromRoom; } if (!drawnObjectList) { m_objects.Draw(graphics, font, brush, pos, Vector.Zero, format); } } }
public static void BeginBox(XGraphics gfx, int number, string title, double borderWidth, double borderHeight, XColor shadowColor, XColor backColor, XColor backColor2, XPen borderPen) { const int dEllipse = 15; XRect rect = new XRect(0, 20, 300, 200); if (number % 2 == 0) rect.X = 300 - 5; rect.Y = 40 + ((number - 1) / 2) * (200 - 5); rect.Inflate(-10, -10); XRect rect2 = rect; rect2.Offset(borderWidth, borderHeight); gfx.DrawRoundedRectangle(new XSolidBrush(shadowColor), rect2, new XSize(dEllipse + 8, dEllipse + 8)); XLinearGradientBrush brush = new XLinearGradientBrush(rect, backColor, backColor2, XLinearGradientMode.Vertical); gfx.DrawRoundedRectangle(borderPen, brush, rect, new XSize(dEllipse, dEllipse)); rect.Inflate(-5, -5); XFont font = new XFont("Verdana", 12, XFontStyle.Regular); gfx.DrawString(title, font, XBrushes.Navy, rect, XStringFormats.TopCenter); rect.Inflate(-10, -5); rect.Y += 20; rect.Height -= 20; state = gfx.Save(); gfx.TranslateTransform(rect.X, rect.Y); }