mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +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")
|
||||
|
||||
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
|
||||
|
||||
DeviceScaleFactor() float64
|
||||
|
@ -55,6 +55,7 @@ type UserInterface struct {
|
||||
lastDeviceScaleFactor float64
|
||||
|
||||
initMonitor *glfw.Monitor
|
||||
initTitle string
|
||||
initFullscreenWidthInDP int
|
||||
initFullscreenHeightInDP int
|
||||
initFullscreen bool
|
||||
@ -194,6 +195,19 @@ func (u *UserInterface) setRunning(running bool) {
|
||||
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 {
|
||||
u.m.RLock()
|
||||
v := u.initFullscreen
|
||||
@ -406,6 +420,7 @@ func (u *UserInterface) IsVsyncEnabled() bool {
|
||||
|
||||
func (u *UserInterface) SetWindowTitle(title string) {
|
||||
if !u.isRunning() {
|
||||
u.setInitTitle(title)
|
||||
return
|
||||
}
|
||||
u.title = title
|
||||
@ -554,7 +569,7 @@ func init() {
|
||||
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).
|
||||
u.t = thread.New()
|
||||
u.graphics = graphics
|
||||
@ -566,7 +581,7 @@ func (u *UserInterface) Run(title string, uicontext driver.UIContext, graphics d
|
||||
go func() {
|
||||
defer cancel()
|
||||
defer close(ch)
|
||||
if err := u.run(title, uicontext); err != nil {
|
||||
if err := u.run(uicontext); err != nil {
|
||||
ch <- err
|
||||
}
|
||||
}()
|
||||
@ -630,7 +645,7 @@ func (u *UserInterface) createWindow() error {
|
||||
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 {
|
||||
// The window is created at initialize().
|
||||
u.window.Destroy()
|
||||
@ -682,8 +697,8 @@ func (u *UserInterface) run(title string, context driver.UIContext) error {
|
||||
u.SetWindowPosition(u.getInitWindowPosition())
|
||||
|
||||
_ = u.t.Call(func() error {
|
||||
u.title = title
|
||||
u.window.SetTitle(title)
|
||||
u.title = u.getInitTitle()
|
||||
u.window.SetTitle(u.title)
|
||||
u.window.Show()
|
||||
|
||||
return nil
|
||||
|
@ -403,8 +403,7 @@ func init() {
|
||||
}))
|
||||
}
|
||||
|
||||
func (u *UserInterface) Run(title string, context driver.UIContext, graphics driver.Graphics) error {
|
||||
document.Set("title", title)
|
||||
func (u *UserInterface) Run(context driver.UIContext, graphics driver.Graphics) error {
|
||||
canvas.Call("focus")
|
||||
u.running = true
|
||||
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.
|
||||
|
||||
u.setGBuildSizeCh = make(chan struct{})
|
||||
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.
|
||||
panic(err)
|
||||
}
|
||||
@ -201,7 +201,8 @@ func (u *UserInterface) RunWithoutMainLoop(width, height int, scale float64, tit
|
||||
ch := make(chan error)
|
||||
go func() {
|
||||
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
|
||||
}
|
||||
}()
|
||||
@ -209,7 +210,7 @@ func (u *UserInterface) RunWithoutMainLoop(width, height int, scale float64, tit
|
||||
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
|
||||
// Crashlytics. A panic is treated as SIGABRT, and there is no way to handle this on Java/Objective-C layer
|
||||
// unfortunately.
|
||||
@ -228,7 +229,6 @@ func (u *UserInterface) run(width, height int, scale float64, title string, cont
|
||||
u.context = context
|
||||
u.graphics = graphics
|
||||
u.m.Unlock()
|
||||
// title is ignored?
|
||||
|
||||
if graphics.IsGL() {
|
||||
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)
|
||||
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 {
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user