From c3c6ff61f50b0f12d494a7ce5039d09978c4a19f Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Tue, 5 Sep 2023 18:14:36 -0400 Subject: [PATCH] Add Tiler interface --- canvas/canvas.go | 1 + canvas/texture.go | 16 ++++++++++++++++ object.go | 2 ++ 3 files changed, 19 insertions(+) diff --git a/canvas/canvas.go b/canvas/canvas.go index 8468f98..64d4273 100644 --- a/canvas/canvas.go +++ b/canvas/canvas.go @@ -47,6 +47,7 @@ type Pen interface { Stroke (color.Color) // Sets the stroke to a solid color Fill (color.Color) // Sets the fill to a solid color Texture (Texture) // Overlaps a texture onto the fill color + Tiler (Tiler) // Changes the way the texture is tiled } // Canvas is an image that supports drawing paths. diff --git a/canvas/texture.go b/canvas/texture.go index 6fb2a05..fe269a5 100644 --- a/canvas/texture.go +++ b/canvas/texture.go @@ -18,3 +18,19 @@ type TextureCloser interface { Texture io.Closer } + +// TileArea represents a tiled area of a texture. +type TileArea struct { + // Source specifies an area of the texture to sample. + Source image.Rectangle + + // Destination specifies an area of the destination to draw the texture + // onto. If Destination is bigger than Source, the empty space will be + // filled by tiling the texture (clipped to source) normally. + Destination image.Rectangle +} + +// Tiler is a type that changes the way a texture is drawn. +type Tiler interface { + Tile (image.Rectangle, Texture) []TileArea +} diff --git a/object.go b/object.go index 869cd45..2b3d246 100644 --- a/object.go +++ b/object.go @@ -136,6 +136,8 @@ type Box interface { // transparent, it will be overlayed atop the color specified by // SetColor(). SetTexture (canvas.Texture) + // SetTiler changes the way the texture is tiled. + SetTiler (canvas.Tiler) // SetBorder sets the Border(s) of the box. The first Border will be the // most outset, and the last Border will be the most inset. SetBorder (...Border)