2022-11-28 22:26:26 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import "os"
|
|
|
|
import "fmt"
|
|
|
|
import "image"
|
2022-11-28 22:50:23 -07:00
|
|
|
import "math/rand"
|
2022-11-28 22:26:26 -07:00
|
|
|
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")
|
2022-11-28 22:50:23 -07:00
|
|
|
application.SetSize(11, 8)
|
2022-11-28 22:26:26 -07:00
|
|
|
|
|
|
|
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)
|
2022-11-28 22:50:23 -07:00
|
|
|
application.OnPress(onPress)
|
2022-11-28 22:26:26 -07:00
|
|
|
|
|
|
|
err = application.Run()
|
|
|
|
if err != nil { panic(err) }
|
|
|
|
}
|
|
|
|
|
2022-11-28 22:50:23 -07:00
|
|
|
func onPress (button stone.Button, modifiers stone.Modifiers) {
|
|
|
|
redraw()
|
|
|
|
application.Draw()
|
|
|
|
}
|
|
|
|
|
2022-11-28 22:26:26 -07:00
|
|
|
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",
|
2022-11-28 22:50:23 -07:00
|
|
|
"all 4\n",
|
|
|
|
"highlight?")
|
2022-11-28 22:26:26 -07:00
|
|
|
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)
|
2022-11-28 22:50:23 -07:00
|
|
|
|
|
|
|
if rand.Int() % 2 == 0 {
|
|
|
|
fillStyle(7, width, stone.StyleNormal)
|
|
|
|
} else {
|
|
|
|
fillStyle(7, width, stone.StyleHighlight)
|
|
|
|
}
|
2022-11-28 22:26:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func fillStyle (yOffset, width int, style stone.Style) {
|
|
|
|
for x := 0; x < width; x ++ {
|
|
|
|
application.SetStyle(x, yOffset, style)
|
2022-11-28 22:50:23 -07:00
|
|
|
application.SetColor(x, yOffset, stone.Color(x % 7 + 1))
|
2022-11-28 22:26:26 -07:00
|
|
|
}
|
|
|
|
}
|