mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-02-03 22:44:28 +01:00
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:
parent
8cb037e902
commit
3fc328db8d
@ -22,7 +22,6 @@ package glfw
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
"math"
|
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
@ -804,8 +803,8 @@ func (u *UserInterface) updateSize() {
|
|||||||
h = u.fromGLFWPixel(float64(wh))
|
h = u.fromGLFWPixel(float64(wh))
|
||||||
}
|
}
|
||||||
// On Linux/UNIX, further adjusting is required (#1307).
|
// On Linux/UNIX, further adjusting is required (#1307).
|
||||||
w = math.Ceil(u.toFramebufferPixel(w))
|
w = u.toFramebufferPixel(w)
|
||||||
h = math.Ceil(u.toFramebufferPixel(h))
|
h = u.toFramebufferPixel(h)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
u.context.Layout(w, h)
|
u.context.Layout(w, h)
|
||||||
|
@ -19,12 +19,14 @@
|
|||||||
package glfw
|
package glfw
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/glfw"
|
"github.com/hajimehoshi/ebiten/internal/glfw"
|
||||||
)
|
)
|
||||||
|
|
||||||
// fromGLFWMonitorPixel must be called from the main thread.
|
// fromGLFWMonitorPixel must be called from the main thread.
|
||||||
func (u *UserInterface) fromGLFWMonitorPixel(x float64) float64 {
|
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.
|
// 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.
|
// toFramebufferPixel must be called from the main thread.
|
||||||
func (u *UserInterface) toFramebufferPixel(x float64) float64 {
|
func (u *UserInterface) toFramebufferPixel(x float64) float64 {
|
||||||
s, _ := currentMonitor(u.window).GetContentScale()
|
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) {
|
func (u *UserInterface) adjustWindowPosition(x, y int) (int, int) {
|
||||||
|
Loading…
Reference in New Issue
Block a user