mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
internal/uidriver/glfw: Bug fix: Treat pixel units correctly
Updates #1385
This commit is contained in:
parent
99b2b5c1ee
commit
585f173d1c
@ -53,13 +53,15 @@ type UserInterface struct {
|
||||
window *glfw.Window
|
||||
|
||||
// windowWidth and windowHeight represents a window size.
|
||||
// The unit is device-dependent pixels.
|
||||
// The units are device-dependent pixels.
|
||||
windowWidth int
|
||||
windowHeight int
|
||||
minWindowWidth int
|
||||
minWindowHeight int
|
||||
maxWindowWidth int
|
||||
maxWindowHeight int
|
||||
|
||||
// The units are device-independent pixels.
|
||||
minWindowWidthInDP int
|
||||
minWindowHeightInDP int
|
||||
maxWindowWidthInDP int
|
||||
maxWindowHeightInDP int
|
||||
|
||||
running uint32
|
||||
toChangeSize bool
|
||||
@ -114,10 +116,10 @@ const (
|
||||
var (
|
||||
theUI = &UserInterface{
|
||||
runnableOnUnfocused: true,
|
||||
minWindowWidth: glfw.DontCare,
|
||||
minWindowHeight: glfw.DontCare,
|
||||
maxWindowWidth: glfw.DontCare,
|
||||
maxWindowHeight: glfw.DontCare,
|
||||
minWindowWidthInDP: glfw.DontCare,
|
||||
minWindowHeightInDP: glfw.DontCare,
|
||||
maxWindowWidthInDP: glfw.DontCare,
|
||||
maxWindowHeightInDP: glfw.DontCare,
|
||||
origPosX: invalidPos,
|
||||
origPosY: invalidPos,
|
||||
initVsync: true,
|
||||
@ -243,22 +245,22 @@ func (u *UserInterface) setRunning(running bool) {
|
||||
}
|
||||
}
|
||||
|
||||
func (u *UserInterface) getWindowSizeLimits() (minw, minh, maxw, maxh int) {
|
||||
func (u *UserInterface) getWindowSizeLimitsInDP() (minw, minh, maxw, maxh int) {
|
||||
u.m.RLock()
|
||||
defer u.m.RUnlock()
|
||||
return u.minWindowWidth, u.minWindowHeight, u.maxWindowWidth, u.maxWindowHeight
|
||||
return u.minWindowWidthInDP, u.minWindowHeightInDP, u.maxWindowWidthInDP, u.maxWindowHeightInDP
|
||||
}
|
||||
|
||||
func (u *UserInterface) setWindowSizeLimits(minw, minh, maxw, maxh int) bool {
|
||||
func (u *UserInterface) setWindowSizeLimitsInDP(minw, minh, maxw, maxh int) bool {
|
||||
u.m.RLock()
|
||||
defer u.m.RUnlock()
|
||||
if u.minWindowWidth == minw && u.minWindowHeight == minh && u.maxWindowWidth == maxw && u.maxWindowHeight == maxh {
|
||||
if u.minWindowWidthInDP == minw && u.minWindowHeightInDP == minh && u.maxWindowWidthInDP == maxw && u.maxWindowHeightInDP == maxh {
|
||||
return false
|
||||
}
|
||||
u.minWindowWidth = minw
|
||||
u.minWindowHeight = minh
|
||||
u.maxWindowWidth = maxw
|
||||
u.maxWindowHeight = maxh
|
||||
u.minWindowWidthInDP = minw
|
||||
u.minWindowHeightInDP = minh
|
||||
u.maxWindowWidthInDP = maxw
|
||||
u.maxWindowHeightInDP = maxh
|
||||
return true
|
||||
}
|
||||
|
||||
@ -1008,24 +1010,34 @@ func (u *UserInterface) swapBuffers() {
|
||||
|
||||
// updateWindowSizeLimits must be called from the main thread.
|
||||
func (u *UserInterface) updateWindowSizeLimits() {
|
||||
minw, minh, maxw, maxh := u.getWindowSizeLimits()
|
||||
minw, minh, maxw, maxh := u.getWindowSizeLimitsInDP()
|
||||
if minw < 0 {
|
||||
minw = glfw.DontCare
|
||||
} else {
|
||||
minw = int(u.toGLFWPixel(float64(minw)))
|
||||
}
|
||||
if minh < 0 {
|
||||
minh = glfw.DontCare
|
||||
} else {
|
||||
minh = int(u.toGLFWPixel(float64(minh)))
|
||||
}
|
||||
if maxw < 0 {
|
||||
maxw = glfw.DontCare
|
||||
} else {
|
||||
maxw = int(u.toGLFWPixel(float64(maxw)))
|
||||
}
|
||||
if maxh < 0 {
|
||||
maxh = glfw.DontCare
|
||||
} else {
|
||||
maxh = int(u.toGLFWPixel(float64(maxh)))
|
||||
}
|
||||
u.window.SetSizeLimits(minw, minh, maxw, maxh)
|
||||
}
|
||||
|
||||
func (u *UserInterface) adjustWindowSizeBasedOnSizeLimits(width, height int) (int, int) {
|
||||
minw, minh, maxw, maxh := u.getWindowSizeLimits()
|
||||
// adjustWindowSizeBasedOnSizeLimitsInDP adjust the size based on the window size limits.
|
||||
// width and height are in device-independent pixels.
|
||||
func (u *UserInterface) adjustWindowSizeBasedOnSizeLimitsInDP(width, height int) (int, int) {
|
||||
minw, minh, maxw, maxh := u.getWindowSizeLimitsInDP()
|
||||
if minw >= 0 && width < minw {
|
||||
width = minw
|
||||
}
|
||||
@ -1043,7 +1055,11 @@ func (u *UserInterface) adjustWindowSizeBasedOnSizeLimits(width, height int) (in
|
||||
|
||||
// setWindowSize must be called from the main thread.
|
||||
func (u *UserInterface) setWindowSize(width, height int, fullscreen bool) {
|
||||
width, height = u.adjustWindowSizeBasedOnSizeLimits(width, height)
|
||||
wdp := int(u.fromGLFWPixel(float64(width)))
|
||||
hdp := int(u.fromGLFWPixel(float64(height)))
|
||||
wdp, hdp = u.adjustWindowSizeBasedOnSizeLimitsInDP(wdp, hdp)
|
||||
width = int(u.toGLFWPixel(float64(wdp)))
|
||||
height = int(u.toGLFWPixel(float64(hdp)))
|
||||
|
||||
if u.windowWidth == width && u.windowHeight == height && u.isFullscreen() == fullscreen && u.lastDeviceScaleFactor == u.deviceScaleFactor() {
|
||||
return
|
||||
|
@ -229,7 +229,7 @@ func (w *window) setPosition(x, y int) {
|
||||
func (w *window) Size() (int, int) {
|
||||
if !w.ui.isRunning() {
|
||||
ww, wh := w.ui.getInitWindowSize()
|
||||
return w.ui.adjustWindowSizeBasedOnSizeLimits(ww, wh)
|
||||
return w.ui.adjustWindowSizeBasedOnSizeLimitsInDP(ww, wh)
|
||||
}
|
||||
ww := int(w.ui.fromGLFWPixel(float64(w.ui.windowWidth)))
|
||||
wh := int(w.ui.fromGLFWPixel(float64(w.ui.windowHeight)))
|
||||
@ -250,36 +250,12 @@ func (w *window) SetSize(width, height int) {
|
||||
}
|
||||
|
||||
func (w *window) SizeLimits() (minw, minh, maxw, maxh int) {
|
||||
minw, minh, maxw, maxh = w.ui.getWindowSizeLimits()
|
||||
if minw >= 0 {
|
||||
minw = int(w.ui.fromGLFWPixel(float64(minw)))
|
||||
}
|
||||
if minh >= 0 {
|
||||
minh = int(w.ui.fromGLFWPixel(float64(minh)))
|
||||
}
|
||||
if maxw >= 0 {
|
||||
maxw = int(w.ui.fromGLFWPixel(float64(maxw)))
|
||||
}
|
||||
if maxh >= 0 {
|
||||
maxh = int(w.ui.fromGLFWPixel(float64(maxh)))
|
||||
}
|
||||
minw, minh, maxw, maxh = w.ui.getWindowSizeLimitsInDP()
|
||||
return
|
||||
}
|
||||
|
||||
func (w *window) SetSizeLimits(minw, minh, maxw, maxh int) {
|
||||
if minw >= 0 {
|
||||
minw = int(w.ui.toGLFWPixel(float64(minw)))
|
||||
}
|
||||
if minh >= 0 {
|
||||
minh = int(w.ui.toGLFWPixel(float64(minh)))
|
||||
}
|
||||
if maxw >= 0 {
|
||||
maxw = int(w.ui.toGLFWPixel(float64(maxw)))
|
||||
}
|
||||
if maxh >= 0 {
|
||||
maxh = int(w.ui.toGLFWPixel(float64(maxh)))
|
||||
}
|
||||
if !w.ui.setWindowSizeLimits(minw, minh, maxw, maxh) {
|
||||
if !w.ui.setWindowSizeLimitsInDP(minw, minh, maxw, maxh) {
|
||||
return
|
||||
}
|
||||
if !w.ui.isRunning() {
|
||||
|
Loading…
Reference in New Issue
Block a user