protected void TestDrawing2(Xwt.Drawing.Context ctx, double x, double y) { ctx.Save(); ctx.Translate(x, y); var arcColor = new Color(1, 0, 1); ctx.Arc(100, 100, 15, 0, 360); ctx.ClosePath(); arcColor.Alpha = 0.4; ctx.SetColor(arcColor); ctx.StrokePreserve(); ctx.Fill(); ctx.Restore(); }
public virtual void Curves1(Context ctx, double x, double y) { ctx.Save (); ctx.Translate (x, y); ctx.SetLineWidth (1); Action curve1 = () => { ctx.MoveTo (0, 30); ctx.CurveTo (20, 0, 50, 0, 60, 25); }; // curve2 with lineTo; curve1 is closed Action curve2 = () => { ctx.LineTo (0, 0); ctx.CurveTo (20, 30, 50, 30, 60, 5); }; Action paint = () => { curve1 (); curve2 (); ctx.ClosePath (); ctx.SetColor (new Color (0, 0, 0, .5)); ctx.StrokePreserve (); ctx.SetColor (new Color (1, 0, 1, .5)); ctx.Fill (); }; paint (); ctx.Translate (0, 40); // curve2 with moveTo; curve1 is open curve2 = () => { ctx.MoveTo (0, 0); ctx.CurveTo (20, 30, 50, 30, 60, 5); }; paint (); ctx.Restore (); //Todo: same stuff with arc }
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 (); }
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); } } } }
void DrawBackground(Context ctx) { // draw shadow ctx.RoundRectangle(bound.Inflate(-1, -1).Offset(1, 3), NodeRadius); ctx.SetColor(NodeColorShadow); ctx.SetLineWidth(4); ctx.Stroke(); // border ctx.RoundRectangle(bound.Inflate(-1, -1), NodeRadius); ctx.SetColor(NodeColorBorder); ctx.SetLineWidth(2); ctx.StrokePreserve(); // background ctx.SetColor(NodeColor); ctx.Fill(); if (hover) { // draw glow ctx.RoundRectangle(bound.Inflate(1, 1), NodeRadius * 2); ctx.SetColor(NodeColorGlow); ctx.SetLineWidth(1); ctx.Stroke(); } }
/// <summary> /// Draws a edge from one marker, to another /// </summary> /// <param name="ctx">Context.</param> /// <param name="from">From.</param> public void Draw(Context ctx, MarkerNode from) { MarkerNode toNode = to as MarkerNode; if (toNode != null) { ComputeStroke(ctx, from, new Point(2.5, 2.5)); ctx.SetLineWidth(4.5); ctx.SetColor(Colors.DimGray.WithAlpha(0.3)); ctx.Stroke(); ComputeStroke(ctx, from); ctx.SetLineWidth(6); ctx.SetColor(Colors.DimGray.WithAlpha(0.7)); ctx.StrokePreserve(); ctx.SetLineWidth(4.0); ctx.SetColor(from.NodeColor.BlendWith(toNode.NodeColor, 0.5).WithAlpha(1.0)); ctx.Stroke(); } }