Moved artist (now art) into another repo

This commit is contained in:
Sasha Koshka 2023-05-03 20:17:48 -04:00
parent 54ea1c283f
commit 501eb34922
36 changed files with 191 additions and 186 deletions

View File

@ -4,7 +4,7 @@ package ability
import "image" import "image"
import "tomo" import "tomo"
import "tomo/input" import "tomo/input"
import "tomo/artist" import "art"
// Layoutable represents an element that needs to perform layout calculations // Layoutable represents an element that needs to perform layout calculations
// before it can draw itself. // before it can draw itself.
@ -24,7 +24,7 @@ type Container interface {
// the specified canvas. The bounds of this canvas specify the area that // the specified canvas. The bounds of this canvas specify the area that
// is actually drawn to, while the Entity bounds specify the actual area // is actually drawn to, while the Entity bounds specify the actual area
// of the element. // of the element.
DrawBackground (artist.Canvas) DrawBackground (art.Canvas)
// HandleChildMinimumSizeChange is called when a child's minimum size is // HandleChildMinimumSizeChange is called when a child's minimum size is
// changed. // changed.

View File

@ -9,14 +9,14 @@ import "golang.org/x/image/font"
import "golang.org/x/image/font/basicfont" import "golang.org/x/image/font/basicfont"
import "tomo" import "tomo"
import "tomo/data" import "tomo/data"
import "tomo/artist" import "art"
import "tomo/artist/artutil" import "art/artutil"
import "tomo/artist/patterns" import "art/patterns"
//go:embed assets/default.png //go:embed assets/default.png
var defaultAtlasBytes []byte var defaultAtlasBytes []byte
var defaultAtlas artist.Canvas var defaultAtlas art.Canvas
var defaultTextures [7][7]artist.Pattern var defaultTextures [7][7]art.Pattern
//go:embed assets/wintergreen-icons-small.png //go:embed assets/wintergreen-icons-small.png
var defaultIconsSmallAtlasBytes []byte var defaultIconsSmallAtlasBytes []byte
var defaultIconsSmall [640]binaryIcon var defaultIconsSmall [640]binaryIcon
@ -24,15 +24,15 @@ var defaultIconsSmall [640]binaryIcon
var defaultIconsLargeAtlasBytes []byte var defaultIconsLargeAtlasBytes []byte
var defaultIconsLarge [640]binaryIcon var defaultIconsLarge [640]binaryIcon
func atlasCell (col, row int, border artist.Inset) { func atlasCell (col, row int, border art.Inset) {
bounds := image.Rect(0, 0, 8, 8).Add(image.Pt(col, row).Mul(8)) bounds := image.Rect(0, 0, 8, 8).Add(image.Pt(col, row).Mul(8))
defaultTextures[col][row] = patterns.Border { defaultTextures[col][row] = patterns.Border {
Canvas: artist.Cut(defaultAtlas, bounds), Canvas: art.Cut(defaultAtlas, bounds),
Inset: border, Inset: border,
} }
} }
func atlasCol (col int, border artist.Inset) { func atlasCol (col int, border art.Inset) {
for index, _ := range defaultTextures[col] { for index, _ := range defaultTextures[col] {
atlasCell(col, index, border) atlasCell(col, index, border)
} }
@ -43,7 +43,7 @@ type binaryIcon struct {
stride int stride int
} }
func (icon binaryIcon) Draw (destination artist.Canvas, color color.RGBA, at image.Point) { func (icon binaryIcon) Draw (destination art.Canvas, color color.RGBA, at image.Point) {
bounds := icon.Bounds().Add(at).Intersect(destination.Bounds()) bounds := icon.Bounds().Add(at).Intersect(destination.Bounds())
point := image.Point { } point := image.Point { }
data, stride := destination.Buffer() data, stride := destination.Buffer()
@ -85,15 +85,15 @@ func binaryIconFrom (source image.Image, clip image.Rectangle) (icon binaryIcon)
func init () { func init () {
defaultAtlasImage, _, _ := image.Decode(bytes.NewReader(defaultAtlasBytes)) defaultAtlasImage, _, _ := image.Decode(bytes.NewReader(defaultAtlasBytes))
defaultAtlas = artist.FromImage(defaultAtlasImage) defaultAtlas = art.FromImage(defaultAtlasImage)
atlasCol(0, artist.I(0)) atlasCol(0, art.I(0))
atlasCol(1, artist.I(3)) atlasCol(1, art.I(3))
atlasCol(2, artist.I(1)) atlasCol(2, art.I(1))
atlasCol(3, artist.I(1)) atlasCol(3, art.I(1))
atlasCol(4, artist.I(1)) atlasCol(4, art.I(1))
atlasCol(5, artist.I(3)) atlasCol(5, art.I(3))
atlasCol(6, artist.I(1)) atlasCol(6, art.I(1))
// set up small icons // set up small icons
defaultIconsSmallAtlasImage, _, _ := image.Decode ( defaultIconsSmallAtlasImage, _, _ := image.Decode (
@ -139,7 +139,7 @@ func (Default) FontFace (style tomo.FontStyle, size tomo.FontSize, c tomo.Case)
} }
// Icon returns an icon from the default set corresponding to the given name. // Icon returns an icon from the default set corresponding to the given name.
func (Default) Icon (id tomo.Icon, size tomo.IconSize, c tomo.Case) artist.Icon { func (Default) Icon (id tomo.Icon, size tomo.IconSize, c tomo.Case) art.Icon {
if size == tomo.IconSizeLarge { if size == tomo.IconSizeLarge {
if id < 0 || int(id) >= len(defaultIconsLarge) { if id < 0 || int(id) >= len(defaultIconsLarge) {
return nil return nil
@ -157,14 +157,14 @@ func (Default) Icon (id tomo.Icon, size tomo.IconSize, c tomo.Case) artist.Icon
// MimeIcon returns an icon from the default set corresponding to the given mime. // MimeIcon returns an icon from the default set corresponding to the given mime.
// type. // type.
func (Default) MimeIcon (data.Mime, tomo.IconSize, tomo.Case) artist.Icon { func (Default) MimeIcon (data.Mime, tomo.IconSize, tomo.Case) art.Icon {
// TODO // TODO
return nil return nil
} }
// Pattern returns a pattern from the default theme corresponding to the given // Pattern returns a pattern from the default theme corresponding to the given
// pattern ID. // pattern ID.
func (Default) Pattern (id tomo.Pattern, state tomo.State, c tomo.Case) artist.Pattern { func (Default) Pattern (id tomo.Pattern, state tomo.State, c tomo.Case) art.Pattern {
offset := 0; switch { offset := 0; switch {
case state.Disabled: offset = 1 case state.Disabled: offset = 1
case state.Pressed && state.On: offset = 4 case state.Pressed && state.On: offset = 4
@ -224,11 +224,11 @@ func (Default) Color (id tomo.Color, state tomo.State, c tomo.Case) color.RGBA {
} }
// Padding returns the default padding value for the given pattern. // Padding returns the default padding value for the given pattern.
func (Default) Padding (id tomo.Pattern, c tomo.Case) artist.Inset { func (Default) Padding (id tomo.Pattern, c tomo.Case) art.Inset {
switch id { switch id {
case tomo.PatternGutter: return artist.I(0) case tomo.PatternGutter: return art.I(0)
case tomo.PatternLine: return artist.I(1) case tomo.PatternLine: return art.I(1)
default: return artist.I(6) default: return art.I(6)
} }
} }

View File

@ -1,6 +1,6 @@
package tomo package tomo
import "tomo/artist" import "art"
// Element represents a basic on-screen object. Extended element interfaces are // Element represents a basic on-screen object. Extended element interfaces are
// defined in the ability module. // defined in the ability module.
@ -8,7 +8,7 @@ type Element interface {
// Draw causes the element to draw to the specified canvas. The bounds // Draw causes the element to draw to the specified canvas. The bounds
// of this canvas specify the area that is actually drawn to, while the // of this canvas specify the area that is actually drawn to, while the
// Entity bounds specify the actual area of the element. // Entity bounds specify the actual area of the element.
Draw (artist.Canvas) Draw (art.Canvas)
// Entity returns this element's entity. // Entity returns this element's entity.
Entity () Entity Entity () Entity

View File

@ -2,8 +2,8 @@ package elements
import "image" import "image"
import "tomo" import "tomo"
import "tomo/artist" import "art"
import "tomo/shatter" import "art/shatter"
var boxCase = tomo.C("tomo", "box") var boxCase = tomo.C("tomo", "box")
@ -61,7 +61,7 @@ func NewVBox (space Space, children ...tomo.Element) (element *Box) {
} }
// Draw causes the element to draw to the specified destination canvas. // Draw causes the element to draw to the specified destination canvas.
func (element *Box) Draw (destination artist.Canvas) { func (element *Box) Draw (destination art.Canvas) {
rocks := make([]image.Rectangle, element.entity.CountChildren()) rocks := make([]image.Rectangle, element.entity.CountChildren())
for index := 0; index < element.entity.CountChildren(); index ++ { for index := 0; index < element.entity.CountChildren(); index ++ {
rocks[index] = element.entity.Child(index).Entity().Bounds() rocks[index] = element.entity.Child(index).Entity().Bounds()
@ -69,7 +69,7 @@ func (element *Box) Draw (destination artist.Canvas) {
tiles := shatter.Shatter(element.entity.Bounds(), rocks...) tiles := shatter.Shatter(element.entity.Bounds(), rocks...)
for _, tile := range tiles { for _, tile := range tiles {
element.entity.DrawBackground(artist.Cut(destination, tile)) element.entity.DrawBackground(art.Cut(destination, tile))
} }
} }
@ -126,7 +126,7 @@ func (element *Box) AdoptExpand (children ...tomo.Element) {
// DrawBackground draws this element's background pattern to the specified // DrawBackground draws this element's background pattern to the specified
// destination canvas. // destination canvas.
func (element *Box) DrawBackground (destination artist.Canvas) { func (element *Box) DrawBackground (destination art.Canvas) {
element.entity.DrawBackground(destination) element.entity.DrawBackground(destination)
} }

View File

@ -3,7 +3,7 @@ package elements
import "image" import "image"
import "tomo" import "tomo"
import "tomo/input" import "tomo/input"
import "tomo/artist" import "art"
import "tomo/textdraw" import "tomo/textdraw"
var buttonCase = tomo.C("tomo", "button") var buttonCase = tomo.C("tomo", "button")
@ -42,7 +42,7 @@ func (element *Button) Entity () tomo.Entity {
} }
// Draw causes the element to draw to the specified destination canvas. // Draw causes the element to draw to the specified destination canvas.
func (element *Button) Draw (destination artist.Canvas) { func (element *Button) Draw (destination art.Canvas) {
state := element.state() state := element.state()
bounds := element.entity.Bounds() bounds := element.entity.Bounds()
pattern := element.entity.Theme().Pattern(tomo.PatternButton, state, buttonCase) pattern := element.entity.Theme().Pattern(tomo.PatternButton, state, buttonCase)

View File

@ -1,8 +1,8 @@
package elements package elements
import "tomo" import "tomo"
import "tomo/artist" import "art"
import "tomo/artist/artutil" import "art/artutil"
var cellCase = tomo.C("tomo", "cell") var cellCase = tomo.C("tomo", "cell")
@ -32,7 +32,7 @@ func (element *Cell) Entity () tomo.Entity {
} }
// Draw causes the element to draw to the specified destination canvas. // Draw causes the element to draw to the specified destination canvas.
func (element *Cell) Draw (destination artist.Canvas) { func (element *Cell) Draw (destination art.Canvas) {
bounds := element.entity.Bounds() bounds := element.entity.Bounds()
pattern := element.entity.Theme().Pattern(tomo.PatternTableCell, element.state(), cellCase) pattern := element.entity.Theme().Pattern(tomo.PatternTableCell, element.state(), cellCase)
if element.child == nil { if element.child == nil {
@ -56,7 +56,7 @@ func (element *Cell) Layout () {
// DrawBackground draws this element's background pattern to the specified // DrawBackground draws this element's background pattern to the specified
// destination canvas. // destination canvas.
func (element *Cell) DrawBackground (destination artist.Canvas) { func (element *Cell) DrawBackground (destination art.Canvas) {
element.entity.Theme().Pattern(tomo.PatternTableCell, element.state(), cellCase). element.entity.Theme().Pattern(tomo.PatternTableCell, element.state(), cellCase).
Draw(destination, element.entity.Bounds()) Draw(destination, element.entity.Bounds())
} }

View File

@ -3,7 +3,7 @@ package elements
import "image" import "image"
import "tomo" import "tomo"
import "tomo/input" import "tomo/input"
import "tomo/artist" import "art"
import "tomo/textdraw" import "tomo/textdraw"
var checkboxCase = tomo.C("tomo", "checkbox") var checkboxCase = tomo.C("tomo", "checkbox")
@ -39,7 +39,7 @@ func (element *Checkbox) Entity () tomo.Entity {
} }
// Draw causes the element to draw to the specified destination canvas. // Draw causes the element to draw to the specified destination canvas.
func (element *Checkbox) Draw (destination artist.Canvas) { func (element *Checkbox) Draw (destination art.Canvas) {
bounds := element.entity.Bounds() bounds := element.entity.Bounds()
boxBounds := image.Rect(0, 0, bounds.Dy(), bounds.Dy()).Add(bounds.Min) boxBounds := image.Rect(0, 0, bounds.Dy(), bounds.Dy()).Add(bounds.Min)

View File

@ -3,7 +3,7 @@ package elements
import "image" import "image"
import "tomo" import "tomo"
import "tomo/input" import "tomo/input"
import "tomo/artist" import "art"
import "tomo/ability" import "tomo/ability"
import "tomo/textdraw" import "tomo/textdraw"
@ -53,7 +53,7 @@ func (element *ComboBox) Entity () tomo.Entity {
} }
// Draw causes the element to draw to the specified destination canvas. // Draw causes the element to draw to the specified destination canvas.
func (element *ComboBox) Draw (destination artist.Canvas) { func (element *ComboBox) Draw (destination art.Canvas) {
state := element.state() state := element.state()
bounds := element.entity.Bounds() bounds := element.entity.Bounds()
pattern := element.entity.Theme().Pattern(tomo.PatternButton, state, comboBoxCase) pattern := element.entity.Theme().Pattern(tomo.PatternButton, state, comboBoxCase)

View File

@ -4,9 +4,9 @@ import "image"
import "path/filepath" import "path/filepath"
import "tomo" import "tomo"
import "tomo/input" import "tomo/input"
import "tomo/artist" import "art"
import "tomo/ability" import "tomo/ability"
import "tomo/shatter" import "art/shatter"
// TODO: base on flow implementation of list. also be able to switch to a table // TODO: base on flow implementation of list. also be able to switch to a table
// variant for a more information dense view. // variant for a more information dense view.
@ -52,7 +52,7 @@ func NewDirectory (
return return
} }
func (element *Directory) Draw (destination artist.Canvas) { func (element *Directory) Draw (destination art.Canvas) {
rocks := make([]image.Rectangle, element.entity.CountChildren()) rocks := make([]image.Rectangle, element.entity.CountChildren())
for index := 0; index < element.entity.CountChildren(); index ++ { for index := 0; index < element.entity.CountChildren(); index ++ {
rocks[index] = element.entity.Child(index).Entity().Bounds() rocks[index] = element.entity.Child(index).Entity().Bounds()
@ -60,7 +60,7 @@ func (element *Directory) Draw (destination artist.Canvas) {
tiles := shatter.Shatter(element.entity.Bounds(), rocks...) tiles := shatter.Shatter(element.entity.Bounds(), rocks...)
for _, tile := range tiles { for _, tile := range tiles {
element.DrawBackground(artist.Cut(destination, tile)) element.DrawBackground(art.Cut(destination, tile))
} }
} }
@ -199,7 +199,7 @@ func (element *Directory) ScrollAxes () (horizontal, vertical bool) {
return false, true return false, true
} }
func (element *Directory) DrawBackground (destination artist.Canvas) { func (element *Directory) DrawBackground (destination art.Canvas) {
element.entity.Theme().Pattern(tomo.PatternPinboard, tomo.State { }, directoryCase). element.entity.Theme().Pattern(tomo.PatternPinboard, tomo.State { }, directoryCase).
Draw(destination, element.entity.Bounds()) Draw(destination, element.entity.Bounds())
} }

View File

@ -2,9 +2,9 @@ package elements
import "image" import "image"
import "tomo" import "tomo"
import "tomo/artist" import "art"
import "tomo/ability" import "tomo/ability"
import "tomo/shatter" import "art/shatter"
var documentCase = tomo.C("tomo", "document") var documentCase = tomo.C("tomo", "document")
@ -33,7 +33,7 @@ func NewDocument (children ...tomo.Element) (element *Document) {
} }
// Draw causes the element to draw to the specified destination canvas. // Draw causes the element to draw to the specified destination canvas.
func (element *Document) Draw (destination artist.Canvas) { func (element *Document) Draw (destination art.Canvas) {
rocks := make([]image.Rectangle, element.entity.CountChildren()) rocks := make([]image.Rectangle, element.entity.CountChildren())
for index := 0; index < element.entity.CountChildren(); index ++ { for index := 0; index < element.entity.CountChildren(); index ++ {
rocks[index] = element.entity.Child(index).Entity().Bounds() rocks[index] = element.entity.Child(index).Entity().Bounds()
@ -41,7 +41,7 @@ func (element *Document) Draw (destination artist.Canvas) {
tiles := shatter.Shatter(element.entity.Bounds(), rocks...) tiles := shatter.Shatter(element.entity.Bounds(), rocks...)
for _, tile := range tiles { for _, tile := range tiles {
element.entity.DrawBackground(artist.Cut(destination, tile)) element.entity.DrawBackground(art.Cut(destination, tile))
} }
} }
@ -132,7 +132,7 @@ func (element *Document) HandleChildFlexibleHeightChange (child ability.Flexible
// DrawBackground draws this element's background pattern to the specified // DrawBackground draws this element's background pattern to the specified
// destination canvas. // destination canvas.
func (element *Document) DrawBackground (destination artist.Canvas) { func (element *Document) DrawBackground (destination art.Canvas) {
element.entity.DrawBackground(destination) element.entity.DrawBackground(destination)
} }

View File

@ -5,7 +5,7 @@ import "io/fs"
import "image" import "image"
import "tomo" import "tomo"
import "tomo/input" import "tomo/input"
import "tomo/artist" import "art"
var fileCase = tomo.C("files", "file") var fileCase = tomo.C("files", "file")
@ -45,7 +45,7 @@ func (element *File) Entity () tomo.Entity {
} }
// Draw causes the element to draw to the specified destination canvas. // Draw causes the element to draw to the specified destination canvas.
func (element *File) Draw (destination artist.Canvas) { func (element *File) Draw (destination art.Canvas) {
// background // background
state := element.state() state := element.state()
bounds := element.entity.Bounds() bounds := element.entity.Bounds()
@ -199,7 +199,7 @@ func (element *File) state () tomo.State {
} }
} }
func (element *File) icon () artist.Icon { func (element *File) icon () art.Icon {
return element.entity.Theme().Icon(element.iconID, tomo.IconSizeLarge, fileCase) return element.entity.Theme().Icon(element.iconID, tomo.IconSizeLarge, fileCase)
} }

View File

@ -5,8 +5,8 @@ import "math"
import "image" import "image"
import "image/color" import "image/color"
import "tomo" import "tomo"
import "tomo/artist" import "art"
import "tomo/artist/shapes" import "art/shapes"
var clockCase = tomo.C("tomo", "clock") var clockCase = tomo.C("tomo", "clock")
@ -30,7 +30,7 @@ func (element *AnalogClock) Entity () tomo.Entity {
} }
// Draw causes the element to draw to the specified destination canvas. // Draw causes the element to draw to the specified destination canvas.
func (element *AnalogClock) Draw (destination artist.Canvas) { func (element *AnalogClock) Draw (destination art.Canvas) {
bounds := element.entity.Bounds() bounds := element.entity.Bounds()
state := tomo.State { } state := tomo.State { }
@ -71,7 +71,7 @@ func (element *AnalogClock) HandleThemeChange () {
} }
func (element *AnalogClock) radialLine ( func (element *AnalogClock) radialLine (
destination artist.Canvas, destination art.Canvas,
source color.RGBA, source color.RGBA,
inner float64, inner float64,
outer float64, outer float64,

View File

@ -3,8 +3,8 @@ package fun
import "image" import "image"
import "tomo" import "tomo"
import "tomo/input" import "tomo/input"
import "tomo/artist" import "art"
import "tomo/artist/artutil" import "art/artutil"
import "tomo/elements/fun/music" import "tomo/elements/fun/music"
var pianoCase = tomo.C("tomo", "piano") var pianoCase = tomo.C("tomo", "piano")
@ -57,7 +57,7 @@ func (element *Piano) Entity () tomo.Entity {
} }
// Draw causes the element to draw to the specified destination canvas. // Draw causes the element to draw to the specified destination canvas.
func (element *Piano) Draw (destination artist.Canvas) { func (element *Piano) Draw (destination art.Canvas) {
element.recalculate() element.recalculate()
state := tomo.State { state := tomo.State {
@ -304,7 +304,7 @@ func (element *Piano) recalculate () {
} }
func (element *Piano) drawFlat ( func (element *Piano) drawFlat (
destination artist.Canvas, destination art.Canvas,
bounds image.Rectangle, bounds image.Rectangle,
pressed bool, pressed bool,
state tomo.State, state tomo.State,
@ -315,7 +315,7 @@ func (element *Piano) drawFlat (
} }
func (element *Piano) drawSharp ( func (element *Piano) drawSharp (
destination artist.Canvas, destination art.Canvas,
bounds image.Rectangle, bounds image.Rectangle,
pressed bool, pressed bool,
state tomo.State, state tomo.State,

View File

@ -2,7 +2,7 @@ package elements
import "image" import "image"
import "tomo" import "tomo"
import "tomo/artist" import "art"
var iconCase = tomo.C("tomo", "icon") var iconCase = tomo.C("tomo", "icon")
@ -44,7 +44,7 @@ func (element *Icon) HandleThemeChange () {
} }
// Draw causes the element to draw to the specified destination canvas. // Draw causes the element to draw to the specified destination canvas.
func (element *Icon) Draw (destination artist.Canvas) { func (element *Icon) Draw (destination art.Canvas) {
if element.entity == nil { return } if element.entity == nil { return }
bounds := element.entity.Bounds() bounds := element.entity.Bounds()
@ -65,7 +65,7 @@ func (element *Icon) Draw (destination artist.Canvas) {
} }
} }
func (element *Icon) icon () artist.Icon { func (element *Icon) icon () art.Icon {
return element.entity.Theme().Icon(element.id, element.size, iconCase) return element.entity.Theme().Icon(element.id, element.size, iconCase)
} }

View File

@ -2,20 +2,20 @@ package elements
import "image" import "image"
import "tomo" import "tomo"
import "tomo/artist" import "art"
import "tomo/artist/patterns" import "art/patterns"
// TODO: this element is lame need to make it better // TODO: this element is lame need to make it better
// Image is an element capable of displaying an image. // Image is an element capable of displaying an image.
type Image struct { type Image struct {
entity tomo.Entity entity tomo.Entity
buffer artist.Canvas buffer art.Canvas
} }
// NewImage creates a new image element. // NewImage creates a new image element.
func NewImage (image image.Image) (element *Image) { func NewImage (image image.Image) (element *Image) {
element = &Image { buffer: artist.FromImage(image) } element = &Image { buffer: art.FromImage(image) }
element.entity = tomo.GetBackend().NewEntity(element) element.entity = tomo.GetBackend().NewEntity(element)
bounds := element.buffer.Bounds() bounds := element.buffer.Bounds()
element.entity.SetMinimumSize(bounds.Dx(), bounds.Dy()) element.entity.SetMinimumSize(bounds.Dx(), bounds.Dy())
@ -28,7 +28,7 @@ func (element *Image) Entity () tomo.Entity {
} }
// Draw causes the element to draw to the specified destination canvas. // Draw causes the element to draw to the specified destination canvas.
func (element *Image) Draw (destination artist.Canvas) { func (element *Image) Draw (destination art.Canvas) {
if element.entity == nil { return } if element.entity == nil { return }
(patterns.Texture { Canvas: element.buffer }). (patterns.Texture { Canvas: element.buffer }).
Draw(destination, element.entity.Bounds()) Draw(destination, element.entity.Bounds())

View File

@ -5,7 +5,7 @@ import "golang.org/x/image/math/fixed"
import "tomo" import "tomo"
import "tomo/data" import "tomo/data"
import "tomo/input" import "tomo/input"
import "tomo/artist" import "art"
import "tomo/textdraw" import "tomo/textdraw"
var labelCase = tomo.C("tomo", "label") var labelCase = tomo.C("tomo", "label")
@ -48,7 +48,7 @@ func (element *Label) Entity () tomo.Entity {
} }
// Draw causes the element to draw to the specified destination canvas. // Draw causes the element to draw to the specified destination canvas.
func (element *Label) Draw (destination artist.Canvas) { func (element *Label) Draw (destination art.Canvas) {
bounds := element.entity.Bounds() bounds := element.entity.Bounds()
if element.wrap { if element.wrap {

View File

@ -3,9 +3,9 @@ package elements
import "image" import "image"
import "tomo" import "tomo"
import "tomo/input" import "tomo/input"
import "tomo/artist" import "art"
import "tomo/ability" import "tomo/ability"
import "tomo/artist/artutil" import "art/artutil"
type list struct { type list struct {
container container
@ -61,7 +61,7 @@ func (element *list) init (children ...tomo.Element) {
element.Adopt(children...) element.Adopt(children...)
} }
func (element *list) Draw (destination artist.Canvas) { func (element *list) Draw (destination art.Canvas) {
rocks := make([]image.Rectangle, element.entity.CountChildren()) rocks := make([]image.Rectangle, element.entity.CountChildren())
for index := 0; index < element.entity.CountChildren(); index ++ { for index := 0; index < element.entity.CountChildren(); index ++ {
rocks[index] = element.entity.Child(index).Entity().Bounds() rocks[index] = element.entity.Child(index).Entity().Bounds()
@ -274,7 +274,7 @@ func (element *list) HandleKeyDown (key input.Key, modifiers input.Modifiers) {
func (element *list) HandleKeyUp(key input.Key, modifiers input.Modifiers) { } func (element *list) HandleKeyUp(key input.Key, modifiers input.Modifiers) { }
func (element *list) DrawBackground (destination artist.Canvas) { func (element *list) DrawBackground (destination art.Canvas) {
element.entity.DrawBackground(destination) element.entity.DrawBackground(destination)
} }

View File

@ -2,7 +2,7 @@ package elements
import "image" import "image"
import "tomo" import "tomo"
import "tomo/artist" import "art"
var progressBarCase = tomo.C("tomo", "progressBar") var progressBarCase = tomo.C("tomo", "progressBar")
@ -29,7 +29,7 @@ func (element *ProgressBar) Entity () tomo.Entity {
} }
// Draw causes the element to draw to the specified destination canvas. // Draw causes the element to draw to the specified destination canvas.
func (element *ProgressBar) Draw (destination artist.Canvas) { func (element *ProgressBar) Draw (destination art.Canvas) {
bounds := element.entity.Bounds() bounds := element.entity.Bounds()
pattern := element.entity.Theme().Pattern(tomo.PatternSunken, tomo.State { }, progressBarCase) pattern := element.entity.Theme().Pattern(tomo.PatternSunken, tomo.State { }, progressBarCase)

View File

@ -3,7 +3,7 @@ package elements
import "image" import "image"
import "tomo" import "tomo"
import "tomo/input" import "tomo/input"
import "tomo/artist" import "art"
import "tomo/ability" import "tomo/ability"
var scrollCase = tomo.C("tomo", "scroll") var scrollCase = tomo.C("tomo", "scroll")
@ -76,7 +76,7 @@ func (element *Scroll) Entity () tomo.Entity {
} }
// Draw causes the element to draw to the specified destination canvas. // Draw causes the element to draw to the specified destination canvas.
func (element *Scroll) Draw (destination artist.Canvas) { func (element *Scroll) Draw (destination art.Canvas) {
if element.horizontal != nil && element.vertical != nil { if element.horizontal != nil && element.vertical != nil {
bounds := element.entity.Bounds() bounds := element.entity.Bounds()
bounds.Min = image.Pt ( bounds.Min = image.Pt (
@ -84,7 +84,7 @@ func (element *Scroll) Draw (destination artist.Canvas) {
bounds.Max.Y - element.horizontal.Entity().Bounds().Dy()) bounds.Max.Y - element.horizontal.Entity().Bounds().Dy())
state := tomo.State { } state := tomo.State { }
deadArea := element.entity.Theme().Pattern(tomo.PatternDead, state, scrollCase) deadArea := element.entity.Theme().Pattern(tomo.PatternDead, state, scrollCase)
deadArea.Draw(artist.Cut(destination, bounds), bounds) deadArea.Draw(art.Cut(destination, bounds), bounds)
} }
} }
@ -131,7 +131,7 @@ func (element *Scroll) Layout () {
// DrawBackground draws this element's background pattern to the specified // DrawBackground draws this element's background pattern to the specified
// destination canvas. // destination canvas.
func (element *Scroll) DrawBackground (destination artist.Canvas) { func (element *Scroll) DrawBackground (destination art.Canvas) {
element.entity.DrawBackground(destination) element.entity.DrawBackground(destination)
} }

View File

@ -3,7 +3,7 @@ package elements
import "image" import "image"
import "tomo" import "tomo"
import "tomo/input" import "tomo/input"
import "tomo/artist" import "art"
// ScrollBar is an element similar to Slider, but it has special behavior that // ScrollBar is an element similar to Slider, but it has special behavior that
// makes it well suited for controlling the viewport position on one axis of a // makes it well suited for controlling the viewport position on one axis of a
@ -63,7 +63,7 @@ func (element *ScrollBar) Entity () tomo.Entity {
} }
// Draw causes the element to draw to the specified destination canvas. // Draw causes the element to draw to the specified destination canvas.
func (element *ScrollBar) Draw (destination artist.Canvas) { func (element *ScrollBar) Draw (destination art.Canvas) {
element.recalculate() element.recalculate()
bounds := element.entity.Bounds() bounds := element.entity.Bounds()

View File

@ -3,7 +3,7 @@ package elements
import "image" import "image"
import "tomo" import "tomo"
import "tomo/input" import "tomo/input"
import "tomo/artist" import "art"
// Slider is a slider control with a floating point value between zero and one. // Slider is a slider control with a floating point value between zero and one.
type Slider struct { type Slider struct {
@ -59,7 +59,7 @@ func (element *slider) Entity () tomo.Entity {
} }
// Draw causes the element to draw to the specified destination canvas. // Draw causes the element to draw to the specified destination canvas.
func (element *slider) Draw (destination artist.Canvas) { func (element *slider) Draw (destination art.Canvas) {
bounds := element.entity.Bounds() bounds := element.entity.Bounds()
element.track = element.entity.Theme().Padding(tomo.PatternGutter, element.c).Apply(bounds) element.track = element.entity.Theme().Padding(tomo.PatternGutter, element.c).Apply(bounds)
if element.vertical { if element.vertical {

View File

@ -1,7 +1,7 @@
package elements package elements
import "tomo" import "tomo"
import "tomo/artist" import "art"
var spacerCase = tomo.C("tomo", "spacer") var spacerCase = tomo.C("tomo", "spacer")
@ -32,7 +32,7 @@ func (element *Spacer) Entity () tomo.Entity {
} }
// Draw causes the element to draw to the specified destination canvas. // Draw causes the element to draw to the specified destination canvas.
func (element *Spacer) Draw (destination artist.Canvas) { func (element *Spacer) Draw (destination art.Canvas) {
bounds := element.entity.Bounds() bounds := element.entity.Bounds()
if element.line { if element.line {

View File

@ -3,7 +3,7 @@ package elements
import "image" import "image"
import "tomo" import "tomo"
import "tomo/input" import "tomo/input"
import "tomo/artist" import "art"
import "tomo/textdraw" import "tomo/textdraw"
var switchCase = tomo.C("tomo", "switch") var switchCase = tomo.C("tomo", "switch")
@ -44,7 +44,7 @@ func (element *Switch) Entity () tomo.Entity {
} }
// Draw causes the element to draw to the specified destination canvas. // Draw causes the element to draw to the specified destination canvas.
func (element *Switch) Draw (destination artist.Canvas) { func (element *Switch) Draw (destination art.Canvas) {
bounds := element.entity.Bounds() bounds := element.entity.Bounds()
handleBounds := image.Rect(0, 0, bounds.Dy(), bounds.Dy()).Add(bounds.Min) handleBounds := image.Rect(0, 0, bounds.Dy(), bounds.Dy()).Add(bounds.Min)
gutterBounds := image.Rect(0, 0, bounds.Dy() * 2, bounds.Dy()).Add(bounds.Min) gutterBounds := image.Rect(0, 0, bounds.Dy() * 2, bounds.Dy()).Add(bounds.Min)

View File

@ -5,20 +5,20 @@ import "time"
import "image" import "image"
import "image/color" import "image/color"
import "tomo" import "tomo"
import "tomo/artist" import "art"
import "tomo/shatter" import "art/shatter"
import "tomo/textdraw" import "tomo/textdraw"
import "tomo/artist/shapes" import "art/shapes"
import "tomo/artist/artutil" import "art/artutil"
import "tomo/artist/patterns" import "art/patterns"
// Artist is an element that displays shapes and patterns drawn by the artist // Artist is an element that displays shapes and patterns drawn by the art
// package in order to test it. // package in order to test it.
type Artist struct { type Artist struct {
entity tomo.Entity entity tomo.Entity
} }
// NewArtist creates a new artist test element. // NewArtist creates a new art test element.
func NewArtist () (element *Artist) { func NewArtist () (element *Artist) {
element = &Artist { } element = &Artist { }
element.entity = tomo.GetBackend().NewEntity(element) element.entity = tomo.GetBackend().NewEntity(element)
@ -30,7 +30,7 @@ func (element *Artist) Entity () tomo.Entity {
return element.entity return element.entity
} }
func (element *Artist) Draw (destination artist.Canvas) { func (element *Artist) Draw (destination art.Canvas) {
bounds := element.entity.Bounds() bounds := element.entity.Bounds()
patterns.Uhex(0x000000FF).Draw(destination, bounds) patterns.Uhex(0x000000FF).Draw(destination, bounds)
@ -81,7 +81,7 @@ func (element *Artist) Draw (destination artist.Canvas) {
} }
tiles := shatter.Shatter(c41.Bounds(), rocks...) tiles := shatter.Shatter(c41.Bounds(), rocks...)
for index, tile := range tiles { for index, tile := range tiles {
[]artist.Pattern { []art.Pattern {
patterns.Uhex(0xFF0000FF), patterns.Uhex(0xFF0000FF),
patterns.Uhex(0x00FF00FF), patterns.Uhex(0x00FF00FF),
patterns.Uhex(0xFF00FFFF), patterns.Uhex(0xFF00FFFF),
@ -115,26 +115,26 @@ func (element *Artist) Draw (destination artist.Canvas) {
c03 := element.cellAt(destination, 0, 3) c03 := element.cellAt(destination, 0, 3)
patterns.Border { patterns.Border {
Canvas: element.thingy(c42), Canvas: element.thingy(c42),
Inset: artist.Inset { 8, 8, 8, 8 }, Inset: art.Inset { 8, 8, 8, 8 },
}.Draw(c03, c03.Bounds()) }.Draw(c03, c03.Bounds())
// 1, 3 // 1, 3
c13 := element.cellAt(destination, 1, 3) c13 := element.cellAt(destination, 1, 3)
patterns.Border { patterns.Border {
Canvas: element.thingy(c42), Canvas: element.thingy(c42),
Inset: artist.Inset { 8, 8, 8, 8 }, Inset: art.Inset { 8, 8, 8, 8 },
}.Draw(c13, c13.Bounds().Inset(10)) }.Draw(c13, c13.Bounds().Inset(10))
// 2, 3 // 2, 3
c23 := element.cellAt(destination, 2, 3) c23 := element.cellAt(destination, 2, 3)
patterns.Border { patterns.Border {
Canvas: element.thingy(c42), Canvas: element.thingy(c42),
Inset: artist.Inset { 8, 8, 8, 8 }, Inset: art.Inset { 8, 8, 8, 8 },
}.Draw(c23, c23.Bounds()) }.Draw(c23, c23.Bounds())
patterns.Border { patterns.Border {
Canvas: element.thingy(c42), Canvas: element.thingy(c42),
Inset: artist.Inset { 8, 8, 8, 8 }, Inset: art.Inset { 8, 8, 8, 8 },
}.Draw(artist.Cut(c23, c23.Bounds().Inset(16)), c23.Bounds()) }.Draw(art.Cut(c23, c23.Bounds().Inset(16)), c23.Bounds())
// how long did that take to render? // how long did that take to render?
drawTime := time.Since(drawStart) drawTime := time.Since(drawStart)
@ -142,7 +142,7 @@ func (element *Artist) Draw (destination artist.Canvas) {
textDrawer.SetFace(element.entity.Theme().FontFace ( textDrawer.SetFace(element.entity.Theme().FontFace (
tomo.FontStyleRegular, tomo.FontStyleRegular,
tomo.FontSizeNormal, tomo.FontSizeNormal,
tomo.C("tomo", "artist"))) tomo.C("tomo", "art")))
textDrawer.SetText ([]rune (fmt.Sprintf ( textDrawer.SetText ([]rune (fmt.Sprintf (
"%dms\n%dus", "%dms\n%dus",
drawTime.Milliseconds(), drawTime.Milliseconds(),
@ -152,7 +152,7 @@ func (element *Artist) Draw (destination artist.Canvas) {
image.Pt(bounds.Min.X + 8, bounds.Max.Y - 24)) image.Pt(bounds.Min.X + 8, bounds.Max.Y - 24))
} }
func (element *Artist) colorLines (destination artist.Canvas, weight int, bounds image.Rectangle) { func (element *Artist) colorLines (destination art.Canvas, weight int, bounds image.Rectangle) {
bounds = bounds.Inset(4) bounds = bounds.Inset(4)
c := artutil.Hex(0xFFFFFFFF) c := artutil.Hex(0xFFFFFFFF)
shapes.ColorLine(destination, c, weight, bounds.Min, bounds.Max) shapes.ColorLine(destination, c, weight, bounds.Min, bounds.Max)
@ -186,18 +186,18 @@ func (element *Artist) colorLines (destination artist.Canvas, weight int, bounds
image.Pt(bounds.Min.X + bounds.Dx() / 2, bounds.Max.Y)) image.Pt(bounds.Min.X + bounds.Dx() / 2, bounds.Max.Y))
} }
func (element *Artist) cellAt (destination artist.Canvas, x, y int) (artist.Canvas) { func (element *Artist) cellAt (destination art.Canvas, x, y int) (art.Canvas) {
bounds := element.entity.Bounds() bounds := element.entity.Bounds()
cellBounds := image.Rectangle { } cellBounds := image.Rectangle { }
cellBounds.Min = bounds.Min cellBounds.Min = bounds.Min
cellBounds.Max.X = bounds.Min.X + bounds.Dx() / 5 cellBounds.Max.X = bounds.Min.X + bounds.Dx() / 5
cellBounds.Max.Y = bounds.Min.Y + (bounds.Dy() - 48) / 4 cellBounds.Max.Y = bounds.Min.Y + (bounds.Dy() - 48) / 4
return artist.Cut (destination, cellBounds.Add (image.Pt ( return art.Cut (destination, cellBounds.Add (image.Pt (
x * cellBounds.Dx(), x * cellBounds.Dx(),
y * cellBounds.Dy()))) y * cellBounds.Dy())))
} }
func (element *Artist) thingy (destination artist.Canvas) (result artist.Canvas) { func (element *Artist) thingy (destination art.Canvas) (result art.Canvas) {
bounds := destination.Bounds() bounds := destination.Bounds()
bounds = image.Rect(0, 0, 32, 32).Add(bounds.Min) bounds = image.Rect(0, 0, 32, 32).Add(bounds.Min)
shapes.FillColorRectangle(destination, artutil.Hex(0x440000FF), bounds) shapes.FillColorRectangle(destination, artutil.Hex(0x440000FF), bounds)
@ -205,5 +205,5 @@ func (element *Artist) thingy (destination artist.Canvas) (result artist.Canvas)
shapes.StrokeColorRectangle(destination, artutil.Hex(0x004400FF), bounds.Inset(4), 1) shapes.StrokeColorRectangle(destination, artutil.Hex(0x004400FF), bounds.Inset(4), 1)
shapes.FillColorRectangle(destination, artutil.Hex(0x004444FF), bounds.Inset(12)) shapes.FillColorRectangle(destination, artutil.Hex(0x004444FF), bounds.Inset(12))
shapes.StrokeColorRectangle(destination, artutil.Hex(0x888888FF), bounds.Inset(8), 1) shapes.StrokeColorRectangle(destination, artutil.Hex(0x888888FF), bounds.Inset(8), 1)
return artist.Cut(destination, bounds) return art.Cut(destination, bounds)
} }

View File

@ -3,9 +3,9 @@ package testing
import "image" import "image"
import "tomo" import "tomo"
import "tomo/input" import "tomo/input"
import "tomo/artist" import "art"
import "tomo/artist/shapes" import "art/shapes"
import "tomo/artist/artutil" import "art/artutil"
var mouseCase = tomo.C("tomo", "mouse") var mouseCase = tomo.C("tomo", "mouse")
@ -29,7 +29,7 @@ func (element *Mouse) Entity () tomo.Entity {
return element.entity return element.entity
} }
func (element *Mouse) Draw (destination artist.Canvas) { func (element *Mouse) Draw (destination art.Canvas) {
bounds := element.entity.Bounds() bounds := element.entity.Bounds()
accent := element.entity.Theme().Color ( accent := element.entity.Theme().Color (
tomo.ColorAccent, tomo.ColorAccent,

View File

@ -6,11 +6,11 @@ import "image"
import "tomo" import "tomo"
import "tomo/data" import "tomo/data"
import "tomo/input" import "tomo/input"
import "tomo/artist" import "art"
import "tomo/textdraw" import "tomo/textdraw"
import "tomo/textmanip" import "tomo/textmanip"
import "tomo/fixedutil" import "tomo/fixedutil"
import "tomo/artist/shapes" import "art/shapes"
var textBoxCase = tomo.C("tomo", "textBox") var textBoxCase = tomo.C("tomo", "textBox")
@ -60,13 +60,13 @@ func (element *TextBox) Entity () tomo.Entity {
} }
// Draw causes the element to draw to the specified destination canvas. // Draw causes the element to draw to the specified destination canvas.
func (element *TextBox) Draw (destination artist.Canvas) { func (element *TextBox) Draw (destination art.Canvas) {
bounds := element.entity.Bounds() bounds := element.entity.Bounds()
state := element.state() state := element.state()
pattern := element.entity.Theme().Pattern(tomo.PatternInput, state, textBoxCase) pattern := element.entity.Theme().Pattern(tomo.PatternInput, state, textBoxCase)
padding := element.entity.Theme().Padding(tomo.PatternInput, textBoxCase) padding := element.entity.Theme().Padding(tomo.PatternInput, textBoxCase)
innerCanvas := artist.Cut(destination, padding.Apply(bounds)) innerCanvas := art.Cut(destination, padding.Apply(bounds))
pattern.Draw(destination, bounds) pattern.Draw(destination, bounds)
offset := element.textOffset() offset := element.textOffset()
@ -208,8 +208,8 @@ func (element *TextBox) textOffset () image.Point {
innerBounds := padding.Apply(bounds) innerBounds := padding.Apply(bounds)
textHeight := element.valueDrawer.LineHeight().Round() textHeight := element.valueDrawer.LineHeight().Round()
return bounds.Min.Add (image.Pt ( return bounds.Min.Add (image.Pt (
padding[artist.SideLeft] - element.scroll, padding[art.SideLeft] - element.scroll,
padding[artist.SideTop] + (innerBounds.Dy() - textHeight) / 2)) padding[art.SideTop] + (innerBounds.Dy() - textHeight) / 2))
} }
func (element *TextBox) atPosition (position image.Point) int { func (element *TextBox) atPosition (position image.Point) int {

View File

@ -3,7 +3,7 @@ package elements
import "image" import "image"
import "tomo" import "tomo"
import "tomo/input" import "tomo/input"
import "tomo/artist" import "art"
import "tomo/textdraw" import "tomo/textdraw"
var toggleButtonCase = tomo.C("tomo", "toggleButton") var toggleButtonCase = tomo.C("tomo", "toggleButton")
@ -47,7 +47,7 @@ func (element *ToggleButton) Entity () tomo.Entity {
} }
// Draw causes the element to draw to the specified destination canvas. // Draw causes the element to draw to the specified destination canvas.
func (element *ToggleButton) Draw (destination artist.Canvas) { func (element *ToggleButton) Draw (destination art.Canvas) {
state := element.state() state := element.state()
bounds := element.entity.Bounds() bounds := element.entity.Bounds()
pattern := element.entity.Theme().Pattern(tomo.PatternButton, state, toggleButtonCase) pattern := element.entity.Theme().Pattern(tomo.PatternButton, state, toggleButtonCase)

View File

@ -1,7 +1,7 @@
package tomo package tomo
import "image" import "image"
import "tomo/artist" import "art"
// Entity is a handle given to elements by the backend. Extended entity // Entity is a handle given to elements by the backend. Extended entity
// interfaces are defined in the ability module. // interfaces are defined in the ability module.
@ -33,7 +33,7 @@ type Entity interface {
// labels. If there is no parent element (that is, the element is // labels. If there is no parent element (that is, the element is
// directly inside of the window), the backend will draw a default // directly inside of the window), the backend will draw a default
// background pattern. // background pattern.
DrawBackground (artist.Canvas) DrawBackground (art.Canvas)
// --- Behaviors relating to parenting --- // --- Behaviors relating to parenting ---

3
go.mod
View File

@ -2,7 +2,10 @@ module tomo
go 1.19 go 1.19
replace art => git.tebibyte.media/tomo/art v1.0.0
require ( require (
art v1.0.0
git.tebibyte.media/sashakoshka/ezprof v0.0.0-20230309044548-401cba83602b git.tebibyte.media/sashakoshka/ezprof v0.0.0-20230309044548-401cba83602b
github.com/jezek/xgbutil v0.0.0-20230403164920-e2f86723ca07 github.com/jezek/xgbutil v0.0.0-20230403164920-e2f86723ca07
golang.org/x/image v0.7.0 golang.org/x/image v0.7.0

2
go.sum
View File

@ -1,5 +1,7 @@
git.tebibyte.media/sashakoshka/ezprof v0.0.0-20230309044548-401cba83602b h1:vPFKR7vjN1VrMdMtpATMrKQobz/cqbPiRrA1EbtG6PM= git.tebibyte.media/sashakoshka/ezprof v0.0.0-20230309044548-401cba83602b h1:vPFKR7vjN1VrMdMtpATMrKQobz/cqbPiRrA1EbtG6PM=
git.tebibyte.media/sashakoshka/ezprof v0.0.0-20230309044548-401cba83602b/go.mod h1:cpXX8SAUDEvZX5m7scoyruavUhEqQ1SByfWzPFHkTbg= git.tebibyte.media/sashakoshka/ezprof v0.0.0-20230309044548-401cba83602b/go.mod h1:cpXX8SAUDEvZX5m7scoyruavUhEqQ1SByfWzPFHkTbg=
git.tebibyte.media/tomo/art v1.0.0 h1:dnP19Irgiho5WH0Im0l5vFYj5sDh4nqVk8hvG+6kW4M=
git.tebibyte.media/tomo/art v1.0.0/go.mod h1:pDQKkKWv/81CLTyH743zCzRWiri05+/4H6eNugarzvE=
github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298 h1:1qlsVAQJXZHsaM8b6OLVo6muQUQd4CwkH/D3fnnbHXA= github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298 h1:1qlsVAQJXZHsaM8b6OLVo6muQUQd4CwkH/D3fnnbHXA=
github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298/go.mod h1:D+QujdIlUNfa0igpNMk6UIvlb6C252URs4yupRUV4lQ= github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298/go.mod h1:D+QujdIlUNfa0igpNMk6UIvlb6C252URs4yupRUV4lQ=
github.com/BurntSushi/graphics-go v0.0.0-20160129215708-b43f31a4a966 h1:lTG4HQym5oPKjL7nGs+csTgiDna685ZXjxijkne828g= github.com/BurntSushi/graphics-go v0.0.0-20160129215708-b43f31a4a966 h1:lTG4HQym5oPKjL7nGs+csTgiDna685ZXjxijkne828g=

View File

@ -9,14 +9,14 @@ import "golang.org/x/image/font"
import "golang.org/x/image/font/basicfont" import "golang.org/x/image/font/basicfont"
import "tomo" import "tomo"
import "tomo/data" import "tomo/data"
import "tomo/artist" import "art"
import "tomo/artist/artutil" import "art/artutil"
import "tomo/artist/patterns" import "art/patterns"
//go:embed assets/wintergreen.png //go:embed assets/wintergreen.png
var defaultAtlasBytes []byte var defaultAtlasBytes []byte
var defaultAtlas artist.Canvas var defaultAtlas art.Canvas
var defaultTextures [17][9]artist.Pattern var defaultTextures [17][9]art.Pattern
//go:embed assets/wintergreen-icons-small.png //go:embed assets/wintergreen-icons-small.png
var defaultIconsSmallAtlasBytes []byte var defaultIconsSmallAtlasBytes []byte
var defaultIconsSmall [640]binaryIcon var defaultIconsSmall [640]binaryIcon
@ -24,15 +24,15 @@ var defaultIconsSmall [640]binaryIcon
var defaultIconsLargeAtlasBytes []byte var defaultIconsLargeAtlasBytes []byte
var defaultIconsLarge [640]binaryIcon var defaultIconsLarge [640]binaryIcon
func atlasCell (col, row int, border artist.Inset) { func atlasCell (col, row int, border art.Inset) {
bounds := image.Rect(0, 0, 16, 16).Add(image.Pt(col, row).Mul(16)) bounds := image.Rect(0, 0, 16, 16).Add(image.Pt(col, row).Mul(16))
defaultTextures[col][row] = patterns.Border { defaultTextures[col][row] = patterns.Border {
Canvas: artist.Cut(defaultAtlas, bounds), Canvas: art.Cut(defaultAtlas, bounds),
Inset: border, Inset: border,
} }
} }
func atlasCol (col int, border artist.Inset) { func atlasCol (col int, border art.Inset) {
for index, _ := range defaultTextures[col] { for index, _ := range defaultTextures[col] {
atlasCell(col, index, border) atlasCell(col, index, border)
} }
@ -43,7 +43,7 @@ type binaryIcon struct {
stride int stride int
} }
func (icon binaryIcon) Draw (destination artist.Canvas, color color.RGBA, at image.Point) { func (icon binaryIcon) Draw (destination art.Canvas, color color.RGBA, at image.Point) {
bounds := icon.Bounds().Add(at).Intersect(destination.Bounds()) bounds := icon.Bounds().Add(at).Intersect(destination.Bounds())
point := image.Point { } point := image.Point { }
data, stride := destination.Buffer() data, stride := destination.Buffer()
@ -85,43 +85,43 @@ func binaryIconFrom (source image.Image, clip image.Rectangle) (icon binaryIcon)
func init () { func init () {
defaultAtlasImage, _, _ := image.Decode(bytes.NewReader(defaultAtlasBytes)) defaultAtlasImage, _, _ := image.Decode(bytes.NewReader(defaultAtlasBytes))
defaultAtlas = artist.FromImage(defaultAtlasImage) defaultAtlas = art.FromImage(defaultAtlasImage)
// PatternDead // PatternDead
atlasCol(0, artist.Inset { }) atlasCol(0, art.Inset { })
// PatternRaised // PatternRaised
atlasCol(1, artist.Inset { 6, 6, 6, 6 }) atlasCol(1, art.Inset { 6, 6, 6, 6 })
// PatternSunken // PatternSunken
atlasCol(2, artist.Inset { 4, 4, 4, 4 }) atlasCol(2, art.Inset { 4, 4, 4, 4 })
// PatternPinboard // PatternPinboard
atlasCol(3, artist.Inset { 2, 2, 2, 2 }) atlasCol(3, art.Inset { 2, 2, 2, 2 })
// PatternButton // PatternButton
atlasCol(4, artist.Inset { 6, 6, 6, 6 }) atlasCol(4, art.Inset { 6, 6, 6, 6 })
// PatternInput // PatternInput
atlasCol(5, artist.Inset { 4, 4, 4, 4 }) atlasCol(5, art.Inset { 4, 4, 4, 4 })
// PatternGutter // PatternGutter
atlasCol(6, artist.Inset { 7, 7, 7, 7 }) atlasCol(6, art.Inset { 7, 7, 7, 7 })
// PatternHandle // PatternHandle
atlasCol(7, artist.Inset { 3, 3, 3, 3 }) atlasCol(7, art.Inset { 3, 3, 3, 3 })
// PatternLine // PatternLine
atlasCol(8, artist.Inset { 1, 1, 1, 1 }) atlasCol(8, art.Inset { 1, 1, 1, 1 })
// PatternMercury // PatternMercury
atlasCol(13, artist.Inset { 2, 2, 2, 2 }) atlasCol(13, art.Inset { 2, 2, 2, 2 })
// PatternTableHead: // PatternTableHead:
atlasCol(14, artist.Inset { 4, 4, 4, 4 }) atlasCol(14, art.Inset { 4, 4, 4, 4 })
// PatternTableCell: // PatternTableCell:
atlasCol(15, artist.Inset { 4, 4, 4, 4 }) atlasCol(15, art.Inset { 4, 4, 4, 4 })
// PatternLamp: // PatternLamp:
atlasCol(16, artist.Inset { 4, 3, 4, 3 }) atlasCol(16, art.Inset { 4, 3, 4, 3 })
// PatternButton: basic.checkbox // PatternButton: basic.checkbox
atlasCol(9, artist.Inset { 3, 3, 3, 3 }) atlasCol(9, art.Inset { 3, 3, 3, 3 })
// PatternRaised: basic.listEntry // PatternRaised: basic.listEntry
atlasCol(10, artist.Inset { 3, 3, 3, 3 }) atlasCol(10, art.Inset { 3, 3, 3, 3 })
// PatternRaised: fun.flatKey // PatternRaised: fun.flatKey
atlasCol(11, artist.Inset { 3, 3, 5, 3 }) atlasCol(11, art.Inset { 3, 3, 5, 3 })
// PatternRaised: fun.sharpKey // PatternRaised: fun.sharpKey
atlasCol(12, artist.Inset { 3, 3, 4, 3 }) atlasCol(12, art.Inset { 3, 3, 4, 3 })
// set up small icons // set up small icons
defaultIconsSmallAtlasImage, _, _ := image.Decode ( defaultIconsSmallAtlasImage, _, _ := image.Decode (
@ -164,7 +164,7 @@ func (Theme) FontFace (style tomo.FontStyle, size tomo.FontSize, c tomo.Case) fo
return basicfont.Face7x13 return basicfont.Face7x13
} }
func (Theme) Icon (id tomo.Icon, size tomo.IconSize, c tomo.Case) artist.Icon { func (Theme) Icon (id tomo.Icon, size tomo.IconSize, c tomo.Case) art.Icon {
if size == tomo.IconSizeLarge { if size == tomo.IconSizeLarge {
if id < 0 || int(id) >= len(defaultIconsLarge) { if id < 0 || int(id) >= len(defaultIconsLarge) {
return nil return nil
@ -180,12 +180,12 @@ func (Theme) Icon (id tomo.Icon, size tomo.IconSize, c tomo.Case) artist.Icon {
} }
} }
func (Theme) MimeIcon (data.Mime, tomo.IconSize, tomo.Case) artist.Icon { func (Theme) MimeIcon (data.Mime, tomo.IconSize, tomo.Case) art.Icon {
// TODO // TODO
return nil return nil
} }
func (Theme) Pattern (id tomo.Pattern, state tomo.State, c tomo.Case) artist.Pattern { func (Theme) Pattern (id tomo.Pattern, state tomo.State, c tomo.Case) art.Pattern {
offset := 0; switch { offset := 0; switch {
case state.Disabled: offset = 1 case state.Disabled: offset = 1
case state.Pressed && state.On: offset = 4 case state.Pressed && state.On: offset = 4
@ -254,31 +254,31 @@ func (Theme) Color (id tomo.Color, state tomo.State, c tomo.Case) color.RGBA {
} [id]) } [id])
} }
func (Theme) Padding (id tomo.Pattern, c tomo.Case) artist.Inset { func (Theme) Padding (id tomo.Pattern, c tomo.Case) art.Inset {
switch id { switch id {
case tomo.PatternSunken: case tomo.PatternSunken:
if c.Match("tomo", "progressBar", "") { if c.Match("tomo", "progressBar", "") {
return artist.I(2, 1, 1, 2) return art.I(2, 1, 1, 2)
} else if c.Match("tomo", "list", "") { } else if c.Match("tomo", "list", "") {
return artist.I(2) return art.I(2)
} else if c.Match("tomo", "flowList", "") { } else if c.Match("tomo", "flowList", "") {
return artist.I(2) return art.I(2)
} else { } else {
return artist.I(8) return art.I(8)
} }
case tomo.PatternPinboard: case tomo.PatternPinboard:
if c.Match("tomo", "piano", "") { if c.Match("tomo", "piano", "") {
return artist.I(2) return art.I(2)
} else { } else {
return artist.I(8) return art.I(8)
} }
case tomo.PatternTableCell: return artist.I(5) case tomo.PatternTableCell: return art.I(5)
case tomo.PatternTableHead: return artist.I(5) case tomo.PatternTableHead: return art.I(5)
case tomo.PatternGutter: return artist.I(0) case tomo.PatternGutter: return art.I(0)
case tomo.PatternLine: return artist.I(1) case tomo.PatternLine: return art.I(1)
case tomo.PatternMercury: return artist.I(5) case tomo.PatternMercury: return art.I(5)
case tomo.PatternLamp: return artist.I(5, 5, 5, 6) case tomo.PatternLamp: return art.I(5, 5, 5, 6)
default: return artist.I(8) default: return art.I(8)
} }
} }

View File

@ -2,7 +2,7 @@ package x
import "image" import "image"
import "tomo" import "tomo"
import "tomo/artist" import "art"
import "tomo/ability" import "tomo/ability"
type entity struct { type entity struct {
@ -159,7 +159,7 @@ func (entity *entity) SetMinimumSize (width, height int) {
} }
} }
func (entity *entity) DrawBackground (destination artist.Canvas) { func (entity *entity) DrawBackground (destination art.Canvas) {
if entity.parent != nil { if entity.parent != nil {
entity.parent.element.(ability.Container).DrawBackground(destination) entity.parent.element.(ability.Container).DrawBackground(destination)
} else if entity.window != nil { } else if entity.window != nil {

View File

@ -1,7 +1,7 @@
package x package x
import "image" import "image"
import "tomo/artist" import "art"
import "tomo/ability" import "tomo/ability"
type entitySet map[*entity] struct { } type entitySet map[*entity] struct { }
@ -22,7 +22,7 @@ func (set entitySet) Add (entity *entity) {
type system struct { type system struct {
child *entity child *entity
focused *entity focused *entity
canvas artist.BasicCanvas canvas art.BasicCanvas
invalidateIgnore bool invalidateIgnore bool
drawingInvalid entitySet drawingInvalid entitySet
@ -167,7 +167,7 @@ func (system *system) draw () {
for entity := range system.drawingInvalid { for entity := range system.drawingInvalid {
if entity.clippedBounds.Empty() { continue } if entity.clippedBounds.Empty() { continue }
entity.element.Draw (artist.Cut ( entity.element.Draw (art.Cut (
system.canvas, system.canvas,
entity.clippedBounds)) entity.clippedBounds))
finalBounds = finalBounds.Union(entity.clippedBounds) finalBounds = finalBounds.Union(entity.clippedBounds)

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 "tomo" import "tomo"
import "tomo/data" import "tomo/data"
import "tomo/artist" import "art"
type mainWindow struct { *window } type mainWindow struct { *window }
type menuWindow struct { *window } type menuWindow struct { *window }
@ -414,7 +414,7 @@ func (window *window) pasteAndPush (region image.Rectangle) {
} }
func (window *window) paste (region image.Rectangle) { func (window *window) paste (region image.Rectangle) {
canvas := artist.Cut(window.canvas, region) canvas := art.Cut(window.canvas, region)
data, stride := canvas.Buffer() data, stride := canvas.Buffer()
bounds := canvas.Bounds().Intersect(window.xCanvas.Bounds()) bounds := canvas.Bounds().Intersect(window.xCanvas.Bounds())

View File

@ -5,7 +5,7 @@ import "unicode"
import "image/draw" import "image/draw"
import "image/color" import "image/color"
import "golang.org/x/image/math/fixed" import "golang.org/x/image/math/fixed"
import "tomo/artist" import "art"
// Drawer is an extended TypeSetter that is able to draw text. Much like // Drawer is an extended TypeSetter that is able to draw text. Much like
// TypeSetter, It has no constructor and its zero value can be used safely. // TypeSetter, It has no constructor and its zero value can be used safely.
@ -13,7 +13,7 @@ type Drawer struct { TypeSetter }
// Draw draws the drawer's text onto the specified canvas at the given offset. // Draw draws the drawer's text onto the specified canvas at the given offset.
func (drawer Drawer) Draw ( func (drawer Drawer) Draw (
destination artist.Canvas, destination art.Canvas,
color color.RGBA, color color.RGBA,
offset image.Point, offset image.Point,
) ( ) (

View File

@ -4,7 +4,7 @@ import "image"
import "image/color" import "image/color"
import "golang.org/x/image/font" import "golang.org/x/image/font"
import "tomo/data" import "tomo/data"
import "tomo/artist" import "art"
// Color lits a number of cannonical colors, each with its own ID. // Color lits a number of cannonical colors, each with its own ID.
type Color int; const ( type Color int; const (
@ -309,7 +309,7 @@ type Hints struct {
// StaticInset defines an inset rectangular area in the middle of the // StaticInset defines an inset rectangular area in the middle of the
// pattern that does not change between PatternStates. If the inset is // pattern that does not change between PatternStates. If the inset is
// zero on all sides, this hint does not apply. // zero on all sides, this hint does not apply.
StaticInset artist.Inset StaticInset art.Inset
// Uniform specifies a singular color for the entire pattern. If the // Uniform specifies a singular color for the entire pattern. If the
// alpha channel is zero, this hint does not apply. // alpha channel is zero, this hint does not apply.
@ -322,15 +322,15 @@ type Theme interface {
FontFace (FontStyle, FontSize, Case) font.Face FontFace (FontStyle, FontSize, Case) font.Face
// Icon returns an appropriate icon given an icon name, size, and case. // Icon returns an appropriate icon given an icon name, size, and case.
Icon (Icon, IconSize, Case) artist.Icon Icon (Icon, IconSize, Case) art.Icon
// Icon returns an appropriate icon given a file mime type, size, and, // Icon returns an appropriate icon given a file mime type, size, and,
// case. // case.
MimeIcon (data.Mime, IconSize, Case) artist.Icon MimeIcon (data.Mime, IconSize, Case) art.Icon
// Pattern returns an appropriate pattern given a pattern name, case, // Pattern returns an appropriate pattern given a pattern name, case,
// and state. // and state.
Pattern (Pattern, State, Case) artist.Pattern Pattern (Pattern, State, Case) art.Pattern
// Color returns an appropriate pattern given a color name, case, and // Color returns an appropriate pattern given a color name, case, and
// state. // state.
@ -338,7 +338,7 @@ type Theme interface {
// Padding returns how much space should be between the bounds of a // Padding returns how much space should be between the bounds of a
// pattern whatever an element draws inside of it. // pattern whatever an element draws inside of it.
Padding (Pattern, Case) artist.Inset Padding (Pattern, Case) art.Inset
// Margin returns the left/right (x) and top/bottom (y) margins that // Margin returns the left/right (x) and top/bottom (y) margins that
// should be put between any self-contained objects drawn within this // should be put between any self-contained objects drawn within this