Add image textures to theme

This commit is contained in:
Sasha Koshka
2023-02-27 12:48:44 -05:00
parent 449922851f
commit de10cde630
5 changed files with 87 additions and 28 deletions

View File

@@ -44,9 +44,7 @@ func (pattern Border) Draw (destination canvas.Canvas, clip image.Rectangle) {
srcSections := nonasect(pattern.Bounds(), pattern.Inset)
srcTextures := [9]Texture { }
for index, section := range srcSections {
srcTextures[index] = Texture {
Canvas: canvas.Cut(pattern, section),
}
srcTextures[index].Canvas = canvas.Cut(pattern, section)
}
dstSections := nonasect(destination.Bounds(), pattern.Inset)

View File

@@ -12,7 +12,8 @@ type Texture struct {
// Draw tiles the pattern's canvas within the clipping bounds. The minimum
// points of the pattern's canvas and the destination canvas will be lined up.
func (pattern Texture) Draw (destination canvas.Canvas, clip image.Rectangle) {
bounds := clip.Canon().Intersect(destination.Bounds())
realBounds := destination.Bounds()
bounds := clip.Canon().Intersect(realBounds)
if bounds.Empty() { return }
dstData, dstStride := destination.Buffer()
@@ -23,8 +24,8 @@ func (pattern Texture) Draw (destination canvas.Canvas, clip image.Rectangle) {
for x := bounds.Min.X; x < bounds.Max.X; x ++ {
dstIndex := x + y * dstStride
srcIndex :=
wrap(x - bounds.Min.X, srcBounds.Min.X, srcBounds.Max.X) +
wrap(x - bounds.Min.Y, srcBounds.Min.Y, srcBounds.Max.Y) * srcStride
wrap(x - realBounds.Min.X, srcBounds.Min.X, srcBounds.Max.X) +
wrap(y - realBounds.Min.Y, srcBounds.Min.Y, srcBounds.Max.Y) * srcStride
dstData[dstIndex] = srcData[srcIndex]
}}
}