Files
inkwell/ui.cursor.go
T
mr.zeroandClaude Opus 5 2429ada090
ci/woodpecker/push/woodpecker Pipeline was successful
A widget declares its layer
Registration order was the only thing deciding what a widget was drawn
over, which forced a domain to keep one ordered list of every widget it
owns — the one shape that cannot be split into a file per widget.

A widget now says where it belongs: Layer, the eight LayerScene..LayerCursor
constants, the optional Layered interface and LayerOf for wrappers. Draw
runs from the bottom layer up, Tick from the top down, and registration
order only breaks ties inside a layer. Every built-in declares its own;
anything that stays quiet sits on LayerHUD, so existing HUDs come out where
they were.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-30 22:19:17 +02:00

39 lines
1.2 KiB
Go

package inkwell
import (
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/vector"
)
// Cursor renders the mouse cursor. When the player has an inventory item
// selected, the item's sprite is drawn at the cursor instead of the
// default crosshair. Registered last so it draws on top.
type Cursor struct {
Name string
}
func (c *Cursor) GetName() string { return c.Name }
func (c *Cursor) Layer() Layer { return LayerCursor }
func (c *Cursor) Tick(ctx *UICtx) {}
func (c *Cursor) Draw(dst *ebiten.Image, ctx *UICtx) {
g := ctx.Game
x, y := g.Input.Pos()
if sel := g.Inventory.Selected(); sel != "" {
if it, ok := g.ItemManager.Get(sel); ok {
img := g.loaded.image(g.AssetManager, it.Sprite)
sw, sh := img.Bounds().Dx(), img.Bounds().Dy()
if sw > 0 && sh > 0 && !g.loaded.isPlaceholder(it.Sprite) {
op := &ebiten.DrawImageOptions{}
op.GeoM.Scale(16/float64(sw), 16/float64(sh))
op.GeoM.Translate(float64(x-8), float64(y-8))
dst.DrawImage(img, op)
return
}
}
}
col := g.Theme().CursorColor
vector.StrokeLine(dst, float32(x-3), float32(y), float32(x+4), float32(y), 1, col, false)
vector.StrokeLine(dst, float32(x), float32(y-3), float32(x), float32(y+4), 1, col, false)
}