mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
glfw: remove global scale variable
This commit is contained in:
parent
93920a4bb0
commit
5ae04dca84
@ -46,8 +46,6 @@ pub const (
|
|||||||
KeyDown = 264
|
KeyDown = 264
|
||||||
)
|
)
|
||||||
|
|
||||||
__global monitor_scale f32
|
|
||||||
|
|
||||||
// joe-c: fix & remove
|
// joe-c: fix & remove
|
||||||
struct TmpGlImportHack {
|
struct TmpGlImportHack {
|
||||||
hack gl.TmpGlImportHack
|
hack gl.TmpGlImportHack
|
||||||
@ -73,6 +71,7 @@ pub struct Window {
|
|||||||
title string
|
title string
|
||||||
mx int
|
mx int
|
||||||
my int
|
my int
|
||||||
|
scale_ f32
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Size {
|
pub struct Size {
|
||||||
@ -142,17 +141,16 @@ pub fn create_window(c WinCfg) &glfw.Window {
|
|||||||
}
|
}
|
||||||
// println('create window wnd=$cwindow ptr==$c.ptr')
|
// println('create window wnd=$cwindow ptr==$c.ptr')
|
||||||
C.glfwSetWindowUserPointer(cwindow, c.ptr)
|
C.glfwSetWindowUserPointer(cwindow, c.ptr)
|
||||||
|
|
||||||
|
mut scale := 1.0
|
||||||
$if windows {
|
$if windows {
|
||||||
C.glfwGetWindowContentScale(cwindow, &monitor_scale, &monitor_scale)
|
C.glfwGetWindowContentScale(cwindow, &scale, &scale)
|
||||||
}
|
|
||||||
$else {
|
|
||||||
monitor_scale = 1.0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
window := &glfw.Window {
|
window := &glfw.Window {
|
||||||
data: cwindow,
|
data: cwindow,
|
||||||
title: c.title,
|
title: c.title,
|
||||||
|
scale_: scale
|
||||||
}
|
}
|
||||||
return window
|
return window
|
||||||
}
|
}
|
||||||
@ -165,8 +163,8 @@ pub fn (w &glfw.Window) make_context_current() {
|
|||||||
C.glfwMakeContextCurrent(w.data)
|
C.glfwMakeContextCurrent(w.data)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (w &glfw.Window) scale() f64 {
|
pub fn (w &glfw.Window) scale() f32 {
|
||||||
return monitor_scale
|
return w.scale_
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn swap_interval(interval int) {
|
pub fn swap_interval(interval int) {
|
||||||
@ -249,12 +247,16 @@ pub fn (w &glfw.Window) set_clipboard_text(s string) {
|
|||||||
C.glfwSetClipboardString(w.data, s.str)
|
C.glfwSetClipboardString(w.data, s.str)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_cursor_pos(glfw_window voidptr) (f64, f64) {
|
pub fn get_cursor_pos(cwindow voidptr) (f64, f64) {
|
||||||
x := f64(0)
|
x := f64(0)
|
||||||
y := f64(0)
|
y := f64(0)
|
||||||
C.glfwGetCursorPos(glfw_window, &x, &y)
|
C.glfwGetCursorPos(cwindow, &x, &y)
|
||||||
|
|
||||||
return x/monitor_scale, y/monitor_scale
|
mut scale := 1.0
|
||||||
|
$if windows {
|
||||||
|
C.glfwGetWindowContentScale(cwindow, &scale, &scale)
|
||||||
|
}
|
||||||
|
return x/scale, y/scale
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (w &glfw.Window) get_cursor_pos() Pos {
|
pub fn (w &glfw.Window) get_cursor_pos() Pos {
|
||||||
@ -263,8 +265,8 @@ pub fn (w &glfw.Window) get_cursor_pos() Pos {
|
|||||||
C.glfwGetCursorPos(w.data, &x, &y)
|
C.glfwGetCursorPos(w.data, &x, &y)
|
||||||
|
|
||||||
return Pos {
|
return Pos {
|
||||||
x: int(x/monitor_scale)
|
x: int(x/w.scale_)
|
||||||
y: int(y/monitor_scale)
|
y: int(y/w.scale_)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -309,15 +311,15 @@ fn C.glfwGetFramebufferSize(window &glfw.Window, width &int, height &int) // pix
|
|||||||
|
|
||||||
// get_window_size in screen coordinates
|
// get_window_size in screen coordinates
|
||||||
pub fn (w &glfw.Window) get_window_size() Size {
|
pub fn (w &glfw.Window) get_window_size() Size {
|
||||||
res := Size{ 0, 0 }
|
res := Size {0, 0}
|
||||||
C.glfwGetWindowSize( w.data, &res.width, &res.height )
|
C.glfwGetWindowSize(w.data, &res.width, &res.height)
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
// get_framebuffer_size in pixels
|
// get_framebuffer_size in pixels
|
||||||
pub fn (w &glfw.Window) get_framebuffer_size() Size {
|
pub fn (w &glfw.Window) get_framebuffer_size() Size {
|
||||||
res := Size{ 0, 0 }
|
res := Size {0, 0}
|
||||||
C.glfwGetFramebufferSize( w.data, &res.width, &res.height )
|
C.glfwGetFramebufferSize(w.data, &res.width, &res.height)
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user