stone/examples/style/main.go

78 lines
1.8 KiB
Go

package main
import "os"
import "fmt"
import "image"
import "math/rand"
import _ "image/png"
import "git.tebibyte.media/sashakoshka/stone"
import _ "git.tebibyte.media/sashakoshka/stone/backends/x"
var application = &stone.Application { }
func main () {
application.SetTitle("style demo")
application.SetSize(11, 8)
iconFile16, err := os.Open("assets/scaffold16.png")
if err != nil { panic(err) }
icon16, _, err := image.Decode(iconFile16)
if err != nil { panic(err) }
iconFile16.Close()
iconFile32, err := os.Open("assets/scaffold32.png")
if err != nil { panic(err) }
icon32, _, err := image.Decode(iconFile32)
if err != nil { panic(err) }
iconFile16.Close()
application.SetIcon([]image.Image { icon16, icon32 })
application.OnStart(redraw)
application.OnResize(redraw)
application.OnPress(onPress)
err = application.Run()
if err != nil { panic(err) }
}
func onPress (button stone.Button, modifiers stone.Modifiers) {
redraw()
application.Draw()
}
func redraw () {
width, _ := application.Size()
application.SetDot(0, 0)
fmt.Fprint (
application,
"normal\n",
"bold\n",
"italic\n",
"underline\n",
"all 3\n",
"highlighted\n",
"all 4\n",
"highlight?")
fillStyle(0, width, stone.StyleNormal)
fillStyle(1, width, stone.StyleBold)
fillStyle(2, width, stone.StyleItalic)
fillStyle(3, width, stone.StyleUnderline)
fillStyle(4, width, stone.StyleBoldItalic | stone.StyleUnderline)
fillStyle(5, width, stone.StyleHighlight)
fillStyle(6, width, stone.StyleBoldItalic | stone.StyleUnderline |
stone.StyleHighlight)
if rand.Int() % 2 == 0 {
fillStyle(7, width, stone.StyleNormal)
} else {
fillStyle(7, width, stone.StyleHighlight)
}
}
func fillStyle (yOffset, width int, style stone.Style) {
for x := 0; x < width; x ++ {
application.SetStyle(x, yOffset, style)
application.SetColor(x, yOffset, stone.Color(x % 7 + 1))
}
}