Added a configuration viewer example
This commit is contained in:
parent
73ae475a7d
commit
19895e6049
10
buffer.go
10
buffer.go
@ -192,9 +192,13 @@ func (buffer *DamageBuffer) Write (bytes []byte) (bytesWritten int, err error) {
|
||||
bytesWritten = len(bytes)
|
||||
|
||||
for _, character := range text {
|
||||
buffer.setRune(buffer.dot.x, buffer.dot.y, character)
|
||||
buffer.dot.x ++
|
||||
if buffer.dot.x > buffer.width { break }
|
||||
if character == '\n' {
|
||||
buffer.dot.x = 0
|
||||
buffer.dot.y ++
|
||||
} else {
|
||||
buffer.setRune(buffer.dot.x, buffer.dot.y, character)
|
||||
buffer.dot.x ++
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
|
106
examples/confview/confview.go
Normal file
106
examples/confview/confview.go
Normal file
@ -0,0 +1,106 @@
|
||||
package main
|
||||
|
||||
import "os"
|
||||
import "image"
|
||||
import "image/color"
|
||||
import _ "image/png"
|
||||
import "git.tebibyte.media/sashakoshka/stone"
|
||||
import "git.tebibyte.media/sashakoshka/stone/config"
|
||||
import _ "git.tebibyte.media/sashakoshka/stone/backends/x"
|
||||
|
||||
var application = &stone.Application { }
|
||||
var inputState struct {
|
||||
x int
|
||||
y int
|
||||
}
|
||||
var globalConfig config.Config
|
||||
|
||||
func main () {
|
||||
application.SetTitle("configuration viewer")
|
||||
application.SetSize(32, 16)
|
||||
|
||||
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.OnPress(onPress)
|
||||
application.OnRelease(onRelease)
|
||||
application.OnMouseMove(onMouseMove)
|
||||
application.OnStart(onStart)
|
||||
application.OnResize(redraw)
|
||||
|
||||
err = application.Run()
|
||||
if err != nil { panic(err) }
|
||||
}
|
||||
|
||||
func onStart () {
|
||||
// this is just copy pasted from config.go
|
||||
globalConfig = config.Config {
|
||||
LegalParameters: map[string] config.Type {
|
||||
"fontNormal": config.TypeString,
|
||||
"fontSize": config.TypeInteger,
|
||||
"padding": config.TypeInteger,
|
||||
"center": config.TypeBoolean,
|
||||
"colorBackground": config.TypeColor,
|
||||
"colorForeground": config.TypeColor,
|
||||
"colorDim": config.TypeColor,
|
||||
"colorRed": config.TypeColor,
|
||||
"colorYellow": config.TypeColor,
|
||||
"colorGreen": config.TypeColor,
|
||||
"colorBlue": config.TypeColor,
|
||||
"colorPurple": config.TypeColor,
|
||||
},
|
||||
|
||||
Parameters: map[string] any {
|
||||
"fontNormal": "",
|
||||
"fontSize": 11,
|
||||
"padding": 2,
|
||||
"center": false,
|
||||
"colorBackground":
|
||||
color.RGBA { R: 0, G: 0, B: 0, A: 0 },
|
||||
"colorForeground":
|
||||
color.RGBA { R: 0xFF, G: 0xFF, B: 0xFF, A: 0xFF },
|
||||
"colorDim":
|
||||
color.RGBA { R: 0x80, G: 0x80, B: 0x80, A: 0xFF },
|
||||
"colorRed":
|
||||
color.RGBA { R: 0xFF, G: 0x00, B: 0x00, A: 0xFF },
|
||||
"colorYellow":
|
||||
color.RGBA { R: 0xFF, G: 0xFF, B: 0x00, A: 0xFF },
|
||||
"colorGreen":
|
||||
color.RGBA { R: 0x00, G: 0xFF, B: 0x00, A: 0xFF },
|
||||
"colorBlue":
|
||||
color.RGBA { R: 0x00, G: 0x80, B: 0xFF, A: 0xFF },
|
||||
"colorPurple":
|
||||
color.RGBA { R: 0x80, G: 0x40, B: 0xFF, A: 0xFF },
|
||||
},
|
||||
}
|
||||
globalConfig.Load("stone")
|
||||
redraw()
|
||||
}
|
||||
|
||||
func redraw () {
|
||||
// i fucking love go interfaces
|
||||
application.Clear()
|
||||
application.SetDot(0, 0)
|
||||
globalConfig.SaveTo(application)
|
||||
}
|
||||
|
||||
func onPress (button stone.Button, modifiers stone.Modifiers) {
|
||||
}
|
||||
|
||||
func onRelease (button stone.Button) {
|
||||
}
|
||||
|
||||
func onMouseMove (x, y int) {
|
||||
inputState.x = x
|
||||
inputState.y = y
|
||||
}
|
@ -50,7 +50,8 @@ func onRelease (button stone.Button) {
|
||||
}
|
||||
}
|
||||
|
||||
func onMouseMove (x, y int) { if mousePressed {
|
||||
func onMouseMove (x, y int) {
|
||||
if mousePressed {
|
||||
application.SetRune(x, y, '#')
|
||||
application.Draw()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user