ux stuff
This commit is contained in:
8
common/control/v1/mouse.go
Normal file
8
common/control/v1/mouse.go
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
package control
|
||||||
|
|
||||||
|
const (
|
||||||
|
MouseLeft MouseButton = iota
|
||||||
|
MouseRight
|
||||||
|
)
|
||||||
|
|
||||||
|
type MouseButton int
|
||||||
23
common/elements/v1/block.go
Normal file
23
common/elements/v1/block.go
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package elements
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/hajimehoshi/ebiten/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewBlock(inline bool) *Block {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
type Block struct {
|
||||||
|
inline bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Block) Draw(ctx context.Context, image *ebiten.Image) error {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Block) OnClick(ctx context.Context, click *ClickEvent) {
|
||||||
|
|
||||||
|
}
|
||||||
32
common/elements/v1/button.go
Normal file
32
common/elements/v1/button.go
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
package elements
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/hajimehoshi/ebiten/v2"
|
||||||
|
"golang.org/x/image/font"
|
||||||
|
)
|
||||||
|
import "git.vezzani.net/ben/games/common/ux/v1"
|
||||||
|
|
||||||
|
type Button struct {
|
||||||
|
Label string
|
||||||
|
LabelPosition
|
||||||
|
Font *font.Face
|
||||||
|
OnClick func(click *ClickEvent) error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Button) getFont() font.Face {
|
||||||
|
if b.Font == nil {
|
||||||
|
return ux.FontFace
|
||||||
|
}
|
||||||
|
|
||||||
|
return *b.Font
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Button) Draw(ctx context.Context, image *ebiten.Image) error {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Button) HandleClick(ctx context.Context, clickEvent *ClickEvent) error {
|
||||||
|
return b.OnClick(click)
|
||||||
|
}
|
||||||
34
common/elements/v1/element.go
Normal file
34
common/elements/v1/element.go
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package elements
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"git.vezzani.net/ben/games/common/control/v1"
|
||||||
|
|
||||||
|
"github.com/hajimehoshi/ebiten/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ClickEvent struct {
|
||||||
|
X, Y int
|
||||||
|
Button control.MouseButton
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
ParentKey = "parent_element"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Clickable interface {
|
||||||
|
HandleClick(ctx context.Context, click *ClickEvent) error
|
||||||
|
}
|
||||||
|
|
||||||
|
type Element interface {
|
||||||
|
Draw(ctx context.Context, image *ebiten.Image) error
|
||||||
|
Size() (w, h int32)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetParent(ctx context.Context) Element {
|
||||||
|
if e, ok := ctx.Value(ParentKey).(Element); ok {
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
1
common/elements/v1/menu.go
Normal file
1
common/elements/v1/menu.go
Normal file
@@ -0,0 +1 @@
|
|||||||
|
package elements
|
||||||
1
common/elements/v1/table.go
Normal file
1
common/elements/v1/table.go
Normal file
@@ -0,0 +1 @@
|
|||||||
|
package elements
|
||||||
10
common/ux/v1/ux.go
Normal file
10
common/ux/v1/ux.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package ux
|
||||||
|
|
||||||
|
import (
|
||||||
|
"golang.org/x/image/font"
|
||||||
|
"golang.org/x/image/font/basicfont"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
FontFace font.Face = basicfont.Face7x13
|
||||||
|
)
|
||||||
@@ -3,12 +3,12 @@ package main
|
|||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"git.vezzani.net/ben/games/games/minesweeper/game"
|
"git.vezzani.net/ben/games/games/minesweeper/v1/game"
|
||||||
"github.com/hajimehoshi/ebiten/v2"
|
"github.com/hajimehoshi/ebiten/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
g := game.New(10, 10, 50)
|
g := game.New(10, 10, 15)
|
||||||
w, h := g.Layout(0, 0)
|
w, h := g.Layout(0, 0)
|
||||||
ebiten.SetWindowSize(w, h)
|
ebiten.SetWindowSize(w, h)
|
||||||
ebiten.SetWindowTitle("Minesweeper")
|
ebiten.SetWindowTitle("Minesweeper")
|
||||||
Reference in New Issue
Block a user