106 lines
2.7 KiB
Go
106 lines
2.7 KiB
Go
package stone
|
|
|
|
import "image"
|
|
import "image/color"
|
|
|
|
// Application represents an application.
|
|
type Application struct {
|
|
DamageBuffer
|
|
|
|
title string
|
|
icons []image.Image
|
|
backend Backend
|
|
config Config
|
|
}
|
|
|
|
// 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.
|
|
func (application *Application) Run () (
|
|
channel chan(Event),
|
|
err error,
|
|
) {
|
|
// 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 = [8]color.Color {
|
|
// background
|
|
color.RGBA { R: 0, G: 0, B: 0, A: 0 },
|
|
// foreground
|
|
color.RGBA { R: 0xFF, G: 0xFF, B: 0xFF, A: 0xFF },
|
|
// red
|
|
color.RGBA { R: 0xFF, G: 0xFF, B: 0xFF, A: 0xFF },
|
|
// orange
|
|
color.RGBA { R: 0xFF, G: 0x80, B: 0x00, A: 0xFF },
|
|
// yellow
|
|
color.RGBA { R: 0xFF, G: 0xFF, B: 0x00, A: 0xFF },
|
|
// green
|
|
color.RGBA { R: 0x00, G: 0xFF, B: 0x00, A: 0xFF },
|
|
// blue
|
|
color.RGBA { R: 0x00, G: 0x00, B: 0xFF, A: 0xFF },
|
|
// purple
|
|
color.RGBA { R: 0x80, G: 0x00, B: 0xFF, A: 0xFF },
|
|
}
|
|
application.config.fontName = ""
|
|
application.config.fontSize = 11
|
|
|
|
application.config.padding = 2
|
|
|
|
application.backend, err = instantiateBackend(application)
|
|
if err != nil { return }
|
|
|
|
channel = make(chan(Event))
|
|
go application.backend.Run(channel)
|
|
|
|
return
|
|
}
|
|
|
|
// Draw "commits" changes made in the buffer to the display.
|
|
func (application *Application) Draw () {
|
|
application.backend.Draw()
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
// Title returns the application's title.
|
|
func (application *Application) Title () (title string) {
|
|
title = application.title
|
|
return
|
|
}
|
|
|
|
// SetIcon takes in a list of different sizes of an icon, and sets it as the
|
|
// application's icon.
|
|
func (application *Application) SetIcon (sizes []image.Image) (err error) {
|
|
application.icons = sizes
|
|
if application.backend != nil {
|
|
err = application.backend.SetIcon(sizes)
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// Icon returns all available sizes of the application's icon. If there is no
|
|
// icon, nil is returned.
|
|
func (application *Application) Icon () (sizes []image.Image) {
|
|
sizes = application.icons
|
|
return
|
|
}
|
|
|
|
// Config returns a pointer to the application's configuration.
|
|
func (application *Application) Config () (config *Config) {
|
|
config = &application.config
|
|
return
|
|
}
|