Skip to content

Commit

Permalink
graphicsdriver/glfw: Bug fix: Convert window size unit correctly on L…
Browse files Browse the repository at this point in the history
…inux/UNIX

Updates hajimehoshi#1307
  • Loading branch information
hajimehoshi committed Sep 18, 2020
1 parent 5278a7c commit 97607f5
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
13 changes: 7 additions & 6 deletions internal/uidriver/glfw/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -789,19 +789,20 @@ func (u *UserInterface) updateSize() {
if sizeChanged {
var w, h float64
_ = u.t.Call(func() error {
var ww, wh int
if u.isFullscreen() {
v := currentMonitor(u.window).GetVideoMode()
ww = v.Width
wh = v.Height
ww, wh := v.Width, v.Height
w = u.toDeviceIndependentPixel(float64(ww))
h = u.toDeviceIndependentPixel(float64(wh))
} else {
// Instead of u.windowWidth and u.windowHeight, use the actual window size here.
// On Windows, the specified size at SetSize and the actual window size might not
// match (#1163).
ww, wh = u.window.GetSize()
ww, wh := u.window.GetSize()
// TODO: Is this correct?
w = u.toDeviceIndependentPixel(float64(ww))
h = u.toDeviceIndependentPixel(float64(wh))
}
w = u.toDeviceIndependentPixel(float64(ww))
h = u.toDeviceIndependentPixel(float64(wh))
return nil
})
u.context.Layout(w, h)
Expand Down
4 changes: 4 additions & 0 deletions internal/uidriver/glfw/ui_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ func (u *UserInterface) toDeviceIndependentPixel(x float64) float64 {
return x
}

func (u *UserInterface) fromGLFWPixel(x float64) float64 {
return x
}

func (u *UserInterface) toGLFWPixel(x float64) float64 {
return x
}
Expand Down
5 changes: 5 additions & 0 deletions internal/uidriver/glfw/ui_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ func (u *UserInterface) toDeviceIndependentPixel(x float64) float64 {
return x / u.deviceScaleFactor()
}

// fromGLFWPixel must be called from the main thread.
func (u *UserInterface) fromGLFWPixel(x float64) float64 {
return x
}

// toGLFWPixel must be called from the main thread.
func (u *UserInterface) toGLFWPixel(x float64) float64 {
return x
Expand Down
5 changes: 5 additions & 0 deletions internal/uidriver/glfw/ui_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ func (u *UserInterface) toDeviceIndependentPixel(x float64) float64 {
return x / u.deviceScaleFactor()
}

// fromGLFWPixel must be called from the main thread.
func (u *UserInterface) fromGLFWPixel(x float64) float64 {
return x / u.deviceScaleFactor()
}

// toGLFWPixel must be called from the main thread.
func (u *UserInterface) toGLFWPixel(x float64) float64 {
return x * u.deviceScaleFactor()
Expand Down
8 changes: 4 additions & 4 deletions internal/uidriver/glfw/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ func (w *window) Position() (int, int) {
mx, my := currentMonitor(w.ui.window).GetPos()
wx -= mx
wy -= my
xf := w.ui.toDeviceIndependentPixel(float64(wx))
yf := w.ui.toDeviceIndependentPixel(float64(wy))
xf := w.ui.fromGLFWPixel(float64(wx))
yf := w.ui.fromGLFWPixel(float64(wy))
x, y = int(xf), int(yf)
return nil
})
Expand Down Expand Up @@ -226,8 +226,8 @@ func (w *window) Size() (int, int) {
if !w.ui.isRunning() {
return w.ui.getInitWindowSize()
}
ww := int(w.ui.toDeviceIndependentPixel(float64(w.ui.windowWidth)))
wh := int(w.ui.toDeviceIndependentPixel(float64(w.ui.windowHeight)))
ww := int(w.ui.fromGLFWPixel(float64(w.ui.windowWidth)))
wh := int(w.ui.fromGLFWPixel(float64(w.ui.windowHeight)))
return ww, wh
}

Expand Down

0 comments on commit 97607f5

Please sign in to comment.