func (c *Checkbox) draw(gc draw2d.GraphicContext) { gc.Clear() gc.SetStrokeColor(color.Black) if c.pressed { gc.SetFillColor(color.RGBA{155, 0, 0, 255}) } else { gc.SetFillColor(color.RGBA{255, 0, 0, 255}) } // Draw background rect x, y := gc.LastPoint() gc.MoveTo(0, 0) gc.LineTo(c.Size.X, 0) gc.LineTo(c.Size.X, c.Size.Y) gc.LineTo(0, c.Size.Y) gc.Close() gc.FillStroke() // Draw inner rect if c.state { gc.SetFillColor(color.Black) gc.MoveTo(5, 5) gc.LineTo(c.Size.X-5, 5) gc.LineTo(c.Size.X-5, c.Size.Y-5) gc.LineTo(5, c.Size.Y-5) gc.Close() gc.FillStroke() } gc.MoveTo(x, y) }
func safeRect(path draw2d.GraphicContext, min, max Coord) { x1, y1 := min.X, min.Y x2, y2 := max.X, max.Y x, y := path.LastPoint() path.MoveTo(x1, y1) path.LineTo(x2, y1) path.LineTo(x2, y2) path.LineTo(x1, y2) path.Close() path.MoveTo(x, y) }