public DrawPolygon ( XBrush brush, PointF points, XFillMode fillmode ) : void | ||
brush | XBrush | |
points | PointF | |
fillmode | XFillMode | |
return | void |
void RenderPolygons(XGraphics gfx) { gfx.TranslateTransform(15, 20); XPen pen = new XPen(XColors.DarkBlue, 2.5); gfx.DrawPolygon(pen, XBrushes.LightCoral, GeometryObjects.GetPentagram(50, new XPoint(60, 70)), XFillMode.Winding); gfx.DrawPolygon(pen, XBrushes.LightCoral, GeometryObjects.GetPentagram(50, new XPoint(180, 70)), XFillMode.Alternate); }
/// <summary> /// Demonstrates the use of XGraphics.Transform. /// </summary> public override void RenderPage(XGraphics gfx) { //gfx.Clear(this.properties.General.BackColor.Color); base.RenderPage(gfx); 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))); }
/// <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))); }
/// <summary> /// Demonstrates the use of XGraphics.DrawPolygon. /// </summary> public override void RenderPage(XGraphics gfx) { base.RenderPage(gfx); gfx.DrawPolygon(properties.Pen2.Pen, GetPentagram(75, new PointF(150, 200))); gfx.DrawPolygon(properties.Brush2.Brush, GetPentagram(75, new PointF(150, 400)), XFillMode.Alternate); gfx.DrawPolygon(properties.Brush2.Brush, GetPentagram(75, new PointF(350, 400)), XFillMode.Winding); gfx.DrawPolygon(properties.Pen2.Pen, properties.Brush2.Brush, GetPentagram(75, new PointF(150, 600)), XFillMode.Alternate); gfx.DrawPolygon(properties.Pen2.Pen, properties.Brush2.Brush, GetPentagram(75, new PointF(350, 600)), XFillMode.Winding); }
/// <summary> /// Demonstrates the use of XGraphics.DrawRoundedRectangle. /// </summary> public override void RenderPage(XGraphics gfx) { base.RenderPage(gfx); // Stroke ellipse gfx.DrawEllipse(properties.Pen1.Pen, 50, 100, 450, 150); // Fill ellipse gfx.DrawEllipse(properties.Brush2.Brush, new Rectangle(50, 300, 450, 150)); // Stroke and fill ellipse gfx.DrawEllipse(properties.Pen2.Pen, properties.Brush2.Brush, new RectangleF(50, 500, 450, 150)); // Stroke circle gfx.DrawEllipse(properties.Pen2.Pen, new XRect(100, 200, 400, 400)); #if DEBUG int count = 360; XPoint[] circle = new XPoint[count]; for (int idx = 0; idx < count; idx++) { double rad = idx * 2 * Math.PI / count; circle[idx].X = Math.Cos(rad) * 200 + 300; circle[idx].Y = Math.Sin(rad) * 200 + 400; } gfx.DrawPolygon(properties.Pen3.Pen, circle); #endif }
void DrawFigures(XGraphics gfx, double W, double H) { /* COWARD'S TRIANGLE */ XPen pen = new XPen(XColors.Black, 1); pen.LineJoin = XLineJoin.Round; XFont T10R = new XFont("Times New Roman", 10, XFontStyle.Regular); XTextFormatter tf = new XTextFormatter(gfx); tf.Alignment = XParagraphAlignment.Center; //Triangles XPoint[] polygon = new XPoint[] { new XPoint(84, 550), new XPoint(84, 685), new XPoint(284, 685) }; gfx.DrawPolygon(pen, XBrushes.Green, polygon, XFillMode.Alternate); polygon = new XPoint[] { new XPoint(Hx, Hy), new XPoint(Nx, Ny), new XPoint(Fx, Fy), new XPoint(284, 685) }; gfx.DrawPolygon(pen, XBrushes.Yellow, polygon, XFillMode.Alternate); polygon = new XPoint[] { new XPoint(84, 550), new XPoint(Nx, Ny), new XPoint(Lx, Ly) }; gfx.DrawPolygon(pen, XBrushes.DarkOrange, polygon, XFillMode.Alternate); polygon = new XPoint[] { new XPoint(Hx, Hy), new XPoint(Nx, Ny), new XPoint(Lx, Ly) }; gfx.DrawPolygon(pen, XBrushes.Red, polygon, XFillMode.Alternate); //Point gfx.DrawEllipse(pen, XBrushes.White, Cx, Cy, 6, 6); //Texts XRect rect = new XRect(72, 550, 10, 10); tf.DrawString("21", T10R, XBrushes.Red, rect); rect = new XRect(72, 687, 10, 10); tf.DrawString("0", T10R, XBrushes.Red, rect); rect = new XRect(150, 687, 50, 10); tf.DrawString("Methane %", T10R, XBrushes.Red, rect); rect = new XRect(270, 687, 15, 10); tf.DrawString("100", T10R, XBrushes.Red, rect); /* ELLICOTT DIAGRAM */ rect = new XRect(297, 550, 112, 75); gfx.DrawRectangle(XPens.Black, XBrushes.DarkOrange, rect); rect = new XRect(409, 550, 112, 75); gfx.DrawRectangle(XPens.Black, XBrushes.Red, rect); rect = new XRect(297, 625, 112, 75); gfx.DrawRectangle(XPens.Black, XBrushes.Green, rect); rect = new XRect(409, 625, 112, 75); gfx.DrawRectangle(XPens.Black, XBrushes.Yellow, rect); //Arrows & Texts pen.LineCap = XLineCap.Round; gfx.DrawLine(pen, 409, 625, 381, 606); gfx.DrawLine(pen, 382, 610, 381, 606); gfx.DrawLine(pen, 385, 606, 381, 606); gfx.DrawString("Lean", T10R, XBrushes.Black, 372, 600); gfx.DrawLine(pen, 409, 625, 437, 644); gfx.DrawLine(pen, 436, 640, 437, 644); gfx.DrawLine(pen, 433, 644, 437, 644); gfx.DrawString("Rich", T10R, XBrushes.Black, 430, 655); gfx.DrawLine(pen, 409, 625, 381, 644); gfx.DrawLine(pen, 382, 640, 381, 644); gfx.DrawLine(pen, 385, 644, 381, 644); gfx.DrawString("Inert", T10R, XBrushes.Black, 372, 655); //Point }
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); }
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); }
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); } } }
public void DrawPentagon(XGraphics gfx) { //set up the background grey XRect backgroundRect = new XRect(20, page_.Height * 0.11, page_.Width - 40, page_.Height * 0.425); DrawingUtil.DrawOutlineRect(backgroundRect, gfx, cornerRadius); gfx.DrawRoundedRectangle(backgroundBrush, backgroundRect, cornerRadius); XPoint center = new XPoint(page_.Width * 0.5, backgroundRect.Y + backgroundRect.Height * 0.6); XPoint[] polyPoints = DrawingUtil.Instance.GeneratePoints(center, 130, 5, gfx); gfx.DrawPolygon(backgroundBrush, polyPoints, XFillMode.Winding); XPen yellowPen = new XPen(XColors.Yellow, 2.5); XPen greenPen = new XPen(XColors.Green, 2.5); XPen perimeterPen = XPens.LightGray; XPen redPen = new XPen(XColors.Red, 2.5); //center out foreach(XPoint p in polyPoints) gfx.DrawLine(greenPen, center, p); XBrush brush = XBrushes.Black; XSize size = new XSize(50, 50); XSize ellipseSize = new XSize(10, 10); //images XImage leftKneeImg = XImage.FromFile(Directory.GetCurrentDirectory() + @"\Content\LKS.png"); XImage rightKneeImg = XImage.FromFile(Directory.GetCurrentDirectory() + @"\Content\RKS.png"); XImage tibia_spineImg = XImage.FromFile(Directory.GetCurrentDirectory() + @"\Content\STA.png"); XImage dosImg = XImage.FromFile(Directory.GetCurrentDirectory() + @"\Content\DOS.png"); XImage pelvicImg = XImage.FromFile(Directory.GetCurrentDirectory() + @"\Content\PS.png"); //infoboxes DrawPentaInfoBox(gfx, polyPoints[0] + new XPoint(-50, -70), tibia_spineImg, userParameters_[dataReadStart + 1]); DrawPentaInfoBox(gfx, polyPoints[1] + new XPoint(25, -35), rightKneeImg, userParameters_[dataReadStart + 8]); DrawPentaInfoBox(gfx, polyPoints[2] + new XPoint(25, -60), pelvicImg, userParameters_[dataReadStart + 2]); DrawPentaInfoBox(gfx, polyPoints[3] + new XPoint(-125, -60), dosImg, userParameters_[dataReadStart + 0]); DrawPentaInfoBox(gfx, polyPoints[4] + new XPoint(-120,-35), leftKneeImg, userParameters_[dataReadStart + 3]); //percentage Lines gfx.DrawString(0 + "%", new XFont("Arial", 10), XBrushes.Black, center + new XPoint(5, 0)); for (int j = 0; j < polyPoints.Length - 1; j++) { XPoint pt1 = polyPoints[j]; XPoint pt2 = polyPoints[j + 1]; for (int i = 10; i > 0; i--) { float increment = -i * 0.1f; if (j < 1) gfx.DrawString((i * 10).ToString() + '%', new XFont("Arial", 8), XBrushes.Black, DrawingUtil.Instance.Interpolate(center, polyPoints[0], increment) + new XPoint(5, 0)); gfx.DrawLine(perimeterPen, DrawingUtil.Instance.Interpolate(center, pt1, increment), DrawingUtil.Instance.Interpolate(center, pt2, increment)); } } XPoint centerTibia = DrawingUtil.Instance.Interpolate(center, polyPoints[0], -userParameters_[dataReadStart + 1].Percentage); XPoint centerRightKnee = DrawingUtil.Instance.Interpolate(center, polyPoints[1], -userParameters_[dataReadStart + 8].Percentage); XPoint centerPelvicStability = DrawingUtil.Instance.Interpolate(center, polyPoints[2], -userParameters_[dataReadStart + 2].Percentage); XPoint centerDos = DrawingUtil.Instance.Interpolate(center, polyPoints[3], -userParameters_[dataReadStart + 0].Percentage); XPoint centerLeftKnee = DrawingUtil.Instance.Interpolate(center, polyPoints[4], -userParameters_[dataReadStart + 3].Percentage); gfx.DrawLine(redPen, center, DrawingUtil.Instance.Interpolate(center, polyPoints[0], -userParameters_[dataReadStart + 1].RedVal)); gfx.DrawLine(redPen, center, DrawingUtil.Instance.Interpolate(center, polyPoints[1], -userParameters_[dataReadStart + 8].RedVal)); gfx.DrawLine(redPen, center, DrawingUtil.Instance.Interpolate(center, polyPoints[2], -userParameters_[dataReadStart + 2].RedVal)); gfx.DrawLine(redPen, center, DrawingUtil.Instance.Interpolate(center, polyPoints[3], -userParameters_[dataReadStart + 0].RedVal)); gfx.DrawLine(redPen, center, DrawingUtil.Instance.Interpolate(center, polyPoints[4], -userParameters_[dataReadStart + 3].RedVal)); gfx.DrawPolygon(new XPen(XColor.FromArgb(1, 0, 255, 255)), new XSolidBrush(XColor.FromArgb(40,255,255,0)), new XPoint[] { centerTibia, centerRightKnee, centerPelvicStability, centerDos, centerLeftKnee }, XFillMode.Alternate); gfx.DrawLines(new XPen(XColors.Orange, 1), new XPoint[] { centerTibia, centerRightKnee, centerPelvicStability, centerDos, centerLeftKnee, centerTibia }); }
/// <summary> /// Draws polygons. /// </summary> void DrawPolygon(XGraphics gfx, int number) { BeginBox(gfx, number, "DrawPolygon"); XPen pen = new XPen(XColors.DarkBlue, 2.5); gfx.DrawPolygon(pen, XBrushes.LightCoral, GetPentagram(50, new XPoint(60, 70)), XFillMode.Winding); gfx.DrawPolygon(pen, XBrushes.LightCoral, GetPentagram(50, new XPoint(180, 70)), XFillMode.Alternate); EndBox(gfx); }
/// <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 }
public void DrawPentagon(XGraphics gfx) { XRect backgroundRect = new XRect(20, page.Height * 0.15, page.Width - 40, page.Height * 0.425); gfx.DrawRoundedRectangle(new XSolidBrush(XColor.FromKnownColor(XKnownColor.Gray)), backgroundRect, new XSize(40, 40)); double c1 = Math.Cos((2 * Math.PI) / 5); double c2 = Math.Cos(Math.PI / 5); double s1 = Math.Sin((2 * Math.PI) / 5); double s2 = Math.Sin((4 * Math.PI) / 5); XPoint[] pentatPoints = new XPoint[5]; XPoint center = new XPoint(page.Width * 0.5, page.Height * 0.425); XPoint top = new XPoint(page.Width * 0.5, page.Height * 0.25); double lengthOfLine = Distance(top, center); XPoint bottomLeft = new XPoint(center.X + (lengthOfLine * -s2), center.Y - (lengthOfLine * -c2)); XPoint bottomRight = new XPoint(center.X + (lengthOfLine * s2), center.Y - (lengthOfLine * -c2)); XPoint topLeft = new XPoint(center.X + (lengthOfLine * -s1), center.Y - (lengthOfLine * c1)); XPoint topRight = new XPoint(center.X + (lengthOfLine * s1), center.Y - (lengthOfLine * c1)); pentatPoints[0] = top; pentatPoints[1] = topRight; pentatPoints[2] = bottomRight; pentatPoints[3] = bottomLeft; pentatPoints[4] = topLeft; gfx.DrawPolygon(XBrushes.DimGray, pentatPoints, XFillMode.Winding); XPen yellowPen = new XPen(XColors.Yellow, 2.5); XPen greenPen = new XPen(XColors.Green, 2.5); XPen perimeterPen = XPens.LightGray; XPen redPen = new XPen(XColors.Red, 2.5); //center out gfx.DrawLine(greenPen, center, top); gfx.DrawLine(greenPen, center, bottomLeft); gfx.DrawLine(greenPen, center, bottomRight); gfx.DrawLine(greenPen, center, topLeft); gfx.DrawLine(greenPen, center, topRight); XBrush brush = XBrushes.Black; XSize size = new XSize(50, 50); XSize ellipseSize = new XSize(10, 10); //images XImage leftKneeImg = XImage.FromFile(@"C:\Users\kevin\Desktop\PDFsharp\samples\Samples C#\Based on WPF\HelloWorld\Content\Left Knee Stability.png"); XImage rightKneeImg = XImage.FromFile(@"C:\Users\kevin\Desktop\PDFsharp\samples\Samples C#\Based on WPF\HelloWorld\Content\Right Knee Stability.png"); XImage tibia_spineImg = XImage.FromFile(@"C:\Users\kevin\Desktop\PDFsharp\samples\Samples C#\Based on WPF\HelloWorld\Content\Tibia Spine Angle.png"); XImage dosImg = XImage.FromFile(@"C:\Users\kevin\Desktop\PDFsharp\samples\Samples C#\Based on WPF\HelloWorld\Content\Depth of Squat.png"); XImage pelvicImg = XImage.FromFile(@"C:\Users\kevin\Desktop\PDFsharp\samples\Samples C#\Based on WPF\HelloWorld\Content\Pelvic Stability.png"); //infoboxes DrawPentaInfoBox(gfx, top + new XPoint(-50, -75), tibia_spineImg, userParameters["Tibia / Spine Angle"]); DrawPentaInfoBox(gfx, topLeft + new XPoint(-100,-35), leftKneeImg, userParameters["LEFT Knee Stability"]); DrawPentaInfoBox(gfx, topRight + new XPoint(25, -35), rightKneeImg, userParameters["RIGHT Knee Stability"]); DrawPentaInfoBox(gfx, bottomRight + new XPoint(25, -60), pelvicImg, userParameters["Pelvic Stability"]); DrawPentaInfoBox(gfx, bottomLeft + new XPoint(-125, -60), dosImg, userParameters["Depth of Squat"]); //percentage Lines gfx.DrawString(0 + "%", new XFont("Arial", 10), XBrushes.Black, center + new XPoint(5,0)); for (int i = 10; i > 0; i--) { float increment = -i * 0.1f; gfx.DrawString((i * 10).ToString() + "%", new XFont("Arial", 8), XBrushes.Black, Interpolate(center, top, increment) + new XPoint(5,0)); gfx.DrawLine(perimeterPen, Interpolate(center,topLeft, increment), Interpolate(center, top, increment)); gfx.DrawLine(perimeterPen, Interpolate(center, top, increment), Interpolate(center, topRight, increment)); gfx.DrawLine(perimeterPen, Interpolate(center, topRight, increment), Interpolate(center, bottomRight, increment)); gfx.DrawLine(perimeterPen, Interpolate(center, bottomRight, increment), Interpolate(center, bottomLeft, increment)); gfx.DrawLine(perimeterPen, Interpolate(center, bottomLeft, increment), Interpolate(center, topLeft, increment)); } XPoint centerTibia = Interpolate(center, top, -userParameters["Tibia / Spine Angle"].Percentage); XPoint centerRightKnee = Interpolate(center, topRight, -userParameters["RIGHT Knee Stability"].Percentage); XPoint centerPelvicStability = Interpolate(center, bottomRight, -userParameters["Pelvic Stability"].Percentage); XPoint centerDos = Interpolate(center, bottomLeft, -userParameters["Depth of Squat"].Percentage); XPoint centerLeftKnee = Interpolate(center, topLeft, -userParameters["LEFT Knee Stability"].Percentage); gfx.DrawLine(redPen, center, Interpolate(center, top, -userParameters["Tibia / Spine Angle"].RedVal)); gfx.DrawLine(redPen, center, Interpolate(center, topRight, -userParameters["RIGHT Knee Stability"].RedVal)); gfx.DrawLine(redPen, center, Interpolate(center, bottomRight, -userParameters["Pelvic Stability"].RedVal)); gfx.DrawLine(redPen, center, Interpolate(center, bottomLeft, -userParameters["Depth of Squat"].RedVal)); gfx.DrawLine(redPen, center, Interpolate(center, topLeft, -userParameters["LEFT Knee Stability"].RedVal)); gfx.DrawPolygon(new XPen(XColor.FromArgb(1, 0, 255, 255)), new XSolidBrush(XColor.FromArgb(127,255,255,0)), new XPoint[] { centerTibia, centerRightKnee, centerPelvicStability, centerDos, centerLeftKnee }, XFillMode.Alternate); }
public void DrawGraph(XGraphics gfx) { double yOff = page_.Height * 0.11; XRect rect = new XRect(20, yOff, page_.Width - 40, page_.Height - (yOff + 20)); DrawingUtil.DrawOutlineRect(rect, gfx, cornerRadius); gfx.DrawRoundedRectangle(backgroundBrush, rect, cornerRadius); XPoint center = new XPoint(page_.Width * 0.5, page_.Height * 0.45); //Left & right boxes XRect leftRect = new XRect(center.X - 250, yOff + 5, 160, 25); XRect rightRect = new XRect(center.X + 90, yOff + 5, 160, 25); DrawingUtil.DrawOutlineRect(leftRect, gfx, new XSize(10,10)); gfx.DrawRoundedRectangle(XBrushes.Yellow, leftRect, new XSize(10, 10)); DrawingUtil.DrawOutlineRect(rightRect, gfx, new XSize(10,10)); gfx.DrawRoundedRectangle(XBrushes.CornflowerBlue, rightRect, new XSize(10, 10)); gfx.DrawString("Left", new XFont("Arial", 20), XBrushes.Black, new XPoint(leftRect.X + 80, leftRect.Y + 15), XStringFormats.Center); gfx.DrawString("Right", new XFont("Arial", 20), XBrushes.Black, new XPoint(rightRect.X + 80, rightRect.Y + 15), XStringFormats.Center); float graphSize = (float)page_.Height * 0.175f; XPoint[] polyPoints = DrawingUtil.Instance.GeneratePoints(center, graphSize, 7, gfx); gfx.DrawPolygon(backgroundBrush, polyPoints, XFillMode.Winding); XPen yellowPen = new XPen(XColors.Yellow, 2.5); XPen greenPen = new XPen(XColors.Green, 2.5); XPen perimeterPen = XPens.LightGray; XPen redPen = new XPen(XColors.Red, 2.5); GraphIcon hipFlexImg = new GraphIcon(XImage.FromFile(Directory.GetCurrentDirectory() + @"\Content\HipFlex.png"),"Hip Flexion"); GraphIcon hamStringImg = new GraphIcon(XImage.FromFile(Directory.GetCurrentDirectory() + @"\Content\HSExt.png"), "Hamstring Extension"); GraphIcon hipAbdImg = new GraphIcon(XImage.FromFile(Directory.GetCurrentDirectory() + @"\Content\HipAbd.png"), "Hip Abduction"); GraphIcon hipIntImg = new GraphIcon(XImage.FromFile(Directory.GetCurrentDirectory() + @"\Content\HipInt.png"), "Hip Internal Rotation"); GraphIcon hipExtImg = new GraphIcon(XImage.FromFile(Directory.GetCurrentDirectory() + @"\Content\HipExt.png"), "Hip External Rotation"); GraphIcon kneeFlexImg = new GraphIcon(XImage.FromFile(Directory.GetCurrentDirectory() + @"\Content\KneeFlex.png"), "Knee Flexion"); GraphIcon AnkleFlexImg = new GraphIcon(XImage.FromFile(Directory.GetCurrentDirectory() + @"\Content\AnkleFlex.png"), "Ankle Flexion"); GraphIcon[] icons = new GraphIcon[] { hipFlexImg, hamStringImg, hipAbdImg, hipIntImg, hipExtImg, kneeFlexImg, AnkleFlexImg }; //center out for (int l = 0; l < polyPoints.Length - 1; l++) gfx.DrawLine(greenPen, center, polyPoints[l]); //percentage Lines & icons gfx.DrawString(0 + "%", new XFont("Arial", 10), XBrushes.Black, center + new XPoint(5, 0)); for (int j = 0; j < polyPoints.Length - 1; j++) { XPoint pt1 = polyPoints[j]; XPoint pt2 = polyPoints[j + 1]; for (int i = 10; i > 0; i--) { float increment = -i * 0.1f; if (j < 1) gfx.DrawString((i * 10).ToString() + '%', new XFont("Arial", 8), XBrushes.Black, DrawingUtil.Instance.Interpolate(center, polyPoints[0], increment) + new XPoint(5, 0)); gfx.DrawLine(perimeterPen, DrawingUtil.Instance.Interpolate(center, pt1, increment), DrawingUtil.Instance.Interpolate(center, pt2, increment)); } XVector vec = new XVector(pt1.X, pt1.Y); XVector vec2 = new XVector(center.X, center.Y); XImage img = icons[j].img; double wRatio = (double)img.PixelWidth / (double)img.PixelHeight; XVector dir = vec2 - vec; dir.Normalize(); double txtOffset = dir.X * -10; XPoint halfmg = new XPoint(-20, -20); XPoint imgpos = new XPoint(dir.X * (-graphSize - 50), dir.Y * (-graphSize - 50)) + center + halfmg; gfx.DrawImage(img, new XRect(imgpos, new XSize(wRatio * 60, 60))); gfx.DrawString(icons[j].txt, arialSmall, XBrushes.Black, imgpos + new XPoint(txtOffset, -10), XStringFormats.Center); } //leftSide XPoint[] percentagePoints = new XPoint[polyPoints.Length - 1]; for (int k = 0; k < polyPoints.Length - 1; k++) { Parameter kv = userParameters_.ElementAt(k); percentagePoints[k] = DrawingUtil.Instance.Interpolate(center, polyPoints[k], -kv.Percentage); gfx.DrawLine(yellowPen, center, DrawingUtil.Instance.Interpolate(center, polyPoints[k], -kv.AmberVal)); gfx.DrawLine(redPen, center, DrawingUtil.Instance.Interpolate(center, polyPoints[k], -kv.RedVal)); } gfx.DrawPolygon(new XPen(XColor.FromArgb(1, 0, 255, 255)), new XSolidBrush(XColor.FromArgb(100, 255, 255, 0)), percentagePoints, XFillMode.Alternate); XPoint[] linePoints = new XPoint[percentagePoints.Length + 1]; for (int i = 0; i < percentagePoints.Length; i++) { linePoints[i] = percentagePoints[i]; } linePoints[linePoints.Length - 1] = percentagePoints[0]; gfx.DrawLines(new XPen(XColor.FromArgb(255, 255, 255, 0), 2), linePoints); //right side for (int k = 10; k < polyPoints.Length + 9; k++) { Parameter kv = userParameters_.ElementAt(k); percentagePoints[k - 10] = DrawingUtil.Instance.Interpolate(center, polyPoints[k - 10], -kv.Percentage); gfx.DrawLine(yellowPen, center, DrawingUtil.Instance.Interpolate(center, polyPoints[k -10], -kv.AmberVal)); gfx.DrawLine(redPen, center, DrawingUtil.Instance.Interpolate(center, polyPoints[k - 10], -kv.RedVal)); } gfx.DrawPolygon(new XPen(XColor.FromArgb(1, 0, 255, 255)), new XSolidBrush(XColor.FromArgb(100, 54, 127, 180)), percentagePoints, XFillMode.Alternate); for (int i = 0; i < percentagePoints.Length; i++) { linePoints[i] = percentagePoints[i]; } linePoints[linePoints.Length - 1] = percentagePoints[0]; gfx.DrawLines(new XPen(XColor.FromArgb(255, 54, 127, 180), 2), linePoints); XRect leftRectLSI = new XRect(center.X - 250, page_.Height * 0.725, 120, 25); XRect rightRectLSI = new XRect(center.X + 70, page_.Height * 0.725, 120, 25); XRect LSIRect = new XRect(page_.Width - 100, page_.Height * 0.725, 35, 25); XSize rad = new XSize(10, 10); DrawingUtil.DrawOutlineRect(leftRectLSI, gfx, rad); DrawingUtil.DrawOutlineRect(rightRectLSI, gfx, rad); DrawingUtil.DrawOutlineRect(LSIRect, gfx, rad); gfx.DrawRoundedRectangle(XBrushes.Yellow, leftRectLSI,rad); gfx.DrawRoundedRectangle(XBrushes.CornflowerBlue, rightRectLSI, rad); gfx.DrawRoundedRectangle(XBrushes.LightGray, LSIRect, rad); gfx.DrawString("Left", new XFont("Arial", 14), XBrushes.Black, new XPoint(leftRectLSI.X + 60, leftRectLSI.Y + 12.5), XStringFormats.Center); gfx.DrawString("Right", new XFont("Arial", 14), XBrushes.Black, new XPoint(rightRectLSI.X + 60, rightRectLSI.Y + 12.5), XStringFormats.Center); gfx.DrawString("LSI", new XFont("Arial", 14), XBrushes.Black, new XPoint(LSIRect.X + 17.5, LSIRect.Y + 10), XStringFormats.Center); for (int l = 0; l < polyPoints.Length - 1; l++) { XBrush leftParamCol = XBrushes.Green; XBrush rightParamCol = XBrushes.Green; XBrush lsiParamCol = XBrushes.Green; XFont arial = new XFont("Arial", 13,XFontStyle.Bold); Parameter leftParam = userParameters_.ElementAt(l); Parameter rightParam = userParameters_.ElementAt(l + 10);; leftParamCol = DrawingUtil.Instance.ChooseBrushColor(leftParam.Color); rightParamCol = DrawingUtil.Instance.ChooseBrushColor(rightParam.Color); char degree = Convert.ToChar('\u00b0'); double increment = l * page_.Height * 0.025; double y = page_.Height * 0.775 + increment; XRect rl = new XRect(leftRectLSI.X + (leftRectLSI.Width * 0.5) - 25, y, 50, 15); DrawingUtil.DrawOutlineRect(rl, gfx, rad); gfx.DrawRoundedRectangle(leftParamCol, rl, rad); gfx.DrawString(leftParam.Value.ToString() + degree, arial, XBrushes.Black, new XPoint(rl.X + 25, rl.Y + 7.5), XStringFormats.Center); XRect rr = new XRect(rightRectLSI.X + (rightRectLSI.Width * 0.5) - 25, y, 50, 15); DrawingUtil.DrawOutlineRect(rr, gfx, rad); gfx.DrawRoundedRectangle(rightParamCol, rr, rad); gfx.DrawString(rightParam.Value.ToString() + degree, arial, XBrushes.Black, new XPoint(rr.X + 25, rr.Y + 7.5), XStringFormats.Center); XRect rlsi = new XRect(LSIRect.X + (LSIRect.Width * 0.5) - 17.5, y, 35, 15); DrawingUtil.DrawOutlineRect(rlsi, gfx, rad); lsiParamCol = DrawingUtil.Instance.ChooseBrushColor(leftParam.LSI, 49, 74); gfx.DrawRoundedRectangle(lsiParamCol, rlsi, rad); gfx.DrawString(leftParam.LSI.ToString("0") + "%", arial, XBrushes.Black, new XPoint(rlsi.X + 17.5, rlsi.Y + 7.5), XStringFormats.Center); gfx.DrawString(leftParam.Name.Substring(4,leftParam.Name.Length - 4), new XFont("Arial", 10), XBrushes.Black, DrawingUtil.Instance.Interpolate(new XPoint(rl.X + rl.Width, y + 7.5), new XPoint(rr.X, y), -0.5), XStringFormats.TopCenter); gfx.DrawLine(XPens.DarkSlateGray, new XPoint(leftRectLSI.X, rl.Y + 17.5), new XPoint(rlsi.X + 35, rl.Y + 17.5)); } }
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); } } }