mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 03:15:35 -04:00
macOS: scale window size with content scale
This fixes bad viewport on macOS #29
This commit is contained in:
parent
97e1b57cda
commit
ec2e4ba9c3
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.gui.rendering.system.window
|
package de.bixilon.minosoft.gui.rendering.system.window
|
||||||
|
|
||||||
|
import de.bixilon.kotlinglm.vec2.Vec2
|
||||||
import de.bixilon.kotlinglm.vec2.Vec2d
|
import de.bixilon.kotlinglm.vec2.Vec2d
|
||||||
import de.bixilon.kotlinglm.vec2.Vec2i
|
import de.bixilon.kotlinglm.vec2.Vec2i
|
||||||
import de.bixilon.kutil.concurrent.pool.DefaultThreadPool
|
import de.bixilon.kutil.concurrent.pool.DefaultThreadPool
|
||||||
@ -127,7 +128,9 @@ class GLFWWindow(
|
|||||||
if (value) {
|
if (value) {
|
||||||
glfwSetWindowMonitor(window, monitor, 15, 15, mode.width(), mode.height(), mode.refreshRate())
|
glfwSetWindowMonitor(window, monitor, 15, 15, mode.width(), mode.height(), mode.refreshRate())
|
||||||
} else {
|
} else {
|
||||||
glfwSetWindowMonitor(window, 0, (mode.width() - DEFAULT_WINDOW_SIZE.x) / 2, (mode.height() - DEFAULT_WINDOW_SIZE.y) / 2, DEFAULT_WINDOW_SIZE.x, DEFAULT_WINDOW_SIZE.y, GLFW_DONT_CARE)
|
val scale = getWindowScale()
|
||||||
|
val size = Vec2i(DEFAULT_WINDOW_SIZE.x / scale.x, DEFAULT_WINDOW_SIZE.y / scale.y)
|
||||||
|
glfwSetWindowMonitor(window, 0, (mode.width() - size.x) / 2, (mode.height() - size.y) / 2, size.x, size.y, GLFW_DONT_CARE)
|
||||||
}
|
}
|
||||||
|
|
||||||
field = value
|
field = value
|
||||||
@ -202,6 +205,8 @@ class GLFWWindow(
|
|||||||
val primaryMonitor = glfwGetPrimaryMonitor()
|
val primaryMonitor = glfwGetPrimaryMonitor()
|
||||||
if (primaryMonitor != MemoryUtil.NULL) {
|
if (primaryMonitor != MemoryUtil.NULL) {
|
||||||
glfwGetVideoMode(primaryMonitor)?.let {
|
glfwGetVideoMode(primaryMonitor)?.let {
|
||||||
|
val scale = getWindowScale()
|
||||||
|
val size = Vec2i(DEFAULT_WINDOW_SIZE.x / scale.x, DEFAULT_WINDOW_SIZE.y / scale.y)
|
||||||
glfwSetWindowPos(window, (it.width() - size.x) / 2, (it.height() - size.y) / 2)
|
glfwSetWindowPos(window, (it.width() - size.x) / 2, (it.height() - size.y) / 2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -300,7 +305,9 @@ class GLFWWindow(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
val previousSize = Vec2i(_size)
|
val previousSize = Vec2i(_size)
|
||||||
_size = Vec2i(width, height)
|
val scale = getWindowScale()
|
||||||
|
val nextSize = Vec2i(width * scale.x, height * scale.y)
|
||||||
|
_size = nextSize
|
||||||
fireGLFWEvent(ResizeWindowEvent(renderWindow, previousSize = previousSize, size = _size))
|
fireGLFWEvent(ResizeWindowEvent(renderWindow, previousSize = previousSize, size = _size))
|
||||||
this.skipNextMouseEvent = true
|
this.skipNextMouseEvent = true
|
||||||
}
|
}
|
||||||
@ -372,6 +379,13 @@ class GLFWWindow(
|
|||||||
glfwSetWindowIcon(window, images)
|
glfwSetWindowIcon(window, images)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getWindowScale(): Vec2 {
|
||||||
|
val x = FloatArray(1)
|
||||||
|
val y = FloatArray(1)
|
||||||
|
glfwGetWindowContentScale(window, x, y)
|
||||||
|
return Vec2(x[0], y[0])
|
||||||
|
}
|
||||||
|
|
||||||
private fun fireGLFWEvent(event: RenderEvent): Boolean {
|
private fun fireGLFWEvent(event: RenderEvent): Boolean {
|
||||||
// ToDo: It looks like glfwPollEvents is mixing threads. This should not happen.
|
// ToDo: It looks like glfwPollEvents is mixing threads. This should not happen.
|
||||||
if (Rendering.currentContext != event.renderWindow) {
|
if (Rendering.currentContext != event.renderWindow) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user