From: Brendan Hansen Date: Mon, 6 Dec 2021 21:38:46 +0000 (-0600) Subject: added more glfw3 mappings X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=2a309f5e5c4b0155fd200e2159df94f99d950add;p=onyx.git added more glfw3 mappings --- diff --git a/modules/glfw3/module.onyx b/modules/glfw3/module.onyx index c2e13f8c..1eed1df0 100644 --- a/modules/glfw3/module.onyx +++ b/modules/glfw3/module.onyx @@ -6,16 +6,36 @@ package glfw3 // Opaque types that are only used by pointer GLFWmonitor_p :: #distinct u64 GLFWwindow_p :: #distinct u64 +GLFWcursor_p :: #distinct u64 GLFWimage :: struct #size 16 { width, height: i32; pixels: ^u8; } +GLFWgamepadstate :: struct { + buttons: [15] u8; + axes: [6] f32; +} + +GLFWvidmode :: struct { + width, height: i32; + redBits, greenBits, blueBits, refreshRate: i32; +} + +GLFWgammaramp :: struct { + red: ^i32; + green: ^i32; + blue: ^i32; + size: i32; +} + #foreign "onyx_glfw3" { glfwInit :: () -> bool --- glfwTerminate :: () -> void --- + glfwInitHint :: (hint, value: i32) -> void --- glfwGetVersion :: (major, minor, rev: ^i32) -> void --- + // glfwGetError :: (description: ^^u8) -> void --- // glfwSetErrorCallback :: (f: (i32, cstr) -> void) -> void --- glfwMakeContextCurrent :: (window: GLFWwindow_p) -> void --- @@ -23,10 +43,68 @@ GLFWimage :: struct #size 16 { glfwSwapInterval :: (interval: i32) -> void --- glfwExtensionSupported :: (name: cstr) -> bool --- + glfwGetInputMode :: (window: GLFWwindow_p, mode: i32) -> i32 --- + glfwSetInputMode :: (window: GLFWwindow_p, mode, value: i32) -> void --- + glfwRawMouseMotionSupported :: () -> i32 --- + // glfwGetKeyName :: (key, scancode: i32) -> cstr --- + glfwGetKeyScancode :: (key: i32) -> i32 --- + glfwGetKey :: (window: GLFWwindow_p, key: i32) -> i32 --- + glfwGetMouseButton :: (window: GLFWwindow_p, button: i32) -> i32 --- + glfwGetCursorPos :: (window: GLFWwindow_p, xpos, ypos: ^f64) -> void --- + glfwSetCursorPos :: (window: GLFWwindow_p, xpos, ypos: f64) -> void --- + glfwCreateCursor :: (image: ^GLFWimage, xhot, yhot: i32) -> GLFWcursor_p --- + glfwCreateStandardCursor :: (shape: i32) -> GLFWcursor_p --- + glfwDestroyCursor :: (cursor: GLFWcursor_p) -> void --- + glfwSetCursor :: (window: GLFWwindow_p, cursor: GLFWcursor_p) -> void --- + // glfwSetKeyCallback + // glfwSetCharCallback + // glfwSetCharModsCallback + // glfwSetMouseButtonCallback + // glfwSetCursorPosCallback + // glfwSetCursorEnterCallback + // glfwSetScrollCallback + // glfwSetDropCallback + glfwJoystickPresent :: (jid: i32) -> i32 --- + // glfwGetJoystickAxes :: (jid: i32, count: ^i32) -> ^f32 --- + // glfwGetJoystickButtons :: (jid: i32, count: ^i32) -> ^u8 --- + // glfwGetJoystickHats :: (jid: i32, count: ^i32) -> ^u8 --- + // glfwGetJoystickName :: (jid: i32) -> ^u8 --- + // glfwGetJoystickGUID :: (jid: i32) -> ^u8 --- + glfwSetJoystickUserPointer :: (jid: i32, pointer: rawptr) -> void --- + glfwGetJoystickUserPointer :: (jid: i32) -> rawptr --- + glfwJoystickIsGamepad :: (jid: i32) -> i32 --- + // glfwSetJoystickCallback + glfwUpdateGamepadMappings :: (string: cstr) -> i32 --- + // glfwGetGamepadName :: (jid: i32) -> cstr --- + glfwGetGamepadState :: (jid: i32, state: ^GLFWgamepadstate) -> i32 --- + glfwSetClipboardString :: (window: GLFWwindow_p, string: cstr) -> void --- + // glfwGetClipboardString :: (window: GLFWwindow_p) -> cstr --- + glfwGetTime :: () -> f64 --- + glfwSetTime :: (time: f64) -> void --- + glfwGetTimerValue :: () -> u64 --- + glfwGetTimerFrequency :: () -> u64 --- + + glfwGetMonitors :: (max_monitors: i32, out_monitors: ^GLFWmonitor_p, out_count: ^i32) -> void --- + glfwGetPrimaryMonitor :: () -> GLFWmonitor_p --- + glfwGetMonitorPos :: (monitor: GLFWmonitor_p, xpos, ypos: ^i32) -> void --- + glfwGetMonitorWorkarea :: (monitor: GLFWmonitor_p, xpos, ypos, width, height: ^i32) -> void --- + glfwGetMonitorPhysicalSize :: (monitor: GLFWmonitor_p, widthMM, heightMM: ^i32) -> void --- + glfwGetMonitorContentScale :: (monitor: GLFWmonitor_p, xscale, yscale: ^f32) -> void --- + // glfwGetMonitorName :: (monitor: GLFWmonitor_p) -> cstr --- + glfwSetMonitorUserPointer :: (monitor: GLFWmonitor_p, pointer: rawptr) -> void --- + glfwGetMonitorUserPointer :: (monitor: GLFWmonitor_p) -> rawptr --- + // glfwSetMonitorCallback + glfwGetVideoModes :: (monitor: GLFWmonitor_p, max_modes: i32, out_modes: ^GLFWvidmode, out_count: ^i32) -> void --- + glfwGetVideoMode :: (monitor: GLFWmonitor_p, out_mode: ^GLFWvidmode) -> void --- + glfwSetGamma :: (monitor: GLFWmonitor_p, gamma: f32) -> void --- + // glfwGetGammaRamp :: (monitor: GLFWmonitor_p, out_ramp: ^GLFWgammramp) -> void --- + // glfwSetGammaRamp :: (monitor: GLFWmonitor_p, ramp: ^GLFWgammramp) -> void --- + + glfwCreateWindow :: (width, height: i32, title: cstr, monitor: GLFWmonitor_p = 0, share: GLFWwindow_p = 0) -> GLFWwindow_p --- glfwDestroyWindow :: (window: GLFWwindow_p) -> void --- glfwWindowShouldClose :: (window: GLFWwindow_p) -> bool --- - glfwSetWindowShouldClose :: (window: GLFWwindow_p, value: i32) -> void --- + glfwSetWindowShouldClose :: (window: GLFWwindow_p, value: bool) -> void --- glfwDefaultWindowHints :: () -> void --- glfwWindowHint :: (hint: i32, value: i32) -> void --- glfwSetWindowTitle :: (window: GLFWwindow_p, title: cstr) -> void --- diff --git a/modules/glfw3/onyx_glfw3.c b/modules/glfw3/onyx_glfw3.c index 11f7134c..6e3145f1 100644 --- a/modules/glfw3/onyx_glfw3.c +++ b/modules/glfw3/onyx_glfw3.c @@ -231,6 +231,224 @@ ONYX_DEF(glfwSwapBuffers, (LONG), ()) { return NULL; } +// glfwGetInputMode :: (window: GLFWwindow_p, mode: i32) -> i32 --- +// glfwSetInputMode :: (window: GLFWwindow_p, mode, value: i32) -> void --- +// glfwRawMouseMotionSupported :: () -> i32 --- +ONYX_DEF(glfwGetInputMode, (LONG, INT), (INT)) { + GLFWwindow *window = (GLFWwindow *) params->data[0].of.i64; + results->data[0] = WASM_I32_VAL(glfwGetInputMode(window, params->data[1].of.i32)); + return NULL; +} + +ONYX_DEF(glfwSetInputMode, (LONG, INT, INT), ()) { + GLFWwindow *window = (GLFWwindow *) params->data[0].of.i64; + glfwSetInputMode(window, params->data[1].of.i32, params->data[2].of.i32); + return NULL; +} + +ONYX_DEF(glfwRawMouseMotionSupported, (), (INT)) { + results->data[0] = WASM_I32_VAL(glfwRawMouseMotionSupported()); + return NULL; +} + +// // glfwGetKeyName :: (key, scancode: i32) -> cstr --- +ONYX_DEF(glfwGetKeyScancode, (INT), (INT)) { + results->data[0] = WASM_I32_VAL(params->data[0].of.i32); + return NULL; +} + +ONYX_DEF(glfwGetKey, (LONG, INT), (INT)) { + GLFWwindow *window = (GLFWwindow *) params->data[0].of.i64; + results->data[0] = WASM_I32_VAL(glfwGetKey(window, params->data[1].of.i32)); + return NULL; +} + +ONYX_DEF(glfwGetMouseButton, (LONG, INT), (INT)) { + GLFWwindow *window = (GLFWwindow *) params->data[0].of.i64; + results->data[0] = WASM_I32_VAL(glfwGetMouseButton(window, params->data[1].of.i32)); + return NULL; +} + +ONYX_DEF(glfwGetCursorPos, (LONG, PTR, PTR), ()) { + GLFWwindow *window = (GLFWwindow *) params->data[0].of.i64; + glfwGetCursorPos(window, (double *) ONYX_PTR(params->data[1].of.i32), (double *) ONYX_PTR(params->data[2].of.i32)); + return NULL; +} + +ONYX_DEF(glfwSetCursorPos, (LONG, DOUBLE, DOUBLE), ()) { + GLFWwindow *window = (GLFWwindow *) params->data[0].of.i64; + glfwSetCursorPos(window, params->data[1].of.f64, params->data[2].of.f64); + return NULL; +} + +ONYX_DEF(glfwCreateCursor, (PTR, INT, INT), (LONG)) { + GLFWimage image = { + *(int *) ONYX_PTR(params->data[0].of.i32 + 0), + *(int *) ONYX_PTR(params->data[0].of.i32 + 4), + ONYX_PTR(params->data[0].of.i32 + 8), + }; + + GLFWcursor *cursor = glfwCreateCursor(&image, params->data[1].of.i32, params->data[2].of.i32); + wasm_val_init_ptr(&results->data[0], cursor); + return NULL; +} + +ONYX_DEF(glfwCreateStandardCursor, (INT), (LONG)) { + GLFWcursor *cursor = glfwCreateStandardCursor(params->data[0].of.i32); + wasm_val_init_ptr(&results->data[0], cursor); + return NULL; +} + +ONYX_DEF(glfwDestroyCursor, (LONG), ()) { + glfwDestroyCursor((GLFWcursor *) params->data[0].of.i64); + return NULL; +} + +ONYX_DEF(glfwSetCursor, (LONG, LONG), ()) { + GLFWwindow *window = (GLFWwindow *) params->data[0].of.i64; + GLFWcursor *cursor = (GLFWcursor *) params->data[1].of.i64; + glfwSetCursor(window, cursor); + return NULL; +} + +// // glfwSetKeyCallback +// // glfwSetCharCallback +// // glfwSetCharModsCallback +// // glfwSetMouseButtonCallback +// // glfwSetCursorPosCallback +// // glfwSetCursorEnterCallback +// // glfwSetScrollCallback +// // glfwSetDropCallback +ONYX_DEF(glfwJoystickPresent, (INT), (INT)) { + results->data[0] = WASM_I32_VAL(glfwJoystickPresent(params->data[0].of.i32)); + return NULL; +} +// // glfwGetJoystickAxes :: (jid: i32, count: ^i32) -> ^f32 --- +// // glfwGetJoystickButtons :: (jid: i32, count: ^i32) -> ^u8 --- +// // glfwGetJoystickHats :: (jid: i32, count: ^i32) -> ^u8 --- +// // glfwGetJoystickName :: (jid: i32) -> ^u8 --- +// // glfwGetJoystickGUID :: (jid: i32) -> ^u8 --- +ONYX_DEF(glfwSetJoystickUserPointer, (INT, PTR), ()) { + glfwSetJoystickUserPointer(params->data[0].of.i32, (void *) (unsigned long) params->data[1].of.i32); + return NULL; +} + +ONYX_DEF(glfwGetJoystickUserPointer, (INT), (PTR)) { + results->data[0] = WASM_I32_VAL((unsigned int) (unsigned long) glfwGetJoystickUserPointer(params->data[0].of.i32)); + return NULL; +} + +ONYX_DEF(glfwJoystickIsGamepad, (INT), (INT)) { + results->data[0] = WASM_I32_VAL(glfwJoystickIsGamepad(params->data[0].of.i32)); + return NULL; +} + +ONYX_DEF(glfwUpdateGamepadMappings, (PTR), (INT)) { + results->data[0] = WASM_I32_VAL(glfwUpdateGamepadMappings(ONYX_PTR(params->data[0].of.i32))); + return NULL; +} + +ONYX_DEF(glfwGetGamepadState, (INT, PTR), (INT)) { + results->data[0] = WASM_I32_VAL(glfwGetGamepadState(params->data[0].of.i32, (GLFWgamepadstate *) ONYX_PTR(params->data[1].of.i32))); + return NULL; +} + +ONYX_DEF(glfwSetClipboardString, (LONG, PTR), ()) { + GLFWwindow *window = (GLFWwindow *) params->data[0].of.i64; + glfwSetClipboardString(window, ONYX_PTR(params->data[1].of.i32)); + return NULL; +} + +ONYX_DEF(glfwGetTime, (), (DOUBLE)) { + results->data[0] = WASM_F64_VAL(glfwGetTime()); + return NULL; +} + +ONYX_DEF(glfwSetTime, (DOUBLE), ()) { + glfwSetTime(params->data[0].of.f64); + return NULL; +} + +ONYX_DEF(glfwGetTimerValue, (), (LONG)) { + results->data[0] = WASM_I64_VAL(glfwGetTimerValue()); + return NULL; +} + +ONYX_DEF(glfwGetTimerFrequency, (), (LONG)) { + results->data[0] = WASM_I64_VAL(glfwGetTimerFrequency()); + return NULL; +} + +// // glfwSetJoystickCallback +// // glfwGetGamepadName :: (jid: i32) -> cstr --- +// // glfwGetClipboardString :: (window: GLFWwindow_p) -> cstr --- + +ONYX_DEF(glfwGetMonitors, (INT, PTR, PTR), ()) { + int monitor_count = params->data[0].of.i32; + int actual_count; + GLFWmonitor** monitors = glfwGetMonitors(&actual_count); + int monitor_ptr = params->data[1].of.i32; + + int count = (actual_count < monitor_count) ? actual_count : monitor_count; + for (int i=0; idata[2].of.i32) = count; + return NULL; +} + +ONYX_DEF(glfwGetPrimaryMonitor, (), (LONG)) { + results->data[0] = WASM_I64_VAL((unsigned long) glfwGetPrimaryMonitor()); + return NULL; +} + +ONYX_DEF(glfwGetMonitorPos, (LONG, PTR, PTR), ()) { + GLFWmonitor *monitor = (GLFWmonitor *) params->data[0].of.i64; + glfwGetMonitorPos(monitor, (int *) ONYX_PTR(params->data[1].of.i32), (int *) ONYX_PTR(params->data[2].of.i32)); + return NULL; +} + +ONYX_DEF(glfwGetMonitorWorkarea, (LONG, PTR, PTR, PTR, PTR), ()) { + GLFWmonitor *monitor = (GLFWmonitor *) params->data[0].of.i64; + glfwGetMonitorWorkarea(monitor, (int *) ONYX_PTR(params->data[1].of.i32), (int *) ONYX_PTR(params->data[2].of.i32), (int *) ONYX_PTR(params->data[3].of.i32), (int *) ONYX_PTR(params->data[4].of.i32)); + return NULL; +} + +ONYX_DEF(glfwGetMonitorPhysicalSize, (LONG, PTR, PTR), ()) { + GLFWmonitor *monitor = (GLFWmonitor *) params->data[0].of.i64; + glfwGetMonitorPhysicalSize(monitor, (int *) ONYX_PTR(params->data[1].of.i32), (int *) ONYX_PTR(params->data[2].of.i32)); + return NULL; +} + +ONYX_DEF(glfwGetMonitorContentScale, (LONG, PTR, PTR), ()) { + GLFWmonitor *monitor = (GLFWmonitor *) params->data[0].of.i64; + glfwGetMonitorContentScale(monitor, (float *) ONYX_PTR(params->data[1].of.i32), (float *) ONYX_PTR(params->data[2].of.i32)); + return NULL; +} + +ONYX_DEF(glfwSetMonitorUserPointer, (LONG, PTR), ()) { + GLFWmonitor *monitor = (GLFWmonitor *) params->data[0].of.i64; + glfwSetMonitorUserPointer(monitor, (void *) (unsigned long) params->data[0].of.i32); + return NULL; +} + +ONYX_DEF(glfwGetMonitorUserPointer, (LONG), (PTR)) { + GLFWmonitor *monitor = (GLFWmonitor *) params->data[0].of.i64; + results->data[0] = WASM_I32_VAL((unsigned int) (unsigned long) glfwGetMonitorUserPointer(monitor)); + return NULL; +} + +// // glfwGetMonitorName :: (monitor: GLFWmonitor_p) -> cstr --- +// // glfwSetMonitorCallback +// glfwGetVideoModes :: (monitor: GLFWmonitor_p, max_modes: i32, out_modes: ^GLFWvidmode, out_count: ^i32) -> void --- +// glfwGetVideoMode :: (monitor: GLFWmonitor_p, out_mode: ^GLFWvidmode) -> void --- +// glfwSetGamma :: (monitor: GLFWmonitor_p, gamma: f32) -> void --- +// // glfwGetGammaRamp :: (monitor: GLFWmonitor_p, out_ramp: ^GLFWgammramp) -> void --- +// // glfwSetGammaRamp :: (monitor: GLFWmonitor_p, ramp: ^GLFWgammramp) -> void --- + + + ONYX_LIBRARY { ONYX_FUNC(glfwInit) ONYX_FUNC(glfwTerminate) @@ -254,5 +472,55 @@ ONYX_LIBRARY { ONYX_FUNC(glfwPostEmptyEvent) ONYX_FUNC(glfwSwapBuffers) + ONYX_FUNC(glfwGetInputMode) + ONYX_FUNC(glfwSetInputMode) + ONYX_FUNC(glfwRawMouseMotionSupported) + ONYX_FUNC(glfwGetKeyScancode) + ONYX_FUNC(glfwGetKey) + ONYX_FUNC(glfwGetMouseButton) + ONYX_FUNC(glfwGetCursorPos) + ONYX_FUNC(glfwSetCursorPos) + ONYX_FUNC(glfwCreateCursor) + ONYX_FUNC(glfwCreateStandardCursor) + ONYX_FUNC(glfwDestroyCursor) + ONYX_FUNC(glfwSetCursor) + ONYX_FUNC(glfwJoystickPresent) + ONYX_FUNC(glfwSetJoystickUserPointer) + ONYX_FUNC(glfwGetJoystickUserPointer) + ONYX_FUNC(glfwJoystickIsGamepad) + ONYX_FUNC(glfwUpdateGamepadMappings) + ONYX_FUNC(glfwGetGamepadState) + ONYX_FUNC(glfwSetClipboardString) + ONYX_FUNC(glfwGetTime) + ONYX_FUNC(glfwSetTime) + ONYX_FUNC(glfwGetTimerValue) + ONYX_FUNC(glfwGetTimerFrequency) + ONYX_FUNC(glfwGetMonitors) + ONYX_FUNC(glfwGetPrimaryMonitor) + ONYX_FUNC(glfwGetMonitorPos) + ONYX_FUNC(glfwGetMonitorWorkarea) + ONYX_FUNC(glfwGetMonitorPhysicalSize) + ONYX_FUNC(glfwGetMonitorContentScale) + ONYX_FUNC(glfwSetMonitorUserPointer) + ONYX_FUNC(glfwGetMonitorUserPointer) + + + // // glfwGetKeyName :: (key, scancode: i32) -> cstr --- + +// // glfwSetKeyCallback +// // glfwSetCharCallback +// // glfwSetCharModsCallback +// // glfwSetMouseButtonCallback +// // glfwSetCursorPosCallback +// // glfwSetCursorEnterCallback +// // glfwSetScrollCallback +// // glfwSetDropCallback +// // glfwGetJoystickAxes :: (jid: i32, count: ^i32) -> ^f32 --- +// // glfwGetJoystickButtons :: (jid: i32, count: ^i32) -> ^u8 --- +// // glfwGetJoystickHats :: (jid: i32, count: ^i32) -> ^u8 --- +// // glfwGetJoystickName :: (jid: i32) -> ^u8 --- +// // glfwGetJoystickGUID :: (jid: i32) -> ^u8 --- + + NULL }; \ No newline at end of file diff --git a/modules/glfw3/onyx_glfw3.so b/modules/glfw3/onyx_glfw3.so index 0822af7a..14787872 100755 Binary files a/modules/glfw3/onyx_glfw3.so and b/modules/glfw3/onyx_glfw3.so differ