window_x11.odin 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // WIP! Does not function yet.
  2. #+build linux
  3. #+private file
  4. package karl2d
  5. @(private="package")
  6. WINDOW_INTERFACE_X11 :: Window_Interface {
  7. state_size = x11_state_size,
  8. init = x11_init,
  9. shutdown = x11_shutdown,
  10. window_handle = x11_window_handle,
  11. process_events = x11_process_events,
  12. get_events = x11_get_events,
  13. get_width = x11_get_width,
  14. get_height = x11_get_height,
  15. clear_events = x11_clear_events,
  16. set_position = x11_set_position,
  17. set_size = x11_set_size,
  18. get_window_scale = x11_get_window_scale,
  19. set_flags = x11_set_flags,
  20. is_gamepad_active = x11_is_gamepad_active,
  21. get_gamepad_axis = x11_get_gamepad_axis,
  22. set_gamepad_vibration = x11_set_gamepad_vibration,
  23. set_internal_state = x11_set_internal_state,
  24. }
  25. import "vendor:x11/xlib"
  26. import "base:runtime"
  27. import "core:log"
  28. import "core:fmt"
  29. _ :: xlib
  30. _ :: log
  31. _ :: fmt
  32. x11_state_size :: proc() -> int {
  33. return size_of(X11_State)
  34. }
  35. x11_init :: proc(
  36. window_state: rawptr,
  37. window_width: int,
  38. window_height: int,
  39. window_title: string,
  40. flags: Window_Flags,
  41. allocator: runtime.Allocator,
  42. ) {
  43. s = (^X11_State)(window_state)
  44. s.allocator = allocator
  45. s.flags = flags
  46. s.width = window_width
  47. s.height = window_height
  48. }
  49. x11_shutdown :: proc() {
  50. }
  51. x11_window_handle :: proc() -> Window_Handle {
  52. return {}
  53. }
  54. x11_process_events :: proc() {
  55. }
  56. x11_get_events :: proc() -> []Window_Event {
  57. return s.events[:]
  58. }
  59. x11_get_width :: proc() -> int {
  60. return s.width
  61. }
  62. x11_get_height :: proc() -> int {
  63. return s.height
  64. }
  65. x11_clear_events :: proc() {
  66. runtime.clear(&s.events)
  67. }
  68. x11_set_position :: proc(x: int, y: int) {
  69. }
  70. x11_set_size :: proc(w, h: int) {
  71. }
  72. x11_get_window_scale :: proc() -> f32 {
  73. return 1
  74. }
  75. x11_set_flags :: proc(flags: Window_Flags) {
  76. s.flags = flags
  77. }
  78. x11_is_gamepad_active :: proc(gamepad: int) -> bool {
  79. if gamepad < 0 || gamepad >= MAX_GAMEPADS {
  80. return false
  81. }
  82. return false
  83. }
  84. x11_get_gamepad_axis :: proc(gamepad: int, axis: Gamepad_Axis) -> f32 {
  85. if gamepad < 0 || gamepad >= MAX_GAMEPADS {
  86. return 0
  87. }
  88. return 0
  89. }
  90. x11_set_gamepad_vibration :: proc(gamepad: int, left: f32, right: f32) {
  91. if gamepad < 0 || gamepad >= MAX_GAMEPADS {
  92. return
  93. }
  94. }
  95. x11_set_internal_state :: proc(state: rawptr) {
  96. assert(state != nil)
  97. s = (^X11_State)(state)
  98. }
  99. X11_State :: struct {
  100. allocator: runtime.Allocator,
  101. width: int,
  102. height: int,
  103. events: [dynamic]Window_Event,
  104. flags: Window_Flags,
  105. }
  106. s: ^X11_State