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
application.config.colors = [4]color.Color {
color.RGBA { R: 0x00, G: 0x00, B: 0x00, A: 0xFF },
color.RGBA { R: 0xFF, G: 0xFF, B: 0xFF, A: 0xFF },
color.RGBA { R: 0x00, G: 0x00, B: 0x00, A: 0xFF },
color.RGBA { R: 0xFF, G: 0xFF, B: 0xFF, A: 0xFF },
color.RGBA { R: 0x81, G: 0xA1, B: 0xC1, A: 0xFF },
color.RGBA { R: 0x4C, G: 0x56, B: 0x6A, A: 0xFF },
color.RGBA { R: 0xD8, G: 0xDE, B: 0xE9, A: 0xFF },
color.RGBA { R: 0x2B, G: 0x30, B: 0x3C, A: 0xFF },
}
// TODO: instead, return the error

View File

@ -1,9 +1,9 @@
package pixel
import "fmt"
import "time"
import "golang.org/x/image/font"
import "github.com/faiface/pixel"
import "github.com/faiface/pixel/text"
import "github.com/faiface/pixel/imdraw"
import "github.com/faiface/pixel/pixelgl"
import "golang.org/x/image/font/basicfont"
@ -17,6 +17,8 @@ type Backend struct {
application *stone.Application
config *stone.Config
backgroundStamper *imdraw.IMDraw
fontAtlas *text.Atlas
textDrawer *text.Text
metrics struct {
cellWidth int
@ -51,6 +53,8 @@ func (backend *Backend) Run (callback func (application *stone.Application)) {
Bounds: backend.calculateWindowSize(),
})
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()
if err != nil { panic(err.Error()) }
@ -150,20 +154,21 @@ func (backend *Backend) draw () {
backend.backgroundStamper.Draw(backend.window)
}
// TODO: draw dirty cells.
backend.textDrawer.Clear()
for x := 0; x < width; x ++ {
for y := 0; y < height; y ++ {
clean := backend.application.Clean(x, y)
// cell := application.content[index]
if clean { continue }
backend.application.MarkClean(x, y)
// draw cell
cell := backend.application.Cell(x, y)
content := cell.Rune()
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) {
for application.Await(0) {
for {
if application.Resized() {
application.SetRune(0, 0, 'h')
application.SetRune(1, 0, 'e')
@ -23,5 +23,7 @@ func run (application *stone.Application) {
application.SetRune(4, 4, ':')
application.SetRune(5, 4, '3')
}
if !application.Await(0) { break }
}
}