holy shit components are rendering whaaaaaaaaaaaaaaaat
This commit was merged in pull request #4.
This commit is contained in:
68
tools/component_test/editor.go
Normal file
68
tools/component_test/editor.go
Normal file
@@ -0,0 +1,68 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
|
||||
"git.vezzani.net/ben/games/common/elements/v1"
|
||||
"git.vezzani.net/ben/games/common/elements/v1/blocks"
|
||||
"git.vezzani.net/ben/games/common/elements/v1/stacks"
|
||||
"git.vezzani.net/ben/games/common/sprites/v1"
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"golang.org/x/image/colornames"
|
||||
)
|
||||
|
||||
var root = stacks.New(
|
||||
stacks.Horizontal(),
|
||||
stacks.BlockOpt(blocks.BackgroundColor(color.White)),
|
||||
stacks.BlockOpt(blocks.Size(200, 200)),
|
||||
stacks.BlockOpt(blocks.Name("parent")),
|
||||
stacks.Children(
|
||||
stacks.New(
|
||||
stacks.BlockOpt(blocks.Name("left")),
|
||||
stacks.Children(
|
||||
blocks.New(blocks.BackgroundColor(colornames.Green)),
|
||||
blocks.New(blocks.BackgroundColor(colornames.Yellow)),
|
||||
)),
|
||||
stacks.New(
|
||||
stacks.BlockOpt(blocks.Name("right")),
|
||||
stacks.Children(
|
||||
blocks.New(blocks.BackgroundColor(colornames.Blue)),
|
||||
blocks.New(blocks.BackgroundColor(colornames.Red)),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
func newEditor() *editor {
|
||||
return &editor{}
|
||||
}
|
||||
|
||||
type editor struct {
|
||||
root elements.Element
|
||||
bounds elements.Bounds
|
||||
}
|
||||
|
||||
//var handleClick = mouse.ClickHandler(root)
|
||||
|
||||
func (e *editor) Update() error {
|
||||
sprites.Update()
|
||||
//handleClick()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *editor) Draw(screen *ebiten.Image) {
|
||||
e.root.Draw(screen)
|
||||
}
|
||||
|
||||
func (e *editor) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int) {
|
||||
if e.bounds.Width != float64(outsideWidth) || e.bounds.Height != float64(outsideHeight) {
|
||||
e.bounds = elements.Bounds{
|
||||
Min: elements.Point{},
|
||||
Width: float64(outsideWidth),
|
||||
Height: float64(outsideHeight),
|
||||
}
|
||||
e.root = root(e.bounds)
|
||||
}
|
||||
|
||||
return outsideWidth, outsideHeight
|
||||
}
|
||||
15
tools/component_test/main.go
Normal file
15
tools/component_test/main.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ebiten.SetWindowSize(480, 320)
|
||||
ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
|
||||
ebiten.SetWindowTitle("Component/Layout Test")
|
||||
e := newEditor()
|
||||
if err := ebiten.RunGame(e); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,48 @@
|
||||
package main
|
||||
|
||||
import "github.com/hajimehoshi/ebiten/v2"
|
||||
import (
|
||||
"image/color"
|
||||
|
||||
"git.vezzani.net/ben/games/common/elements/v1"
|
||||
"git.vezzani.net/ben/games/common/elements/v1/blocks"
|
||||
"git.vezzani.net/ben/games/common/elements/v1/stacks"
|
||||
"git.vezzani.net/ben/games/common/sprites/v1"
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"golang.org/x/image/colornames"
|
||||
)
|
||||
|
||||
var menu = stacks.New(
|
||||
stacks.BlockOpt(blocks.BackgroundColor(color.White)),
|
||||
stacks.BlockOpt(blocks.Size(100, 200)),
|
||||
stacks.Children(
|
||||
blocks.New(blocks.BackgroundColor(colornames.Green)),
|
||||
blocks.New(),
|
||||
),
|
||||
)
|
||||
|
||||
func newEditor() *editor {
|
||||
return &editor{}
|
||||
}
|
||||
|
||||
type editor struct {
|
||||
}
|
||||
|
||||
func (e *editor) Update() error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
sprites.Update()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *editor) Draw(screen *ebiten.Image) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
b := screen.Bounds()
|
||||
menu(elements.Bounds{
|
||||
ZX: float64(b.Min.X),
|
||||
ZY: float64(b.Min.Y),
|
||||
WX: float64(b.Max.X),
|
||||
WY: float64(b.Max.Y),
|
||||
}).Draw(screen)
|
||||
}
|
||||
|
||||
func (e *editor) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
return outsideWidth, outsideHeight
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ebiten.SetWindowSize(480, 320)
|
||||
ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
|
||||
if err := ebiten.RunGame(); err != nil {
|
||||
ebiten.SetWindowTitle("Sprite Editor")
|
||||
e := newEditor()
|
||||
if err := ebiten.RunGame(e); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user