From abe835c734a68775c3f0885c2439743aa8f84bd0 Mon Sep 17 00:00:00 2001 From: Michael Fogleman Date: Fri, 19 Feb 2016 21:15:22 -0500 Subject: [PATCH] DrawRoundedRectangle --- README.md | 1 + context.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/README.md b/README.md index 34a1a8e..585f35c 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ or circles? What a pain! ```go DrawLine(x1, y1, x2, y2 float64) DrawRectangle(x, y, w, h float64) +DrawRoundedRectangle(x, y, w, h, r float64) DrawCircle(x, y, r float64) DrawArc(x, y, r, angle1, angle2 float64) DrawEllipse(x, y, rx, ry float64) diff --git a/context.go b/context.go index 090da64..041d200 100644 --- a/context.go +++ b/context.go @@ -274,6 +274,20 @@ func (dc *Context) DrawRectangle(x, y, w, h float64) { dc.LineTo(x, y) } +func (dc *Context) DrawRoundedRectangle(x, y, w, h, r float64) { + x0, x1, x2, x3 := x, x+r, x+w-r, x+w + y0, y1, y2, y3 := y, y+r, y+h-r, y+h + dc.MoveTo(x1, y0) + dc.LineTo(x2, y0) + dc.DrawArc(x2, y1, r, Radians(270), Radians(360)) + dc.LineTo(x3, y2) + dc.DrawArc(x2, y2, r, Radians(0), Radians(90)) + dc.LineTo(x1, y3) + dc.DrawArc(x1, y2, r, Radians(90), Radians(180)) + dc.LineTo(x0, y1) + dc.DrawArc(x1, y1, r, Radians(180), Radians(270)) +} + func (dc *Context) DrawEllipticalArc(x, y, rx, ry, angle1, angle2 float64) { const n = 16 for i := 0; i < n; i++ {