Skip to content

Commit

Permalink
uidriver/glfw: Adjust monitor sizes with math.Ceil
Browse files Browse the repository at this point in the history
deviceScaleFactor() sometimes returns an unnice value (e.g.,
1.502361). Add math.Ceil whenever the calculation involves the
device scale factor.
  • Loading branch information
hajimehoshi committed Sep 21, 2020
1 parent 8cb037e commit 3fc328d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 2 additions & 3 deletions internal/uidriver/glfw/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package glfw
import (
"fmt"
"image"
"math"
"os"
"runtime"
"sync"
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions internal/uidriver/glfw/ui_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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) {
Expand Down

0 comments on commit 3fc328d

Please sign in to comment.