themes and styles
This commit is contained in:
@@ -74,6 +74,10 @@ type PrimitiveDrawer interface {
|
||||
// Clear operations must NOT change clip state.
|
||||
ClearAllTo(bg color.Color)
|
||||
ClearRectTo(x, y, w, h int, bg color.Color)
|
||||
|
||||
DrawImage(img image.Image, x, y int)
|
||||
|
||||
DrawImageScaled(img image.Image, x, y, w, h int)
|
||||
}
|
||||
|
||||
// ggClipRect stores one clip rectangle in canvas pixel coordinates.
|
||||
@@ -336,3 +340,28 @@ func (d *GGDrawer) ClearRectTo(x, y, w, h int, bg color.Color) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GGDrawer) DrawImage(img image.Image, x, y int) {
|
||||
g.DC.DrawImage(img, x, y)
|
||||
}
|
||||
|
||||
func (g *GGDrawer) DrawImageScaled(img image.Image, x, y, w, h int) {
|
||||
if w <= 0 || h <= 0 {
|
||||
return
|
||||
}
|
||||
b := img.Bounds()
|
||||
srcW := b.Dx()
|
||||
srcH := b.Dy()
|
||||
if srcW <= 0 || srcH <= 0 {
|
||||
return
|
||||
}
|
||||
|
||||
g.DC.Push()
|
||||
// Translate to destination top-left.
|
||||
g.DC.Translate(float64(x), float64(y))
|
||||
// Scale so that the source bounds map to (w,h).
|
||||
g.DC.Scale(float64(w)/float64(srcW), float64(h)/float64(srcH))
|
||||
// Draw at origin in the scaled coordinate system.
|
||||
g.DC.DrawImage(img, 0, 0)
|
||||
g.DC.Pop()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user