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

View File

@ -5,18 +5,17 @@ package artutil
import "image"
import "image/color"
import "git.tebibyte.media/sashakoshka/tomo/artist"
import "git.tebibyte.media/sashakoshka/tomo/canvas"
import "git.tebibyte.media/sashakoshka/tomo/shatter"
// 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())
return destination.Bounds()
}
// DrawClip lets you draw several subsets of a pattern at once.
func DrawClip (
destination canvas.Canvas,
destination artist.Canvas,
source artist.Pattern,
bounds image.Rectangle,
subsets ...image.Rectangle,
@ -24,7 +23,7 @@ func DrawClip (
updatedRegion image.Rectangle,
) {
for _, subset := range subsets {
source.Draw(canvas.Cut(destination, subset), bounds)
source.Draw(artist.Cut(destination, subset), bounds)
updatedRegion = updatedRegion.Union(subset)
}
return
@ -33,7 +32,7 @@ func DrawClip (
// DrawShatter is like an inverse of DrawClip, drawing nothing in the areas
// specified by "rocks".
func DrawShatter (
destination canvas.Canvas,
destination artist.Canvas,
source artist.Pattern,
bounds image.Rectangle,
rocks ...image.Rectangle,
@ -48,8 +47,8 @@ func DrawShatter (
// 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
// it because that is horrible and cruel to the computer.
func AllocateSample (source artist.Pattern, width, height int) canvas.Canvas {
allocated := canvas.NewBasicCanvas(width, height)
func AllocateSample (source artist.Pattern, width, height int) artist.Canvas {
allocated := artist.NewBasicCanvas(width, height)
Fill(allocated, source)
return allocated
}

View File

@ -1,7 +1,6 @@
package patterns
import "image"
import "git.tebibyte.media/sashakoshka/tomo/canvas"
import "git.tebibyte.media/sashakoshka/tomo/artist"
// 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
// responds well to being resized.
type Border struct {
canvas.Canvas
artist.Canvas
artist.Inset
}
// Draw draws the border pattern onto the destination canvas within the given
// 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())
if drawBounds.Empty() { return }
srcSections := nonasect(pattern.Bounds(), pattern.Inset)
srcTextures := [9]Texture { }
for index, section := range srcSections {
srcTextures[index].Canvas = canvas.Cut(pattern, section)
srcTextures[index].Canvas = artist.Cut(pattern, section)
}
dstSections := nonasect(bounds, pattern.Inset)

View File

@ -1,18 +1,18 @@
package patterns
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
// vertically.
type Texture struct {
canvas.Canvas
artist.Canvas
}
// 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
// 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())
if dstBounds.Empty() { return }

View File

@ -2,19 +2,19 @@ package patterns
import "image"
import "image/color"
import "git.tebibyte.media/sashakoshka/tomo/canvas"
import "git.tebibyte.media/sashakoshka/tomo/artist"
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.
type Uniform color.RGBA
// 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)
}
// Uhex creates a new Uniform pattern from an RGBA integer value.
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 "image"
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
// 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.
func FillEllipse (
destination canvas.Canvas,
source canvas.Canvas,
destination artist.Canvas,
source artist.Canvas,
bounds image.Rectangle,
) (
updatedRegion image.Rectangle,
@ -42,8 +42,8 @@ func FillEllipse (
}
func StrokeEllipse (
destination canvas.Canvas,
source canvas.Canvas,
destination artist.Canvas,
source artist.Canvas,
bounds image.Rectangle,
weight int,
) {
@ -170,7 +170,7 @@ func (context ellipsePlottingContext) plotEllipse () {
// FillColorEllipse fills an ellipse within the destination canvas with a solid
// color.
func FillColorEllipse (
destination canvas.Canvas,
destination artist.Canvas,
color color.RGBA,
bounds image.Rectangle,
) (
@ -196,7 +196,7 @@ func FillColorEllipse (
// StrokeColorEllipse is similar to FillColorEllipse, but it draws an inset
// outline of an ellipse instead.
func StrokeColorEllipse (
destination canvas.Canvas,
destination artist.Canvas,
color color.RGBA,
bounds image.Rectangle,
weight int,

View File

@ -2,12 +2,12 @@ package shapes
import "image"
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
// and color.
func ColorLine (
destination canvas.Canvas,
destination artist.Canvas,
color color.RGBA,
weight int,
min image.Point,

View File

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

View File

@ -2,7 +2,7 @@ package x
import "image"
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/config"

View File

@ -13,7 +13,7 @@ import "github.com/jezek/xgbutil/mousebind"
import "github.com/jezek/xgbutil/xgraphics"
import "git.tebibyte.media/sashakoshka/tomo"
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 menuWindow struct { *window }

View File

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