This commit is contained in:
Sasha Koshka 2023-04-30 13:45:21 -04:00
parent b92bdced9c
commit 800ee2570f
18 changed files with 38 additions and 51 deletions

View File

@ -5,18 +5,17 @@ package artutil
import "image" import "image"
import "image/color" import "image/color"
import "git.tebibyte.media/sashakoshka/tomo/artist" import "git.tebibyte.media/sashakoshka/tomo/artist"
import "git.tebibyte.media/sashakoshka/tomo/canvas"
import "git.tebibyte.media/sashakoshka/tomo/shatter" import "git.tebibyte.media/sashakoshka/tomo/shatter"
// Fill fills the destination canvas with the given pattern. // Fill fills the destination canvas with the given pattern.
func Fill (destination canvas.Canvas, source artist.Pattern) (updated image.Rectangle) { func Fill (destination artist.Canvas, source artist.Pattern) (updated image.Rectangle) {
source.Draw(destination, destination.Bounds()) source.Draw(destination, destination.Bounds())
return destination.Bounds() return destination.Bounds()
} }
// DrawClip lets you draw several subsets of a pattern at once. // DrawClip lets you draw several subsets of a pattern at once.
func DrawClip ( func DrawClip (
destination canvas.Canvas, destination artist.Canvas,
source artist.Pattern, source artist.Pattern,
bounds image.Rectangle, bounds image.Rectangle,
subsets ...image.Rectangle, subsets ...image.Rectangle,
@ -24,7 +23,7 @@ func DrawClip (
updatedRegion image.Rectangle, updatedRegion image.Rectangle,
) { ) {
for _, subset := range subsets { for _, subset := range subsets {
source.Draw(canvas.Cut(destination, subset), bounds) source.Draw(artist.Cut(destination, subset), bounds)
updatedRegion = updatedRegion.Union(subset) updatedRegion = updatedRegion.Union(subset)
} }
return return
@ -33,7 +32,7 @@ func DrawClip (
// DrawShatter is like an inverse of DrawClip, drawing nothing in the areas // DrawShatter is like an inverse of DrawClip, drawing nothing in the areas
// specified by "rocks". // specified by "rocks".
func DrawShatter ( func DrawShatter (
destination canvas.Canvas, destination artist.Canvas,
source artist.Pattern, source artist.Pattern,
bounds image.Rectangle, bounds image.Rectangle,
rocks ...image.Rectangle, rocks ...image.Rectangle,
@ -48,8 +47,8 @@ func DrawShatter (
// resulting canvas can be sourced from shape drawing functions. I beg of you // resulting canvas can be sourced from shape drawing functions. I beg of you
// please do not call this every time you need to draw a shape with a pattern on // please do not call this every time you need to draw a shape with a pattern on
// it because that is horrible and cruel to the computer. // it because that is horrible and cruel to the computer.
func AllocateSample (source artist.Pattern, width, height int) canvas.Canvas { func AllocateSample (source artist.Pattern, width, height int) artist.Canvas {
allocated := canvas.NewBasicCanvas(width, height) allocated := artist.NewBasicCanvas(width, height)
Fill(allocated, source) Fill(allocated, source)
return allocated return allocated
} }

View File

@ -1,7 +1,6 @@
package patterns package patterns
import "image" import "image"
import "git.tebibyte.media/sashakoshka/tomo/canvas"
import "git.tebibyte.media/sashakoshka/tomo/artist" import "git.tebibyte.media/sashakoshka/tomo/artist"
// Border is a pattern that behaves similarly to border-image in CSS. It divides // Border is a pattern that behaves similarly to border-image in CSS. It divides
@ -31,20 +30,20 @@ import "git.tebibyte.media/sashakoshka/tomo/artist"
// This pattern can be used to make a static image texture into something that // This pattern can be used to make a static image texture into something that
// responds well to being resized. // responds well to being resized.
type Border struct { type Border struct {
canvas.Canvas artist.Canvas
artist.Inset artist.Inset
} }
// Draw draws the border pattern onto the destination canvas within the given // Draw draws the border pattern onto the destination canvas within the given
// bounds. // bounds.
func (pattern Border) Draw (destination canvas.Canvas, bounds image.Rectangle) { func (pattern Border) Draw (destination artist.Canvas, bounds image.Rectangle) {
drawBounds := bounds.Canon().Intersect(destination.Bounds()) drawBounds := bounds.Canon().Intersect(destination.Bounds())
if drawBounds.Empty() { return } if drawBounds.Empty() { return }
srcSections := nonasect(pattern.Bounds(), pattern.Inset) srcSections := nonasect(pattern.Bounds(), pattern.Inset)
srcTextures := [9]Texture { } srcTextures := [9]Texture { }
for index, section := range srcSections { for index, section := range srcSections {
srcTextures[index].Canvas = canvas.Cut(pattern, section) srcTextures[index].Canvas = artist.Cut(pattern, section)
} }
dstSections := nonasect(bounds, pattern.Inset) dstSections := nonasect(bounds, pattern.Inset)

View File

@ -1,18 +1,18 @@
package patterns package patterns
import "image" import "image"
import "git.tebibyte.media/sashakoshka/tomo/canvas" import "git.tebibyte.media/sashakoshka/tomo/artist"
// Texture is a pattern that tiles the content of a canvas both horizontally and // Texture is a pattern that tiles the content of a canvas both horizontally and
// vertically. // vertically.
type Texture struct { type Texture struct {
canvas.Canvas artist.Canvas
} }
// Draw tiles the pattern's canvas within the given bounds. The minimum // Draw tiles the pattern's canvas within the given bounds. The minimum
// point of the pattern's canvas will be lined up with the minimum point of the // point of the pattern's canvas will be lined up with the minimum point of the
// bounding rectangle. // bounding rectangle.
func (pattern Texture) Draw (destination canvas.Canvas, bounds image.Rectangle) { func (pattern Texture) Draw (destination artist.Canvas, bounds image.Rectangle) {
dstBounds := bounds.Canon().Intersect(destination.Bounds()) dstBounds := bounds.Canon().Intersect(destination.Bounds())
if dstBounds.Empty() { return } if dstBounds.Empty() { return }

View File

@ -2,19 +2,19 @@ package patterns
import "image" import "image"
import "image/color" import "image/color"
import "git.tebibyte.media/sashakoshka/tomo/canvas"
import "git.tebibyte.media/sashakoshka/tomo/artist" import "git.tebibyte.media/sashakoshka/tomo/artist"
import "git.tebibyte.media/sashakoshka/tomo/artist/shapes" import "git.tebibyte.media/sashakoshka/tomo/artist/shapes"
import "git.tebibyte.media/sashakoshka/tomo/artist/artutil"
// Uniform is a pattern that draws a solid color. // Uniform is a pattern that draws a solid color.
type Uniform color.RGBA type Uniform color.RGBA
// Draw fills the bounding rectangle with the pattern's color. // Draw fills the bounding rectangle with the pattern's color.
func (pattern Uniform) Draw (destination canvas.Canvas, bounds image.Rectangle) { func (pattern Uniform) Draw (destination artist.Canvas, bounds image.Rectangle) {
shapes.FillColorRectangle(destination, color.RGBA(pattern), bounds) shapes.FillColorRectangle(destination, color.RGBA(pattern), bounds)
} }
// Uhex creates a new Uniform pattern from an RGBA integer value. // Uhex creates a new Uniform pattern from an RGBA integer value.
func Uhex (color uint32) (uniform Uniform) { func Uhex (color uint32) (uniform Uniform) {
return Uniform(artist.Hex(color)) return Uniform(artutil.Hex(color))
} }

View File

@ -3,7 +3,7 @@ package shapes
import "math" import "math"
import "image" import "image"
import "image/color" import "image/color"
import "git.tebibyte.media/sashakoshka/tomo/canvas" import "git.tebibyte.media/sashakoshka/tomo/artist"
// TODO: redo fill ellipse, stroke ellipse, etc. so that it only takes in // TODO: redo fill ellipse, stroke ellipse, etc. so that it only takes in
// destination and source, using the bounds of destination as the bounds of the // destination and source, using the bounds of destination as the bounds of the
@ -11,8 +11,8 @@ import "git.tebibyte.media/sashakoshka/tomo/canvas"
// of both canvases. // of both canvases.
func FillEllipse ( func FillEllipse (
destination canvas.Canvas, destination artist.Canvas,
source canvas.Canvas, source artist.Canvas,
bounds image.Rectangle, bounds image.Rectangle,
) ( ) (
updatedRegion image.Rectangle, updatedRegion image.Rectangle,
@ -42,8 +42,8 @@ func FillEllipse (
} }
func StrokeEllipse ( func StrokeEllipse (
destination canvas.Canvas, destination artist.Canvas,
source canvas.Canvas, source artist.Canvas,
bounds image.Rectangle, bounds image.Rectangle,
weight int, weight int,
) { ) {
@ -170,7 +170,7 @@ func (context ellipsePlottingContext) plotEllipse () {
// FillColorEllipse fills an ellipse within the destination canvas with a solid // FillColorEllipse fills an ellipse within the destination canvas with a solid
// color. // color.
func FillColorEllipse ( func FillColorEllipse (
destination canvas.Canvas, destination artist.Canvas,
color color.RGBA, color color.RGBA,
bounds image.Rectangle, bounds image.Rectangle,
) ( ) (
@ -196,7 +196,7 @@ func FillColorEllipse (
// StrokeColorEllipse is similar to FillColorEllipse, but it draws an inset // StrokeColorEllipse is similar to FillColorEllipse, but it draws an inset
// outline of an ellipse instead. // outline of an ellipse instead.
func StrokeColorEllipse ( func StrokeColorEllipse (
destination canvas.Canvas, destination artist.Canvas,
color color.RGBA, color color.RGBA,
bounds image.Rectangle, bounds image.Rectangle,
weight int, weight int,

View File

@ -2,12 +2,12 @@ package shapes
import "image" import "image"
import "image/color" import "image/color"
import "git.tebibyte.media/sashakoshka/tomo/canvas" import "git.tebibyte.media/sashakoshka/tomo/artist"
// ColorLine draws a line from one point to another with the specified weight // ColorLine draws a line from one point to another with the specified weight
// and color. // and color.
func ColorLine ( func ColorLine (
destination canvas.Canvas, destination artist.Canvas,
color color.RGBA, color color.RGBA,
weight int, weight int,
min image.Point, min image.Point,

View File

@ -2,14 +2,14 @@ package shapes
import "image" import "image"
import "image/color" import "image/color"
import "git.tebibyte.media/sashakoshka/tomo/canvas" import "git.tebibyte.media/sashakoshka/tomo/artist"
import "git.tebibyte.media/sashakoshka/tomo/shatter" import "git.tebibyte.media/sashakoshka/tomo/shatter"
// TODO: return updatedRegion for all routines in this package // TODO: return updatedRegion for all routines in this package
func FillRectangle ( func FillRectangle (
destination canvas.Canvas, destination artist.Canvas,
source canvas.Canvas, source artist.Canvas,
bounds image.Rectangle, bounds image.Rectangle,
) ( ) (
updatedRegion image.Rectangle, updatedRegion image.Rectangle,
@ -38,8 +38,8 @@ func FillRectangle (
} }
func StrokeRectangle ( func StrokeRectangle (
destination canvas.Canvas, destination artist.Canvas,
source canvas.Canvas, source artist.Canvas,
bounds image.Rectangle, bounds image.Rectangle,
weight int, weight int,
) ( ) (
@ -55,8 +55,8 @@ func StrokeRectangle (
// FillRectangleShatter is like FillRectangle, but it does not draw in areas // FillRectangleShatter is like FillRectangle, but it does not draw in areas
// specified in "rocks". // specified in "rocks".
func FillRectangleShatter ( func FillRectangleShatter (
destination canvas.Canvas, destination artist.Canvas,
source canvas.Canvas, source artist.Canvas,
bounds image.Rectangle, bounds image.Rectangle,
rocks ...image.Rectangle, rocks ...image.Rectangle,
) ( ) (
@ -65,7 +65,7 @@ func FillRectangleShatter (
tiles := shatter.Shatter(bounds, rocks...) tiles := shatter.Shatter(bounds, rocks...)
for _, tile := range tiles { for _, tile := range tiles {
FillRectangle ( FillRectangle (
canvas.Cut(destination, tile), artist.Cut(destination, tile),
source, tile) source, tile)
updatedRegion = updatedRegion.Union(tile) updatedRegion = updatedRegion.Union(tile)
} }
@ -75,7 +75,7 @@ func FillRectangleShatter (
// FillColorRectangle fills a rectangle within the destination canvas with a // FillColorRectangle fills a rectangle within the destination canvas with a
// solid color. // solid color.
func FillColorRectangle ( func FillColorRectangle (
destination canvas.Canvas, destination artist.Canvas,
color color.RGBA, color color.RGBA,
bounds image.Rectangle, bounds image.Rectangle,
) ( ) (
@ -97,7 +97,7 @@ func FillColorRectangle (
// FillColorRectangleShatter is like FillColorRectangle, but it does not draw in // FillColorRectangleShatter is like FillColorRectangle, but it does not draw in
// areas specified in "rocks". // areas specified in "rocks".
func FillColorRectangleShatter ( func FillColorRectangleShatter (
destination canvas.Canvas, destination artist.Canvas,
color color.RGBA, color color.RGBA,
bounds image.Rectangle, bounds image.Rectangle,
rocks ...image.Rectangle, rocks ...image.Rectangle,
@ -115,7 +115,7 @@ func FillColorRectangleShatter (
// StrokeColorRectangle is similar to FillColorRectangle, but it draws an inset // StrokeColorRectangle is similar to FillColorRectangle, but it draws an inset
// outline of the given rectangle instead. // outline of the given rectangle instead.
func StrokeColorRectangle ( func StrokeColorRectangle (
destination canvas.Canvas, destination artist.Canvas,
color color.RGBA, color color.RGBA,
bounds image.Rectangle, bounds image.Rectangle,
weight int, weight int,

View File

@ -1,4 +0,0 @@
// Package all links most common backends.
package all
import _ "git.tebibyte.media/sashakoshka/tomo/backends/x"

View File

@ -1,3 +0,0 @@
// Package backends contains sub-packages that register backends with tomo when
// linked into a program.
package backends

View File

@ -2,7 +2,7 @@ package x
import "image" import "image"
import "git.tebibyte.media/sashakoshka/tomo" import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/canvas" import "git.tebibyte.media/sashakoshka/tomo/artist"
type entity struct { type entity struct {
window *window window *window

View File

@ -2,7 +2,7 @@ package x
import "image" import "image"
import "git.tebibyte.media/sashakoshka/tomo" import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/canvas" import "git.tebibyte.media/sashakoshka/tomo/artist"
import "git.tebibyte.media/sashakoshka/tomo/default/theme" import "git.tebibyte.media/sashakoshka/tomo/default/theme"
import "git.tebibyte.media/sashakoshka/tomo/default/config" import "git.tebibyte.media/sashakoshka/tomo/default/config"

View File

@ -13,7 +13,7 @@ import "github.com/jezek/xgbutil/mousebind"
import "github.com/jezek/xgbutil/xgraphics" import "github.com/jezek/xgbutil/xgraphics"
import "git.tebibyte.media/sashakoshka/tomo" import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/data" import "git.tebibyte.media/sashakoshka/tomo/data"
import "git.tebibyte.media/sashakoshka/tomo/canvas" import "git.tebibyte.media/sashakoshka/tomo/artist"
type mainWindow struct { *window } type mainWindow struct { *window }
type menuWindow struct { *window } type menuWindow struct { *window }

View File

@ -121,7 +121,3 @@ func (backend *Backend) SetConfig (config tomo.Config) {
func (backend *Backend) assert () { func (backend *Backend) assert () {
if backend == nil { panic("nil backend") } if backend == nil { panic("nil backend") }
} }
func init () {
tomo.RegisterBackend(NewBackend)
}