ui: Bug fix: DeviceScaleFactor should return the current monitor's scale

This commit is contained in:
Hajime Hoshi 2018-10-08 01:11:13 +09:00
parent 16a9bac487
commit f3b7148564
4 changed files with 17 additions and 7 deletions

View File

@ -22,10 +22,6 @@ var (
m sync.Mutex m sync.Mutex
) )
func Get() float64 {
return GetAt(0, 0)
}
func GetAt(x, y int) float64 { func GetAt(x, y int) float64 {
m.Lock() m.Lock()
defer m.Unlock() defer m.Unlock()

View File

@ -495,6 +495,21 @@ func SetWindowDecorated(decorated bool) {
// return nil // return nil
} }
func DeviceScaleFactor() float64 {
f := 0.0
u := currentUI
if !u.isRunning() {
return devicescale.GetAt(currentMonitor().GetPos())
}
_ = u.runOnMainThread(func() error {
m := u.currentMonitor()
f = devicescale.GetAt(m.GetPos())
return nil
})
return f
}
func Run(width, height int, scale float64, title string, g GraphicsContext, mainloop bool) error { func Run(width, height int, scale float64, title string, g GraphicsContext, mainloop bool) error {
u := currentUI u := currentUI
// GLContext must be created before setting the screen size, which requires // GLContext must be created before setting the screen size, which requires

View File

@ -84,7 +84,7 @@ func getDeviceScale() float64 {
defer deviceScaleM.Unlock() defer deviceScaleM.Unlock()
if deviceScaleVal == 0 { if deviceScaleVal == 0 {
deviceScaleVal = devicescale.Get() deviceScaleVal = devicescale.GetAt(0, 0)
} }
return deviceScaleVal return deviceScaleVal
} }

3
run.go
View File

@ -23,7 +23,6 @@ import (
"sync/atomic" "sync/atomic"
"github.com/hajimehoshi/ebiten/internal/clock" "github.com/hajimehoshi/ebiten/internal/clock"
"github.com/hajimehoshi/ebiten/internal/devicescale"
"github.com/hajimehoshi/ebiten/internal/png" "github.com/hajimehoshi/ebiten/internal/png"
"github.com/hajimehoshi/ebiten/internal/shareable" "github.com/hajimehoshi/ebiten/internal/shareable"
"github.com/hajimehoshi/ebiten/internal/ui" "github.com/hajimehoshi/ebiten/internal/ui"
@ -528,7 +527,7 @@ func SetWindowIcon(iconImages []image.Image) {
// //
// DeviceScaleFactor is concurrent-safe. // DeviceScaleFactor is concurrent-safe.
func DeviceScaleFactor() float64 { func DeviceScaleFactor() float64 {
return devicescale.Get() return ui.DeviceScaleFactor()
} }
// IsVsyncEnabled returns a boolean value indicating whether // IsVsyncEnabled returns a boolean value indicating whether