90 lines
2.4 KiB
Go
90 lines
2.4 KiB
Go
package stone
|
|
|
|
import "time"
|
|
import "image/color"
|
|
|
|
type Application struct {
|
|
DamageBuffer
|
|
|
|
title string
|
|
backend Backend
|
|
config Config
|
|
}
|
|
|
|
func (application *Application) SetSize (width, height int) {
|
|
application.DamageBuffer.SetSize(width, height)
|
|
// application.updateWindowSize()
|
|
}
|
|
|
|
func (application *Application) SetTitle (title string) {
|
|
application.title = title
|
|
application.backend.SetTitle(title)
|
|
}
|
|
|
|
func (application *Application) Run (callback func (application *Application)) {
|
|
// default values for certain parameters
|
|
width, height := application.Size()
|
|
if width < 1 { width = 80 }
|
|
if height < 1 { height = 20 }
|
|
application.DamageBuffer.SetSize(width, height)
|
|
|
|
// 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 },
|
|
}
|
|
|
|
application.backend.Run(callback)
|
|
}
|
|
|
|
func (application *Application) Await (timeout time.Duration) (keepRunning bool) {
|
|
keepRunning = application.Await(timeout)
|
|
return
|
|
}
|
|
|
|
func (application *Application) Poll () (keepRunning bool) {
|
|
keepRunning = application.Poll()
|
|
return
|
|
}
|
|
|
|
func (application *Application) Title () (title string) {
|
|
title = application.title
|
|
return
|
|
}
|
|
|
|
func (application *Application) Config () (config *Config) {
|
|
config = &application.config
|
|
return
|
|
}
|
|
|
|
// func (application *Application) Resized () (resized bool) {
|
|
// resized = application.boundsDirty
|
|
// return
|
|
// }
|
|
|
|
|
|
// // updateWindowSize updates the window size according to the buffer size.
|
|
// func (application *Application) updateWindowSize () {
|
|
// if application.window == nil { return }
|
|
// application.window.SetBounds(application.calculateWindowSize())
|
|
// }
|
|
|
|
// updateBufferSize updats the buffer size according to the window size.
|
|
// func (application *Application) updateBufferSize () {
|
|
// if application.window == nil {
|
|
// panic("call to application.updateBufferSize before window exists")
|
|
// }
|
|
//
|
|
// windowBounds := application.window.Bounds().Max
|
|
//
|
|
// if windowBounds != application.previousBounds {
|
|
// application.previousBounds = windowBounds
|
|
// application.boundsDirty = true
|
|
// application.DamageBuffer.SetSize (
|
|
// int(windowBounds.X) / application.metrics.cellWidth,
|
|
// int(windowBounds.Y) / application.metrics.cellHeight)
|
|
// }
|
|
// }
|