themes and styles

This commit is contained in:
IliaDenisov
2026-03-08 15:31:17 +02:00
parent e37a67bc99
commit 1c2fc30127
39 changed files with 2693 additions and 199 deletions
+29
View File
@@ -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()
}