Individually clear dirty cells
This commit is contained in:
parent
e12fb3d7db
commit
11cab091dc
@ -1,19 +1,22 @@
|
||||
package pixel
|
||||
|
||||
import "fmt"
|
||||
import "time"
|
||||
import "golang.org/x/image/font"
|
||||
import "github.com/faiface/pixel"
|
||||
import "github.com/faiface/pixel/imdraw"
|
||||
import "github.com/faiface/pixel/pixelgl"
|
||||
import "golang.org/x/image/font/basicfont"
|
||||
import "git.tebibyte.media/sashakoshka/stone"
|
||||
|
||||
type Backend struct {
|
||||
window *pixelgl.Window
|
||||
boundsDirty bool
|
||||
previousBounds pixel.Vec
|
||||
fontFace font.Face
|
||||
application *stone.Application
|
||||
config *stone.Config
|
||||
window *pixelgl.Window
|
||||
boundsDirty bool
|
||||
previousBounds pixel.Vec
|
||||
fontFace font.Face
|
||||
application *stone.Application
|
||||
config *stone.Config
|
||||
backgroundStamper *imdraw.IMDraw
|
||||
|
||||
metrics struct {
|
||||
cellWidth int
|
||||
@ -37,6 +40,7 @@ func (backend *Backend) Run (callback func (application *stone.Application)) {
|
||||
}
|
||||
|
||||
pixelgl.Run (func () {
|
||||
// construct the window, and all that
|
||||
var err error
|
||||
backend.window, err = pixelgl.NewWindow (pixelgl.WindowConfig {
|
||||
Resizable: true,
|
||||
@ -46,6 +50,7 @@ func (backend *Backend) Run (callback func (application *stone.Application)) {
|
||||
Title: backend.application.Title(),
|
||||
Bounds: backend.calculateWindowSize(),
|
||||
})
|
||||
backend.backgroundStamper = imdraw.New(nil)
|
||||
backend.Poll()
|
||||
|
||||
if err != nil { panic(err.Error()) }
|
||||
@ -115,6 +120,7 @@ func (backend *Backend) Resized () (resized bool) {
|
||||
|
||||
func (backend *Backend) draw () {
|
||||
// didDrawing := false
|
||||
width, height := backend.application.Size()
|
||||
|
||||
if backend.boundsDirty {
|
||||
backend.window.Clear (
|
||||
@ -122,28 +128,42 @@ func (backend *Backend) draw () {
|
||||
backend.boundsDirty = false
|
||||
// didDrawing = true
|
||||
} else {
|
||||
// TODO: clear out dirty cells before drawing them (we don't
|
||||
// want to clear them out if we have already just cleared
|
||||
// everything out)
|
||||
// clear out dirty cells before drawing them. this is in an else
|
||||
// block because if the bounds were dirty, we have already
|
||||
// cleared the entire screen.
|
||||
|
||||
|
||||
backend.backgroundStamper.Clear()
|
||||
backend.backgroundStamper.Color =
|
||||
backend.config.Color(stone.ColorApplication)
|
||||
for x := 0; x < width; x ++ {
|
||||
for y := 0; y < height; y ++ {
|
||||
clean := backend.application.Clean(x, y)
|
||||
if clean { continue }
|
||||
|
||||
backend.backgroundStamper.Push (
|
||||
backend.vectorAtPosition(x, y),
|
||||
backend.vectorAtPosition(x + 1, y + 1))
|
||||
backend.backgroundStamper.Rectangle(1)
|
||||
// didDrawing = true
|
||||
}
|
||||
}
|
||||
backend.backgroundStamper.Draw(backend.window)
|
||||
}
|
||||
|
||||
// TODO: draw dirty cells.
|
||||
width, height := backend.application.Size()
|
||||
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)
|
||||
|
||||
// didDrawing = true // TODO: set didDrawing up there ^
|
||||
backend.application.MarkClean(x, y)
|
||||
}
|
||||
}
|
||||
|
||||
@ -160,6 +180,13 @@ func (backend *Backend) processEvents () {
|
||||
}
|
||||
}
|
||||
|
||||
func (backend *Backend) vectorAtPosition (x, y int) (vector pixel.Vec) {
|
||||
vector = pixel.V (
|
||||
float64(x * backend.metrics.cellWidth),
|
||||
float64(y * backend.metrics.cellHeight))
|
||||
return
|
||||
}
|
||||
|
||||
func (backend *Backend) calculateWindowSize () (bounds pixel.Rect) {
|
||||
width, height := backend.application.Size()
|
||||
bounds = pixel.R (
|
||||
|
Loading…
Reference in New Issue
Block a user