This commit is contained in:
2025-08-18 14:57:01 -04:00
parent 627ca88732
commit ee69afdb02
9 changed files with 155 additions and 2 deletions

View File

@@ -0,0 +1,8 @@
package control
const (
MouseLeft MouseButton = iota
MouseRight
)
type MouseButton int

View 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) {
}

View File

@@ -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 {
}

View File

@@ -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
}

View File

@@ -0,0 +1 @@
package elements

View File

@@ -0,0 +1 @@
package elements

13
common/ux/v1/ux.go Normal file
View File

@@ -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
)

View File

@@ -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")