Fixed coordinate system
This commit is contained in:
parent
d739c0a6ed
commit
6e5cbd50f5
@ -36,6 +36,8 @@ func (application *Application) Run (callback func (application *Application)) {
|
||||
color.RGBA { R: 0x2B, G: 0x30, B: 0x3C, A: 0xFF },
|
||||
}
|
||||
|
||||
application.config.padding = 4
|
||||
|
||||
// TODO: instead, return the error
|
||||
var err error
|
||||
application.backend, err = instantiateBackend(application)
|
||||
|
@ -12,7 +12,7 @@ import "git.tebibyte.media/sashakoshka/stone"
|
||||
type Backend struct {
|
||||
window *pixelgl.Window
|
||||
boundsDirty bool
|
||||
previousBounds pixel.Vec
|
||||
windowBounds pixel.Vec
|
||||
fontFace font.Face
|
||||
application *stone.Application
|
||||
config *stone.Config
|
||||
@ -166,19 +166,28 @@ func (backend *Backend) draw () {
|
||||
if content < 32 { continue }
|
||||
|
||||
// draw cell
|
||||
backend.textDrawer.Dot = backend.vectorAtPosition(x, y)
|
||||
backend.textDrawer.Dot = backend.vectorAtPosition(x, y + 1)
|
||||
backend.textDrawer.WriteRune(content)
|
||||
backend.textDrawer.Draw(backend.window, pixel.IM)
|
||||
}
|
||||
}
|
||||
|
||||
backend.backgroundStamper.Clear()
|
||||
backend.backgroundStamper.Color =
|
||||
backend.config.Color(stone.ColorBackground)
|
||||
backend.backgroundStamper.Push (
|
||||
backend.vectorAtPosition(0, 0),
|
||||
backend.vectorAtPosition(width, height))
|
||||
backend.backgroundStamper.Rectangle(1)
|
||||
backend.backgroundStamper.Draw(backend.window)
|
||||
|
||||
backend.window.SwapBuffers()
|
||||
}
|
||||
|
||||
func (backend *Backend) processEvents () {
|
||||
newBounds := backend.window.Bounds().Max
|
||||
backend.boundsDirty = backend.previousBounds != newBounds
|
||||
backend.previousBounds = newBounds
|
||||
backend.boundsDirty = backend.windowBounds != newBounds
|
||||
backend.windowBounds = newBounds
|
||||
|
||||
if backend.boundsDirty {
|
||||
// TODO: set size of buffer
|
||||
@ -186,9 +195,12 @@ func (backend *Backend) processEvents () {
|
||||
}
|
||||
|
||||
func (backend *Backend) vectorAtPosition (x, y int) (vector pixel.Vec) {
|
||||
padding := backend.config.Padding() * backend.metrics.cellWidth
|
||||
|
||||
vector = pixel.V (
|
||||
float64(x * backend.metrics.cellWidth),
|
||||
float64(y * backend.metrics.cellHeight))
|
||||
float64 (x * backend.metrics.cellWidth + padding),
|
||||
backend.windowBounds.Y - float64 (
|
||||
y * backend.metrics.cellHeight + padding))
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -20,8 +20,17 @@ func run (application *stone.Application) {
|
||||
application.SetRune(6, 0, 'l')
|
||||
application.SetRune(7, 0, 'd')
|
||||
application.SetRune(8, 0, '!')
|
||||
application.SetRune(4, 4, ':')
|
||||
application.SetRune(5, 4, '3')
|
||||
application.SetRune(4, 1, ':')
|
||||
application.SetRune(5, 1, '3')
|
||||
application.SetRune(0, 2, 'A')
|
||||
application.SetRune(1, 2, 'A')
|
||||
application.SetRune(2, 2, 'A')
|
||||
application.SetRune(3, 2, 'A')
|
||||
application.SetRune(4, 2, 'A')
|
||||
application.SetRune(5, 2, 'A')
|
||||
application.SetRune(6, 2, 'A')
|
||||
application.SetRune(7, 2, 'A')
|
||||
application.SetRune(8, 2, 'A')
|
||||
}
|
||||
|
||||
if !application.Await(0) { break }
|
||||
|
Loading…
Reference in New Issue
Block a user