Twenty pieces of a retro desktop: Desktop, DesktopIcon, Taskbar, StartMenu, AppWindow, Calculator, Notepad, Minesweeper, ControlPanel, TrayIcons, ShutdownScreen, BootScreen, Screensaver, Snake, Dock, RunDialog, DiskDefrag, WallpaperPicker, ClipboardPanel and LockScreen. The calculator really adds up and calls division by zero GAME OVER; Minesweeper and Snake are playable, first click always safe; START cascades its submenus without moving the rows already open; windows drag by whole dots; the screensaver's logo changes color at each wall and sparkles in a corner; the defragmenter is oddly soothing. Clocks that step back hold at zero, and typed or copied text never reaches the log. icon.Bomb is the new 12x12 mine.
58 lines
1.5 KiB
Go
58 lines
1.5 KiB
Go
package desk
|
|
|
|
import (
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
|
)
|
|
|
|
type wakeKey struct{}
|
|
|
|
// wake is input between frames; from is the first pointer.
|
|
type wake struct {
|
|
woke, seen bool
|
|
from [2]float32
|
|
}
|
|
|
|
// cover fills the window; keys, clicks, long moves end it.
|
|
func cover(c *ui.Context, k pixel.Kit, text string, open *bool, moves bool, draw func(g pixel.Canvas)) (anchor, panel *ui.Element, woke bool) {
|
|
anchor = ui.Box(c).Role(ui.RoleNone)
|
|
st := ui.Local(anchor, wakeKey{}, func() wake { return wake{} })
|
|
was := *open
|
|
if st.woke {
|
|
*open = false
|
|
}
|
|
if !*open {
|
|
*st = wake{}
|
|
}
|
|
panel = ui.DialogBase(c, open, func(back, panel *ui.Element) {
|
|
back.Draw(func(p *ui.Painter, r ui.Rect) { draw(k.Canvas(p, r)) })
|
|
back.HandleInput(func(ev ui.InputEvent) bool {
|
|
// Any button and the wheel end it, as keys do.
|
|
if ev.Kind == ui.InputPointerDown || ev.Kind == ui.InputScroll {
|
|
st.woke = true
|
|
}
|
|
if !moves || ev.Kind != ui.InputPointerMove {
|
|
return false
|
|
}
|
|
// The first move marks the spot; eight dots away wakes.
|
|
at := [2]float32{ev.X / k.Dot(), ev.Y / k.Dot()}
|
|
if !st.seen {
|
|
st.from, st.seen = at, true
|
|
}
|
|
if dx, dy := at[0]-st.from[0], at[1]-st.from[1]; dx*dx+dy*dy > 64 {
|
|
st.woke = true
|
|
}
|
|
return false
|
|
})
|
|
panel.Focusable().FocusRing(false).Label(text).HandleInput(func(ev ui.InputEvent) bool {
|
|
if ev.Kind == ui.InputKeyDown {
|
|
st.woke = true
|
|
return true
|
|
}
|
|
return false
|
|
})
|
|
})
|
|
return anchor, panel, was && !*open
|
|
}
|