From 49a5a2bf4e448f886fef3fe75f47ca9ca546fa15 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 27 Oct 2019 17:13:17 +0900 Subject: [PATCH] uidriver/js: Bug fix: Needed to initialize pseudoScale with the given scale Updates #960, #973 --- examples/moire/main.go | 6 +----- examples/windowsize/main.go | 6 +----- internal/uidriver/js/ui.go | 1 + run.go | 2 +- 4 files changed, 4 insertions(+), 11 deletions(-) diff --git a/examples/moire/main.go b/examples/moire/main.go index 4eebd8a05..0fe4b69b9 100644 --- a/examples/moire/main.go +++ b/examples/moire/main.go @@ -70,8 +70,6 @@ func update(screen *ebiten.Image) error { screenScale = 2 case 2: screenScale = 1 - case 0: - // screenScale can be 0 on browsers or mobiles. Ignore this. default: panic("not reached") } @@ -79,9 +77,7 @@ func update(screen *ebiten.Image) error { if inpututil.IsKeyJustPressed(ebiten.KeyF) { fullscreen = !fullscreen } - if screenScale > 0 { - ebiten.SetScreenScale(screenScale) - } + ebiten.SetScreenScale(screenScale) ebiten.SetFullscreen(fullscreen) if ebiten.IsDrawingSkipped() { diff --git a/examples/windowsize/main.go b/examples/windowsize/main.go index 47d90be93..f0f630e06 100644 --- a/examples/windowsize/main.go +++ b/examples/windowsize/main.go @@ -108,8 +108,6 @@ func update(screen *ebiten.Image) error { screenScale = 2 case 2: screenScale = 0.75 - case 0: - // screenScale can be 0 on browsers or mobiles. Ignore this. default: panic("not reached") } @@ -142,9 +140,7 @@ func update(screen *ebiten.Image) error { } ebiten.SetScreenSize(screenWidth, screenHeight) - if screenScale > 0 { - ebiten.SetScreenScale(screenScale) - } + ebiten.SetScreenScale(screenScale) ebiten.SetFullscreen(fullscreen) ebiten.SetRunnableInBackground(runnableInBackground) ebiten.SetCursorVisible(cursorVisible) diff --git a/internal/uidriver/js/ui.go b/internal/uidriver/js/ui.go index e690968fe..1c8cbf7ed 100644 --- a/internal/uidriver/js/ui.go +++ b/internal/uidriver/js/ui.go @@ -424,6 +424,7 @@ func (u *UserInterface) Run(width, height int, scale float64, title string, cont document.Set("title", title) u.setScreenSize(width, height) + u.pseudoScale = scale canvas.Call("focus") ch := u.loop(context) if runtime.GOARCH == "wasm" { diff --git a/run.go b/run.go index 30181a310..28d238689 100644 --- a/run.go +++ b/run.go @@ -240,7 +240,7 @@ func SetScreenScale(scale float64) { // ScreenScale returns the current screen scale. // -// ScreenScale returns a value set by SetScreenScale or Run on browsers. +// On browsers, this value does not affect actual rendering. // // If Run is not called, this returns 0. //