mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
ui: fixes so that the ui demo works on linux too
* Implement os.resource_abs_path/1 . * Implement glfw.get_window_size and glfw.get_framebuffer_size .
This commit is contained in:
committed by
Alexander Medvednikov
parent
607656d616
commit
f317b65808
@@ -101,7 +101,7 @@ pub fn init_glfw() {
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ pub fn window_hint(key, val int) {
|
||||
C.glfwWindowHint(key, val)
|
||||
}
|
||||
|
||||
pub fn create_window(c WinCfg) &Window {
|
||||
pub fn create_window(c WinCfg) &glfw.Window {
|
||||
if c.borderless {
|
||||
window_hint(C.GLFW_RESIZABLE, 0)
|
||||
window_hint(C.GLFW_DECORATED, 0)
|
||||
@@ -133,18 +133,18 @@ pub fn create_window(c WinCfg) &Window {
|
||||
}
|
||||
println('create window wnd=$cwindow ptr==$c.ptr')
|
||||
C.glfwSetWindowUserPointer(cwindow, c.ptr)
|
||||
window := &Window {
|
||||
window := &glfw.Window {
|
||||
data: cwindow,
|
||||
title: c.title,
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
pub fn (w &Window) make_context_current() {
|
||||
pub fn (w &glfw.Window) make_context_current() {
|
||||
C.glfwMakeContextCurrent(w.data)
|
||||
}
|
||||
|
||||
@@ -164,31 +164,31 @@ pub fn set_should_close(w voidptr, close bool) {
|
||||
C.glfwSetWindowShouldClose(w, close)
|
||||
}
|
||||
|
||||
pub fn (w &Window) should_close() bool {
|
||||
pub fn (w &glfw.Window) should_close() bool {
|
||||
return C.glfwWindowShouldClose(w.data)
|
||||
}
|
||||
|
||||
pub fn (w &Window) swap_buffers() {
|
||||
pub fn (w &glfw.Window) swap_buffers() {
|
||||
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)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
pub fn (w mut Window) on_click(cb voidptr) {
|
||||
pub fn (w mut glfw.Window) on_click(cb voidptr) {
|
||||
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)
|
||||
}
|
||||
|
||||
pub fn (w &Window) on_scroll(cb voidptr) {
|
||||
pub fn (w &glfw.Window) on_scroll(cb voidptr) {
|
||||
C.glfwSetScrollCallback(w.data, cb)
|
||||
}
|
||||
|
||||
@@ -196,11 +196,11 @@ pub fn post_empty_event() {
|
||||
C.glfwPostEmptyEvent()
|
||||
}
|
||||
|
||||
pub fn (w mut Window) onkeydown(cb voidptr) {
|
||||
pub fn (w mut glfw.Window) onkeydown(cb voidptr) {
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -212,11 +212,11 @@ pub fn key_pressed(wnd voidptr, key int) bool {
|
||||
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)))
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -227,7 +227,7 @@ pub fn get_cursor_pos(glfw_window voidptr) (f64, f64) {
|
||||
return x,y
|
||||
}
|
||||
|
||||
pub fn (w &Window) get_cursor_pos() Pos {
|
||||
pub fn (w &glfw.Window) get_cursor_pos() Pos {
|
||||
x := f64(0)
|
||||
y := f64(0)
|
||||
C.glfwGetCursorPos(w.data, &x, &y)
|
||||
@@ -247,16 +247,16 @@ pub fn set_cursor(c 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)
|
||||
|
||||
}
|
||||
|
||||
pub fn (w &Window) user_ptr() voidptr {
|
||||
pub fn (w &glfw.Window) user_ptr() voidptr {
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -273,6 +273,23 @@ pub fn get_monitor_size() Size {
|
||||
return Size{mode.width, mode.height}
|
||||
}
|
||||
|
||||
fn C.glfwGetWindowSize(window &glfw.Window, width &int, height &int) // screen coordinates
|
||||
fn C.glfwGetFramebufferSize(window &glfw.Window, width &int, height &int) // pixels
|
||||
|
||||
// get_window_size in screen coordinates
|
||||
pub fn (w &glfw.Window) get_window_size() Size {
|
||||
res := Size{ 0, 0 }
|
||||
C.glfwGetWindowSize( w.data, &res.width, &res.height )
|
||||
return res
|
||||
}
|
||||
|
||||
// get_framebuffer_size in pixels
|
||||
pub fn (w &glfw.Window) get_framebuffer_size() Size {
|
||||
res := Size{ 0, 0 }
|
||||
C.glfwGetFramebufferSize( w.data, &res.width, &res.height )
|
||||
return res
|
||||
}
|
||||
|
||||
pub fn (size Size) str() string {
|
||||
return '{$size.width, $size.height}'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user