Cells are now drawn
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user