stone/application.go

89 lines
2.1 KiB
Go
Raw Normal View History

2022-10-31 19:51:28 +00:00
package stone
2022-11-10 07:02:08 +00:00
import "image"
2022-10-31 19:51:28 +00:00
import "image/color"
2022-11-09 06:01:13 +00:00
// Application represents an application.
2022-10-31 19:51:28 +00:00
type Application struct {
DamageBuffer
title string
2022-11-10 07:02:08 +00:00
icons []image.Image
2022-10-31 19:51:28 +00:00
backend Backend
config Config
}
2022-11-09 06:18:56 +00: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 20:52:49 +00:00
func (application *Application) Run () (
2022-11-09 06:18:56 +00:00
channel chan(Event),
err error,
2022-11-06 19:47:37 +00:00
) {
2022-10-31 19:51:28 +00: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 22:43:57 +00: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 19:51:28 +00:00
}
application.config.fontName = ""
application.config.fontSize = 11
2022-11-05 22:56:56 +00:00
2022-11-11 20:01:36 +00:00
application.config.padding = 2
2022-10-31 19:51:28 +00:00
2022-11-02 19:14:59 +00:00
application.backend, err = instantiateBackend(application)
2022-11-06 19:47:37 +00:00
if err != nil { return }
2022-11-09 20:52:49 +00:00
channel = make(chan(Event))
2022-11-09 23:53:14 +00:00
go application.backend.Run(channel)
2022-11-06 19:47:37 +00:00
return
2022-10-31 19:51:28 +00:00
}
2022-11-09 23:53:14 +00:00
// Draw "commits" changes made in the buffer to the display.
func (application *Application) Draw () {
application.backend.Draw()
}
2022-11-10 07:02:08 +00:00
// SetTitle sets the application's title. If in a window, it will appear as the
// window's name.
func (application *Application) SetTitle (title string) (err error) {
application.title = title
if application.backend != nil {
err = application.backend.SetTitle(title)
}
return
}
func (application *Application) Title () (title string) {
title = application.title
return
}
func (application *Application) SetIcon (sizes []image.Image) (err error) {
application.icons = sizes
if application.backend != nil {
err = application.backend.SetIcon(sizes)
}
return
}
func (application *Application) Icon () (sizes []image.Image) {
sizes = application.icons
return
}
2022-11-09 23:53:14 +00:00
// Config returns a pointer to the application's configuration.
func (application *Application) Config () (config *Config) {
config = &application.config
return
}