forked from joejulian/gio
ui/app,apps: unexport ChangeStage and Stage
I'm not convinced the API is right. For exmaple, an event that notifies a program when to save its state is both smaller and might be sufficient. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -185,7 +185,6 @@ func (a *App) run() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case app.ChangeStage:
|
|
||||||
case *app.Command:
|
case *app.Command:
|
||||||
switch e.Type {
|
switch e.Type {
|
||||||
case app.CommandBack:
|
case app.CommandBack:
|
||||||
|
|||||||
+15
-15
@@ -23,8 +23,8 @@ type Draw struct {
|
|||||||
sync bool
|
sync bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type ChangeStage struct {
|
type changeStage struct {
|
||||||
Stage Stage
|
stage stage
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command is a system event.
|
// Command is a system event.
|
||||||
@@ -34,7 +34,7 @@ type Command struct {
|
|||||||
Cancel bool
|
Cancel bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type Stage uint8
|
type stage uint8
|
||||||
type CommandType uint8
|
type CommandType uint8
|
||||||
|
|
||||||
type Input interface {
|
type Input interface {
|
||||||
@@ -42,9 +42,9 @@ type Input interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
StageDead Stage = iota
|
stageDead stage = iota
|
||||||
StageInvisible
|
stageInvisible
|
||||||
StageVisible
|
stageVisible
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -97,21 +97,21 @@ func Windows() <-chan *Window {
|
|||||||
return windows
|
return windows
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l Stage) String() string {
|
func (l stage) String() string {
|
||||||
switch l {
|
switch l {
|
||||||
case StageDead:
|
case stageDead:
|
||||||
return "StageDead"
|
return "stageDead"
|
||||||
case StageInvisible:
|
case stageInvisible:
|
||||||
return "StageInvisible"
|
return "stageInvisible"
|
||||||
case StageVisible:
|
case stageVisible:
|
||||||
return "StageVisible"
|
return "stageVisible"
|
||||||
default:
|
default:
|
||||||
panic("unexpected Stage value")
|
panic("unexpected stage value")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ Draw) ImplementsEvent() {}
|
func (_ Draw) ImplementsEvent() {}
|
||||||
func (_ ChangeStage) ImplementsEvent() {}
|
func (_ changeStage) ImplementsEvent() {}
|
||||||
func (_ *Command) ImplementsEvent() {}
|
func (_ *Command) ImplementsEvent() {}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|||||||
+10
-10
@@ -38,7 +38,7 @@ type window struct {
|
|||||||
dpi int
|
dpi int
|
||||||
fontScale float32
|
fontScale float32
|
||||||
|
|
||||||
stage Stage
|
stage stage
|
||||||
started bool
|
started bool
|
||||||
|
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
@@ -96,7 +96,7 @@ func onCreateView(env *C.JNIEnv, class C.jclass, view C.jobject) C.jlong {
|
|||||||
views[handle] = w
|
views[handle] = w
|
||||||
w.loadConfig(env, class)
|
w.loadConfig(env, class)
|
||||||
windows <- ow
|
windows <- ow
|
||||||
w.setStage(StageInvisible)
|
w.setStage(stageInvisible)
|
||||||
return handle
|
return handle
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +104,7 @@ func onCreateView(env *C.JNIEnv, class C.jclass, view C.jobject) C.jlong {
|
|||||||
func onDestroyView(env *C.JNIEnv, class C.jclass, handle C.jlong) {
|
func onDestroyView(env *C.JNIEnv, class C.jclass, handle C.jlong) {
|
||||||
w := views[handle]
|
w := views[handle]
|
||||||
delete(views, handle)
|
delete(views, handle)
|
||||||
w.setStage(StageDead)
|
w.setStage(stageDead)
|
||||||
C.gio_jni_DeleteGlobalRef(env, w.view)
|
C.gio_jni_DeleteGlobalRef(env, w.view)
|
||||||
w.view = 0
|
w.view = 0
|
||||||
}
|
}
|
||||||
@@ -113,7 +113,7 @@ func onDestroyView(env *C.JNIEnv, class C.jclass, handle C.jlong) {
|
|||||||
func onStopView(env *C.JNIEnv, class C.jclass, handle C.jlong) {
|
func onStopView(env *C.JNIEnv, class C.jclass, handle C.jlong) {
|
||||||
w := views[handle]
|
w := views[handle]
|
||||||
w.started = false
|
w.started = false
|
||||||
w.setStage(StageInvisible)
|
w.setStage(stageInvisible)
|
||||||
}
|
}
|
||||||
|
|
||||||
//export onStartView
|
//export onStartView
|
||||||
@@ -131,7 +131,7 @@ func onSurfaceDestroyed(env *C.JNIEnv, class C.jclass, handle C.jlong) {
|
|||||||
w.mu.Lock()
|
w.mu.Lock()
|
||||||
w.win = nil
|
w.win = nil
|
||||||
w.mu.Unlock()
|
w.mu.Unlock()
|
||||||
w.setStage(StageInvisible)
|
w.setStage(stageInvisible)
|
||||||
}
|
}
|
||||||
|
|
||||||
//export onSurfaceChanged
|
//export onSurfaceChanged
|
||||||
@@ -155,7 +155,7 @@ func onLowMemory() {
|
|||||||
func onConfigurationChanged(env *C.JNIEnv, class C.jclass, view C.jlong) {
|
func onConfigurationChanged(env *C.JNIEnv, class C.jclass, view C.jlong) {
|
||||||
w := views[view]
|
w := views[view]
|
||||||
w.loadConfig(env, class)
|
w.loadConfig(env, class)
|
||||||
if w.stage >= StageVisible {
|
if w.stage >= stageVisible {
|
||||||
w.draw(true)
|
w.draw(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -166,7 +166,7 @@ func onFrameCallback(env *C.JNIEnv, class C.jclass, view C.jlong, nanos C.jlong)
|
|||||||
if !exist {
|
if !exist {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if w.stage < StageVisible {
|
if w.stage < stageVisible {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.mu.Lock()
|
w.mu.Lock()
|
||||||
@@ -197,16 +197,16 @@ func (w *window) setVisible() {
|
|||||||
if width == 0 || height == 0 {
|
if width == 0 || height == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.setStage(StageVisible)
|
w.setStage(stageVisible)
|
||||||
w.draw(true)
|
w.draw(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) setStage(stage Stage) {
|
func (w *window) setStage(stage stage) {
|
||||||
if stage == w.stage {
|
if stage == w.stage {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.stage = stage
|
w.stage = stage
|
||||||
w.event(ChangeStage{stage})
|
w.event(changeStage{stage})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) display() unsafe.Pointer {
|
func (w *window) display() unsafe.Pointer {
|
||||||
|
|||||||
+4
-4
@@ -59,7 +59,7 @@ func onCreate(view C.CFTypeRef) {
|
|||||||
C.gio_addLayerToView(view, w.layer)
|
C.gio_addLayerToView(view, w.layer)
|
||||||
views[view] = w
|
views[view] = w
|
||||||
windows <- ow
|
windows <- ow
|
||||||
w.w.event(ChangeStage{StageInvisible})
|
w.w.event(changeStage{stageInvisible})
|
||||||
}
|
}
|
||||||
|
|
||||||
//export onDraw
|
//export onDraw
|
||||||
@@ -72,7 +72,7 @@ func onDraw(view C.CFTypeRef, dpi, sdpi, width, height C.CGFloat, sync C.int) {
|
|||||||
w.visible.Store(true)
|
w.visible.Store(true)
|
||||||
C.gio_updateView(view, w.layer)
|
C.gio_updateView(view, w.layer)
|
||||||
if !wasVisible {
|
if !wasVisible {
|
||||||
w.w.event(ChangeStage{StageVisible})
|
w.w.event(changeStage{stageVisible})
|
||||||
}
|
}
|
||||||
isSync := false
|
isSync := false
|
||||||
if sync != 0 {
|
if sync != 0 {
|
||||||
@@ -96,14 +96,14 @@ func onDraw(view C.CFTypeRef, dpi, sdpi, width, height C.CGFloat, sync C.int) {
|
|||||||
func onStop(view C.CFTypeRef) {
|
func onStop(view C.CFTypeRef) {
|
||||||
w := views[view]
|
w := views[view]
|
||||||
w.visible.Store(false)
|
w.visible.Store(false)
|
||||||
w.w.event(ChangeStage{StageInvisible})
|
w.w.event(changeStage{stageInvisible})
|
||||||
}
|
}
|
||||||
|
|
||||||
//export onDestroy
|
//export onDestroy
|
||||||
func onDestroy(view C.CFTypeRef) {
|
func onDestroy(view C.CFTypeRef) {
|
||||||
w := views[view]
|
w := views[view]
|
||||||
delete(views, view)
|
delete(views, view)
|
||||||
w.w.event(ChangeStage{StageDead})
|
w.w.event(changeStage{stageDead})
|
||||||
C.gio_removeLayer(w.layer)
|
C.gio_removeLayer(w.layer)
|
||||||
C.CFRelease(w.layer)
|
C.CFRelease(w.layer)
|
||||||
w.layer = 0
|
w.layer = 0
|
||||||
|
|||||||
+1
-1
@@ -56,7 +56,7 @@ func createWindow(opts *WindowOptions) error {
|
|||||||
w.w = newWindow(w)
|
w.w = newWindow(w)
|
||||||
go func() {
|
go func() {
|
||||||
windows <- w.w
|
windows <- w.w
|
||||||
w.w.event(ChangeStage{StageVisible})
|
w.w.event(changeStage{stageVisible})
|
||||||
w.draw(true)
|
w.draw(true)
|
||||||
select {}
|
select {}
|
||||||
w.cleanup()
|
w.cleanup()
|
||||||
|
|||||||
+7
-7
@@ -33,7 +33,7 @@ func init() {
|
|||||||
type window struct {
|
type window struct {
|
||||||
view C.CFTypeRef
|
view C.CFTypeRef
|
||||||
w *Window
|
w *Window
|
||||||
stage Stage
|
stage stage
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only support one main window for now.
|
// Only support one main window for now.
|
||||||
@@ -61,12 +61,12 @@ func (w *window) setAnimating(anim bool) {
|
|||||||
C.gio_setAnimating(w.view, animb)
|
C.gio_setAnimating(w.view, animb)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) setStage(stage Stage) {
|
func (w *window) setStage(stage stage) {
|
||||||
if stage == w.stage {
|
if stage == w.stage {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.stage = stage
|
w.stage = stage
|
||||||
w.w.event(ChangeStage{stage})
|
w.w.event(changeStage{stage})
|
||||||
}
|
}
|
||||||
|
|
||||||
//export gio_onFrameCallback
|
//export gio_onFrameCallback
|
||||||
@@ -134,7 +134,7 @@ func (w *window) draw(sync bool) {
|
|||||||
}
|
}
|
||||||
cfg := getConfig()
|
cfg := getConfig()
|
||||||
cfg.Now = time.Now()
|
cfg.Now = time.Now()
|
||||||
w.setStage(StageVisible)
|
w.setStage(stageVisible)
|
||||||
w.w.event(Draw{
|
w.w.event(Draw{
|
||||||
Size: image.Point{
|
Size: image.Point{
|
||||||
X: width,
|
X: width,
|
||||||
@@ -161,20 +161,20 @@ func getConfig() ui.Config {
|
|||||||
func gio_onTerminate(view C.CFTypeRef) {
|
func gio_onTerminate(view C.CFTypeRef) {
|
||||||
w := views[view]
|
w := views[view]
|
||||||
delete(views, view)
|
delete(views, view)
|
||||||
w.setStage(StageDead)
|
w.setStage(stageDead)
|
||||||
close(windows)
|
close(windows)
|
||||||
}
|
}
|
||||||
|
|
||||||
//export gio_onHide
|
//export gio_onHide
|
||||||
func gio_onHide(view C.CFTypeRef) {
|
func gio_onHide(view C.CFTypeRef) {
|
||||||
w := views[view]
|
w := views[view]
|
||||||
w.setStage(StageInvisible)
|
w.setStage(stageInvisible)
|
||||||
}
|
}
|
||||||
|
|
||||||
//export gio_onShow
|
//export gio_onShow
|
||||||
func gio_onShow(view C.CFTypeRef) {
|
func gio_onShow(view C.CFTypeRef) {
|
||||||
w := views[view]
|
w := views[view]
|
||||||
w.setStage(StageVisible)
|
w.setStage(stageVisible)
|
||||||
}
|
}
|
||||||
|
|
||||||
//export gio_onCreate
|
//export gio_onCreate
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ type window struct {
|
|||||||
w *Window
|
w *Window
|
||||||
width int
|
width int
|
||||||
height int
|
height int
|
||||||
stage Stage
|
stage stage
|
||||||
|
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
animating bool
|
animating bool
|
||||||
@@ -239,7 +239,7 @@ func createNativeWindow(opts *WindowOptions) (*window, error) {
|
|||||||
}
|
}
|
||||||
w := &window{
|
w := &window{
|
||||||
hwnd: hwnd,
|
hwnd: hwnd,
|
||||||
stage: StageInvisible,
|
stage: stageInvisible,
|
||||||
}
|
}
|
||||||
winMap[hwnd] = w
|
winMap[hwnd] = w
|
||||||
w.hdc, err = getDC(hwnd)
|
w.hdc, err = getDC(hwnd)
|
||||||
@@ -310,7 +310,7 @@ func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr
|
|||||||
w.scrollEvent(wParam, lParam)
|
w.scrollEvent(wParam, lParam)
|
||||||
case _WM_DESTROY:
|
case _WM_DESTROY:
|
||||||
delete(winMap, hwnd)
|
delete(winMap, hwnd)
|
||||||
w.setStage(StageDead)
|
w.setStage(stageDead)
|
||||||
case _WM_REDRAW:
|
case _WM_REDRAW:
|
||||||
w.mu.Lock()
|
w.mu.Lock()
|
||||||
anim := w.animating
|
anim := w.animating
|
||||||
@@ -324,9 +324,9 @@ func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr
|
|||||||
case _WM_SIZE:
|
case _WM_SIZE:
|
||||||
switch wParam {
|
switch wParam {
|
||||||
case _SIZE_MINIMIZED:
|
case _SIZE_MINIMIZED:
|
||||||
w.setStage(StageInvisible)
|
w.setStage(stageInvisible)
|
||||||
case _SIZE_MAXIMIZED, _SIZE_RESTORED:
|
case _SIZE_MAXIMIZED, _SIZE_RESTORED:
|
||||||
w.setStage(StageVisible)
|
w.setStage(stageVisible)
|
||||||
w.draw(true)
|
w.draw(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -359,7 +359,7 @@ func (w *window) scrollEvent(wParam, lParam uintptr) {
|
|||||||
// Adapted from https://blogs.msdn.microsoft.com/oldnewthing/20060126-00/?p=32513/
|
// Adapted from https://blogs.msdn.microsoft.com/oldnewthing/20060126-00/?p=32513/
|
||||||
func (w *window) loop() error {
|
func (w *window) loop() error {
|
||||||
loop:
|
loop:
|
||||||
for w.stage > StageDead {
|
for w.stage > stageDead {
|
||||||
var msg msg
|
var msg msg
|
||||||
// Since posted messages are always returned before system messages,
|
// Since posted messages are always returned before system messages,
|
||||||
// but we want our WM_REDRAW to always come last, just like WM_PAINT.
|
// but we want our WM_REDRAW to always come last, just like WM_PAINT.
|
||||||
@@ -398,9 +398,9 @@ func (w *window) postRedraw() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) setStage(s Stage) {
|
func (w *window) setStage(s stage) {
|
||||||
w.stage = s
|
w.stage = s
|
||||||
w.w.event(ChangeStage{s})
|
w.w.event(changeStage{s})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) draw(sync bool) {
|
func (w *window) draw(sync bool) {
|
||||||
|
|||||||
+12
-16
@@ -35,7 +35,7 @@ type Window struct {
|
|||||||
events chan Event
|
events chan Event
|
||||||
|
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
stage Stage
|
stage stage
|
||||||
size image.Point
|
size image.Point
|
||||||
syncGPU bool
|
syncGPU bool
|
||||||
animating bool
|
animating bool
|
||||||
@@ -62,7 +62,7 @@ func newWindow(nw *window) *Window {
|
|||||||
w := &Window{
|
w := &Window{
|
||||||
driver: nw,
|
driver: nw,
|
||||||
events: make(chan Event),
|
events: make(chan Event),
|
||||||
stage: StageInvisible,
|
stage: stageInvisible,
|
||||||
}
|
}
|
||||||
return w
|
return w
|
||||||
}
|
}
|
||||||
@@ -103,7 +103,7 @@ func (w *Window) Draw(root *ui.Ops) {
|
|||||||
w.hasNextFrame = false
|
w.hasNextFrame = false
|
||||||
w.syncGPU = false
|
w.syncGPU = false
|
||||||
w.mu.Unlock()
|
w.mu.Unlock()
|
||||||
if stage < StageVisible {
|
if stage < stageVisible {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if w.gpu != nil {
|
if w.gpu != nil {
|
||||||
@@ -176,7 +176,7 @@ func (w *Window) updateAnimation() {
|
|||||||
w.mu.Lock()
|
w.mu.Lock()
|
||||||
defer w.mu.Unlock()
|
defer w.mu.Unlock()
|
||||||
animate := false
|
animate := false
|
||||||
if w.stage >= StageVisible && w.hasNextFrame {
|
if w.stage >= stageVisible && w.hasNextFrame {
|
||||||
if dt := time.Until(w.nextFrame); dt <= 0 {
|
if dt := time.Until(w.nextFrame); dt <= 0 {
|
||||||
animate = true
|
animate = true
|
||||||
} else {
|
} else {
|
||||||
@@ -208,14 +208,10 @@ func (w *Window) Size() image.Point {
|
|||||||
return w.size
|
return w.size
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Window) Stage() Stage {
|
func (w *Window) IsAlive() bool {
|
||||||
w.mu.Lock()
|
w.mu.Lock()
|
||||||
defer w.mu.Unlock()
|
defer w.mu.Unlock()
|
||||||
return w.stage
|
return w.stage != stageDead && w.err == nil
|
||||||
}
|
|
||||||
|
|
||||||
func (w *Window) IsAlive() bool {
|
|
||||||
return w.Stage() != StageDead && w.err == nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Window) contextDriver() interface{} {
|
func (w *Window) contextDriver() interface{} {
|
||||||
@@ -234,9 +230,9 @@ func (w *Window) event(e Event) {
|
|||||||
case *Command:
|
case *Command:
|
||||||
needAck = true
|
needAck = true
|
||||||
needRedraw = true
|
needRedraw = true
|
||||||
case ChangeStage:
|
case changeStage:
|
||||||
w.stage = e.Stage
|
w.stage = e.stage
|
||||||
if w.stage > StageDead {
|
if w.stage > stageDead {
|
||||||
needAck = true
|
needAck = true
|
||||||
w.syncGPU = true
|
w.syncGPU = true
|
||||||
}
|
}
|
||||||
@@ -244,7 +240,7 @@ func (w *Window) event(e Event) {
|
|||||||
if e.Size == (image.Point{}) {
|
if e.Size == (image.Point{}) {
|
||||||
panic(errors.New("internal error: zero-sized Draw"))
|
panic(errors.New("internal error: zero-sized Draw"))
|
||||||
}
|
}
|
||||||
if w.stage < StageVisible {
|
if w.stage < stageVisible {
|
||||||
// No drawing if not visible.
|
// No drawing if not visible.
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -270,14 +266,14 @@ func (w *Window) event(e Event) {
|
|||||||
w.syncGPU = false
|
w.syncGPU = false
|
||||||
w.mu.Unlock()
|
w.mu.Unlock()
|
||||||
switch {
|
switch {
|
||||||
case stage < StageVisible:
|
case stage < stageVisible:
|
||||||
w.gpu.Release()
|
w.gpu.Release()
|
||||||
w.gpu = nil
|
w.gpu = nil
|
||||||
case sync:
|
case sync:
|
||||||
w.gpu.Refresh()
|
w.gpu.Refresh()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if stage == StageDead {
|
if stage == stageDead {
|
||||||
close(w.events)
|
close(w.events)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user