91 lines
2.2 KiB
Go
91 lines
2.2 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
|
|
"github.com/ebitenui/ebitenui"
|
|
"github.com/ebitenui/ebitenui/image"
|
|
"github.com/ebitenui/ebitenui/widget"
|
|
"github.com/hajimehoshi/ebiten/v2"
|
|
"github.com/hajimehoshi/ebiten/v2/text/v2"
|
|
"golang.org/x/image/colornames"
|
|
"golang.org/x/image/font/gofont/goregular"
|
|
)
|
|
|
|
type Editor struct {
|
|
ui *ebitenui.UI
|
|
}
|
|
|
|
func NewEditor() *Editor {
|
|
root := widget.NewContainer(
|
|
widget.ContainerOpts.BackgroundImage(
|
|
image.NewNineSliceColor(colornames.Gainsboro),
|
|
))
|
|
root.AddChild(
|
|
widget.NewButton(
|
|
widget.ButtonOpts.TextLabel("Open Sprite Sheet..."),
|
|
widget.ButtonOpts.TextFace(DefaultFont()),
|
|
widget.ButtonOpts.TextColor(&widget.ButtonTextColor{
|
|
Idle: colornames.Gainsboro,
|
|
Hover: colornames.Gainsboro,
|
|
Pressed: colornames.Gainsboro,
|
|
}),
|
|
widget.ButtonOpts.Image(&widget.ButtonImage{
|
|
Idle: DefaultNineSlice(colornames.Darkslategray),
|
|
Hover: DefaultNineSlice(Mix(colornames.Darkslategray, colornames.Mediumseagreen, 0.4)),
|
|
Disabled: DefaultNineSlice(Mix(colornames.Darkslategray, colornames.Gainsboro, 0.8)),
|
|
Pressed: PressedNineSlice(Mix(colornames.Darkslategray, colornames.Black, 0.4)),
|
|
PressedHover: PressedNineSlice(Mix(colornames.Darkslategray, colornames.Black, 0.4)),
|
|
}),
|
|
widget.ButtonOpts.WidgetOpts(
|
|
widget.WidgetOpts.LayoutData(widget.AnchorLayoutData{
|
|
VerticalPosition: widget.AnchorLayoutPositionCenter,
|
|
HorizontalPosition: widget.AnchorLayoutPositionCenter,
|
|
}),
|
|
widget.WidgetOpts.MinSize(180, 48),
|
|
),
|
|
),
|
|
)
|
|
|
|
return &Editor{
|
|
ui: &ebitenui.UI{Container: root},
|
|
}
|
|
}
|
|
|
|
func (e *Editor) Update() error {
|
|
e.ui.Update()
|
|
return nil
|
|
}
|
|
|
|
func (e *Editor) Draw(screen *ebiten.Image) {
|
|
e.ui.Draw(screen)
|
|
}
|
|
|
|
func (e *Editor) Layout(w, h int) (int, int) {
|
|
return w, h
|
|
}
|
|
|
|
func DefaultFont() *text.Face {
|
|
s, err := text.NewGoTextFaceSource(bytes.NewReader(goregular.TTF))
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
var f text.Face
|
|
|
|
f = &text.GoTextFace{
|
|
Source: s,
|
|
Size: 20,
|
|
}
|
|
|
|
return &f
|
|
}
|
|
|
|
func main() {
|
|
ebiten.SetWindowSize(480, 320)
|
|
ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
|
|
if err := ebiten.RunGame(NewEditor()); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|