stone/application.go

51 lines
1.3 KiB
Go
Raw Normal View History

2022-10-31 13:51:28 -06:00
package stone
import "image/color"
2022-11-08 23:01:13 -07:00
// Application represents an application.
2022-10-31 13:51:28 -06:00
type Application struct {
DamageBuffer
title string
backend Backend
config Config
}
2022-11-08 23:01:13 -07:00
// SetTitle sets the application's title. If in a window, it will appear as the
// window's name.
2022-10-31 13:51:28 -06:00
func (application *Application) SetTitle (title string) {
application.title = title
application.backend.SetTitle(title)
}
2022-11-08 23:18:56 -07:00
// Run initializes the application, starts it, and then returns a channel that
// broadcasts events. If no suitable backend can be found, an error is returned.
2022-11-09 13:52:49 -07:00
func (application *Application) Run () (
2022-11-08 23:18:56 -07:00
channel chan(Event),
err error,
2022-11-06 12:47:37 -07:00
) {
2022-10-31 13:51:28 -06:00
// 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 {
2022-11-05 16:43:57 -06:00
color.RGBA { R: 0x2B, G: 0x30, B: 0x3C, A: 0xFF },
color.RGBA { R: 0x4C, G: 0x56, B: 0x6A, A: 0xFF },
color.RGBA { R: 0x2E, G: 0x34, B: 0x40, A: 0xFF },
color.RGBA { R: 0xA8, G: 0x55, B: 0x5D, A: 0xFF },
2022-10-31 13:51:28 -06:00
}
2022-11-05 16:56:56 -06:00
application.config.padding = 4
2022-10-31 13:51:28 -06:00
2022-11-02 13:14:59 -06:00
application.backend, err = instantiateBackend(application)
2022-11-06 12:47:37 -07:00
if err != nil { return }
2022-11-09 13:52:49 -07:00
channel = make(chan(Event))
application.backend.Run(channel)
2022-11-06 12:47:37 -07:00
return
2022-10-31 13:51:28 -06:00
}