This commit is contained in:
Sasha Koshka 2023-02-16 14:57:46 -05:00
parent 50e9c3b1c9
commit e3369ab3d4
2 changed files with 24 additions and 19 deletions

View File

@ -15,23 +15,19 @@ import "git.tebibyte.media/sashakoshka/tomo/elements/core"
type Artist struct { type Artist struct {
*core.Core *core.Core
core core.CoreControl core core.CoreControl
cellBounds image.Rectangle
} }
// NewArtist creates a new artist test element. // NewArtist creates a new artist test element.
func NewArtist () (element *Artist) { func NewArtist () (element *Artist) {
element = &Artist { } element = &Artist { }
element.Core, element.core = core.NewCore(element.draw) element.Core, element.core = core.NewCore(element.draw)
element.core.SetMinimumSize(480, 600) element.core.SetMinimumSize(240, 360)
return return
} }
func (element *Artist) draw () { func (element *Artist) draw () {
bounds := element.Bounds() bounds := element.Bounds()
artist.FillRectangle(element.core, artist.NewUniform(hex(0)), bounds) artist.FillRectangle(element.core, artist.NewUniform(hex(0)), bounds)
element.cellBounds.Max.X = bounds.Min.X + bounds.Dx() / 5
element.cellBounds.Max.Y = bounds.Min.Y + (bounds.Dy() - 48) / 8
drawStart := time.Now() drawStart := time.Now()
@ -158,16 +154,6 @@ func (element *Artist) draw () {
element.cellAt(x, 4)) element.cellAt(x, 4))
} }
// how long did that take to render?
drawTime := time.Since(drawStart)
textDrawer := textdraw.Drawer { }
textDrawer.SetFace(defaultfont.FaceRegular)
textDrawer.SetText ([]rune (fmt.Sprintf (
"%dms\n%dus",
drawTime.Milliseconds(),
drawTime.Microseconds())))
textDrawer.Draw(element.core, uhex(0xFFFFFFFF), image.Pt(8, bounds.Max.Y - 24))
// 0, 5 // 0, 5
artist.FillRectangle ( artist.FillRectangle (
element.core, element.core,
@ -292,6 +278,18 @@ func (element *Artist) draw () {
}, },
element.cellAt(3, 7), element.cellAt(3, 7),
) )
// how long did that take to render?
drawTime := time.Since(drawStart)
textDrawer := textdraw.Drawer { }
textDrawer.SetFace(defaultfont.FaceRegular)
textDrawer.SetText ([]rune (fmt.Sprintf (
"%dms\n%dus",
drawTime.Milliseconds(),
drawTime.Microseconds())))
textDrawer.Draw (
element.core, uhex(0xFFFFFFFF),
image.Pt(bounds.Min.X + 8, bounds.Max.Y - 24))
} }
func (element *Artist) lines (weight int, bounds image.Rectangle) { func (element *Artist) lines (weight int, bounds image.Rectangle) {
@ -329,9 +327,14 @@ func (element *Artist) lines (weight int, bounds image.Rectangle) {
} }
func (element *Artist) cellAt (x, y int) (image.Rectangle) { func (element *Artist) cellAt (x, y int) (image.Rectangle) {
return element.cellBounds.Add (image.Pt ( bounds := element.Bounds()
x * element.cellBounds.Dx(), cellBounds := image.Rectangle { }
y * element.cellBounds.Dy())) cellBounds.Min = bounds.Min
cellBounds.Max.X = bounds.Min.X + bounds.Dx() / 5
cellBounds.Max.Y = bounds.Min.Y + (bounds.Dy() - 48) / 8
return cellBounds.Add (image.Pt (
x * cellBounds.Dx(),
y * cellBounds.Dy()))
} }
func hex (n uint32) (c color.RGBA) { func hex (n uint32) (c color.RGBA) {

View File

@ -45,12 +45,14 @@ func run () {
form.Adopt(basicElements.NewCheckbox("Skin", true), false) form.Adopt(basicElements.NewCheckbox("Skin", true), false)
form.Adopt(basicElements.NewCheckbox("Blood", false), false) form.Adopt(basicElements.NewCheckbox("Blood", false), false)
form.Adopt(basicElements.NewCheckbox("Bone", false), false) form.Adopt(basicElements.NewCheckbox("Bone", false), false)
art := testing.NewArtist()
list := basicElements.NewList ( list := basicElements.NewList (
basicElements.NewListEntry("button", func () { turnPage(button) }), basicElements.NewListEntry("button", func () { turnPage(button) }),
basicElements.NewListEntry("mouse", func () { turnPage(mouse) }), basicElements.NewListEntry("mouse", func () { turnPage(mouse) }),
basicElements.NewListEntry("input", func () { turnPage(input) }), basicElements.NewListEntry("input", func () { turnPage(input) }),
basicElements.NewListEntry("form", func () { turnPage(form) })) basicElements.NewListEntry("form", func () { turnPage(form) }),
basicElements.NewListEntry("art", func () { turnPage(art) }))
list.OnNoEntrySelected(func () { turnPage (intro) }) list.OnNoEntrySelected(func () { turnPage (intro) })
list.Collapse(96, 0) list.Collapse(96, 0)