mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
ui: setScreenSize in ui_glfw.go no longer returns error
This commit is contained in:
parent
0ba28d1183
commit
b6b61fc003
@ -126,16 +126,10 @@ func SetScreenSize(width, height int) (bool, error) {
|
|||||||
return false, errors.New("ui: Run is not called yet")
|
return false, errors.New("ui: Run is not called yet")
|
||||||
}
|
}
|
||||||
r := false
|
r := false
|
||||||
if err := u.runOnMainThread(func() error {
|
_ = u.runOnMainThread(func() error {
|
||||||
var err error
|
u.setScreenSize(width, height, u.scale)
|
||||||
r, err = u.setScreenSize(width, height, u.scale)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}); err != nil {
|
})
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
return r, nil
|
return r, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,16 +139,10 @@ func SetScreenScale(scale float64) (bool, error) {
|
|||||||
return false, errors.New("ui: Run is not called yet")
|
return false, errors.New("ui: Run is not called yet")
|
||||||
}
|
}
|
||||||
r := false
|
r := false
|
||||||
if err := u.runOnMainThread(func() error {
|
_ = u.runOnMainThread(func() error {
|
||||||
var err error
|
u.setScreenSize(u.width, u.height, scale)
|
||||||
r, err = u.setScreenSize(u.width, u.height, scale)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}); err != nil {
|
})
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
return r, nil
|
return r, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,11 +185,7 @@ func Run(width, height int, scale float64, title string, g GraphicsContext) erro
|
|||||||
if err := u.runOnMainThread(func() error {
|
if err := u.runOnMainThread(func() error {
|
||||||
m := glfw.GetPrimaryMonitor()
|
m := glfw.GetPrimaryMonitor()
|
||||||
v := m.GetVideoMode()
|
v := m.GetVideoMode()
|
||||||
r, err := u.setScreenSize(width, height, scale)
|
if !u.setScreenSize(width, height, scale) {
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if !r {
|
|
||||||
return errors.New("ui: Fail to set the screen size")
|
return errors.New("ui: Fail to set the screen size")
|
||||||
}
|
}
|
||||||
u.window.SetTitle(title)
|
u.window.SetTitle(title)
|
||||||
@ -295,22 +279,20 @@ func (u *userInterface) loop(g GraphicsContext) error {
|
|||||||
if err := glContext.BindScreenFramebuffer(); err != nil {
|
if err := glContext.BindScreenFramebuffer(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := u.runOnMainThread(func() error {
|
_ = u.runOnMainThread(func() error {
|
||||||
return u.swapBuffers()
|
u.swapBuffers()
|
||||||
}); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u *userInterface) swapBuffers() error {
|
|
||||||
u.window.SwapBuffers()
|
|
||||||
return nil
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterface) setScreenSize(width, height int, scale float64) (bool, error) {
|
func (u *userInterface) swapBuffers() {
|
||||||
|
u.window.SwapBuffers()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *userInterface) setScreenSize(width, height int, scale float64) bool {
|
||||||
if u.width == width && u.height == height && u.scale == scale {
|
if u.width == width && u.height == height && u.scale == scale {
|
||||||
return false, nil
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
origScale := u.scale
|
origScale := u.scale
|
||||||
@ -323,16 +305,14 @@ func (u *userInterface) setScreenSize(width, height int, scale float64) (bool, e
|
|||||||
const minWindowWidth = 252
|
const minWindowWidth = 252
|
||||||
if int(float64(width)*u.actualScreenScale()) < minWindowWidth {
|
if int(float64(width)*u.actualScreenScale()) < minWindowWidth {
|
||||||
u.scale = origScale
|
u.scale = origScale
|
||||||
return false, nil
|
return false
|
||||||
}
|
}
|
||||||
u.width = width
|
u.width = width
|
||||||
u.height = height
|
u.height = height
|
||||||
|
|
||||||
// To make sure the current existing framebuffers are rendered,
|
// To make sure the current existing framebuffers are rendered,
|
||||||
// swap buffers here before SetSize is called.
|
// swap buffers here before SetSize is called.
|
||||||
if err := u.swapBuffers(); err != nil {
|
u.swapBuffers()
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
ch := make(chan struct{})
|
ch := make(chan struct{})
|
||||||
window := u.window
|
window := u.window
|
||||||
@ -353,5 +333,5 @@ event:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
u.sizeChanged = true
|
u.sizeChanged = true
|
||||||
return true, nil
|
return true
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user