func draw(widget Widget, gc graphic.Context, clip geom.Rect, origin geom.Point) { bounds := widget.Bounds() if clip.Intersect(geom.Rect{ X: bounds.X + origin.X, Y: bounds.Y + origin.Y, W: bounds.W, H: bounds.H, }).Empty() { return } gc.Save() gc.Configure(graphic.State{ Transform: graphic.Translation(bounds.X, bounds.Y), Clip: geom.Rect{W: bounds.W, H: bounds.H}, }) if d, ok := widget.(Drawable); ok { d.Draw(gc) } if c, ok := widget.(Container); ok { origin = bounds.Origin() for _, w := range c.Children() { draw(w, gc, clip, origin) } } gc.Restore() }
func (self *Image) Draw(gc graphic.Context) { if self.area.Size() == self.imageSize() { // When the image is rendered in its natural size we turn off // interpolation to get a more accurate visual. gc.Configure(graphic.State{ Interpolation: graphic.InterpolationNone, }) } gc.Draw(self.Image(), self.area) if self.selected() { gc.Configure(graphic.State{ Color: color.NRGBA{153, 204, 255, 200}, }) gc.Fill(self.area) } }