mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
driver: Remove 'title' argument from UI.Run
This commit is contained in:
parent
8b995b086b
commit
57d527bea2
@ -31,7 +31,7 @@ type UIContext interface {
|
|||||||
var RegularTermination = errors.New("regular termination")
|
var RegularTermination = errors.New("regular termination")
|
||||||
|
|
||||||
type UI interface {
|
type UI interface {
|
||||||
Run(title string, context UIContext, graphics Graphics) error
|
Run(context UIContext, graphics Graphics) error
|
||||||
RunWithoutMainLoop(width, height int, scale float64, title string, context UIContext, graphics Graphics) <-chan error
|
RunWithoutMainLoop(width, height int, scale float64, title string, context UIContext, graphics Graphics) <-chan error
|
||||||
|
|
||||||
DeviceScaleFactor() float64
|
DeviceScaleFactor() float64
|
||||||
|
@ -55,6 +55,7 @@ type UserInterface struct {
|
|||||||
lastDeviceScaleFactor float64
|
lastDeviceScaleFactor float64
|
||||||
|
|
||||||
initMonitor *glfw.Monitor
|
initMonitor *glfw.Monitor
|
||||||
|
initTitle string
|
||||||
initFullscreenWidthInDP int
|
initFullscreenWidthInDP int
|
||||||
initFullscreenHeightInDP int
|
initFullscreenHeightInDP int
|
||||||
initFullscreen bool
|
initFullscreen bool
|
||||||
@ -194,6 +195,19 @@ func (u *UserInterface) setRunning(running bool) {
|
|||||||
u.m.Unlock()
|
u.m.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (u *UserInterface) getInitTitle() string {
|
||||||
|
u.m.RLock()
|
||||||
|
v := u.initTitle
|
||||||
|
u.m.RUnlock()
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *UserInterface) setInitTitle(title string) {
|
||||||
|
u.m.RLock()
|
||||||
|
u.initTitle = title
|
||||||
|
u.m.RUnlock()
|
||||||
|
}
|
||||||
|
|
||||||
func (u *UserInterface) isInitFullscreen() bool {
|
func (u *UserInterface) isInitFullscreen() bool {
|
||||||
u.m.RLock()
|
u.m.RLock()
|
||||||
v := u.initFullscreen
|
v := u.initFullscreen
|
||||||
@ -406,6 +420,7 @@ func (u *UserInterface) IsVsyncEnabled() bool {
|
|||||||
|
|
||||||
func (u *UserInterface) SetWindowTitle(title string) {
|
func (u *UserInterface) SetWindowTitle(title string) {
|
||||||
if !u.isRunning() {
|
if !u.isRunning() {
|
||||||
|
u.setInitTitle(title)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
u.title = title
|
u.title = title
|
||||||
@ -554,7 +569,7 @@ func init() {
|
|||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserInterface) Run(title string, uicontext driver.UIContext, graphics driver.Graphics) error {
|
func (u *UserInterface) Run(uicontext driver.UIContext, graphics driver.Graphics) error {
|
||||||
// Initialize the main thread first so the thread is available at u.run (#809).
|
// Initialize the main thread first so the thread is available at u.run (#809).
|
||||||
u.t = thread.New()
|
u.t = thread.New()
|
||||||
u.graphics = graphics
|
u.graphics = graphics
|
||||||
@ -566,7 +581,7 @@ func (u *UserInterface) Run(title string, uicontext driver.UIContext, graphics d
|
|||||||
go func() {
|
go func() {
|
||||||
defer cancel()
|
defer cancel()
|
||||||
defer close(ch)
|
defer close(ch)
|
||||||
if err := u.run(title, uicontext); err != nil {
|
if err := u.run(uicontext); err != nil {
|
||||||
ch <- err
|
ch <- err
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@ -630,7 +645,7 @@ func (u *UserInterface) createWindow() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserInterface) run(title string, context driver.UIContext) error {
|
func (u *UserInterface) run(context driver.UIContext) error {
|
||||||
if err := u.t.Call(func() error {
|
if err := u.t.Call(func() error {
|
||||||
// The window is created at initialize().
|
// The window is created at initialize().
|
||||||
u.window.Destroy()
|
u.window.Destroy()
|
||||||
@ -682,8 +697,8 @@ func (u *UserInterface) run(title string, context driver.UIContext) error {
|
|||||||
u.SetWindowPosition(u.getInitWindowPosition())
|
u.SetWindowPosition(u.getInitWindowPosition())
|
||||||
|
|
||||||
_ = u.t.Call(func() error {
|
_ = u.t.Call(func() error {
|
||||||
u.title = title
|
u.title = u.getInitTitle()
|
||||||
u.window.SetTitle(title)
|
u.window.SetTitle(u.title)
|
||||||
u.window.Show()
|
u.window.Show()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -403,8 +403,7 @@ func init() {
|
|||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserInterface) Run(title string, context driver.UIContext, graphics driver.Graphics) error {
|
func (u *UserInterface) Run(context driver.UIContext, graphics driver.Graphics) error {
|
||||||
document.Set("title", title)
|
|
||||||
canvas.Call("focus")
|
canvas.Call("focus")
|
||||||
u.running = true
|
u.running = true
|
||||||
ch := u.loop(context)
|
ch := u.loop(context)
|
||||||
|
@ -183,12 +183,12 @@ func (u *UserInterface) appMain(a app.App) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserInterface) Run(title string, context driver.UIContext, graphics driver.Graphics) error {
|
func (u *UserInterface) Run(context driver.UIContext, graphics driver.Graphics) error {
|
||||||
// TODO: Remove width/height/scale arguments. They are not used from gomobile-build.
|
// TODO: Remove width/height/scale arguments. They are not used from gomobile-build.
|
||||||
|
|
||||||
u.setGBuildSizeCh = make(chan struct{})
|
u.setGBuildSizeCh = make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
if err := u.run(16, 16, 1, title, context, graphics, true); err != nil {
|
if err := u.run(16, 16, 1, context, graphics, true); err != nil {
|
||||||
// As mobile apps never ends, Loop can't return. Just panic here.
|
// As mobile apps never ends, Loop can't return. Just panic here.
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@ -201,7 +201,8 @@ func (u *UserInterface) RunWithoutMainLoop(width, height int, scale float64, tit
|
|||||||
ch := make(chan error)
|
ch := make(chan error)
|
||||||
go func() {
|
go func() {
|
||||||
defer close(ch)
|
defer close(ch)
|
||||||
if err := u.run(width, height, scale, title, context, graphics, false); err != nil {
|
// title is ignored?
|
||||||
|
if err := u.run(width, height, scale, context, graphics, false); err != nil {
|
||||||
ch <- err
|
ch <- err
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@ -209,7 +210,7 @@ func (u *UserInterface) RunWithoutMainLoop(width, height int, scale float64, tit
|
|||||||
return ch
|
return ch
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserInterface) run(width, height int, scale float64, title string, context driver.UIContext, graphics driver.Graphics, mainloop bool) (err error) {
|
func (u *UserInterface) run(width, height int, scale float64, context driver.UIContext, graphics driver.Graphics, mainloop bool) (err error) {
|
||||||
// Convert the panic to a regular error so that Java/Objective-C layer can treat this easily e.g., for
|
// Convert the panic to a regular error so that Java/Objective-C layer can treat this easily e.g., for
|
||||||
// Crashlytics. A panic is treated as SIGABRT, and there is no way to handle this on Java/Objective-C layer
|
// Crashlytics. A panic is treated as SIGABRT, and there is no way to handle this on Java/Objective-C layer
|
||||||
// unfortunately.
|
// unfortunately.
|
||||||
@ -228,7 +229,6 @@ func (u *UserInterface) run(width, height int, scale float64, title string, cont
|
|||||||
u.context = context
|
u.context = context
|
||||||
u.graphics = graphics
|
u.graphics = graphics
|
||||||
u.m.Unlock()
|
u.m.Unlock()
|
||||||
// title is ignored?
|
|
||||||
|
|
||||||
if graphics.IsGL() {
|
if graphics.IsGL() {
|
||||||
var ctx gl.Context
|
var ctx gl.Context
|
||||||
|
3
run.go
3
run.go
@ -157,7 +157,8 @@ func Run(f func(*Image) error, width, height int, scale float64, title string) e
|
|||||||
|
|
||||||
theUIContext = newUIContext(game, scale)
|
theUIContext = newUIContext(game, scale)
|
||||||
fixWindowPosition(int(float64(width)*scale), int(float64(height)*scale))
|
fixWindowPosition(int(float64(width)*scale), int(float64(height)*scale))
|
||||||
if err := uiDriver().Run(title, theUIContext, graphicsDriver()); err != nil {
|
SetWindowTitle(title)
|
||||||
|
if err := uiDriver().Run(theUIContext, graphicsDriver()); err != nil {
|
||||||
if err == driver.RegularTermination {
|
if err == driver.RegularTermination {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user