1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

glfw: temporary fix

This commit is contained in:
yuyi 2020-03-28 19:47:24 +08:00 committed by GitHub
parent 784d27f41b
commit 9fb218d379
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -109,7 +109,7 @@ pub fn init_glfw() {
C.glfwWindowHint(C.GLFW_OPENGL_PROFILE, C.GLFW_OPENGL_CORE_PROFILE) C.glfwWindowHint(C.GLFW_OPENGL_PROFILE, C.GLFW_OPENGL_CORE_PROFILE)
} }
pub fn (w &Window) destroy() { pub fn (w &glfw.Window) destroy() {
C.glfwDestroyWindow(w.data) C.glfwDestroyWindow(w.data)
} }
@ -126,7 +126,7 @@ pub fn window_hint(key, val int) {
C.glfwWindowHint(key, val) C.glfwWindowHint(key, val)
} }
pub fn create_window(c WinCfg) &Window { pub fn create_window(c glfw.WinCfg) &glfw.Window {
if c.borderless { if c.borderless {
window_hint(C.GLFW_RESIZABLE, 0) window_hint(C.GLFW_RESIZABLE, 0)
window_hint(C.GLFW_DECORATED, 0) window_hint(C.GLFW_DECORATED, 0)
@ -155,7 +155,7 @@ pub fn create_window(c WinCfg) &Window {
scale = 1.0 scale = 1.0
} }
window := &Window { window := &glfw.Window {
data: cwindow, data: cwindow,
title: c.title, title: c.title,
scale_: scale scale_: scale
@ -163,15 +163,15 @@ pub fn create_window(c WinCfg) &Window {
return window return window
} }
pub fn (w &Window) set_title(title string) { pub fn (w &glfw.Window) set_title(title string) {
C.glfwSetWindowTitle(w.data, title.str) C.glfwSetWindowTitle(w.data, title.str)
} }
pub fn (w &Window) make_context_current() { pub fn (w &glfw.Window) make_context_current() {
C.glfwMakeContextCurrent(w.data) C.glfwMakeContextCurrent(w.data)
} }
pub fn (w &Window) scale() f32 { pub fn (w &glfw.Window) scale() f32 {
return w.scale_ return w.scale_
} }
@ -191,39 +191,39 @@ pub fn set_should_close(w voidptr, close bool) {
C.glfwSetWindowShouldClose(w, close) C.glfwSetWindowShouldClose(w, close)
} }
pub fn (w &Window) set_should_close(close bool) { pub fn (w &glfw.Window) set_should_close(close bool) {
C.glfwSetWindowShouldClose(w.data, close) C.glfwSetWindowShouldClose(w.data, close)
} }
pub fn (w &Window) should_close() bool { pub fn (w &glfw.Window) should_close() bool {
return C.glfwWindowShouldClose(w.data) return C.glfwWindowShouldClose(w.data)
} }
pub fn (w &Window) swap_buffers() { pub fn (w &glfw.Window) swap_buffers() {
C.glfwSwapBuffers(w.data) C.glfwSwapBuffers(w.data)
} }
pub fn (w mut Window) onmousemove(cb voidptr) { pub fn (w mut glfw.Window) onmousemove(cb voidptr) {
C.glfwSetCursorPosCallback(w.data, cb) C.glfwSetCursorPosCallback(w.data, cb)
} }
pub fn (w mut Window) set_mouse_button_callback(cb voidptr) { pub fn (w mut glfw.Window) set_mouse_button_callback(cb voidptr) {
C.glfwSetMouseButtonCallback(w.data, cb) C.glfwSetMouseButtonCallback(w.data, cb)
} }
pub fn (w mut Window) on_resize(cb voidptr) { pub fn (w mut glfw.Window) on_resize(cb voidptr) {
C.glfwSetWindowSizeCallback(w.data, cb) C.glfwSetWindowSizeCallback(w.data, cb)
} }
pub fn (w mut Window) on_click(cb voidptr) { pub fn (w mut glfw.Window) on_click(cb voidptr) {
C.glfwSetMouseButtonCallback(w.data, cb) C.glfwSetMouseButtonCallback(w.data, cb)
} }
pub fn (w &Window) set_scroll_callback(cb voidptr) { pub fn (w &glfw.Window) set_scroll_callback(cb voidptr) {
C.glfwSetScrollCallback(w.data, cb) C.glfwSetScrollCallback(w.data, cb)
} }
pub fn (w &Window) on_scroll(cb voidptr) { pub fn (w &glfw.Window) on_scroll(cb voidptr) {
C.glfwSetScrollCallback(w.data, cb) C.glfwSetScrollCallback(w.data, cb)
} }
@ -231,11 +231,11 @@ pub fn post_empty_event() {
C.glfwPostEmptyEvent() C.glfwPostEmptyEvent()
} }
pub fn (w mut Window) onkeydown(cb voidptr) { pub fn (w mut glfw.Window) onkeydown(cb voidptr) {
C.glfwSetKeyCallback(w.data, cb) C.glfwSetKeyCallback(w.data, cb)
} }
pub fn (w mut Window) onchar(cb voidptr) { pub fn (w mut glfw.Window) onchar(cb voidptr) {
C.glfwSetCharModsCallback(w.data, cb) C.glfwSetCharModsCallback(w.data, cb)
} }
@ -247,11 +247,11 @@ pub fn key_pressed(wnd voidptr, key int) bool {
return int(C.glfwGetKey(wnd, key)) == C.GLFW_PRESS return int(C.glfwGetKey(wnd, key)) == C.GLFW_PRESS
} }
pub fn (w &Window) get_clipboard_text() string { pub fn (w &glfw.Window) get_clipboard_text() string {
return string(byteptr(C.glfwGetClipboardString(w.data))) return string(byteptr(C.glfwGetClipboardString(w.data)))
} }
pub fn (w &Window) set_clipboard_text(s string) { pub fn (w &glfw.Window) set_clipboard_text(s string) {
C.glfwSetClipboardString(w.data, s.str) C.glfwSetClipboardString(w.data, s.str)
} }
@ -270,7 +270,7 @@ pub fn get_cursor_pos(cwindow voidptr) (f64, f64) {
return x/scale, y/scale return x/scale, y/scale
} }
pub fn (w &Window) get_cursor_pos() Pos { pub fn (w &glfw.Window) get_cursor_pos() Pos {
x := f64(0) x := f64(0)
y := f64(0) y := f64(0)
C.glfwGetCursorPos(w.data, &x, &y) C.glfwGetCursorPos(w.data, &x, &y)
@ -291,16 +291,16 @@ pub fn set_cursor(c Cursor) {
C.glfwSetCursor(0, C.GLFW_IBEAM_CURSOR) C.glfwSetCursor(0, C.GLFW_IBEAM_CURSOR)
} }
pub fn (w &Window) set_cursor(c Cursor) { pub fn (w &glfw.Window) set_cursor(c Cursor) {
C.glfwSetCursor(w.data, C.GLFW_IBEAM_CURSOR) C.glfwSetCursor(w.data, C.GLFW_IBEAM_CURSOR)
} }
pub fn (w &Window) user_ptr() voidptr { pub fn (w &glfw.Window) user_ptr() voidptr {
return C.glfwGetWindowUserPointer(w.data) return C.glfwGetWindowUserPointer(w.data)
} }
pub fn (w &Window) set_user_ptr(ptr voidptr) { pub fn (w &glfw.Window) set_user_ptr(ptr voidptr) {
C.glfwSetWindowUserPointer(w.data, ptr) C.glfwSetWindowUserPointer(w.data, ptr)
} }
@ -317,18 +317,18 @@ pub fn get_monitor_size() Size {
return Size{mode.width, mode.height} return Size{mode.width, mode.height}
} }
fn C.glfwGetWindowSize(window &Window, width &int, height &int) // screen coordinates fn C.glfwGetWindowSize(window &glfw.Window, width &int, height &int) // screen coordinates
fn C.glfwGetFramebufferSize(window &Window, width &int, height &int) // pixels fn C.glfwGetFramebufferSize(window &glfw.Window, width &int, height &int) // pixels
// get_window_size in screen coordinates // get_window_size in screen coordinates
pub fn (w &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 &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