karl2d.doc.odin 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. // This file is purely documentational. It is generated from the contents of 'karl2d.odin'.
  2. #+build ignore
  3. package karl2d
  4. //-----------------------------------------------//
  5. // SETUP, WINDOW MANAGEMENT AND FRAME MANAGEMENT //
  6. //-----------------------------------------------//
  7. // Opens a window and initializes some internal state. The internal state will use `allocator` for
  8. // all dynamically allocated memory. The return value can be ignored unless you need to later call
  9. // `set_internal_state`.
  10. init :: proc(window_width: int, window_height: int, window_title: string,
  11. window_creation_flags := Window_Flags {},
  12. allocator := context.allocator, loc := #caller_location) -> ^State
  13. // Returns true the user has pressed the close button on the window, or used a key stroke such as
  14. // ALT+F4 on Windows. The application can decide if it wants to shut down or if it wants to show
  15. // some kind of confirmation dialogue.
  16. //
  17. // Commonly used for creating the "main loop" of a game: `for k2.shutdown_wanted {}`
  18. shutdown_wanted :: proc() -> bool
  19. // Closes the window and cleans up the internal state.
  20. shutdown :: proc()
  21. // Clear the "screen" with the supplied color. By default this will clear your window. But if you
  22. // have set a Render Texture using `set_render_texture` procedure, then that Render Texture will be
  23. // cleared instead.
  24. clear :: proc(color: Color)
  25. // "Flips the backbuffer": Call at end of frame to make everything you've drawn appear on the screen.
  26. //
  27. // When you draw using for example `draw_texture`, then that stuff is drawn to an invisible texture
  28. // called a "backbuffer". This makes sure that we don't see half-drawn frames. So when you are happy
  29. // with a frame and want to show it to the player, use this procedure.
  30. //
  31. // Also, this procedure clears the frame_allocator that Karl2D uses for internal allocations that
  32. // have the lifetime of a single frame.
  33. //
  34. // WebGL note: WebGL does the backbuffer flipping automatically. But you should still call this to
  35. // make Karl2D clear its frame allocator.
  36. present :: proc()
  37. // Call at start or end of frame to process all events that have arrived to the window. This
  38. // includes keyboard, mouse, gamepad and window events.
  39. //
  40. // WARNING: Not calling this will make your program impossible to interact with.
  41. process_events :: proc()
  42. // Gets the width of the drawing area within the window. The returned number is not scaled by any
  43. // monitor DPI scaling. You do that manually using the number returned by `get_window_scale()`.
  44. get_screen_width :: proc() -> int
  45. // Gets the height of the drawing area within the window. The returned number is not scaled by any
  46. // monitor DPI scaling. You do that manually using the number returned by `get_window_scale()`.
  47. get_screen_height :: proc() -> int
  48. // Moves the window.
  49. //
  50. // WebGL note: This moves the canvas within the window, which may not be what you want.
  51. set_window_position :: proc(x: int, y: int)
  52. // Resize the window to a new size. If the window has the flag Resizable set, then the backbuffer
  53. // will also be resized.
  54. set_window_size :: proc(width: int, height: int)
  55. // Fetch the scale of the window. This usually comes from some DPI scaling setting in the OS.
  56. // 1 means 100% scale, 1.5 means 150% etc.
  57. get_window_scale :: proc() -> f32
  58. set_window_flags :: proc(flags: Window_Flags)
  59. // Flushes the current batch. This sends off everything to the GPU that has been queued in the
  60. // current batch. Normally, you do not need to do this manually. It is done automatically when these
  61. // procedures run:
  62. //
  63. // - present
  64. // - set_camera
  65. // - set_shader
  66. // - set_shader_constant
  67. // - set_scissor_rect
  68. // - draw_texture_* IF previous draw did not use the same texture (1)
  69. // - draw_rect_*, draw_circle_*, draw_line IF previous draw did not use the shapes drawing texture (2)
  70. //
  71. // (1) When drawing textures, the current texture is fed into the active shader. Everything within
  72. // the same batch must use the same texture. So drawing with a new texture will draw the current
  73. // batch. You can combine several textures into an atlas to get bigger batches.
  74. //
  75. // (2) In order to use the same shader for shapes drawing and textured drawing, the shapes drawing
  76. // uses a blank, white texture. For the same reasons as (1), drawing something else than shapes
  77. // before drawing a shape will break up the batches. TODO: Add possibility to customize shape
  78. // drawing texture so that you can put it into an atlas.
  79. //
  80. // The batch has maximum size of VERTEX_BUFFER_MAX bytes. The shader dictates how big a vertex is
  81. // so the maximum number of vertices that can be drawn in each batch is
  82. // VERTEX_BUFFER_MAX / shader.vertex_size
  83. draw_current_batch :: proc()
  84. //-------//
  85. // INPUT //
  86. //-------//
  87. // Returns true if a keyboard key went down between the current and the previous frame. Set when
  88. // 'process_events' runs (probably once per frame).
  89. key_went_down :: proc(key: Keyboard_Key) -> bool
  90. // Returns true if a keyboard key went up (was released) between the current and the previous frame.
  91. // Set when 'process_events' runs (probably once per frame).
  92. key_went_up :: proc(key: Keyboard_Key) -> bool
  93. // Returns true if a keyboard is currently being held down. Set when 'process_events' runs (probably
  94. // once per frame).
  95. key_is_held :: proc(key: Keyboard_Key) -> bool
  96. mouse_button_went_down :: proc(button: Mouse_Button) -> bool
  97. mouse_button_went_up :: proc(button: Mouse_Button) -> bool
  98. mouse_button_is_held :: proc(button: Mouse_Button) -> bool
  99. get_mouse_wheel_delta :: proc() -> f32
  100. get_mouse_position :: proc() -> Vec2
  101. get_mouse_delta :: proc() -> Vec2
  102. is_gamepad_active :: proc(gamepad: Gamepad_Index) -> bool
  103. gamepad_button_went_down :: proc(gamepad: Gamepad_Index, button: Gamepad_Button) -> bool
  104. gamepad_button_went_up :: proc(gamepad: Gamepad_Index, button: Gamepad_Button) -> bool
  105. gamepad_button_is_held :: proc(gamepad: Gamepad_Index, button: Gamepad_Button) -> bool
  106. get_gamepad_axis :: proc(gamepad: Gamepad_Index, axis: Gamepad_Axis) -> f32
  107. // Set the left and right vibration motor speed. The range of left and right is 0 to 1. Note that on
  108. // most gamepads, the left motor is "low frequency" and the right motor is "high frequency". They do
  109. // not vibrate with the same speed.
  110. set_gamepad_vibration :: proc(gamepad: Gamepad_Index, left: f32, right: f32)
  111. //---------//
  112. // DRAWING //
  113. //---------//
  114. draw_rect :: proc(r: Rect, c: Color)
  115. draw_rect_vec :: proc(pos: Vec2, size: Vec2, c: Color)
  116. draw_rect_ex :: proc(r: Rect, origin: Vec2, rot: f32, c: Color)
  117. draw_rect_outline :: proc(r: Rect, thickness: f32, color: Color)
  118. draw_circle :: proc(center: Vec2, radius: f32, color: Color, segments := 16)
  119. draw_circle_outline :: proc(center: Vec2, radius: f32, thickness: f32, color: Color, segments := 16)
  120. draw_line :: proc(start: Vec2, end: Vec2, thickness: f32, color: Color)
  121. draw_texture :: proc(tex: Texture, pos: Vec2, tint := WHITE)
  122. draw_texture_rect :: proc(tex: Texture, rect: Rect, pos: Vec2, tint := WHITE)
  123. draw_texture_ex :: proc(tex: Texture, src: Rect, dst: Rect, origin: Vec2, rotation: f32, tint := WHITE)
  124. measure_text :: proc(text: string, font_size: f32) -> Vec2
  125. draw_text :: proc(text: string, pos: Vec2, font_size: f32, color: Color)
  126. draw_text_ex :: proc(font_handle: Font_Handle, text: string, pos: Vec2, font_size: f32, color: Color)
  127. //--------------------//
  128. // TEXTURE MANAGEMENT //
  129. //--------------------//
  130. create_texture :: proc(width: int, height: int, format: Pixel_Format) -> Texture
  131. // Load a texture from disk and upload it to the GPU so you can draw it to the screen.
  132. // Supports PNG, BMP, TGA and baseline PNG. Note that progressive PNG files are not supported!
  133. //
  134. // The `options` parameter can be used to specify things things such as premultiplication of alpha.
  135. load_texture_from_file :: proc(filename: string, options: Load_Texture_Options = {}) -> Texture
  136. // Load a texture from a byte slice and upload it to the GPU so you can draw it to the screen.
  137. // Supports PNG, BMP, TGA and baseline PNG. Note that progressive PNG files are not supported!
  138. //
  139. // The `options` parameter can be used to specify things things such as premultiplication of alpha.
  140. load_texture_from_bytes :: proc(bytes: []u8, options: Load_Texture_Options = {}) -> Texture
  141. // Load raw texture data. You need to specify the data, size and format of the texture yourself.
  142. // This assumes that there is no header in the data. If your data has a header (you read the data
  143. // from a file on disk), then please use `load_texture_from_bytes` instead.
  144. load_texture_from_bytes_raw :: proc(bytes: []u8, width: int, height: int, format: Pixel_Format) -> Texture
  145. // Get a rectangle that spans the whole texture. Coordinates will be (x, y) = (0, 0) and size
  146. // (w, h) = (texture_width, texture_height)
  147. get_texture_rect :: proc(t: Texture) -> Rect
  148. // Update a texture with new pixels. `bytes` is the new pixel data. `rect` is the rectangle in
  149. // `tex` where the new pixels should end up.
  150. update_texture :: proc(tex: Texture, bytes: []u8, rect: Rect) -> bool
  151. destroy_texture :: proc(tex: Texture)
  152. // Controls how a texture should be filtered. You can choose "point" or "linear" filtering. Which
  153. // means "pixly" or "smooth". This filter will be used for up and down-scaling as well as for
  154. // mipmap sampling. Use `set_texture_filter_ex` if you need to control these settings separately.
  155. set_texture_filter :: proc(t: Texture, filter: Texture_Filter)
  156. // Controls how a texture should be filtered. `scale_down_filter` and `scale_up_filter` controls how
  157. // the texture is filtered when we render the texture at a smaller or larger size.
  158. // `mip_filter` controls how the texture is filtered when it is sampled using _mipmapping_.
  159. //
  160. // TODO: Add mipmapping generation controls for texture and refer to it from here.
  161. set_texture_filter_ex :: proc(
  162. t: Texture,
  163. scale_down_filter: Texture_Filter,
  164. scale_up_filter: Texture_Filter,
  165. mip_filter: Texture_Filter,
  166. )
  167. //-----------------//
  168. // RENDER TEXTURES //
  169. //-----------------//
  170. // Create a texture that you can render into. Meaning that you can draw into it instead of drawing
  171. // onto the screen. Set the texture using `set_render_texture`.
  172. create_render_texture :: proc(width: int, height: int) -> Render_Texture
  173. // Destroy a Render_Texture previously created using `create_render_texture`.
  174. destroy_render_texture :: proc(render_texture: Render_Texture)
  175. // Make all rendering go into a texture instead of onto the screen. Create the render texture using
  176. // `create_render_texture`. Pass `nil` to resume drawing onto the screen.
  177. set_render_texture :: proc(render_texture: Maybe(Render_Texture))
  178. //-------//
  179. // FONTS //
  180. //-------//
  181. load_font_from_file :: proc(filename: string) -> Font_Handle
  182. load_font_from_bytes :: proc(data: []u8) -> Font_Handle
  183. destroy_font :: proc(font: Font_Handle)
  184. get_default_font :: proc() -> Font_Handle
  185. //---------//
  186. // SHADERS //
  187. //---------//
  188. load_shader_from_file :: proc(
  189. vertex_filename: string,
  190. fragment_filename: string,
  191. layout_formats: []Pixel_Format = {}
  192. ) -> Shader
  193. load_shader_from_memory :: proc(
  194. vertex_shader_bytes: []byte,
  195. fragment_shader_bytes: []byte,
  196. layout_formats: []Pixel_Format = {},
  197. ) -> Shader
  198. destroy_shader :: proc(shader: Shader)
  199. get_default_shader :: proc() -> Shader
  200. set_shader :: proc(shader: Maybe(Shader))
  201. set_shader_constant :: proc(shd: Shader, loc: Shader_Constant_Location, val: any)
  202. override_shader_input :: proc(shader: Shader, input: int, val: any)
  203. pixel_format_size :: proc(f: Pixel_Format) -> int
  204. //-------------------------------//
  205. // CAMERA AND COORDINATE SYSTEMS //
  206. //-------------------------------//
  207. set_camera :: proc(camera: Maybe(Camera))
  208. screen_to_world :: proc(pos: Vec2, camera: Camera) -> Vec2
  209. world_to_screen :: proc(pos: Vec2, camera: Camera) -> Vec2
  210. get_camera_view_matrix :: proc(c: Camera) -> Mat4
  211. get_camera_world_matrix :: proc(c: Camera) -> Mat4
  212. //------//
  213. // MISC //
  214. //------//
  215. // Choose how the alpha channel is used when mixing half-transparent color with what is already
  216. // drawn. The default is the .Alpha mode, but you also have the option of using .Premultiply_Alpha.
  217. set_blend_mode :: proc(mode: Blend_Mode)
  218. set_scissor_rect :: proc(scissor_rect: Maybe(Rect))
  219. // Restore the internal state using the pointer returned by `init`. Useful after reloading the
  220. // library (for example, when doing code hot reload).
  221. set_internal_state :: proc(state: ^State)
  222. //---------------------//
  223. // TYPES AND CONSTANTS //
  224. //---------------------//
  225. Vec2 :: [2]f32
  226. Vec3 :: [3]f32
  227. Vec4 :: [4]f32
  228. Mat4 :: matrix[4,4]f32
  229. // A two dimensional vector of integer numeric type.
  230. Vec2i :: [2]int
  231. // A rectangle that sits at position (x, y) and has size (w, h).
  232. Rect :: struct {
  233. x, y: f32,
  234. w, h: f32,
  235. }
  236. // An RGBA (Red, Green, Blue, Alpha) color. Each channel can have a value between 0 and 255.
  237. Color :: [4]u8
  238. WHITE :: Color { 255, 255, 255, 255 }
  239. BLACK :: Color { 0, 0, 0, 255 }
  240. GRAY :: Color { 127, 127, 127, 255 }
  241. RED :: Color { 198, 40, 90, 255 }
  242. GREEN :: Color { 30, 240, 30, 255 }
  243. BLANK :: Color { 0, 0, 0, 0 }
  244. BLUE :: Color { 30, 116, 240, 255 }
  245. // These are from Raylib. They are here so you can easily port a Raylib program to Karl2D.
  246. RL_LIGHTGRAY :: Color { 200, 200, 200, 255 }
  247. RL_GRAY :: Color { 130, 130, 130, 255 }
  248. RL_DARKGRAY :: Color { 80, 80, 80, 255 }
  249. RL_YELLOW :: Color { 253, 249, 0, 255 }
  250. RL_GOLD :: Color { 255, 203, 0, 255 }
  251. RL_ORANGE :: Color { 255, 161, 0, 255 }
  252. RL_PINK :: Color { 255, 109, 194, 255 }
  253. RL_RED :: Color { 230, 41, 55, 255 }
  254. RL_MAROON :: Color { 190, 33, 55, 255 }
  255. RL_GREEN :: Color { 0, 228, 48, 255 }
  256. RL_LIME :: Color { 0, 158, 47, 255 }
  257. RL_DARKGREEN :: Color { 0, 117, 44, 255 }
  258. RL_SKYBLUE :: Color { 102, 191, 255, 255 }
  259. RL_BLUE :: Color { 0, 121, 241, 255 }
  260. RL_DARKBLUE :: Color { 0, 82, 172, 255 }
  261. RL_PURPLE :: Color { 200, 122, 255, 255 }
  262. RL_VIOLET :: Color { 135, 60, 190, 255 }
  263. RL_DARKPURPLE :: Color { 112, 31, 126, 255 }
  264. RL_BEIGE :: Color { 211, 176, 131, 255 }
  265. RL_BROWN :: Color { 127, 106, 79, 255 }
  266. RL_DARKBROWN :: Color { 76, 63, 47, 255 }
  267. RL_WHITE :: WHITE
  268. RL_BLACK :: BLACK
  269. RL_BLANK :: BLANK
  270. RL_MAGENTA :: Color { 255, 0, 255, 255 }
  271. RL_RAYWHITE :: Color { 245, 245, 245, 255 }
  272. Texture :: struct {
  273. handle: Texture_Handle,
  274. width: int,
  275. height: int,
  276. }
  277. Load_Texture_Option :: enum {
  278. Premultiply_Alpha,
  279. }
  280. Load_Texture_Options :: bit_set[Load_Texture_Option]
  281. Blend_Mode :: enum {
  282. Alpha,
  283. Premultiplied_Alpha, // Requires the alpha-channel to be multiplied into texture RGB channels.
  284. }
  285. Render_Texture :: struct {
  286. texture: Texture,
  287. render_target: Render_Target_Handle,
  288. }
  289. Texture_Filter :: enum {
  290. Point, // Similar to "nearest neighbor". Pixly texture scaling.
  291. Linear, // Smoothed texture scaling.
  292. }
  293. Camera :: struct {
  294. target: Vec2,
  295. offset: Vec2,
  296. rotation: f32,
  297. zoom: f32,
  298. }
  299. Window_Flag :: enum {
  300. Resizable,
  301. }
  302. Window_Flags :: bit_set[Window_Flag]
  303. Shader_Handle :: distinct Handle
  304. SHADER_NONE :: Shader_Handle {}
  305. Shader_Constant_Location :: struct {
  306. offset: int,
  307. size: int,
  308. }
  309. Shader :: struct {
  310. handle: Shader_Handle,
  311. // We store the CPU-side value of all constants in a single buffer to have less allocations.
  312. // The 'constants' array says where in this buffer each constant is, and 'constant_lookup'
  313. // maps a name to a constant location.
  314. constants_data: []u8,
  315. constants: []Shader_Constant_Location,
  316. constant_lookup: map[string]Shader_Constant_Location,
  317. // Maps built in constant types such as "model view projection matrix" to a location.
  318. constant_builtin_locations: [Shader_Builtin_Constant]Maybe(Shader_Constant_Location),
  319. texture_bindpoints: []Texture_Handle,
  320. texture_lookup: map[string]int,
  321. default_texture_index: Maybe(int),
  322. inputs: []Shader_Input,
  323. input_overrides: []Shader_Input_Value_Override,
  324. default_input_offsets: [Shader_Default_Inputs]int,
  325. vertex_size: int,
  326. }
  327. SHADER_INPUT_VALUE_MAX_SIZE :: 256
  328. Shader_Input_Value_Override :: struct {
  329. val: [SHADER_INPUT_VALUE_MAX_SIZE]u8,
  330. used: int,
  331. }
  332. Shader_Input_Type :: enum {
  333. F32,
  334. Vec2,
  335. Vec3,
  336. Vec4,
  337. }
  338. Shader_Builtin_Constant :: enum {
  339. MVP,
  340. }
  341. Shader_Default_Inputs :: enum {
  342. Unknown,
  343. Position,
  344. UV,
  345. Color,
  346. }
  347. Shader_Input :: struct {
  348. name: string,
  349. register: int,
  350. type: Shader_Input_Type,
  351. format: Pixel_Format,
  352. }
  353. Pixel_Format :: enum {
  354. Unknown,
  355. RGBA_32_Float,
  356. RGB_32_Float,
  357. RG_32_Float,
  358. R_32_Float,
  359. RGBA_8_Norm,
  360. RG_8_Norm,
  361. R_8_Norm,
  362. R_8_UInt,
  363. }
  364. Font :: struct {
  365. atlas: Texture,
  366. // internal
  367. fontstash_handle: int,
  368. }
  369. Handle :: hm.Handle
  370. Texture_Handle :: distinct Handle
  371. Render_Target_Handle :: distinct Handle
  372. Font_Handle :: distinct int
  373. FONT_NONE :: Font_Handle {}
  374. TEXTURE_NONE :: Texture_Handle {}
  375. RENDER_TARGET_NONE :: Render_Target_Handle {}
  376. // This keeps track of the internal state of the library. Usually, you do not need to poke at it.
  377. // It is created and kept as a global variable when 'init' is called. However, 'init' also returns
  378. // the pointer to it, so you can later use 'set_internal_state' to restore it (after for example hot
  379. // reload).
  380. State :: struct {
  381. allocator: runtime.Allocator,
  382. frame_arena: runtime.Arena,
  383. frame_allocator: runtime.Allocator,
  384. win: Window_Interface,
  385. window_state: rawptr,
  386. rb: Render_Backend_Interface,
  387. rb_state: rawptr,
  388. fs: fs.FontContext,
  389. shutdown_wanted: bool,
  390. mouse_position: Vec2,
  391. mouse_delta: Vec2,
  392. mouse_wheel_delta: f32,
  393. key_went_down: #sparse [Keyboard_Key]bool,
  394. key_went_up: #sparse [Keyboard_Key]bool,
  395. key_is_held: #sparse [Keyboard_Key]bool,
  396. mouse_button_went_down: #sparse [Mouse_Button]bool,
  397. mouse_button_went_up: #sparse [Mouse_Button]bool,
  398. mouse_button_is_held: #sparse [Mouse_Button]bool,
  399. gamepad_button_went_down: [MAX_GAMEPADS]#sparse [Gamepad_Button]bool,
  400. gamepad_button_went_up: [MAX_GAMEPADS]#sparse [Gamepad_Button]bool,
  401. gamepad_button_is_held: [MAX_GAMEPADS]#sparse [Gamepad_Button]bool,
  402. window: Window_Handle,
  403. default_font: Font_Handle,
  404. fonts: [dynamic]Font,
  405. shape_drawing_texture: Texture_Handle,
  406. batch_font: Font_Handle,
  407. batch_camera: Maybe(Camera),
  408. batch_shader: Shader,
  409. batch_scissor: Maybe(Rect),
  410. batch_texture: Texture_Handle,
  411. batch_render_target: Render_Target_Handle,
  412. batch_blend_mode: Blend_Mode,
  413. view_matrix: Mat4,
  414. proj_matrix: Mat4,
  415. depth: f32,
  416. depth_start: f32,
  417. depth_increment: f32,
  418. vertex_buffer_cpu: []u8,
  419. vertex_buffer_cpu_used: int,
  420. default_shader: Shader,
  421. }
  422. // Support for up to 255 mouse buttons. Cast an int to type `Mouse_Button` to use things outside the
  423. // options presented here.
  424. Mouse_Button :: enum {
  425. Left,
  426. Right,
  427. Middle,
  428. Max = 255,
  429. }
  430. // Based on Raylib / GLFW
  431. Keyboard_Key :: enum {
  432. None = 0,
  433. // Numeric keys (top row)
  434. N0 = 48,
  435. N1 = 49,
  436. N2 = 50,
  437. N3 = 51,
  438. N4 = 52,
  439. N5 = 53,
  440. N6 = 54,
  441. N7 = 55,
  442. N8 = 56,
  443. N9 = 57,
  444. // Letter keys
  445. A = 65,
  446. B = 66,
  447. C = 67,
  448. D = 68,
  449. E = 69,
  450. F = 70,
  451. G = 71,
  452. H = 72,
  453. I = 73,
  454. J = 74,
  455. K = 75,
  456. L = 76,
  457. M = 77,
  458. N = 78,
  459. O = 79,
  460. P = 80,
  461. Q = 81,
  462. R = 82,
  463. S = 83,
  464. T = 84,
  465. U = 85,
  466. V = 86,
  467. W = 87,
  468. X = 88,
  469. Y = 89,
  470. Z = 90,
  471. // Special characters
  472. Apostrophe = 39,
  473. Comma = 44,
  474. Minus = 45,
  475. Period = 46,
  476. Slash = 47,
  477. Semicolon = 59,
  478. Equal = 61,
  479. Left_Bracket = 91,
  480. Backslash = 92,
  481. Right_Bracket = 93,
  482. Backtick = 96,
  483. // Function keys, modifiers, caret control etc
  484. Space = 32,
  485. Escape = 256,
  486. Enter = 257,
  487. Tab = 258,
  488. Backspace = 259,
  489. Insert = 260,
  490. Delete = 261,
  491. Right = 262,
  492. Left = 263,
  493. Down = 264,
  494. Up = 265,
  495. Page_Up = 266,
  496. Page_Down = 267,
  497. Home = 268,
  498. End = 269,
  499. Caps_Lock = 280,
  500. Scroll_Lock = 281,
  501. Num_Lock = 282,
  502. Print_Screen = 283,
  503. Pause = 284,
  504. F1 = 290,
  505. F2 = 291,
  506. F3 = 292,
  507. F4 = 293,
  508. F5 = 294,
  509. F6 = 295,
  510. F7 = 296,
  511. F8 = 297,
  512. F9 = 298,
  513. F10 = 299,
  514. F11 = 300,
  515. F12 = 301,
  516. Left_Shift = 340,
  517. Left_Control = 341,
  518. Left_Alt = 342,
  519. Left_Super = 343,
  520. Right_Shift = 344,
  521. Right_Control = 345,
  522. Right_Alt = 346,
  523. Right_Super = 347,
  524. Menu = 348,
  525. // Numpad keys
  526. NP_0 = 320,
  527. NP_1 = 321,
  528. NP_2 = 322,
  529. NP_3 = 323,
  530. NP_4 = 324,
  531. NP_5 = 325,
  532. NP_6 = 326,
  533. NP_7 = 327,
  534. NP_8 = 328,
  535. NP_9 = 329,
  536. NP_Decimal = 330,
  537. NP_Divide = 331,
  538. NP_Multiply = 332,
  539. NP_Subtract = 333,
  540. NP_Add = 334,
  541. NP_Enter = 335,
  542. NP_Equal = 336,
  543. }
  544. MAX_GAMEPADS :: 4
  545. // A value between 0 and MAX_GAMEPADS - 1
  546. Gamepad_Index :: int
  547. Gamepad_Axis :: enum {
  548. Left_Stick_X,
  549. Left_Stick_Y,
  550. Right_Stick_X,
  551. Right_Stick_Y,
  552. Left_Trigger,
  553. Right_Trigger,
  554. }
  555. Gamepad_Button :: enum {
  556. // DPAD buttons
  557. Left_Face_Up,
  558. Left_Face_Down,
  559. Left_Face_Left,
  560. Left_Face_Right,
  561. Right_Face_Up, // XBOX: Y, PS: Triangle
  562. Right_Face_Down, // XBOX: A, PS: X
  563. Right_Face_Left, // XBOX: X, PS: Square
  564. Right_Face_Right, // XBOX: B, PS: Circle
  565. Left_Shoulder,
  566. Left_Trigger,
  567. Right_Shoulder,
  568. Right_Trigger,
  569. Left_Stick_Press, // Clicking the left analogue stick
  570. Right_Stick_Press, // Clicking the right analogue stick
  571. Middle_Face_Left, // Select / back / options button
  572. Middle_Face_Middle, // PS button (not available on XBox)
  573. Middle_Face_Right, // Start
  574. }