package main
import (
"github.com/gogpu/gogpu"
"github.com/gogpu/gpucontext"
)
// the following types and methods provide thin wrappers around the GoGPU
// API to facilitate effective testing of the SUT via test injection.
// app wraps gogpu.App to facilitate testing.
type app interface {
Quit()
RequestRedraw()
SetTitle(string)
SetMenu(*gogpu.Menu)
SetCustomMenu(string, *gogpu.Menu)
Run() error
PrimaryWindow() window
StartAnimation() animToken
OnSurfaceAvailable(func()) *gogpu.App
OnDraw(func(*gogpu.Context)) *gogpu.App
OnClose(func()) *gogpu.App
OnUpdate(func(float64)) *gogpu.App
SetQuitOnLastWindowClosed(bool) *gogpu.App
NewWindow(gogpu.Config) (*gogpu.Window, error)
GetSystemMenu(gogpu.SystemMenu) systemMenuHandle
DeviceProvider() gogpu.DeviceProvider
EventSource() gpucontext.EventSource
GPUContextProvider() gpucontext.DeviceProvider
}
// wraps gogpu.App.
type gogpuApp struct {
*gogpu.App
}
// wraps gogpu.Window.
type window interface {
Visible() bool
Show()
Hide()
Close()
SetOnDraw(func(_ *gogpu.Context))
SetOnKeyPress(func(gpucontext.Key, gpucontext.Modifiers))
SetOnPointer(func(gpucontext.PointerEvent))
SetOnClose(func() bool)
}
// animToken wraps gogpu.AnimationToken.
type animToken interface {
Stop()
}
// thin shim to satisfy atomic.Value requiring a non-nil interface.
type tokenRef struct {
token animToken
}
// fakes for testing
type fakeApp struct {
*gogpuApp
animating bool
animToken animToken
appMenu *gogpu.Menu
customMenus map[string]*gogpu.Menu
appMenuHandle systemMenuHandle
reqRedrawCalled,
quitCalled bool
}
f.appMenu = m
f.appMenuHandle = &fakeSystemMenuHandle{}
}
if f.customMenus == nil {
f.customMenus = make(map[string]*gogpu.Menu)
}
f.customMenus[s] = m
}
type fakeWin struct {
visible,
hasFocus,
showCalled,
hideCalled bool
onDraw func(*gogpu.Context)
onClose func() bool
onKeyPress func(gpucontext.Key, gpucontext.Modifiers)
}
type fakeToken struct {
stopCalled bool
}
f.stopCalled = true
}
type systemMenuHandle interface {
AddItem(gogpu.MenuItem) bool
}
type fakeSystemMenuHandle struct {
items []gogpu.MenuItem
}
f.items = append(f.items, mi)
return true
}