Individually clear dirty cells
This commit is contained in:
		
							parent
							
								
									e12fb3d7db
								
							
						
					
					
						commit
						11cab091dc
					
				@ -1,8 +1,10 @@
 | 
				
			|||||||
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/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"
 | 
				
			||||||
import "git.tebibyte.media/sashakoshka/stone"
 | 
					import "git.tebibyte.media/sashakoshka/stone"
 | 
				
			||||||
@ -14,6 +16,7 @@ type Backend struct {
 | 
				
			|||||||
	fontFace          font.Face
 | 
						fontFace          font.Face
 | 
				
			||||||
	application       *stone.Application
 | 
						application       *stone.Application
 | 
				
			||||||
	config            *stone.Config
 | 
						config            *stone.Config
 | 
				
			||||||
 | 
						backgroundStamper *imdraw.IMDraw
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	metrics struct {
 | 
						metrics struct {
 | 
				
			||||||
		cellWidth  int
 | 
							cellWidth  int
 | 
				
			||||||
@ -37,6 +40,7 @@ func (backend *Backend) Run (callback func (application *stone.Application)) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	pixelgl.Run (func () {
 | 
						pixelgl.Run (func () {
 | 
				
			||||||
 | 
							// construct the window, and all that
 | 
				
			||||||
		var err error
 | 
							var err error
 | 
				
			||||||
		backend.window, err = pixelgl.NewWindow (pixelgl.WindowConfig {
 | 
							backend.window, err = pixelgl.NewWindow (pixelgl.WindowConfig {
 | 
				
			||||||
			Resizable:   true,
 | 
								Resizable:   true,
 | 
				
			||||||
@ -46,6 +50,7 @@ func (backend *Backend) Run (callback func (application *stone.Application)) {
 | 
				
			|||||||
			Title:       backend.application.Title(),
 | 
								Title:       backend.application.Title(),
 | 
				
			||||||
			Bounds:      backend.calculateWindowSize(),
 | 
								Bounds:      backend.calculateWindowSize(),
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
							backend.backgroundStamper = imdraw.New(nil)
 | 
				
			||||||
		backend.Poll()
 | 
							backend.Poll()
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		if err != nil { panic(err.Error()) }
 | 
							if err != nil { panic(err.Error()) }
 | 
				
			||||||
@ -115,6 +120,7 @@ func (backend *Backend) Resized () (resized bool) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (backend *Backend) draw () {
 | 
					func (backend *Backend) draw () {
 | 
				
			||||||
	// didDrawing := false
 | 
						// didDrawing := false
 | 
				
			||||||
 | 
						width, height := backend.application.Size()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if backend.boundsDirty {
 | 
						if backend.boundsDirty {
 | 
				
			||||||
		backend.window.Clear (
 | 
							backend.window.Clear (
 | 
				
			||||||
@ -122,28 +128,42 @@ func (backend *Backend) draw () {
 | 
				
			|||||||
		backend.boundsDirty = false
 | 
							backend.boundsDirty = false
 | 
				
			||||||
		// didDrawing = true
 | 
							// didDrawing = true
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		// TODO: clear out dirty cells before drawing them (we don't
 | 
							// clear out dirty cells before drawing them. this is in an else
 | 
				
			||||||
		// want to clear them out if we have already just cleared
 | 
							// block because if the bounds were dirty, we have already
 | 
				
			||||||
		// everything out)
 | 
							// 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.
 | 
						// TODO: draw dirty cells.
 | 
				
			||||||
	width, height := backend.application.Size()
 | 
					 | 
				
			||||||
	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]
 | 
								// cell  := application.content[index]
 | 
				
			||||||
			if clean { continue }
 | 
								if clean { continue }
 | 
				
			||||||
 | 
								backend.application.MarkClean(x, y)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			// draw cell
 | 
								// 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)
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
			// 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) {
 | 
					func (backend *Backend) calculateWindowSize () (bounds pixel.Rect) {
 | 
				
			||||||
	width, height := backend.application.Size()
 | 
						width, height := backend.application.Size()
 | 
				
			||||||
	bounds = pixel.R (
 | 
						bounds = pixel.R (
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user