uidriver/glfw: Adjust monitor sizes with math.Ceil

deviceScaleFactor() sometimes returns an unnice value (e.g.,
1.502361). Add math.Ceil whenever the calculation involves the
device scale factor.
This commit is contained in:
Hajime Hoshi 2020-09-21 18:52:24 +09:00
parent 8cb037e902
commit 3fc328db8d
2 changed files with 6 additions and 5 deletions

View File

@ -22,7 +22,6 @@ package glfw
import (
"fmt"
"image"
"math"
"os"
"runtime"
"sync"
@ -804,8 +803,8 @@ func (u *UserInterface) updateSize() {
h = u.fromGLFWPixel(float64(wh))
}
// On Linux/UNIX, further adjusting is required (#1307).
w = math.Ceil(u.toFramebufferPixel(w))
h = math.Ceil(u.toFramebufferPixel(h))
w = u.toFramebufferPixel(w)
h = u.toFramebufferPixel(h)
return nil
})
u.context.Layout(w, h)

View File

@ -19,12 +19,14 @@
package glfw
import (
"math"
"github.com/hajimehoshi/ebiten/internal/glfw"
)
// fromGLFWMonitorPixel must be called from the main thread.
func (u *UserInterface) fromGLFWMonitorPixel(x float64) float64 {
return x / u.deviceScaleFactor()
return math.Ceil(x / u.deviceScaleFactor())
}
// fromGLFWPixel must be called from the main thread.
@ -44,7 +46,7 @@ func (u *UserInterface) toGLFWPixel(x float64) float64 {
// toFramebufferPixel must be called from the main thread.
func (u *UserInterface) toFramebufferPixel(x float64) float64 {
s, _ := currentMonitor(u.window).GetContentScale()
return x / u.deviceScaleFactor() * float64(s)
return math.Ceil(x * float64(s) / u.deviceScaleFactor())
}
func (u *UserInterface) adjustWindowPosition(x, y int) (int, int) {