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 sealed void OnDraw(Context ctx, Rectangle bounds) { var frame = GetFrame (ctx.ScaleFactor); var fixedWidth = frame.Bitmap.Width - 2 - frame.StretchableWidth; var fixedHeight = frame.Bitmap.Height - 2 - frame.StretchableHeight; double totalVariableWidth = bounds.Width - fixedWidth / frame.ScaleFactor; double totalVariableHeight = bounds.Height - fixedHeight / frame.ScaleFactor; double remainingVariableHeight = totalVariableHeight; double y = bounds.Y, yb = 1; int tileIndex = 0; ctx.Save (); if (totalVariableWidth < 0) { if (fixedWidth > 0) ctx.Scale (bounds.Width / fixedWidth, 1); totalVariableWidth = 0; } if (totalVariableHeight < 0) { if (fixedHeight > 0) ctx.Scale (1, bounds.Height / fixedHeight); totalVariableHeight = 0; } foreach (var vs in frame.VerticalSections) { double sh = CalcSectionSize (frame, vs, totalVariableHeight, frame.StretchableHeight, ref remainingVariableHeight); double x = bounds.X, xb = 1; double remainingVariableWidth = totalVariableWidth; foreach (var hs in frame.HorizontalSections) { var sourceRegion = new Rectangle (xb, yb, hs.Size, vs.Size); double sw = CalcSectionSize (frame, hs, totalVariableWidth, frame.StretchableWidth, ref remainingVariableWidth); var targetRegion = new Rectangle (x, y, sw, sh); if (vs.Mode != RenderMode.Tile && hs.Mode != RenderMode.Tile) { var t = GetTile (frame, tileIndex, sourceRegion); ctx.DrawImage (t, targetRegion); } else { double pw = hs.Size / frame.ScaleFactor; double ph = vs.Size / frame.ScaleFactor; if (hs.Mode == RenderMode.Stretch) { pw = targetRegion.Width; } if (vs.Mode == RenderMode.Stretch) { ph = targetRegion.Height; } ctx.Save (); ctx.Translate (targetRegion.Location); targetRegion.Location = Point.Zero; ctx.Pattern = new ImagePattern (GetTile (frame, tileIndex, sourceRegion).WithSize (pw, ph)); ctx.NewPath (); ctx.Rectangle (targetRegion); ctx.Fill (); ctx.Restore (); } x += sw; xb += hs.Size; tileIndex++; } yb += vs.Size; y += sh; } ctx.Restore (); }
void DrawSerie (Context ctx, Serie serie) { ctx.NewPath (); ctx.Rectangle (left, top, width + 1, height + 1); ctx.Clip (); ctx.NewPath (); ctx.SetColor (serie.Color); ctx.SetLineWidth (serie.LineWidth); bool first = true; bool blockMode = serie.DisplayMode == DisplayMode.BlockLine; double lastY = 0; foreach (Data d in serie.GetData (startX, endX)) { double x, y; GetPoint (d.X, d.Y, out x, out y); if (first) { ctx.MoveTo (x, y); lastY = y; first = false; } else { if (blockMode) { if (lastY != y) ctx.LineTo (x, lastY); ctx.LineTo (x, y); } else ctx.LineTo (x, y); } lastY = y; } ctx.Stroke (); }
void Draw (Context ctx, bool fill) { var parent = (RoundedFrameBox)Parent; var border = parent.BorderSpacing; var radius = parent.cornerRadius; var rect = Bounds; ctx.MoveTo (rect.X, rect.Y); if (border.Top > 0) { ctx.NewPath (); if (radius.TopLeft > 0) ctx.Arc (rect.Left + radius.TopLeft + border.Left / 2, rect.Top + radius.TopLeft + border.Top / 2, radius.TopLeft, 180, 270); else PathTo (ctx, rect.Left, rect.Top + border.Top / 2, fill); if (radius.TopRight > 0) { ctx.LineTo (rect.Right - (radius.TopRight + border.Right / 2), rect.Top + border.Top / 2); ctx.Arc (rect.Right - (radius.TopRight + border.Right / 2), rect.Top + radius.TopRight + border.Top / 2, radius.TopRight, 270, 0); } else ctx.LineTo (rect.Right, rect.Top + border.Top / 2); } else PathTo (ctx, rect.Right - border.Right / 2, rect.Top, fill); if (border.Right > 0) // TODO: round corners if top/bottom border disabled ctx.LineTo (rect.Right - border.Right / 2, rect.Bottom - (border.Bottom > 0 ? radius.BottomRight : 0)); else PathTo (ctx, rect.Right - border.Right / 2, rect.Bottom - (border.Bottom > 0 ? radius.BottomRight : 0), fill); if (border.Bottom > 0) { if (radius.BottomRight > 0) ctx.Arc (rect.Right - (radius.BottomRight + border.Right / 2), rect.Bottom - (radius.BottomRight + border.Bottom / 2), radius.BottomRight, 0, 90); else PathTo (ctx, rect.Right, rect.Bottom - border.Bottom / 2, fill); if (radius.BottomLeft > 0) { ctx.LineTo (rect.Left + (radius.BottomLeft + border.Left / 2), rect.Bottom - border.Bottom / 2); ctx.Arc (rect.Left + radius.BottomLeft + border.Left / 2, rect.Bottom - (radius.BottomLeft + border.Bottom / 2), radius.BottomLeft, 90, 180); } else ctx.LineTo (rect.Left + border.Left / 2, rect.Bottom - border.Bottom / 2); } else PathTo (ctx, rect.Left + border.Left / 2, rect.Bottom - border.Bottom / 2, fill); if (border.Left > 0) // TODO: round corners if top/bottom border disabled ctx.LineTo (rect.Left + border.Left / 2, rect.Top + (border.Top > 0 ? radius.TopLeft : 0)); else PathTo (ctx, rect.Left + border.Left / 2, rect.Top + (border.Top > 0 ? radius.TopLeft : 0), fill); if (fill) { ctx.SetColor (parent.innerColor); ctx.Fill (); } else { ctx.SetColor (parent.borderColor); ctx.SetLineWidth (parent.borderWidth); ctx.Stroke (); } }
public static void DrawRoundRectangle(Xwt.Drawing.Context cr, bool topLeftRound, bool topRightRound, bool bottomLeftRound, bool bottomRightRound, double x, double y, double r, double w, double h) { // UA****BQ // H C // * * // G D // TF****ES cr.NewPath(); if (topLeftRound) { cr.MoveTo(x + r, y); // Move to A } else { cr.MoveTo(x, y); // Move to U } if (topRightRound) { cr.LineTo(x + w - r, y); // Straight line to B cr.CurveTo(x + w, y, x + w, y, x + w, y + r); // Curve to C, Control points are both at Q } else { cr.LineTo(x + w, y); // Straight line to Q } if (bottomRightRound) { cr.LineTo(x + w, y + h - r); // Move to D cr.CurveTo(x + w, y + h, x + w, y + h, x + w - r, y + h); // Curve to E } else { cr.LineTo(x + w, y + h); // Move to S } if (bottomLeftRound) { cr.LineTo(x + r, y + h); // Line to F cr.CurveTo(x, y + h, x, y + h, x, y + h - r); // Curve to G } else { cr.LineTo(x, y + h); // Line to T } if (topLeftRound) { cr.LineTo(x, y + r); // Line to H cr.CurveTo(x, y, x, y, x + r, y); // Curve to A } else { cr.LineTo(x, y); // Line to U } cr.ClosePath(); }
void DrawBorder(Context ctx, double x, double y, double w, double h, double radius, double thickness) { // test limits (without using multiplication) if (radius > w - radius) radius = w / 2; if (radius > h - radius) radius = h / 2; // approximate (quite close) the arc using a bezier curve double arc = ArcToBezier * radius; ctx.SetLineWidth (thickness); // top-left corner ctx.NewPath (); ctx.MoveTo (x, y + radius); ctx.CurveTo (x, y + radius - arc, x + radius - arc, y, x + radius, y); ctx.Pattern = GetCornerGradient (x + radius, y + radius, radius, thickness / 2); ctx.Stroke (); // top edge ctx.NewPath (); ctx.MoveTo (x + radius - 0.5, y); ctx.LineTo (x + w - radius + 0.5, y); ctx.Pattern = GetTopEdgeGradient (y, thickness / 2); ctx.Stroke (); // top-right corner ctx.NewPath (); ctx.MoveTo (x + w - radius, y); ctx.CurveTo (x + w - radius + arc, y, x + w, y + arc, x + w, y + radius); ctx.Pattern = GetCornerGradient (x + w - radius, y + radius, radius, thickness / 2); ctx.Stroke (); // right edge ctx.NewPath (); ctx.MoveTo (x + w, y + radius - 0.5); ctx.LineTo (x + w, y + h - radius + 0.5); ctx.Pattern = GetRightEdgeGradient (x + w, thickness / 2); ctx.Stroke (); // bottom-right corner ctx.NewPath (); ctx.MoveTo (x + w, y + h - radius); ctx.CurveTo (x + w, y + h - radius + arc, x + w + arc - radius, y + h, x + w - radius, y + h); ctx.Pattern = GetCornerGradient (x + w - radius, y + h - radius, radius, thickness / 2); ctx.Stroke (); // bottom edge ctx.NewPath (); ctx.MoveTo (x + w - radius + 0.5, y + h); ctx.LineTo (x + radius - 0.5, y + h); ctx.Pattern = GetBottomEdgeGradient (y + h, thickness / 2); ctx.Stroke (); // bottom-left corner ctx.NewPath (); ctx.MoveTo (x + radius, y + h); ctx.CurveTo (x + radius - arc, y + h, x, y + h - arc, x, y + h - radius); ctx.Pattern = GetCornerGradient (x + radius, y + h - radius, radius, thickness / 2); ctx.Stroke (); // left edge ctx.NewPath (); ctx.MoveTo (x, y + h - radius + 0.5); ctx.LineTo (x, y + radius - 0.5); ctx.Pattern = GetLeftEdgeGradient (x, thickness / 2); ctx.Stroke (); }
static void DrawBorder(Context ctx, double x, double y, double w, double h, double radius) { ctx.NewPath (); // test limits (without using multiplication) if (radius > w - radius) radius = w / 2; if (radius > h - radius) radius = h / 2; // approximate (quite close) the arc using a bezier curve double arc = ArcToBezier * radius; // top-left corner ctx.MoveTo (x + radius, y); // top edge ctx.LineTo (x + w - radius, y); // top-right corner ctx.CurveTo (x + w - radius + arc, y, x + w, y + arc, x + w, y + radius); // right edge ctx.LineTo (x + w, y + h - radius); // bottom-right corner ctx.CurveTo (x + w, y + h - radius + arc, x + w + arc - radius, y + h, x + w - radius, y + h); // bottom edge ctx.LineTo (x + radius, y + h); // bottom-left corner ctx.CurveTo (x + radius - arc, y + h, x, y + h - arc, x, y + h - radius); // left edge ctx.LineTo (x, y + radius); // top-left corner ctx.CurveTo (x, y + radius - arc, x + radius - arc, y, x + radius, y); }
protected sealed override void OnDraw(Context ctx, Rectangle bounds) { if (bounds.Width <= 0 || bounds.Height <= 0) { return; } var frame = GetFrame(ctx.ScaleFactor); var fixedWidth = frame.Bitmap.Width - 2 - frame.StretchableWidth; var fixedHeight = frame.Bitmap.Height - 2 - frame.StretchableHeight; double totalVariableWidth = bounds.Width - fixedWidth / frame.ScaleFactor; double totalVariableHeight = bounds.Height - fixedHeight / frame.ScaleFactor; double remainingVariableHeight = totalVariableHeight; double y = bounds.Y, yb = 1; int tileIndex = 0; ctx.Save(); if (totalVariableWidth < 0) { if (fixedWidth > 0) { ctx.Scale(bounds.Width / fixedWidth, 1); } totalVariableWidth = 0; } if (totalVariableHeight < 0) { if (fixedHeight > 0) { ctx.Scale(1, bounds.Height / fixedHeight); } totalVariableHeight = 0; } foreach (var vs in frame.VerticalSections) { double sh = CalcSectionSize(frame, vs, totalVariableHeight, frame.StretchableHeight, ref remainingVariableHeight); double x = bounds.X, xb = 1; double remainingVariableWidth = totalVariableWidth; foreach (var hs in frame.HorizontalSections) { var sourceRegion = new Rectangle(xb, yb, hs.Size, vs.Size); double sw = CalcSectionSize(frame, hs, totalVariableWidth, frame.StretchableWidth, ref remainingVariableWidth); var targetRegion = new Rectangle(x, y, sw, sh); if (vs.Mode != RenderMode.Tile && hs.Mode != RenderMode.Tile) { var t = GetTile(frame, tileIndex, sourceRegion); ctx.DrawImage(t, targetRegion); } else { double pw = hs.Size / frame.ScaleFactor; double ph = vs.Size / frame.ScaleFactor; if (hs.Mode == RenderMode.Stretch) { pw = targetRegion.Width; } if (vs.Mode == RenderMode.Stretch) { ph = targetRegion.Height; } if (pw <= 0 || ph <= 0) { continue; } ctx.Save(); ctx.Translate(targetRegion.Location); targetRegion.Location = Point.Zero; ctx.Pattern = new ImagePattern(GetTile(frame, tileIndex, sourceRegion).WithSize(pw, ph)); ctx.NewPath(); ctx.Rectangle(targetRegion); ctx.Fill(); ctx.Restore(); } x += sw; xb += hs.Size; tileIndex++; } yb += vs.Size; y += sh; } 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); } } } }