mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-13 20:42:07 +01:00
internal/ui: refactoring: move device-scale implementation to internal/ui for browsers
The returned value from internal/devicescale.At never changes for browsers, so the detection of devicePixelRatio updates didn't work in the first place. Also, there is not a good way to detect the change [1]. This change moves the logic from internal/devicescale to internal/ui. We aim to merge these packages as a device scale factor belongs to a monitor and internal/ui manages monitors. [1] https://crbug.com/123694
This commit is contained in:
parent
5de9c5da61
commit
506a1de259
@ -1,31 +0,0 @@
|
|||||||
// Copyright 2018 The Ebiten Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package devicescale
|
|
||||||
|
|
||||||
import (
|
|
||||||
"syscall/js"
|
|
||||||
)
|
|
||||||
|
|
||||||
func impl(x, y int) float64 {
|
|
||||||
window := js.Global().Get("window")
|
|
||||||
if !window.Truthy() {
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
ratio := window.Get("devicePixelRatio").Float()
|
|
||||||
if ratio == 0 {
|
|
||||||
ratio = 1
|
|
||||||
}
|
|
||||||
return ratio
|
|
||||||
}
|
|
@ -21,7 +21,6 @@ import (
|
|||||||
"syscall/js"
|
"syscall/js"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/devicescale"
|
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/file"
|
"github.com/hajimehoshi/ebiten/v2/internal/file"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/gamepad"
|
"github.com/hajimehoshi/ebiten/v2/internal/gamepad"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||||
@ -95,7 +94,7 @@ type userInterfaceImpl struct {
|
|||||||
onceUpdateCalled bool
|
onceUpdateCalled bool
|
||||||
lastCaptureExitTime time.Time
|
lastCaptureExitTime time.Time
|
||||||
|
|
||||||
lastDeviceScaleFactor float64
|
deviceScaleFactor float64
|
||||||
|
|
||||||
err error
|
err error
|
||||||
|
|
||||||
@ -280,7 +279,16 @@ func (u *userInterfaceImpl) SetCursorShape(shape CursorShape) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) DeviceScaleFactor() float64 {
|
func (u *userInterfaceImpl) DeviceScaleFactor() float64 {
|
||||||
return devicescale.GetAt(0, 0)
|
if u.deviceScaleFactor != 0 {
|
||||||
|
return u.deviceScaleFactor
|
||||||
|
}
|
||||||
|
|
||||||
|
ratio := window.Get("devicePixelRatio").Float()
|
||||||
|
if ratio == 0 {
|
||||||
|
ratio = 1
|
||||||
|
}
|
||||||
|
u.deviceScaleFactor = ratio
|
||||||
|
return u.deviceScaleFactor
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) outsideSize() (float64, float64) {
|
func (u *userInterfaceImpl) outsideSize() (float64, float64) {
|
||||||
@ -354,11 +362,13 @@ func (u *userInterfaceImpl) updateImpl(force bool) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
a := u.DeviceScaleFactor()
|
if !u.onceUpdateCalled {
|
||||||
if u.lastDeviceScaleFactor != a {
|
|
||||||
u.updateScreenSize()
|
u.updateScreenSize()
|
||||||
}
|
}
|
||||||
u.lastDeviceScaleFactor = a
|
|
||||||
|
// TODO: If DeviceScaleFactor changes, call updateScreenSize.
|
||||||
|
// Now there is not a good way to detect the change.
|
||||||
|
// See also https://crbug.com/123694.
|
||||||
|
|
||||||
w, h := u.outsideSize()
|
w, h := u.outsideSize()
|
||||||
if force {
|
if force {
|
||||||
@ -401,7 +411,9 @@ func (u *userInterfaceImpl) loop(game Game) <-chan error {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if u.needsUpdate() {
|
if u.needsUpdate() {
|
||||||
|
defer func() {
|
||||||
u.onceUpdateCalled = true
|
u.onceUpdateCalled = true
|
||||||
|
}()
|
||||||
u.renderingScheduled = false
|
u.renderingScheduled = false
|
||||||
if err := u.update(); err != nil {
|
if err := u.update(); err != nil {
|
||||||
close(reqStopAudioCh)
|
close(reqStopAudioCh)
|
||||||
|
Loading…
Reference in New Issue
Block a user