Cells are now drawn

This commit is contained in:
Sasha Koshka 2022-11-05 18:43:57 -04:00
parent 11cab091dc
commit d739c0a6ed
3 changed files with 17 additions and 10 deletions

View File

@ -30,10 +30,10 @@ func (application *Application) Run (callback func (application *Application)) {
// TODO: load these from a file // TODO: load these from a file
application.config.colors = [4]color.Color { application.config.colors = [4]color.Color {
color.RGBA { R: 0x00, G: 0x00, B: 0x00, A: 0xFF }, color.RGBA { R: 0x81, G: 0xA1, B: 0xC1, A: 0xFF },
color.RGBA { R: 0xFF, G: 0xFF, B: 0xFF, A: 0xFF }, color.RGBA { R: 0x4C, G: 0x56, B: 0x6A, A: 0xFF },
color.RGBA { R: 0x00, G: 0x00, B: 0x00, A: 0xFF }, color.RGBA { R: 0xD8, G: 0xDE, B: 0xE9, A: 0xFF },
color.RGBA { R: 0xFF, G: 0xFF, B: 0xFF, A: 0xFF }, color.RGBA { R: 0x2B, G: 0x30, B: 0x3C, A: 0xFF },
} }
// TODO: instead, return the error // TODO: instead, return the error

View File

@ -1,9 +1,9 @@
package pixel package pixel
import "fmt"
import "time" import "time"
import "golang.org/x/image/font" import "golang.org/x/image/font"
import "github.com/faiface/pixel" import "github.com/faiface/pixel"
import "github.com/faiface/pixel/text"
import "github.com/faiface/pixel/imdraw" import "github.com/faiface/pixel/imdraw"
import "github.com/faiface/pixel/pixelgl" import "github.com/faiface/pixel/pixelgl"
import "golang.org/x/image/font/basicfont" import "golang.org/x/image/font/basicfont"
@ -17,6 +17,8 @@ type Backend struct {
application *stone.Application application *stone.Application
config *stone.Config config *stone.Config
backgroundStamper *imdraw.IMDraw backgroundStamper *imdraw.IMDraw
fontAtlas *text.Atlas
textDrawer *text.Text
metrics struct { metrics struct {
cellWidth int cellWidth int
@ -51,6 +53,8 @@ func (backend *Backend) Run (callback func (application *stone.Application)) {
Bounds: backend.calculateWindowSize(), Bounds: backend.calculateWindowSize(),
}) })
backend.backgroundStamper = imdraw.New(nil) backend.backgroundStamper = imdraw.New(nil)
backend.fontAtlas = text.NewAtlas(backend.fontFace, text.ASCII)
backend.textDrawer = text.New(pixel.V(0, 0), backend.fontAtlas)
backend.Poll() backend.Poll()
if err != nil { panic(err.Error()) } if err != nil { panic(err.Error()) }
@ -150,20 +154,21 @@ func (backend *Backend) draw () {
backend.backgroundStamper.Draw(backend.window) backend.backgroundStamper.Draw(backend.window)
} }
// TODO: draw dirty cells. backend.textDrawer.Clear()
for x := 0; x < width; x ++ { for x := 0; x < width; x ++ {
for y := 0; y < height; y ++ { for y := 0; y < height; y ++ {
clean := backend.application.Clean(x, y) clean := backend.application.Clean(x, y)
// cell := application.content[index]
if clean { continue } if clean { continue }
backend.application.MarkClean(x, y) backend.application.MarkClean(x, y)
// draw cell
cell := backend.application.Cell(x, y) cell := backend.application.Cell(x, y)
content := cell.Rune() content := cell.Rune()
if content < 32 { continue } if content < 32 { continue }
fmt.Println(content)
// draw cell
backend.textDrawer.Dot = backend.vectorAtPosition(x, y)
backend.textDrawer.WriteRune(content)
backend.textDrawer.Draw(backend.window, pixel.IM)
} }
} }

View File

@ -9,7 +9,7 @@ func main () {
} }
func run (application *stone.Application) { func run (application *stone.Application) {
for application.Await(0) { for {
if application.Resized() { if application.Resized() {
application.SetRune(0, 0, 'h') application.SetRune(0, 0, 'h')
application.SetRune(1, 0, 'e') application.SetRune(1, 0, 'e')
@ -23,5 +23,7 @@ func run (application *stone.Application) {
application.SetRune(4, 4, ':') application.SetRune(4, 4, ':')
application.SetRune(5, 4, '3') application.SetRune(5, 4, '3')
} }
if !application.Await(0) { break }
} }
} }