diff --git a/common/control/v1/mouse.go b/common/control/v1/mouse.go new file mode 100644 index 0000000..73e5121 --- /dev/null +++ b/common/control/v1/mouse.go @@ -0,0 +1,8 @@ +package control + +const ( + MouseLeft MouseButton = iota + MouseRight +) + +type MouseButton int diff --git a/common/elements/v1/block.go b/common/elements/v1/block.go new file mode 100644 index 0000000..54f118e --- /dev/null +++ b/common/elements/v1/block.go @@ -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) { + +} diff --git a/common/elements/v1/button.go b/common/elements/v1/button.go new file mode 100644 index 0000000..4e0e3b6 --- /dev/null +++ b/common/elements/v1/button.go @@ -0,0 +1,65 @@ +package elements + +import ( + "context" + "image/color" + + "github.com/ebitengine/gomobile/event/mouse" + "github.com/hajimehoshi/ebiten/v2" + "golang.org/x/image/font" +) +import "git.vezzani.net/ben/games/common/ux/v1" + +type XAlign int +type YAlign int + +const ( + AlignCente XAlign = iota + AlignLeft + AlignRight +) + +const ( + AlignCenter YAlign = iota + AlignTop + AlignBottom +) + +type Button struct { + Label string + OnClick func() error + OnRightClick func() error + Style struct { + XAlign XAlign + YAlign YAlign + Offset int + Font *font.Face + BackgroundColor color.Color + } + + down bool +} + +func (b *Button) HandleMouseMove(ctx context.Context, s MouseState) error { + +} + +func (b *Button) HandleMouseDown(_ context.Context, _ MouseState) error { + return nil +} + +func (b *Button) HandleMouseUp(ctx context.Context, s MouseState) error { + if +} + +func (b *Button) getFont() font.Face { + if b.Style.Font == nil { + return ux.FontFace + } + + return *b.Style.Font +} + +func (b *Button) Draw(ctx context.Context, image *ebiten.Image) error { + +} diff --git a/common/elements/v1/element.go b/common/elements/v1/element.go new file mode 100644 index 0000000..5038732 --- /dev/null +++ b/common/elements/v1/element.go @@ -0,0 +1,42 @@ +package elements + +import ( + "context" + + "github.com/hajimehoshi/ebiten/v2" +) + +type MouseState struct { + X, Y int32 + LeftDown, RightDown bool +} + +const ( + ParentKey = "parent_element" + ZeroKey = "zero" +) + +type Mouseable interface { + HandleMouseMove(ctx context.Context, s MouseState) error + HandleMouseDown(ctx context.Context, s MouseState) error + HandleMouseUp(ctx context.Context, s MouseState) error +} + +type Element interface { + Draw(ctx context.Context, image *ebiten.Image) error + Size() (w, h int32) +} + +func GetZero(ctx context.Context) (x, y int32) { + if v, ok := ctx.Value(ZeroKey).([2]int32); ok { + return v[0], v[1] + } + return 0, 0 +} + +func GetParent(ctx context.Context) Element { + if e, ok := ctx.Value(ParentKey).(Element); ok { + return e + } + return nil +} diff --git a/common/elements/v1/menu.go b/common/elements/v1/menu.go new file mode 100644 index 0000000..8a64ab6 --- /dev/null +++ b/common/elements/v1/menu.go @@ -0,0 +1 @@ +package elements diff --git a/common/elements/v1/table.go b/common/elements/v1/table.go new file mode 100644 index 0000000..8a64ab6 --- /dev/null +++ b/common/elements/v1/table.go @@ -0,0 +1 @@ +package elements diff --git a/common/ux/v1/ux.go b/common/ux/v1/ux.go new file mode 100644 index 0000000..03490e5 --- /dev/null +++ b/common/ux/v1/ux.go @@ -0,0 +1,13 @@ +package ux + +import ( + "image/color" + + "golang.org/x/image/font" + "golang.org/x/image/font/basicfont" +) + +var ( + FontFace font.Face = basicfont.Face7x13 + BackgroundColor color.Color = color.White +) diff --git a/games/minesweeper/game/game.go b/games/minesweeper/v1/game/game.go similarity index 100% rename from games/minesweeper/game/game.go rename to games/minesweeper/v1/game/game.go diff --git a/games/minesweeper/main.go b/games/minesweeper/v1/main.go similarity index 74% rename from games/minesweeper/main.go rename to games/minesweeper/v1/main.go index b23f639..8a6b190 100644 --- a/games/minesweeper/main.go +++ b/games/minesweeper/v1/main.go @@ -3,12 +3,12 @@ package main import ( "log" - "git.vezzani.net/ben/games/games/minesweeper/game" + "git.vezzani.net/ben/games/games/minesweeper/v1/game" "github.com/hajimehoshi/ebiten/v2" ) func main() { - g := game.New(10, 10, 50) + g := game.New(10, 10, 15) w, h := g.Layout(0, 0) ebiten.SetWindowSize(w, h) ebiten.SetWindowTitle("Minesweeper")