public virtual void Rotate(Xwt.Drawing.Context ctx, double x, double y) { ctx.Save(); ctx.Translate(x + 30, y + 30); ctx.SetLineWidth(3); // Rotation double end = 270; for (double n = 0; n <= end; n += 5) { ctx.Save(); ctx.Rotate(n); ctx.MoveTo(0, 0); ctx.RelLineTo(30, 0); double c = n / end; ctx.SetColor(new Color(c, c, c)); ctx.Stroke(); ctx.Restore(); } //ctx.ResetTransform(); ctx.Restore(); }
public virtual void Rotate(Xwt.Drawing.Context ctx, double x, double y) { // draws a line along the x-axis from (0,0) to (r,0) with a constant translation and an increasing // rotational component. This composite transform is then applied to a vertical line, with inverse // color, and an additional x-offset, to form a mirror image figure for easy visual comparison. // These transformed points must be drawn with the identity CTM, hence the Restore() each time. ctx.Save(); // save caller's context (assumed to be the Identity CTM) ctx.SetLineWidth(3); // should align exactly if drawn with half-pixel coordinates // Vector length (pixels) and rotation limit (degrees) double r = 30; double end = 270; for (double n = 0; n <= end; n += 5) { ctx.Save(); // save context and identity CTM for each line // Set up translation to centre point of first figure, ensuring pixel alignment ctx.Translate(x + 30.5, y + 30.5); ctx.Rotate(n); ctx.MoveTo(0, 0); ctx.RelLineTo(r, 0); double c = n / end; ctx.SetColor(new Color(c, c, c)); ctx.Stroke(); // stroke first figure with composite Translation and Rotation CTM // Generate mirror image figure as a visual test of TransformPoints Point p0 = new Point(0, 0); Point p1 = new Point(0, -r); Point[] p = new Point[] { p0, p1 }; ctx.TransformPoints(p); // using composite transformation ctx.Restore(); // restore identity CTM ctx.Save(); // save again (to restore after additional Translation) ctx.Translate(2 * r + 1, 0); // extra x-offset to clear first figure ctx.MoveTo(p[0]); ctx.LineTo(p[1]); c = 1 - c; ctx.SetColor(new Color(c, c, c)); ctx.Stroke(); // stroke transformed points with offset in CTM ctx.Restore(); // restore identity CTM for next line } ctx.Restore(); // restore caller's context }
protected override void OnDraw(Xwt.Drawing.Context ctx) { base.OnDraw(ctx); ctx.Translate(30, 30); double end = 270; for (double n = 0; n <= end; n += 5) { ctx.Save(); ctx.Rotate(n); ctx.MoveTo(0, 0); ctx.RelLineTo(30, 0); double c = n / end; ctx.SetColor(new Color(c, c, c)); ctx.Stroke(); ctx.Restore(); } }
/// <summary> /// Visual test for pixel alignment and odd/even line widths /// </summary> public void Lines (Context ctx) { ctx.Save (); ctx.SetColor (Colors.Black); int nPairs = 4; double length = 90; double gap = 2; // set half-pixel y-coordinate for sharp single-pixel-wide line // on first line of Canvas, extending to match line pairs below ctx.SetLineWidth (1); double x = 0; double y = 0.5; double end = x + 2*(length - 1) + gap; ctx.MoveTo (x, y); ctx.LineTo (end, y); ctx.Stroke (); // draw pairs of lines with odd and even widths, // each pair aligned on half-pixel y-coordinates y = 4.5; for (int w = 1; w <= nPairs; ++w) { x = 0; ctx.SetLineWidth (w); ctx.MoveTo (x, y); ctx.RelLineTo (length-1, 0); ctx.Stroke (); ctx.SetLineWidth (w + 1); x += (gap + length - 1); ctx.MoveTo (x, y); ctx.RelLineTo (length-1, 0); ctx.Stroke (); y += w * 2 + gap; } ctx.Restore (); }
public virtual void Rotate(Xwt.Drawing.Context ctx, double x, double y) { ctx.Save(); ctx.Translate(x + 30, y + 30); ctx.SetLineWidth(3); // Rotation double end = 270; double r = 30; for (double n = 0; n <= end; n += 5) { ctx.Save(); ctx.Rotate(n); ctx.MoveTo(0, 0); ctx.RelLineTo(r, 0); double c = n / end; ctx.SetColor(new Color(c, c, c)); ctx.Stroke(); // Visual test for TransformPoints Point p0 = new Point(0, 0); Point p1 = new Point(0, -r); Point[] p = new Point[] { p0, p1 }; ctx.TransformPoints(p); ctx.ResetTransform(); ctx.Translate(2 * r + 1, 0); ctx.MoveTo(p[0]); ctx.LineTo(p[1]); c = 1 - c; ctx.SetColor(new Color(c, c, c)); ctx.Stroke(); ctx.Restore(); } ctx.Restore(); }
public virtual void Rectangles (Context ctx, double x, double y) { ctx.Save (); ctx.Translate (x, y); // Simple rectangles ctx.SetLineWidth (1); ctx.Rectangle (0, 0, 10, 10); ctx.SetColor (Colors.Black); ctx.Fill (); ctx.Rectangle (15, 0, 10, 10); ctx.SetColor (Colors.Black); ctx.Stroke (); ctx.SetLineWidth (3); ctx.Rectangle (0, 15, 10, 10); ctx.SetColor (Colors.Black); ctx.Fill (); ctx.Rectangle (15, 15, 10, 10); ctx.SetColor (Colors.Black); ctx.Stroke (); ctx.Restore (); // Rectangle with hole ctx.Save (); ctx.Translate (x + 50, y); ctx.Rectangle (0, 0, 40, 40); ctx.MoveTo (35, 35); ctx.RelLineTo (0, -20); ctx.RelLineTo (-20, 0); ctx.RelLineTo (0, 20); ctx.ClosePath (); ctx.SetColor (Colors.Black); ctx.Fill (); ctx.Restore (); // Rounded Rectangle with Arcs ctx.Save (); ctx.Translate (x + 120, y); var r = 5; var l = 0; var t = 0; var w = 50; var h = 30; ctx.SetColor (Colors.Black); // top left ctx.Arc (l + r, t + r, r, 180, 270); // top right ctx.Arc (l + w - r, t + r, r, 270, 0); // bottom right ctx.Arc (l + w - r, t + h - r, r, 0, 90); // bottom left ctx.Arc (l + r, t + h - r, r, 90, 180); ctx.ClosePath (); ctx.StrokePreserve (); ctx.SetColor (Colors.AntiqueWhite); ctx.Fill (); ctx.Restore (); }
public static void DrawRoundRectangle (Context cr, double x, double y, double r, double w, double h) { const double ARC_TO_BEZIER = 0.55228475; double radius_x = r; double radius_y = r / 4; if (radius_x > w - radius_x) radius_x = w / 2; if (radius_y > h - radius_y) radius_y = h / 2; double c1 = ARC_TO_BEZIER * radius_x; double c2 = ARC_TO_BEZIER * radius_y; cr.NewPath (); cr.MoveTo (x + radius_x, y); cr.RelLineTo (w - 2 * radius_x, 0.0); cr.RelCurveTo (c1, 0.0, radius_x, c2, radius_x, radius_y); cr.RelLineTo (0, h - 2 * radius_y); cr.RelCurveTo (0.0, c2, c1 - radius_x, radius_y, -radius_x, radius_y); cr.RelLineTo (-w + 2 * radius_x, 0); cr.RelCurveTo (-c1, 0, -radius_x, -c2, -radius_x, -radius_y); cr.RelLineTo (0, -h + 2 * radius_y); cr.RelCurveTo (0.0, -c2, radius_x - c1, -radius_y, radius_x, -radius_y); cr.ClosePath (); }
protected override void OnDraw(Xwt.Drawing.Context ctx) { base.OnDraw(ctx); // Simple rectangles ctx.SetLineWidth(1); ctx.Rectangle(100, 5, 10, 10); ctx.SetColor(Color.Black); ctx.Fill(); ctx.Rectangle(115, 5, 10, 10); ctx.SetColor(Color.Black); ctx.Stroke(); // ctx.SetLineWidth(3); ctx.Rectangle(100, 20, 10, 10); ctx.SetColor(Color.Black); ctx.Fill(); ctx.Rectangle(115, 20, 10, 10); ctx.SetColor(Color.Black); ctx.Stroke(); // Rectangle with hole ctx.Rectangle(10, 100, 40, 40); ctx.MoveTo(45, 135); ctx.RelLineTo(0, -20); ctx.RelLineTo(-20, 0); ctx.RelLineTo(0, 20); ctx.ClosePath(); ctx.SetColor(Color.Black); ctx.Fill(); // Dashed lines ctx.SetLineDash(15, 10, 10, 5, 5); ctx.Rectangle(100, 100, 100, 100); ctx.Stroke(); ctx.SetLineDash(0); ImageBuilder ib = new ImageBuilder(30, 30, ImageFormat.ARGB32); ib.Context.Arc(15, 15, 15, 0, 360); ib.Context.SetColor(new Color(1, 0, 1)); ib.Context.Rectangle(0, 0, 5, 5); ib.Context.Fill(); var img = ib.ToImage(); ctx.DrawImage(img, 90, 90); ctx.DrawImage(img, 90, 140, 50, 10); ctx.Arc(190, 190, 15, 0, 360); ctx.SetColor(new Color(1, 0, 1, 0.4)); ctx.Fill(); ctx.Save(); ctx.Translate(90, 220); ctx.Pattern = new ImagePattern(img); ctx.Rectangle(0, 0, 100, 70); ctx.Fill(); ctx.Restore(); ctx.Translate(30, 30); double end = 270; for (double n = 0; n <= end; n += 5) { ctx.Save(); ctx.Rotate(n); ctx.MoveTo(0, 0); ctx.RelLineTo(30, 0); double c = n / end; ctx.SetColor(new Color(c, c, c)); ctx.Stroke(); ctx.Restore(); } ctx.ResetTransform(); }
void DrawCursor (Context ctx, ChartCursor cursor) { ctx.SetColor (cursor.Color); double x, y; GetPoint (cursor.Value, cursor.Value, out x, out y); if (cursor.Dimension == AxisDimension.X) { double cy = top - AreaBorderWidth - 1; ctx.MoveTo (x, cy); ctx.LineTo (x + (cursor.HandleSize/2), cy - cursor.HandleSize + 1); ctx.LineTo (x - (cursor.HandleSize/2), cy - cursor.HandleSize + 1); ctx.ClosePath (); if (activeCursor == cursor) ctx.FillPreserve (); ctx.Stroke (); ctx.MoveTo (x, top); ctx.RelLineTo (0, height); ctx.Stroke (); } else { throw new NotSupportedException (); } }
protected override void OnDraw(Context ctx, Rectangle dirtyRect) { base.OnDraw(ctx, dirtyRect); for (int i = 0; i < Size.Width / checkerboard.Width; i++) { for (int j = 0; j < Size.Height / checkerboard.Height; j++) { ctx.DrawImage(checkerboard, i * checkerboard.Width, j * checkerboard.Height); } } ctx.SetLineWidth(1); ctx.SetColor(color); ctx.Rectangle(0, 0, Size.Width - 20, Size.Height); ctx.Fill(); ctx.SetColor(DefaultColor); ctx.Rectangle(Size.Width - 20, 0, 20, Size.Height); ctx.Fill(); ctx.SetColor(Colors.Black); ctx.Rectangle(0, 0, Size.Width, Size.Height); ctx.Stroke(); //ctx.SetColor(Color.Brightness > .5 ? Colors.White : Colors.Black); ctx.SetColor(((-1 * Color.Brightness) + 1) * 1.15 + (Color.Alpha) > 1.2 ? Colors.White : Colors.Black); ctx.DrawTextLayout(new TextLayout(this) { Text = Color.ToHexString().ToUpper() }, 2, 3); if (mover && (IsDefaultColor || mx <= Size.Width - 20)) { ctx.SetColor(new Color(1, 1, 1, .33)); ctx.Rectangle(0, 0, Size.Width - (IsDefaultColor ? 0 : 20), Size.Height); ctx.Fill(); } if (!IsDefaultColor) { if (mover && mx > Size.Width - 20) { ctx.SetColor(new Color(1, 1, 1, .33)); ctx.Rectangle(Size.Width - 20, 0, 20, Size.Height); ctx.Fill(); } ctx.SetColor(Colors.Black); ctx.MoveTo(Size.Width - 19.5, 0); ctx.RelLineTo(0, Size.Height); ctx.Stroke(); if (mover) ctx.DrawImage(resetImage, Size.Width - 18, (Size.Height - 16) / 2, 16, 16); } }
protected override void OnDraw(Context ctx, Rectangle dirtyRect) { base.OnDraw (ctx, dirtyRect); FrameBox parent = (FrameBox)Parent; var border = parent.borderWidth; var r = Bounds; //ctx.SetLineDash (0); ctx.SetColor (parent.borderColor); if (border.Top > 0) { ctx.MoveTo (r.X, r.Y + border.Top / 2); ctx.RelLineTo (r.Width, 0); ctx.SetLineWidth (border.Top); ctx.Stroke (); } if (border.Bottom > 0) { ctx.MoveTo (r.X, r.Bottom - border.Bottom / 2); ctx.RelLineTo (r.Width, 0); ctx.SetLineWidth (border.Bottom); ctx.Stroke (); } if (border.Left > 0) { ctx.MoveTo (r.X + border.Left / 2, r.Y + border.Top); ctx.RelLineTo (0, r.Height - border.Top - border.Bottom); ctx.SetLineWidth (border.Left); ctx.Stroke (); } if (border.Right > 0) { ctx.MoveTo (r.Right - border.Right / 2, r.Y + border.Top); ctx.RelLineTo (0, r.Height - border.Top - border.Bottom); ctx.SetLineWidth (border.Right); ctx.Stroke (); } }
void DrawFocus( Context ctx, double x, double y ) { if (!cursorVisible) return; double r = 16; ctx.Save (); x += 0.5; y += 0.5; ctx.SetLineWidth (3); ctx.SetColor (new Color (0, 0, 0, 0.5)); ctx.Arc (x, y, r, 0, 360); ctx.Stroke (); ctx.SetLineWidth (1); ctx.MoveTo (x+r, y); ctx.RelLineTo (r, 0); ctx.MoveTo (x-r, y); ctx.RelLineTo (-r, 0); ctx.MoveTo (x, y+r); ctx.RelLineTo (0, r); ctx.MoveTo (x, y-r); ctx.RelLineTo (0, -r); ctx.Stroke (); r += 10; ctx.Arc (x, y, r, 10, 80); ctx.Stroke (); ctx.Arc (x, y, r, 100, 170); ctx.Stroke (); ctx.Arc (x, y, r, 190, 260); ctx.Stroke (); ctx.Arc (x, y, r, 280, 350); ctx.Stroke (); ctx.Restore (); }
void DrawPopover(Context ctx) { lock (trackerLock) { if (actualTrackerHitResult != null) { var trackerSettings = DefaultTrackerSettings; if (actualTrackerHitResult.Series != null && !string.IsNullOrEmpty(actualTrackerHitResult.Series.TrackerKey)) trackerSettings = trackerDefinitions[actualTrackerHitResult.Series.TrackerKey]; if (trackerSettings.Enabled) { var extents = actualTrackerHitResult.LineExtents; if (Math.Abs(extents.Width) < double.Epsilon) { extents = new OxyRect(actualTrackerHitResult.XAxis.ScreenMin.X, extents.Top, actualTrackerHitResult.XAxis.ScreenMax.X - actualTrackerHitResult.XAxis.ScreenMin.X, extents.Height); } if (Math.Abs(extents.Height) < double.Epsilon) { extents = new OxyRect(extents.Left, actualTrackerHitResult.YAxis.ScreenMin.Y, extents.Width, actualTrackerHitResult.YAxis.ScreenMax.Y - actualTrackerHitResult.YAxis.ScreenMin.Y); } var pos = actualTrackerHitResult.Position; if (trackerSettings.HorizontalLineVisible) { renderContext.DrawLine( new[] { new ScreenPoint(extents.Left, pos.Y), new ScreenPoint(extents.Right, pos.Y) }, trackerSettings.HorizontalLineColor, trackerSettings.HorizontalLineWidth, trackerSettings.HorizontalLineActualDashArray, LineJoin.Miter, true); } if (trackerSettings.VerticalLineVisible) { renderContext.DrawLine( new[] { new ScreenPoint(pos.X, extents.Top), new ScreenPoint(pos.X, extents.Bottom) }, trackerSettings.VerticalLineColor, trackerSettings.VerticalLineWidth, trackerSettings.VerticalLineActualDashArray, LineJoin.Miter, true); } TextLayout text = new TextLayout(); text.Font = trackerSettings.Font; text.Text = actualTrackerHitResult.Text; var arrowTop = actualTrackerHitResult.Position.Y <= Bounds.Height / 2; const int arrowPadding = 10; var textSize = text.GetSize(); var outerSize = new Size(textSize.Width + (trackerSettings.Padding * 2), textSize.Height + (trackerSettings.Padding * 2) + arrowPadding); var trackerBounds = new Rectangle(pos.X - (outerSize.Width / 2), 0, outerSize.Width, outerSize.Height - arrowPadding); if (arrowTop) trackerBounds.Y = pos.Y + arrowPadding + trackerSettings.BorderWidth; else trackerBounds.Y = pos.Y - outerSize.Height - trackerSettings.BorderWidth; var borderColor = trackerSettings.BorderColor.ToXwtColor(); ctx.RoundRectangle(trackerBounds, 6); ctx.SetLineWidth(trackerSettings.BorderWidth); ctx.SetColor(borderColor); ctx.StrokePreserve(); ctx.SetColor(trackerSettings.Background.ToXwtColor()); ctx.Fill(); ctx.Save(); var arrowX = trackerBounds.Center.X; var arrowY = arrowTop ? trackerBounds.Top : trackerBounds.Bottom; ctx.NewPath(); ctx.MoveTo(arrowX, arrowY); var triangleSide = 2 * arrowPadding / Math.Sqrt(3); var halfSide = triangleSide / 2; var verticalModifier = arrowTop ? -1 : 1; ctx.RelMoveTo(-halfSide, 0); ctx.RelLineTo(halfSide, verticalModifier * arrowPadding); ctx.RelLineTo(halfSide, verticalModifier * -arrowPadding); ctx.SetColor(borderColor); ctx.StrokePreserve(); ctx.ClosePath(); ctx.SetColor(trackerSettings.Background.ToXwtColor()); ctx.Fill(); ctx.Restore(); ctx.SetColor(trackerSettings.TextColor.ToXwtColor()); ctx.DrawTextLayout(text, trackerBounds.Left + trackerSettings.Padding, trackerBounds.Top + trackerSettings.Padding); } } } }