mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-11 19:48:54 +01:00
ui: Update device scale on browsers (#644)
This commit is contained in:
parent
21c1ee5dfb
commit
635d624b77
@ -41,6 +41,11 @@ type userInterface struct {
|
|||||||
sizeChanged bool
|
sizeChanged bool
|
||||||
windowFocus bool
|
windowFocus bool
|
||||||
pageVisible bool
|
pageVisible bool
|
||||||
|
|
||||||
|
deviceScale float64
|
||||||
|
frame int64
|
||||||
|
deviceScaleUpdated int64
|
||||||
|
lastActualScale float64
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentUI = &userInterface{
|
var currentUI = &userInterface{
|
||||||
@ -173,13 +178,23 @@ func (u *userInterface) actualScreenScale() float64 {
|
|||||||
// * Chrome just after restoring the lost context
|
// * Chrome just after restoring the lost context
|
||||||
// * Safari
|
// * Safari
|
||||||
// Let's use the devicePixelRatio as it is here.
|
// Let's use the devicePixelRatio as it is here.
|
||||||
return u.getScale() * devicescale.DeviceScale()
|
if u.deviceScale == 0 || u.frame-u.deviceScaleUpdated > 30 {
|
||||||
|
u.deviceScale = devicescale.DeviceScale()
|
||||||
|
u.deviceScaleUpdated = u.frame
|
||||||
|
}
|
||||||
|
return u.getScale() * u.deviceScale
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterface) updateGraphicsContext(g GraphicsContext) {
|
func (u *userInterface) updateGraphicsContext(g GraphicsContext) {
|
||||||
|
a := u.actualScreenScale()
|
||||||
|
if u.lastActualScale != a {
|
||||||
|
u.updateScreenSize()
|
||||||
|
}
|
||||||
|
u.lastActualScale = a
|
||||||
|
|
||||||
if u.sizeChanged {
|
if u.sizeChanged {
|
||||||
u.sizeChanged = false
|
u.sizeChanged = false
|
||||||
g.SetSize(u.width, u.height, u.actualScreenScale())
|
g.SetSize(u.width, u.height, a)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,6 +240,7 @@ func (u *userInterface) loop(g GraphicsContext) error {
|
|||||||
close(ch)
|
close(ch)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
u.frame++
|
||||||
if u.vsync {
|
if u.vsync {
|
||||||
requestAnimationFrame.Invoke(cf)
|
requestAnimationFrame.Invoke(cf)
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user