├── .gitignore ├── AUTHORS.txt ├── INSTALL.txt ├── LICENSE.txt ├── README.md ├── examples ├── Makefile ├── README.txt ├── assets │ └── circle64.bmp ├── ex_audio_drivers.ml ├── ex_cpu_count.ml ├── ex_draw_render.ml ├── ex_empty_win.ml ├── ex_event.ml ├── ex_fill_rand_col.ml ├── ex_gl.ml ├── ex_glattr.ml ├── ex_mouse_pos.ml ├── ex_mv_sprite_rend.ml ├── ex_mv_sprite_surf.ml ├── ex_pixel.ml ├── ex_platform.ml ├── ex_power.ml ├── ex_render_points.ml ├── ex_simple_wav.ml ├── ex_sprite.ml ├── ex_surf.ml ├── ex_text_input.ml └── ex_version.ml ├── opam ├── src ├── META ├── Makefile ├── Makefile.config.unix ├── Makefile.config.win32 ├── PausableTimer.ml ├── PausableTimer.mli ├── dep2dot.ml ├── dir_sep.ml ├── poly_var.ml ├── poly_var_stubs.c ├── prm.ml ├── sdl.ml ├── sdl_header ├── sdl_keycode.var.list ├── sdl_platform_stub.c ├── sdl_scancode.var.list ├── sdlaudio.ml ├── sdlaudio.mli ├── sdlaudio_stub.c ├── sdlaudio_stub.h ├── sdlba.ml ├── sdlblendMode.ml ├── sdlblendMode.mli ├── sdlblendMode_stub.c ├── sdlblendMode_stub.h ├── sdlclipboard.ml ├── sdlclipboard.mli ├── sdlclipboard_stub.c ├── sdlcpuinfo.ml ├── sdlcpuinfo.mli ├── sdlcpuinfo_stub.c ├── sdlerror.ml ├── sdlerror.mli ├── sdlerror_stub.c ├── sdlevent.ml ├── sdlevent.mli ├── sdlevent_stub.c ├── sdlfilesystem.ml ├── sdlfilesystem.mli ├── sdlfilesystem_stub.c ├── sdlgl.ml ├── sdlgl.mli ├── sdlgl_stub.c ├── sdlhat.ml ├── sdlhat.mli ├── sdlhint.ml ├── sdlhint.mli ├── sdlhint_stub.c ├── sdlinit.ml ├── sdlinit.mli ├── sdlinit_stub.c ├── sdljoystick.ml ├── sdljoystick.mli ├── sdljoystick_stub.c ├── sdlkeyboard.ml ├── sdlkeyboard.mli ├── sdlkeyboard_stub.c ├── sdlkeycode.ml ├── sdlkeycode.mli ├── sdlkeymod.ml ├── sdlkeymod.mli ├── sdlkeymod_stub.c ├── sdlkeymod_stub.h ├── sdlmouse.ml ├── sdlmouse.mli ├── sdlmouse_stub.c ├── sdlpixel.ml ├── sdlpixel.mli ├── sdlpixelFormat.ml ├── sdlpixelFormat.mli ├── sdlpixelFormat_stub.c ├── sdlpixelFormat_stub.h ├── sdlpixel_stub.c ├── sdlpixel_stub.h ├── sdlpoint_stub.h ├── sdlpower.ml ├── sdlpower.mli ├── sdlpower_stub.c ├── sdlquit.ml ├── sdlquit.mli ├── sdlquit_stub.c ├── sdlrect.ml ├── sdlrect.mli ├── sdlrect_stub.c ├── sdlrect_stub.h ├── sdlrender.ml ├── sdlrender.mli ├── sdlrender_stub.c ├── sdlrender_stub.h ├── sdlrwops.ml ├── sdlrwops.mli ├── sdlrwops_stub.c ├── sdlrwops_stub.h ├── sdlscancode.ml ├── sdlscancode.mli ├── sdlsurface.ml ├── sdlsurface.mli ├── sdlsurface_ba.ml ├── sdlsurface_ba.mli ├── sdlsurface_ba_stub.c ├── sdlsurface_stub.c ├── sdlsurface_stub.h ├── sdltexture.ml ├── sdltexture.mli ├── sdltextureAccess.ml ├── sdltextureAccess.mli ├── sdltexture_ba.ml ├── sdltexture_ba.mli ├── sdltexture_ba_stub.c ├── sdltexture_stub.c ├── sdltexture_stub.h ├── sdltimer.ml ├── sdltimer.mli ├── sdltimer_stub.c ├── sdltype.ml ├── sdltype.mli ├── sdlversion.ml ├── sdlversion.mli ├── sdlversion_stub.c ├── sdlwindow.ml ├── sdlwindow.mli ├── sdlwindow_stub.c ├── sdlwindow_stub.h ├── style1.dot └── variant.ml └── tests ├── test_rect.ml └── test_surf_ba.ml /.gitignore: -------------------------------------------------------------------------------- 1 | *.[oa] 2 | *.cm[ioxa] 3 | *.cmx[as] 4 | *.byte 5 | *.opt 6 | *.native 7 | *.bin 8 | *.exe 9 | *.so 10 | *.dll 11 | a.out 12 | .*.swp 13 | _* 14 | *~ 15 | src/Makefile.config 16 | src/*_depend.mk 17 | src/sdl.mli 18 | src/sdlba.mli 19 | src/*.gen.c 20 | src/doc/*.html 21 | src/doc/*.css 22 | -------------------------------------------------------------------------------- /AUTHORS.txt: -------------------------------------------------------------------------------- 1 | Florent Monnier 2 | Main original author and maintainer 3 | 4 | David Cade 5 | Provided events handling of SDL_TextInputEvent and SDL_TextEditingEvent 6 | 7 | Piotr Mardziel <@piotrm0> 8 | Provided Sdlsurface_ba.get_pixels 9 | 10 | Alexandru Scvortov 11 | wrapped SDL_GetWindowSize() as Sdlwindow.get_size 12 | wrapped SDL_RWclose() as RWops.close 13 | 14 | Guillaume Munch-Maccagnoni 15 | Naked pointers checks and fixes 16 | 17 | Carsten Elton Sørensen 18 | Add SDL_SetRenderTarget binding 19 | Implement "hints" API 20 | Implement texture locking and creation with access type 21 | Add events subsystem 22 | Add support for HiDPI 23 | Add Sdlrender.get_output_size 24 | Use new OCaml macros when available 25 | 26 | -------------------------------------------------------------------------------- /INSTALL.txt: -------------------------------------------------------------------------------- 1 | === Linux, Cygwin, and OSX === 2 | 3 | Under an Unix-like system, go in the directory src/ 4 | and create a file named "Makefile.config" based on 5 | "Makefile.config.win32" or "Makefile.config.unix". 6 | 7 | Then you can run: 8 | $ make gen 9 | $ make dep 10 | $ make opt byte 11 | 12 | ---------------- 13 | 14 | If you want to use the module 'Sdlsurface_ba' which uses ocaml bigarrays 15 | you also have to run these targets: 16 | $ make ba 17 | $ make baopt 18 | 19 | ---------------- 20 | 21 | If you compiled and installed SDL2 with 22 | ./configure --prefix=/tmp/SDL2-temp 23 | then you need to make sure that the utility "sdl2-config" 24 | can be found in the path: 25 | 26 | $ export PATH="$PATH:/tmp/SDL2-temp/bin" 27 | 28 | ---------------- 29 | 30 | After the compilation, complete the installation with: 31 | $ make install 32 | 33 | By default the installation will be done in the directory: 34 | DESTDIR="`ocamlc -where`/sdl2" 35 | you can install in another directory with: 36 | $ make install DESTDIR="/tmp/mysdl2" 37 | 38 | ---------------- 39 | 40 | If you wish to install the accompanying libraries then 41 | you should install the C headers of the stubs with: 42 | $ make install_h 43 | or 44 | $ make findinstall_h 45 | 46 | ---------------- 47 | 48 | Install using ocamlfind: 49 | $ make findinstall 50 | 51 | ---------------- 52 | 53 | To uninstall: 54 | $ make uninstall 55 | or 56 | $ make finduninstall 57 | 58 | === Documentation === 59 | 60 | The API documentation can be generated with: 61 | $ make doc 62 | 63 | === Other Environments === 64 | 65 | Please tell me how to do in other environments. 66 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (C) 2013 2014 2019 Florent Monnier 2 | 3 | This software is provided "AS-IS", without any express or implied warranty. 4 | In no event will the authors be held liable for any damages arising from 5 | the use of this software. 6 | 7 | Permission is granted to anyone to use this software without restrictions 8 | for any purpose, including commercial applications, and to alter it and 9 | redistribute it freely. 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OCaml and SDL 2.0 2 | 3 | ![OCaml and SDL]( 4 | http://openclipart.org/image/250px/svg_to_png/174316/games.png) 5 | 6 | ## Introduction 7 | 8 | OCamlSDL2 is an OCaml interface to the SDL2 library. 9 | 10 | If you are searching for OCaml bindings for SDL 1.2 11 | then you should go there instead: 12 | [ocamlsdl.sf.net]( 13 | http://ocamlsdl.sourceforge.net/) 14 | 15 | 16 | ## Versions 17 | 18 | This version of the bindings is known to work with 19 | SDL 2.0.9 or 2.0.10 and OCaml 4.07.1 until 4.13.1 20 | 21 | 22 | ## Compile and Install 23 | 24 | Read the file "INSTALL.txt" for instructions about how 25 | to compile and install. 26 | 27 | 28 | ## Opam 29 | 30 | You can install ocamlsdl2 with opam. 31 | 32 | If you installed SDL2 version 2.0.9 or later you can install the last version: 33 | ``` 34 | $ opam install ocamlsdl2 35 | ``` 36 | But if you still use an older version of SDL2 like for example SDL2 version 37 | 2.0.6 then you should install a previous version of the bindings: 38 | ``` 39 | $ opam install ocamlsdl2.0.02 40 | ``` 41 | To know which version of the SDL2 is on your system, you can use the command: 42 | ``` 43 | $ sdl2-config --version 44 | ``` 45 | To install the source directory (tarball release or git clone): 46 | ``` 47 | $ opam install . 48 | ``` 49 | 50 | 51 | ## API Documentation 52 | 53 | The API documentation can be browsed online: 54 | 55 | https://fccm.github.io/OCamlSDL2/ 56 | 57 | 58 | ## Accompanying libraries 59 | 60 | There are also bindings for the accompanying libraries: 61 | (unlike the main ocamlsdl2 these are not tested on Windows yet) 62 | 63 | - https://github.com/fccm/OCamlSDL2_TTF 64 | - https://github.com/fccm/OCamlSDL2_Image 65 | - https://github.com/fccm/OCamlSDL2_Mixer 66 | - https://github.com/fccm/OCamlSDL2_Net 67 | - https://github.com/fccm/OCamlSDL2_Gfx 68 | 69 | 70 | ## Dune 71 | 72 | If you use Dune to build your project, you can use this instruction 73 | to your dune file: 74 | ``` 75 | (libraries sdl2) 76 | ``` 77 | 78 | ## License 79 | 80 | This software is provided "AS-IS", without any express 81 | or implied warranty. 82 | In no event will the authors be held liable for any 83 | damages arising from the use of this software. 84 | 85 | Permission is granted to anyone to use this software 86 | for any purpose, including commercial applications, 87 | and to alter it and redistribute it freely. 88 | 89 | -------------------------------------------------------------------------------- /examples/Makefile: -------------------------------------------------------------------------------- 1 | # OCamlSDL2 - An OCaml interface to the SDL2 library 2 | # Copyright (C) 2013 Florent Monnier 3 | # 4 | # This software is provided "AS-IS", without any express or implied warranty. 5 | # In no event will the authors be held liable for any damages arising from 6 | # the use of this software. 7 | # 8 | # Permission is granted to anyone to use this software for any purpose, 9 | # including commercial applications, and to alter it and redistribute it freely. 10 | 11 | OCAML := ocaml 12 | OCAMLC := ocamlc -g 13 | OCAMLOPT := ocamlopt -g 14 | #INC_DIR := +sdl2 15 | INC_DIR := ../src 16 | FILE := 17 | OUT_BIN := "$(shell basename $(FILE) .ml).exe" 18 | 19 | all: 20 | 21 | test: 22 | $(OCAMLOPT) -I $(INC_DIR) sdl2.cmxa \ 23 | $(FILE) -o $(OUT_BIN) 24 | 25 | clean: 26 | $(RM) *.[oas] *.cm[ioax] *.cmx[as] *.so *.dll *.opt *.exe 27 | 28 | .PHONY: all clean test 29 | -------------------------------------------------------------------------------- /examples/README.txt: -------------------------------------------------------------------------------- 1 | - ex_empty_win.ml : opens an empty window, waits 2 seconds and closes it. 2 | - ex_mv_sprite_surf.ml : displays a simple sprite moving in the window, 3 | using the "Surface" module. 4 | - ex_mv_sprite_rend.ml : does the same than "ex_mv_sprite_surf.ml" but 5 | using the new "Render" API. 6 | - ex_cpu_count.ml : prints in the terminal the number of CPU. 7 | - ex_event.ml : opens a window and prints events in the terminal 8 | every events that occure in this window. 9 | - ex_platform.ml : prints the platform in the terminal (Windows, Linux, etc.) 10 | - ex_power.ml : prints the power state in the terminal. 11 | - ex_version.ml : prints the SDL version in the terminal. 12 | - ex_fill_rand_col.ml : opens a window and fills it with a random color until 13 | some key is pressed. 14 | - ex_surf.ml : opens a window and draws rectangles in it using the "Surface" 15 | module. 16 | - ex_draw_render.ml : opens a window and draws primitives in it using the new 17 | "Render" API. 18 | - ex_audio_drivers.ml : displays the available audio drivers. 19 | - ex_pixel.ml : converts RGB values into a given pixel format. 20 | - ex_glattr.ml : tests GL-attributes 21 | - ex_mouse_pos.ml : demonstrates how to get the mouse state. 22 | - ex_gl.ml : shows how to use SDL2 for OpenGL windowing. 23 | - ex_render_points.ml : draws points using the "Render" API. 24 | - ex_simple_wav.ml : load and play a .wav file. 25 | - ex_sprite.ml : demonstrate how to set a transparent background for a sprite. 26 | - ex_text_input.ml : text input example 27 | -------------------------------------------------------------------------------- /examples/assets/circle64.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fccm/OCamlSDL2/f5ebc786113315d0785084e333e30797dee3fd2a/examples/assets/circle64.bmp -------------------------------------------------------------------------------- /examples/ex_audio_drivers.ml: -------------------------------------------------------------------------------- 1 | open Sdl 2 | 3 | let () = 4 | let drivers = Audio.get_drivers () in 5 | Array.iteri (fun i driver -> 6 | Printf.printf "driver[%d]: %S\n" i driver; 7 | ) drivers; 8 | Audio.init ~driver_name:drivers.(0); 9 | Printf.printf "current_driver: %S\n" 10 | (Audio.get_current_driver ()); 11 | Audio.quit () 12 | -------------------------------------------------------------------------------- /examples/ex_cpu_count.ml: -------------------------------------------------------------------------------- 1 | open Sdl 2 | 3 | let () = 4 | let n = CPUInfo.get_CPU_count () in 5 | Printf.printf "CPU count: %d\n" n 6 | -------------------------------------------------------------------------------- /examples/ex_draw_render.ml: -------------------------------------------------------------------------------- 1 | let () = 2 | let width, height = (640, 480) in 3 | Random.self_init (); 4 | Sdl.init [`VIDEO]; 5 | let window, renderer = 6 | Sdlrender.create_window_and_renderer ~width ~height ~flags:[] 7 | in 8 | for i = 1 to 32 do 9 | let r, g, b = 10 | (Random.int 256, 11 | Random.int 256, 12 | Random.int 256) 13 | in 14 | let alpha = 255 in 15 | Sdlrender.set_draw_color3 renderer r g b alpha; 16 | for i = 1 to 640 * 480 / 32 do 17 | let x = Random.int 640 18 | and y = Random.int 480 in 19 | Sdlrender.draw_point2 renderer ~x ~y; 20 | done; 21 | Sdlrender.render_present renderer; 22 | Sdltimer.delay 40; 23 | done; 24 | Sdlwindow.hide window; 25 | Sdltimer.delay 1000; 26 | Sdlwindow.show window; 27 | Sdlrender.render_present renderer; 28 | Sdltimer.delay 2000; 29 | Sdl.quit () 30 | -------------------------------------------------------------------------------- /examples/ex_empty_win.ml: -------------------------------------------------------------------------------- 1 | let () = 2 | Sdl.init [`VIDEO]; 3 | let width, height = (320, 240) in 4 | let _ = 5 | Sdlwindow.create2 6 | ~title:"Let's try SDL2 with OCaml!" 7 | ~x:`undefined ~y:`undefined ~width ~height 8 | ~flags:[] 9 | in 10 | Sdltimer.delay 2000; 11 | Sdl.quit () 12 | -------------------------------------------------------------------------------- /examples/ex_fill_rand_col.ml: -------------------------------------------------------------------------------- 1 | let () = 2 | let width, height = (640, 480) in 3 | let title = "Let's try SDL2 with OCaml!" in 4 | let window = 5 | Sdlwindow.create2 ~title 6 | ~x:`undefined ~y:`undefined ~width ~height 7 | ~flags:[Sdlwindow.Resizable] 8 | in 9 | let surf = Sdlwindow.get_surface window in 10 | let color = 0x00BB00_l in 11 | let rect = Sdlrect.make4 0 0 width height in 12 | Sdlsurface.fill_rect surf rect color; 13 | Sdlwindow.update_surface window; 14 | let rec aux () = 15 | match Sdlevent.poll_event () with 16 | | Some Sdlevent.Quit _ | Some Sdlevent.KeyDown _ -> () 17 | | _ -> 18 | Sdltimer.delay 160; 19 | Sdlsurface.fill_rect surf rect 20 | (Int32.of_int (Random.int (0xFFFFFF + 1))); 21 | Sdlwindow.update_surface window; 22 | aux () 23 | in 24 | aux () 25 | -------------------------------------------------------------------------------- /examples/ex_gl.ml: -------------------------------------------------------------------------------- 1 | open Sdl 2 | open Sdlwindow 3 | 4 | let display () = 5 | GlClear.color (0.6, 0.2, 0.0); 6 | GlClear.clear [`color]; 7 | GlDraw.color (1.0, 0.8, 0.0); 8 | GlMat.mode `projection; 9 | GlMat.load_identity (); 10 | GlMat.ortho ~x:(-1.0,1.0) ~y:(-1.0,1.0) ~z:(-1.0,1.0); 11 | GlDraw.begins `polygon; 12 | GlDraw.vertex ~x:(-0.5) ~y:(-0.5) (); 13 | GlDraw.vertex ~x:(-0.5) ~y:( 0.5) (); 14 | GlDraw.vertex ~x:( 0.5) ~y:( 0.5) (); 15 | GlDraw.vertex ~x:( 0.5) ~y:(-0.5) (); 16 | GlDraw.ends (); 17 | Gl.flush () 18 | 19 | let () = 20 | Sdl.init [`VIDEO]; 21 | let width, height = (640, 480) in 22 | let win = 23 | Sdlwindow.create2 24 | ~title:"SDL2, OGL?" 25 | ~x:(`pos 10) 26 | ~y:(`pos 40) 27 | ~width ~height 28 | ~flags:[OpenGL; Resizable] 29 | in 30 | let rndr = 31 | let index = 0 in 32 | let flags = [Render.Accelerated] in 33 | Sdlrender.create_renderer ~win ~index ~flags 34 | in 35 | ignore(rndr); 36 | 37 | (* 38 | Sdlgl.extension_supported ~extension:string -> bool 39 | *) 40 | let ctx = Sdlgl.create_context ~win in 41 | let x = Sdlgl.make_current ~win ~ctx in 42 | let sw = Sdlgl.get_swap_interval () in 43 | Printf.printf "cur: %d\n%!" x; 44 | Printf.printf "swap: %d\n%!" sw; 45 | 46 | let driver_infos = Sdlrender.get_render_drivers () in 47 | Array.iter (fun driver_info -> 48 | Printf.printf " \ 49 | render-name: '%s'\n \ 50 | max_texture_width: %d\n \ 51 | max_texture_height: %d\n\n%!" 52 | driver_info.Render.name 53 | driver_info.Render.max_texture_width 54 | driver_info.Render.max_texture_height 55 | ) driver_infos; 56 | 57 | (* 58 | Printf.printf " \ 59 | vendor: %s\n \ 60 | renderer: %s\n \ 61 | version: %s\n\n%!" 62 | (Sdlogl.get_vendor_string ()) 63 | (Sdlogl.get_renderer_string ()) 64 | (Sdlogl.get_version_string ()); 65 | *) 66 | 67 | for i = 1 to 4 do 68 | display (); 69 | Sdlgl.swap_window win; 70 | Printf.printf ".%!"; 71 | Sdltimer.delay 600; 72 | done; 73 | Printf.printf "\n%!"; 74 | Sdlgl.delete_context ctx; 75 | Sdl.quit () 76 | -------------------------------------------------------------------------------- /examples/ex_glattr.ml: -------------------------------------------------------------------------------- 1 | open Sdl 2 | open Sdlgl 3 | 4 | let main () = 5 | Sdlinit.init [`VIDEO]; 6 | 7 | Sdlgl.set_attribute GL_RED_SIZE 5; 8 | Sdlgl.set_attribute GL_GREEN_SIZE 6; 9 | Sdlgl.set_attribute GL_BLUE_SIZE 5; 10 | Sdlgl.set_attribute GL_DEPTH_SIZE 16; 11 | Sdlgl.set_attribute GL_DOUBLEBUFFER 1; 12 | 13 | let window = 14 | Sdlwindow.create2 15 | ~title:"OpenGL Window" 16 | ~x:(`pos 10) 17 | ~y:(`pos 10) 18 | ~width:640 19 | ~height:480 20 | ~flags:[Sdlwindow.OpenGL] 21 | in 22 | 23 | let context = Sdlgl.create_context window in 24 | ignore(context); 25 | 26 | Printf.printf 27 | "Red size: %d, Green size: %d, Blue size: %d\n%!" 28 | (Sdlgl.get_attribute GL_RED_SIZE) 29 | (Sdlgl.get_attribute GL_GREEN_SIZE) 30 | (Sdlgl.get_attribute GL_BLUE_SIZE); 31 | 32 | Sdltimer.delay 2000; 33 | Sdl.quit () 34 | ;; 35 | 36 | let () = 37 | try main () 38 | with e -> 39 | prerr_endline (Sdlerror.get_error ()); 40 | raise e 41 | 42 | -------------------------------------------------------------------------------- /examples/ex_mouse_pos.ml: -------------------------------------------------------------------------------- 1 | let () = 2 | Random.self_init (); 3 | let width, height = (640, 480) in 4 | let rgb = 5 | (100 + Random.int 156, 6 | 100 + Random.int 156, 7 | 100 + Random.int 156) 8 | in 9 | let alpha = 255 in 10 | Sdl.init [`VIDEO]; 11 | let window, renderer = 12 | Sdlrender.create_window_and_renderer ~width ~height ~flags:[] 13 | in 14 | Sdlrender.set_draw_color renderer (0,0,0) alpha; 15 | Sdlrender.clear renderer; 16 | Sdlrender.set_draw_color renderer rgb alpha; 17 | let rec aux () = 18 | let xy, buttons = Sdlmouse.get_state () in 19 | Sdlrender.draw_point renderer xy; 20 | Sdlrender.render_present renderer; 21 | Printf.printf ".%!"; 22 | List.iter print_endline ( 23 | List.map Sdlmouse.to_string buttons); 24 | Sdltimer.delay 10; 25 | match Sdlevent.poll_event () with 26 | | Some Sdlevent.Quit _ -> Sdl.quit () 27 | | _ -> aux () 28 | in 29 | aux () 30 | -------------------------------------------------------------------------------- /examples/ex_mv_sprite_rend.ml: -------------------------------------------------------------------------------- 1 | open Sdlevent 2 | open Sdl 3 | 4 | let proc_events = function 5 | | KeyDown { keycode = Keycode.Q } 6 | | KeyDown { keycode = Keycode.Escape } 7 | | KeyDown { scancode = Scancode.ESCAPE } 8 | | Quit _ -> 9 | Sdl.quit (); 10 | exit 0 11 | | e -> () 12 | 13 | 14 | let load_sprite renderer ~filename = 15 | let surf = Surface.load_bmp ~filename in 16 | let tex = Texture.create_from_surface renderer surf in 17 | Surface.free surf; 18 | (tex) 19 | 20 | let () = 21 | let width, height = (640, 480) in 22 | Sdl.init [`VIDEO; `JOYSTICK]; 23 | at_exit print_newline; 24 | let window = 25 | Window.create 26 | ~pos:(`centered, `centered) 27 | ~dims:(width, height) 28 | ~title:"SDL2 Sprite Render" 29 | ~flags:[Window.Resizable] 30 | in 31 | let rndr = 32 | Render.create_renderer window (-1) [Render.Accelerated] 33 | in 34 | 35 | let filename = "assets/circle64.bmp" in 36 | let circ = load_sprite rndr ~filename in 37 | 38 | let src_rect = Rect.make4 0 0 64 64 in 39 | let dst_rect = Rect.make4 100 100 64 64 in 40 | 41 | let render t dt = 42 | let x = (t / 10) mod width in 43 | let dst_rect = { dst_rect with Rect.x } in 44 | Render.clear rndr; 45 | Render.set_scale rndr (1.0, 1.0); 46 | Render.copy rndr 47 | ~texture:circ 48 | ~src_rect 49 | ~dst_rect (); 50 | Render.render_present rndr; 51 | in 52 | 53 | let joy_num = Joystick.num_joysticks () in 54 | for i = 0 to pred joy_num do 55 | ignore(Joystick.j_open i) 56 | done; 57 | 58 | let rec event_loop () = 59 | match Event.poll_event () with 60 | | None -> () 61 | | Some ev -> 62 | proc_events ev; 63 | event_loop () 64 | in 65 | let rec main_loop last_t = 66 | event_loop (); 67 | let t = Timer.get_ticks () in 68 | let dt = t - last_t in 69 | render t dt; 70 | (* 71 | Timer.delay (max 0 (10 - dt)); 72 | *) 73 | main_loop t 74 | in 75 | main_loop (Timer.get_ticks ()) 76 | 77 | -------------------------------------------------------------------------------- /examples/ex_mv_sprite_surf.ml: -------------------------------------------------------------------------------- 1 | open Sdlevent 2 | open Sdl 3 | 4 | let proc_events = function 5 | | KeyDown { keycode = Keycode.Q } 6 | | KeyDown { keycode = Keycode.Escape } 7 | | KeyDown { scancode = Scancode.ESCAPE } 8 | | Quit _ -> 9 | Sdl.quit (); 10 | exit 0 11 | | e -> () 12 | 13 | 14 | let () = 15 | let width, height = (640, 480) in 16 | Sdl.init [`VIDEO; `JOYSTICK]; 17 | at_exit print_newline; 18 | let window = 19 | Window.create 20 | ~pos:(`centered, `centered) 21 | ~dims:(width, height) 22 | ~title:"SDL2 Sprite Surface" 23 | ~flags:[Window.Resizable] 24 | in 25 | let screen = Window.get_surface window in 26 | let filename = "assets/circle64.bmp" in 27 | let surf = Surface.load_bmp ~filename in 28 | 29 | let screen_rect = Rect.make4 0 0 width height in 30 | let src_rect = Rect.make4 0 0 width height in 31 | let dst_rect = Rect.make4 100 100 64 64 in 32 | let render t dt = 33 | Surface.fill_rect 34 | ~dst:screen ~rect:screen_rect 35 | ~color:0x000000l; 36 | let x = (t / 10) mod width in 37 | let dst_rect = { dst_rect with Rect.x } in 38 | let _ = 39 | Surface.blit_surface 40 | ~src:surf ~dst:screen 41 | ~src_rect ~dst_rect 42 | in 43 | Window.update_surface window; 44 | in 45 | 46 | let joy_num = Joystick.num_joysticks () in 47 | for i = 0 to pred joy_num do 48 | ignore(Joystick.j_open i) 49 | done; 50 | 51 | let rec event_loop () = 52 | match Event.poll_event () with 53 | | None -> () 54 | | Some ev -> 55 | proc_events ev; 56 | event_loop () 57 | in 58 | let rec main_loop last_t = 59 | event_loop (); 60 | let t = Timer.get_ticks () in 61 | let dt = t - last_t in 62 | render t dt; 63 | (* 64 | Timer.delay (max 0 (40 - dt)); 65 | *) 66 | main_loop t 67 | in 68 | main_loop (Timer.get_ticks ()) 69 | -------------------------------------------------------------------------------- /examples/ex_pixel.ml: -------------------------------------------------------------------------------- 1 | open Sdl 2 | 3 | let test_rgb () = 4 | let fmt = PixelFormat.RGB888 in 5 | Printf.printf "Using pixel format: %s\n" 6 | (Pixel.get_pixel_format_name fmt); 7 | let pixel_format = Pixel.alloc_format fmt in 8 | let rgb = (255, 128, 0) in 9 | let color = Pixel.map_RGB pixel_format rgb in 10 | Printf.printf "pixel binary data: 0x%06lX\n" color; 11 | let r, g, b = Pixel.get_RGB color pixel_format in 12 | Printf.printf "color RGB values: %d %d %d\n" r g b; 13 | Pixel.free_format pixel_format; 14 | ;; 15 | 16 | let test_rgba () = 17 | let fmt = PixelFormat.RGBA8888 in 18 | Printf.printf "Using pixel format: %s\n" 19 | (Pixel.get_pixel_format_name fmt); 20 | let pixel_format = Pixel.alloc_format fmt in 21 | let rgba = (255, 128, 0, 96) in 22 | let color = Pixel.map_RGBA pixel_format rgba in 23 | Printf.printf "pixel binary data: 0x%08lX\n" color; 24 | let r, g, b, a = Pixel.get_RGBA color pixel_format in 25 | Printf.printf "color RGBA values: %d %d %d %d\n" r g b a; 26 | Pixel.free_format pixel_format; 27 | ;; 28 | 29 | let () = test_rgba () 30 | -------------------------------------------------------------------------------- /examples/ex_platform.ml: -------------------------------------------------------------------------------- 1 | let () = 2 | Printf.printf 3 | "- Platform: %s\n" 4 | (Sdl.get_platform ()) 5 | -------------------------------------------------------------------------------- /examples/ex_power.ml: -------------------------------------------------------------------------------- 1 | open Sdlpower 2 | 3 | let string_power_state = function 4 | | `powerstate_Unknown -> "cannot determine power status" 5 | | `powerstate_On_Battery -> "Not plugged in, running on the battery" 6 | | `powerstate_No_Battery -> "Plugged in, no battery available" 7 | | `powerstate_Charging -> "Plugged in, charging battery" 8 | | `powerstate_Charged -> "Plugged in, battery charged" 9 | 10 | let () = 11 | let state, secs, pct = get_power_info () in 12 | Printf.printf "secs: %d\npct:%d\npower state: %s\n" 13 | secs pct 14 | (string_power_state state) 15 | -------------------------------------------------------------------------------- /examples/ex_render_points.ml: -------------------------------------------------------------------------------- 1 | let () = 2 | Random.self_init (); 3 | Sdl.init [`VIDEO]; 4 | let width, height = (320, 240) in 5 | let window, renderer = 6 | Sdlrender.create_window_and_renderer ~width ~height ~flags:[] 7 | in 8 | Sdlrender.set_draw_color3 renderer 0 0 0 255; 9 | Sdlrender.clear renderer; 10 | 11 | let rec loop () = 12 | let r = Random.int 255 in 13 | let g = Random.int 255 in 14 | let b = Random.int 255 in 15 | Sdlrender.set_draw_color3 renderer r g b 255; 16 | let x = Random.int 320 in 17 | let y = Random.int 240 in 18 | Sdlrender.draw_point2 renderer ~x ~y; 19 | let x = Random.int 320 in 20 | let y = Random.int 240 in 21 | Sdlrender.set_draw_color3 renderer 0 0 0 255; 22 | Sdlrender.draw_point2 renderer ~x ~y; 23 | Sdlrender.render_present renderer; 24 | match Sdlevent.poll_event () with 25 | | Some Sdlevent.Quit _ -> Sdl.quit () 26 | | _ -> loop () 27 | in 28 | loop () 29 | -------------------------------------------------------------------------------- /examples/ex_simple_wav.ml: -------------------------------------------------------------------------------- 1 | (* example from: 2 | http://gigi.nullneuron.net/gigilabs/playing-a-wav-file-using-sdl2/ 3 | *) 4 | open Sdl 5 | 6 | let () = 7 | Sdl.init [`AUDIO]; 8 | 9 | let wav_spec = Audio.new_audio_spec () in 10 | 11 | (* load WAV file *) 12 | let wav_buf, wav_len = 13 | Audio.load_wav "./_tremLoadingloopl.wav" wav_spec in 14 | 15 | (* open audio device *) 16 | let device_id = Audio.open_audio_device_simple wav_spec in 17 | 18 | (* play audio *) 19 | Audio.queue_audio device_id wav_buf wav_len; 20 | Audio.unpause_audio_device device_id; 21 | 22 | (* keep application running long enough to hear the sound *) 23 | Timer.delay 9000; 24 | 25 | (* clean up *) 26 | Audio.close_audio_device device_id; 27 | Audio.free_audio_spec wav_spec; 28 | Audio.free_wav wav_buf; 29 | 30 | Sdl.quit () 31 | -------------------------------------------------------------------------------- /examples/ex_sprite.ml: -------------------------------------------------------------------------------- 1 | open Sdl 2 | 3 | let proc_events = function 4 | | Event.KeyDown { keycode = Keycode.Q; _ } 5 | | Event.KeyDown { keycode = Keycode.Escape; _ } 6 | | Event.Quit _ -> Sdl.quit (); exit 0 7 | | _ -> () 8 | 9 | 10 | let rec event_loop () = 11 | match Event.poll_event () with 12 | | None -> () 13 | | Some ev -> 14 | proc_events ev; 15 | event_loop () 16 | 17 | 18 | let pixel_for_surface ~surface ~rgb = 19 | let fmt = Surface.get_pixelformat_t surface in 20 | let pixel_format = Pixel.alloc_format fmt in 21 | let pixel = Pixel.map_RGB pixel_format rgb in 22 | Pixel.free_format pixel_format; 23 | (pixel) 24 | 25 | 26 | let load_sprite renderer ~filename = 27 | let surface = Surface.load_bmp ~filename in 28 | (* transparent pixel from white background *) 29 | let rgb = (255, 255, 255) in 30 | let key = pixel_for_surface ~surface ~rgb in 31 | Surface.set_color_key surface ~enable:true ~key; 32 | let tex = Texture.create_from_surface renderer surface in 33 | Surface.free surface; 34 | (tex) 35 | 36 | 37 | let () = 38 | let width, height = (320, 240) in 39 | Sdl.init [`VIDEO]; 40 | let window, render = 41 | Render.create_window_and_renderer ~width ~height ~flags:[] 42 | in 43 | (* 44 | wget https://opengameart.org/sites/default/files/shipsheetparts.PNG 45 | convert shipsheetparts.PNG shipsheetparts.bmp 46 | *) 47 | let filename = "/tmp/shipsheetparts.bmp" in 48 | let texture = load_sprite render ~filename in 49 | 50 | let src_rect = Rect.make4 20 14 43 33 in 51 | let dst_rect = Rect.make4 80 80 43 33 in 52 | 53 | let render () = 54 | Render.set_draw_color render (100, 100, 100) 255; 55 | Render.clear render; 56 | Render.copy render ~texture ~src_rect ~dst_rect (); 57 | Render.render_present render; 58 | in 59 | 60 | let rec main_loop () = 61 | event_loop (); 62 | render (); 63 | Timer.delay 80; 64 | main_loop () 65 | in 66 | main_loop () 67 | -------------------------------------------------------------------------------- /examples/ex_surf.ml: -------------------------------------------------------------------------------- 1 | open Sdl 2 | 3 | let color_of_rgb surf ~rgb = 4 | let fmt_kind = Surface.get_pixelformat_t surf in 5 | Printf.printf "# pixel_format kind: %s\n%!" 6 | (Pixel.get_pixel_format_name fmt_kind); 7 | let fmt = Pixel.alloc_format fmt_kind in 8 | let color = Pixel.map_RGB fmt ~rgb in 9 | Pixel.free_format fmt; 10 | (color) 11 | 12 | let f surf win x y w h ~rgb ~msec = 13 | let color = color_of_rgb ~rgb surf in 14 | let rect = Rect.make4 x y w h in 15 | Surface.fill_rect ~dst:surf ~rect ~color; 16 | Window.update_surface win; 17 | Timer.delay msec; 18 | ;; 19 | 20 | let () = 21 | Sdl.init [`VIDEO]; 22 | let win = 23 | Window.create2 24 | ~title:"OCaml SDL2 rectangles" 25 | ~x:`centered ~y:`centered 26 | ~width:640 ~height:480 27 | ~flags:[Window.Resizable] 28 | in 29 | let surf = Window.get_surface win in 30 | f surf win 20 20 200 120 ~rgb:(0,255,0) ~msec:600; 31 | f surf win 60 60 200 200 ~rgb:(255,0,0) ~msec:600; 32 | f surf win 0 0 100 100 ~rgb:(0,0,255) ~msec:2000; 33 | (* 34 | Surface.save_bmp surf ~filename:"test.bmp"; 35 | *) 36 | Sdl.quit () 37 | -------------------------------------------------------------------------------- /examples/ex_text_input.ml: -------------------------------------------------------------------------------- 1 | (* This example requires a terminal with a UTF-8 locale *) 2 | 3 | let () = 4 | let width, height = (200, 200) in 5 | Sdl.init [`VIDEO]; 6 | let window, renderer = 7 | Sdlrender.create_window_and_renderer ~width ~height ~flags:[] 8 | in 9 | Sdlrender.set_draw_color renderer (0,0,0) 255; 10 | Sdlrender.clear renderer; 11 | let text = ref "" in 12 | (* This is required in order to tell SDL to generate 13 | the Text_Input and Text_Editing events *) 14 | Sdlkeyboard.start_text_input (); 15 | let rec aux () = 16 | let open Sdlevent in 17 | match poll_event () with 18 | | Some Quit _ -> Sdl.quit () 19 | | Some Text_Input ti -> 20 | (* Add the text to the already edited text *) 21 | text := !text ^ ti.ti_text; 22 | Printf.printf "text: %s\n%!" !text; 23 | aux () 24 | | Some Text_Editing te -> 25 | (* Update the composition. To correctly place the 26 | cursor and the selection, we need something like 27 | Camomile to correctly split the UTF-8 string. As I 28 | do not want to depend on that for this example, we 29 | will simply print the values. *) 30 | Printf.printf 31 | "text: %s editing: %s cursor: %d selection length: %d\n" 32 | !text 33 | te.te_text 34 | te.te_begin 35 | te.te_length; 36 | aux () 37 | | _ -> aux () 38 | in 39 | aux () 40 | -------------------------------------------------------------------------------- /examples/ex_version.ml: -------------------------------------------------------------------------------- 1 | let print_version label (major, minor, patch) = 2 | Printf.printf "%s: (%d, %d, %d)\n" label major minor patch 3 | 4 | let () = 5 | let runtime_version = Sdlversion.get_runtime_version () in 6 | let compiled_version = Sdlversion.get_compiled_version () in 7 | print_version "runtime version " runtime_version; 8 | print_version "compiled version" compiled_version; 9 | Printf.printf "revision: %d, %s\n" 10 | (Sdlversion.get_revision_number ()) 11 | (Sdlversion.get_revision_string ()) 12 | -------------------------------------------------------------------------------- /opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | name: "ocamlsdl2" 3 | maintainer: "monnier.florent@gmail.com" 4 | authors: [ 5 | "Florent Monnier" 6 | "Piotr Mardziel" 7 | "David Cadé" 8 | "Guillaume Munch-Maccagnoni" 9 | "Carsten Elton Sørensen" 10 | ] 11 | license: "restrictionless Zlib" 12 | homepage: "https://github.com/fccm/OCamlSDL2" 13 | bug-reports: "https://github.com/fccm/OCamlSDL2/issues" 14 | dev-repo: "git+https://github.com/fccm/OCamlSDL2.git" 15 | doc: "https://fccm.github.io/OCamlSDL2/" 16 | 17 | tags: [ "bindings" "graphics" "audio" "multimedia" "opengl" "cross-platform" ] 18 | synopsis: "Interface to the SDL2 library" 19 | description: """ 20 | An OCaml interface to the SDL2 multimedia library for Linux, MacOS and Windows. 21 | 22 | SDL2 homepage: https://www.libsdl.org/ 23 | 24 | This version of the bindings is known to work with SDL2 versions 25 | 2.0.9 and 2.0.10 26 | """ 27 | depends: [ 28 | "ocaml" 29 | "ocamlfind" {build} 30 | "conf-sdl2" 31 | ] 32 | build: [ 33 | ["cp" "src/Makefile.config.unix" "src/Makefile.config"] {"%{os}%" != "win32"} 34 | ["cp" "src/Makefile.config.win32" "src/Makefile.config"] {"%{os}%" = "win32"} 35 | [make "-C" "src" "gen"] 36 | [make "-C" "src" "dep"] 37 | [make "-C" "src" "opt"] 38 | [make "-C" "src" "byte"] 39 | ] 40 | install: [ 41 | [make "-C" "src" "findinstall"] 42 | [make "-C" "src" "findinstall_h"] 43 | ] 44 | -------------------------------------------------------------------------------- /src/META: -------------------------------------------------------------------------------- 1 | name = "sdl2" 2 | description = "bindings to the SDL2 library" 3 | license = "Zlib" 4 | version = "0.05" 5 | 6 | archive(byte) = "sdl2.cma" 7 | archive(native) = "sdl2.cmxa" 8 | plugin(byte) = "sdl2.cma" 9 | plugin(native) = "sdl2.cmxs" 10 | 11 | package "ba" ( 12 | description = "SDL2 with Bigarrays for buffer interexchange" 13 | requires = "sdl2 bigarray" 14 | 15 | archive(byte) = "sdl2-ba.cma" 16 | archive(native) = "sdl2-ba.cmxa" 17 | plugin(byte) = "sdl2-ba.cma" 18 | plugin(native) = "sdl2-ba.cmxs" 19 | ) 20 | 21 | -------------------------------------------------------------------------------- /src/Makefile.config.unix: -------------------------------------------------------------------------------- 1 | # Config for Linux 2 | 3 | OCAMLC := ocamlc -g 4 | #OCAMLOPT_PARAMS := -g -w A -warn-error A -ccopt "$(CC_PARAMS)" 5 | OCAMLOPT_PARAMS := -g -ccopt "$(CC_PARAMS)" 6 | OCAMLOPT = ocamlopt -g -cc "$(CC)" $(OCAMLOPT_PARAMS) 7 | #OCAMLMKLIB := ocamlmklib -v 8 | OCAMLMKLIB := ocamlmklib 9 | 10 | -------------------------------------------------------------------------------- /src/Makefile.config.win32: -------------------------------------------------------------------------------- 1 | # Config for Cygwin/MinGW 2 | 3 | #CC_PARAMS := -Wall -Werror 4 | CC_PARAMS := 5 | CC = c:/cygwin/bin/i686-w64-mingw32-gcc.exe -g $(CC_PARAMS) 6 | 7 | OCAMLC = ocamlc -cc "$(CC)" 8 | 9 | #OCAMLOPT_PARAMS := -g -w A -warn-error A -ccopt "$(CC_PARAMS)" 10 | OCAMLOPT_PARAMS := -g -ccopt "$(CC_PARAMS)" 11 | OCAMLOPT = ocamlopt -cc "$(CC)" $(OCAMLOPT_PARAMS) 12 | 13 | OCAMLMKLIB = ocamlmklib \ 14 | -ocamlc '$(OCAMLC)' -ocamlopt '$(OCAMLOPT)' 15 | 16 | -------------------------------------------------------------------------------- /src/PausableTimer.ml: -------------------------------------------------------------------------------- 1 | (* PausableTimer - A pausable timer for use with OCamlSDL2 2 | Copyright (C) 2020 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | 12 | type t = { 13 | mutable t1: int; 14 | mutable time: int; 15 | mutable paused: bool 16 | } 17 | 18 | let create () = { 19 | t1 = 0; 20 | time = 0; 21 | paused = false; 22 | } 23 | 24 | let is_paused timer = 25 | timer.paused 26 | 27 | let get_ticks timer = 28 | if timer.paused 29 | then timer.t1 - timer.time 30 | else (Sdltimer.get_ticks ()) - timer.time 31 | 32 | let pause timer = 33 | if not timer.paused then begin 34 | timer.t1 <- Sdltimer.get_ticks (); 35 | timer.paused <- true; 36 | end 37 | 38 | let restart timer = 39 | if timer.paused then begin 40 | let t2 = Sdltimer.get_ticks () in 41 | timer.time <- timer.time + (t2 - timer.t1); 42 | timer.paused <- false; 43 | end 44 | 45 | let toggle_pause timer = 46 | if not timer.paused 47 | then pause timer 48 | else restart timer 49 | -------------------------------------------------------------------------------- /src/PausableTimer.mli: -------------------------------------------------------------------------------- 1 | type t 2 | 3 | val create : unit -> t 4 | 5 | val is_paused : t -> bool 6 | 7 | val get_ticks : t -> int 8 | 9 | val pause : t -> unit 10 | 11 | val restart : t -> unit 12 | 13 | val toggle_pause : t -> unit 14 | -------------------------------------------------------------------------------- /src/dep2dot.ml: -------------------------------------------------------------------------------- 1 | #load "str.cma" 2 | 3 | let input_line ic = 4 | try Some (input_line ic) 5 | with End_of_file -> close_in ic; None 6 | 7 | let load_lines filename = 8 | let ic = open_in filename in 9 | let rec aux acc = 10 | match input_line ic with 11 | | Some line -> aux (line::acc) 12 | | None -> (List.rev acc) 13 | in 14 | aux [] 15 | 16 | let ends_with s c = 17 | if s = "" then false else 18 | let n = String.length s in 19 | (s.[n-1] = c) 20 | 21 | let join s1 s2 = 22 | let len = String.length s1 in 23 | (String.sub s1 0 (len-1)) ^ s2 24 | 25 | let join_lines lines = 26 | let rec aux acc = function 27 | | line1 :: line2 :: tail 28 | when ends_with line1 '\\' -> 29 | aux ((join line1 line2) :: acc) tail 30 | | line :: tail -> 31 | aux (line :: acc) tail 32 | | [] -> 33 | (List.rev acc) 34 | in 35 | aux [] lines 36 | 37 | let char_pos c s = 38 | let len = String.length s in 39 | let rec aux i = 40 | if i >= len then None else 41 | if s.[i] = c then Some i else 42 | aux (i+1) 43 | in 44 | aux 0 45 | 46 | let char_split c s = 47 | match char_pos c s with 48 | | None -> (s, "") 49 | | Some p -> 50 | let a = String.sub s 0 p 51 | and b = String.sub s (p+1) (String.length s - (p+1)) in 52 | (a, b) 53 | 54 | let to_list s = 55 | let reg = Str.regexp "[ ]+" in 56 | let lst = Str.split reg s in 57 | (List.map String.trim lst) 58 | 59 | let chop_extension s = 60 | try Filename.chop_extension s 61 | with Invalid_argument _ -> s 62 | 63 | let chop_extensions lst = 64 | List.map chop_extension lst 65 | 66 | let uniq lst = 67 | let rec aux acc = function 68 | | [] -> (List.rev acc) 69 | | x::xs -> if List.mem x acc then aux acc xs else aux (x::acc) xs 70 | in 71 | aux [] lst 72 | 73 | let list_assoc v lst = 74 | try Some (List.assoc v lst) 75 | with Not_found -> (None) 76 | 77 | let list_assoc_all v lst = 78 | let rec aux acc lst = 79 | match list_assoc v lst with 80 | | Some x -> aux (x::acc) (List.remove_assoc v lst) 81 | | None -> (List.rev acc) 82 | in 83 | aux [] lst 84 | 85 | let list_items lst = 86 | let lst = List.map (fun (a, b) -> a::b) lst in 87 | let lst = List.flatten lst in 88 | (uniq lst) 89 | 90 | let join_deps lst = 91 | let items = list_items lst in 92 | List.map (fun item -> 93 | let deps = List.flatten (list_assoc_all item lst) in 94 | (item, uniq deps) 95 | ) items 96 | 97 | let print_nodes lst = 98 | List.iter (fun (a, b) -> 99 | Printf.printf " %s [ label = \"%s\" ]\n" a a 100 | ) lst 101 | 102 | let print_deps lst = 103 | List.iter (fun (a, b) -> 104 | List.iter (fun d -> 105 | Printf.printf " %s -> %s\n" a d 106 | ) b 107 | ) lst 108 | 109 | let () = 110 | let lines = load_lines Sys.argv.(1) in 111 | let lines = join_lines lines in 112 | let lst = List.map (char_split ':') lines in 113 | let lst = List.map (fun (a, b) -> String.trim a, to_list b) lst in 114 | let lst = List.map (fun (a, b) -> (chop_extension a, 115 | chop_extensions b)) lst in 116 | let lst = List.map (fun (a, b) -> (String.capitalize a, 117 | List.map String.capitalize b)) lst in 118 | let lst = join_deps lst in 119 | 120 | print_nodes lst; 121 | print_newline (); 122 | print_deps lst; 123 | ;; 124 | -------------------------------------------------------------------------------- /src/dir_sep.ml: -------------------------------------------------------------------------------- 1 | print_endline Filename.dir_sep 2 | -------------------------------------------------------------------------------- /src/poly_var.ml: -------------------------------------------------------------------------------- 1 | let input_line ic = 2 | try Some (input_line ic) 3 | with End_of_file -> close_in ic; None 4 | 5 | let load_lines fn = 6 | let ic = open_in fn in 7 | let rec aux acc = 8 | match input_line ic with 9 | | Some line -> aux (line::acc) 10 | | None -> List.rev acc 11 | in 12 | aux [] 13 | 14 | external hash_var : string -> int 15 | = "my_caml_hash_variant" 16 | 17 | let pad s n = 18 | let len = String.length s in 19 | let p = max 0 (n - len) in 20 | s ^ (String.make p ' ') 21 | 22 | let read_lines lines = 23 | let pat = Str.regexp "[\t]+" in 24 | let lst = 25 | List.fold_left (fun acc line -> 26 | match Str.split pat line with 27 | | [a; b] -> (a, b)::acc 28 | | lst -> 29 | List.iter (Printf.eprintf " / %s") lst; 30 | Printf.eprintf "\n======\n"; 31 | (acc) 32 | ) [] lines 33 | in 34 | (List.rev lst) 35 | 36 | let prepare_vars vars = 37 | let n1, n2 = 38 | List.fold_left (fun (n1, n2) (c_val, poly_var) -> 39 | let s1 = String.length c_val 40 | and s2 = String.length poly_var in 41 | (max n1 s1, max n2 s2) 42 | ) (0, 0) vars 43 | in 44 | List.map (fun (c_val, poly_var) -> 45 | (c_val, pad c_val n1, 46 | poly_var, pad poly_var n2, 47 | hash_var poly_var) 48 | ) vars 49 | 50 | let parse_cmd argv = 51 | match List.tl (Array.to_list argv) with 52 | | ["-c"; filename] -> (`C, filename) 53 | | ["-ml"; filename] -> (`ML, filename) 54 | | ["-table"; filename] -> (`Table, filename) 55 | | _ -> assert false 56 | 57 | let print_ml = 58 | List.iter (fun (_, _, poly_var, _, _) -> 59 | Printf.printf " | `%s\n" poly_var) 60 | 61 | let print_c = 62 | List.iter (fun (c_val, p_c_val, poly_var, p_poly_var, h) -> 63 | Printf.printf "#define MLVAR_%s 0x%08X\n" p_poly_var h) 64 | 65 | let print_table = 66 | List.iter (fun (c_val, p_c_val, poly_var, p_poly_var, _) -> 67 | Printf.printf " MLVAR_%s,\t%s,\n" poly_var c_val) 68 | 69 | let () = 70 | let out_kind, in_file = parse_cmd Sys.argv in 71 | let lines = load_lines in_file in 72 | let vars = read_lines lines in 73 | let vars = prepare_vars vars in 74 | match out_kind with 75 | | `C -> print_c vars 76 | | `ML -> print_ml vars 77 | | `Table -> print_table vars 78 | -------------------------------------------------------------------------------- /src/poly_var_stubs.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Florent Monnier 2 | 3 | This software is provided "AS-IS", without any express or implied warranty. 4 | In no event will the authors be held liable for any damages arising from 5 | the use of this software. 6 | 7 | Permission is granted to anyone to use this software for any purpose, 8 | including commercial applications, and to alter it and redistribute it freely. 9 | */ 10 | #include 11 | 12 | CAMLprim value 13 | my_caml_hash_variant(value s) 14 | { 15 | return Val_long( 16 | caml_hash_variant(String_val(s))); 17 | } 18 | -------------------------------------------------------------------------------- /src/prm.ml: -------------------------------------------------------------------------------- 1 | let () = 2 | let args = List.tl (Array.to_list Sys.argv) in 3 | let args = 4 | List.filter (fun arg -> 5 | String.length arg > 2 && arg.[0] = '-' && 6 | match arg.[1] with 7 | | 'l' | 'L' -> true 8 | | _ -> false 9 | ) args 10 | in 11 | print_string (String.concat " " args) 12 | -------------------------------------------------------------------------------- /src/sdl.ml: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (** Prefixless modules *) 12 | 13 | include Sdlinit 14 | include Sdlquit 15 | 16 | external get_platform : unit -> string 17 | = "caml_SDL_GetPlatform" 18 | 19 | module Init = struct 20 | include Sdlinit 21 | end 22 | module Quit = struct 23 | include Sdlquit 24 | end 25 | module Window = struct 26 | include Sdlwindow 27 | end 28 | module Surface = struct 29 | include Sdlsurface 30 | end 31 | module Render = struct 32 | include Sdlrender 33 | end 34 | module Texture = struct 35 | include Sdltexture 36 | end 37 | module TextureAccess = struct 38 | include SdltextureAccess 39 | end 40 | module PixelFormat = struct 41 | include SdlpixelFormat 42 | end 43 | module Pixel = struct 44 | include Sdlpixel 45 | end 46 | module BlendMode = struct 47 | include SdlblendMode 48 | end 49 | module Event = struct 50 | include Sdlevent 51 | end 52 | module Keyboard = struct 53 | include Sdlkeyboard 54 | end 55 | module Keycode = struct 56 | include Sdlkeycode 57 | end 58 | module Scancode = struct 59 | include Sdlscancode 60 | end 61 | module Keymod = struct 62 | include Sdlkeymod 63 | end 64 | module Mouse = struct 65 | include Sdlmouse 66 | end 67 | module Joystick = struct 68 | include Sdljoystick 69 | end 70 | module Hat = struct 71 | include Sdlhat 72 | end 73 | module Rect = struct 74 | include Sdlrect 75 | end 76 | module Timer = struct 77 | include Sdltimer 78 | end 79 | module Clipboard = struct 80 | include Sdlclipboard 81 | end 82 | module GL = struct 83 | include Sdlgl 84 | end 85 | module Audio = struct 86 | include Sdlaudio 87 | end 88 | module Filesystem = struct 89 | include Sdlfilesystem 90 | end 91 | module Version = struct 92 | include Sdlversion 93 | end 94 | module CPUInfo = struct 95 | include Sdlcpuinfo 96 | end 97 | module Power = struct 98 | include Sdlpower 99 | end 100 | module RWops = struct 101 | include Sdlrwops 102 | end 103 | module Error = struct 104 | include Sdlerror 105 | end 106 | module Hint = struct 107 | include Sdlhint 108 | end 109 | 110 | -------------------------------------------------------------------------------- /src/sdl_header: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (** Prefixless modules *) 12 | 13 | (* This is a generated file, with: 14 | ocamlc -i sdl.ml > sdl.mli 15 | *) 16 | 17 | -------------------------------------------------------------------------------- /src/sdl_keycode.var.list: -------------------------------------------------------------------------------- 1 | SDLK_UNKNOWN 2 | SDLK_RETURN 3 | SDLK_ESCAPE 4 | SDLK_BACKSPACE 5 | SDLK_TAB 6 | SDLK_SPACE 7 | SDLK_EXCLAIM 8 | SDLK_QUOTEDBL 9 | SDLK_HASH 10 | SDLK_PERCENT 11 | SDLK_DOLLAR 12 | SDLK_AMPERSAND 13 | SDLK_QUOTE 14 | SDLK_LEFTPAREN 15 | SDLK_RIGHTPAREN 16 | SDLK_ASTERISK 17 | SDLK_PLUS 18 | SDLK_COMMA 19 | SDLK_MINUS 20 | SDLK_PERIOD 21 | SDLK_SLASH 22 | SDLK_0 23 | SDLK_1 24 | SDLK_2 25 | SDLK_3 26 | SDLK_4 27 | SDLK_5 28 | SDLK_6 29 | SDLK_7 30 | SDLK_8 31 | SDLK_9 32 | SDLK_COLON 33 | SDLK_SEMICOLON 34 | SDLK_LESS 35 | SDLK_EQUALS 36 | SDLK_GREATER 37 | SDLK_QUESTION 38 | SDLK_AT 39 | SDLK_LEFTBRACKET 40 | SDLK_BACKSLASH 41 | SDLK_RIGHTBRACKET 42 | SDLK_CARET 43 | SDLK_UNDERSCORE 44 | SDLK_BACKQUOTE 45 | SDLK_a 46 | SDLK_b 47 | SDLK_c 48 | SDLK_d 49 | SDLK_e 50 | SDLK_f 51 | SDLK_g 52 | SDLK_h 53 | SDLK_i 54 | SDLK_j 55 | SDLK_k 56 | SDLK_l 57 | SDLK_m 58 | SDLK_n 59 | SDLK_o 60 | SDLK_p 61 | SDLK_q 62 | SDLK_r 63 | SDLK_s 64 | SDLK_t 65 | SDLK_u 66 | SDLK_v 67 | SDLK_w 68 | SDLK_x 69 | SDLK_y 70 | SDLK_z 71 | SDLK_CAPSLOCK 72 | SDLK_F1 73 | SDLK_F2 74 | SDLK_F3 75 | SDLK_F4 76 | SDLK_F5 77 | SDLK_F6 78 | SDLK_F7 79 | SDLK_F8 80 | SDLK_F9 81 | SDLK_F10 82 | SDLK_F11 83 | SDLK_F12 84 | SDLK_PRINTSCREEN 85 | SDLK_SCROLLLOCK 86 | SDLK_PAUSE 87 | SDLK_INSERT 88 | SDLK_HOME 89 | SDLK_PAGEUP 90 | SDLK_DELETE 91 | SDLK_END 92 | SDLK_PAGEDOWN 93 | SDLK_RIGHT 94 | SDLK_LEFT 95 | SDLK_DOWN 96 | SDLK_UP 97 | SDLK_NUMLOCKCLEAR 98 | SDLK_KP_DIVIDE 99 | SDLK_KP_MULTIPLY 100 | SDLK_KP_MINUS 101 | SDLK_KP_PLUS 102 | SDLK_KP_ENTER 103 | SDLK_KP_1 104 | SDLK_KP_2 105 | SDLK_KP_3 106 | SDLK_KP_4 107 | SDLK_KP_5 108 | SDLK_KP_6 109 | SDLK_KP_7 110 | SDLK_KP_8 111 | SDLK_KP_9 112 | SDLK_KP_0 113 | SDLK_KP_PERIOD 114 | SDLK_APPLICATION 115 | SDLK_POWER 116 | SDLK_KP_EQUALS 117 | SDLK_F13 118 | SDLK_F14 119 | SDLK_F15 120 | SDLK_F16 121 | SDLK_F17 122 | SDLK_F18 123 | SDLK_F19 124 | SDLK_F20 125 | SDLK_F21 126 | SDLK_F22 127 | SDLK_F23 128 | SDLK_F24 129 | SDLK_EXECUTE 130 | SDLK_HELP 131 | SDLK_MENU 132 | SDLK_SELECT 133 | SDLK_STOP 134 | SDLK_AGAIN 135 | SDLK_UNDO 136 | SDLK_CUT 137 | SDLK_COPY 138 | SDLK_PASTE 139 | SDLK_FIND 140 | SDLK_MUTE 141 | SDLK_VOLUMEUP 142 | SDLK_VOLUMEDOWN 143 | SDLK_KP_COMMA 144 | SDLK_KP_EQUALSAS400 145 | SDLK_ALTERASE 146 | SDLK_SYSREQ 147 | SDLK_CANCEL 148 | SDLK_CLEAR 149 | SDLK_PRIOR 150 | SDLK_RETURN2 151 | SDLK_SEPARATOR 152 | SDLK_OUT 153 | SDLK_OPER 154 | SDLK_CLEARAGAIN 155 | SDLK_CRSEL 156 | SDLK_EXSEL 157 | SDLK_KP_00 158 | SDLK_KP_000 159 | SDLK_THOUSANDSSEPARATOR 160 | SDLK_DECIMALSEPARATOR 161 | SDLK_CURRENCYUNIT 162 | SDLK_CURRENCYSUBUNIT 163 | SDLK_KP_LEFTPAREN 164 | SDLK_KP_RIGHTPAREN 165 | SDLK_KP_LEFTBRACE 166 | SDLK_KP_RIGHTBRACE 167 | SDLK_KP_TAB 168 | SDLK_KP_BACKSPACE 169 | SDLK_KP_A 170 | SDLK_KP_B 171 | SDLK_KP_C 172 | SDLK_KP_D 173 | SDLK_KP_E 174 | SDLK_KP_F 175 | SDLK_KP_XOR 176 | SDLK_KP_POWER 177 | SDLK_KP_PERCENT 178 | SDLK_KP_LESS 179 | SDLK_KP_GREATER 180 | SDLK_KP_AMPERSAND 181 | SDLK_KP_DBLAMPERSAND 182 | SDLK_KP_VERTICALBAR 183 | SDLK_KP_DBLVERTICALBAR 184 | SDLK_KP_COLON 185 | SDLK_KP_HASH 186 | SDLK_KP_SPACE 187 | SDLK_KP_AT 188 | SDLK_KP_EXCLAM 189 | SDLK_KP_MEMSTORE 190 | SDLK_KP_MEMRECALL 191 | SDLK_KP_MEMCLEAR 192 | SDLK_KP_MEMADD 193 | SDLK_KP_MEMSUBTRACT 194 | SDLK_KP_MEMMULTIPLY 195 | SDLK_KP_MEMDIVIDE 196 | SDLK_KP_PLUSMINUS 197 | SDLK_KP_CLEAR 198 | SDLK_KP_CLEARENTRY 199 | SDLK_KP_BINARY 200 | SDLK_KP_OCTAL 201 | SDLK_KP_DECIMAL 202 | SDLK_KP_HEXADECIMAL 203 | SDLK_LCTRL 204 | SDLK_LSHIFT 205 | SDLK_LALT 206 | SDLK_LGUI 207 | SDLK_RCTRL 208 | SDLK_RSHIFT 209 | SDLK_RALT 210 | SDLK_RGUI 211 | SDLK_MODE 212 | SDLK_AUDIONEXT 213 | SDLK_AUDIOPREV 214 | SDLK_AUDIOSTOP 215 | SDLK_AUDIOPLAY 216 | SDLK_AUDIOMUTE 217 | SDLK_MEDIASELECT 218 | SDLK_WWW 219 | SDLK_MAIL 220 | SDLK_CALCULATOR 221 | SDLK_COMPUTER 222 | SDLK_AC_SEARCH 223 | SDLK_AC_HOME 224 | SDLK_AC_BACK 225 | SDLK_AC_FORWARD 226 | SDLK_AC_STOP 227 | SDLK_AC_REFRESH 228 | SDLK_AC_BOOKMARKS 229 | SDLK_BRIGHTNESSDOWN 230 | SDLK_BRIGHTNESSUP 231 | SDLK_DISPLAYSWITCH 232 | SDLK_KBDILLUMTOGGLE 233 | SDLK_KBDILLUMDOWN 234 | SDLK_KBDILLUMUP 235 | SDLK_EJECT 236 | SDLK_SLEEP 237 | -------------------------------------------------------------------------------- /src/sdl_platform_stub.c: -------------------------------------------------------------------------------- 1 | #define CAML_NAME_SPACE 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | CAMLprim value 8 | caml_SDL_GetPlatform(value unit) 9 | { 10 | const char *platform_name = SDL_GetPlatform(); 11 | return caml_copy_string(platform_name); 12 | } 13 | -------------------------------------------------------------------------------- /src/sdlaudio.ml: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (* Audio *) 12 | 13 | type t 14 | 15 | type format = 16 | | AUDIO_U8 17 | | AUDIO_S8 18 | | AUDIO_U16LSB 19 | | AUDIO_S16LSB 20 | | AUDIO_U16MSB 21 | | AUDIO_S16MSB 22 | | AUDIO_U16 23 | | AUDIO_S16 24 | | AUDIO_S32LSB 25 | | AUDIO_S32MSB 26 | | AUDIO_S32 27 | | AUDIO_F32LSB 28 | | AUDIO_F32MSB 29 | | AUDIO_F32 30 | | AUDIO_U16SYS 31 | | AUDIO_S16SYS 32 | | AUDIO_S32SYS 33 | | AUDIO_F32SYS 34 | 35 | external get_drivers : 36 | unit -> string array 37 | = "caml_SDL_GetAudioDrivers" 38 | 39 | external init : driver_name:string -> unit 40 | = "caml_SDL_AudioInit" 41 | 42 | external quit : unit -> unit 43 | = "caml_SDL_AudioQuit" 44 | 45 | external get_current_driver : unit -> string 46 | = "caml_SDL_GetCurrentAudioDriver" 47 | 48 | type status = 49 | | Stopped 50 | | Playing 51 | | Paused 52 | 53 | external get_status : unit -> status 54 | = "caml_SDL_GetAudioStatus" 55 | 56 | let string_of_status = function 57 | | Stopped -> "Stopped" 58 | | Playing -> "Playing" 59 | | Paused -> "Paused" 60 | 61 | external pause : pause_on:bool -> unit 62 | = "caml_SDL_PauseAudio" 63 | 64 | external lock : unit -> unit 65 | = "caml_SDL_LockAudio" 66 | 67 | external unlock : unit -> unit 68 | = "caml_SDL_UnlockAudio" 69 | 70 | external close : unit -> unit 71 | = "caml_SDL_CloseAudio" 72 | 73 | type audio_spec 74 | 75 | external new_audio_spec : unit -> audio_spec 76 | = "caml_SDL_alloc_audio_spec" 77 | 78 | external free_audio_spec : audio_spec -> unit 79 | = "caml_SDL_free_audio_spec" 80 | 81 | type audio_buffer 82 | 83 | external load_wav : filename:string -> spec:audio_spec -> audio_buffer * int32 84 | = "caml_SDL_LoadWAV" 85 | 86 | external free_wav : audio_buffer -> unit 87 | = "caml_SDL_FreeWAV" 88 | 89 | type audio_device_id 90 | 91 | external open_audio_device_simple : audio_spec -> audio_device_id 92 | = "caml_SDL_OpenAudioDevice_simple" 93 | 94 | external queue_audio : audio_device_id -> audio_buffer -> int32 -> unit 95 | = "caml_SDL_QueueAudio" 96 | 97 | external unpause_audio_device : audio_device_id -> unit 98 | = "caml_SDL_UnpauseAudioDevice" 99 | 100 | external pause_audio_device : audio_device_id -> unit 101 | = "caml_SDL_PauseAudioDevice" 102 | 103 | external close_audio_device : audio_device_id -> unit 104 | = "caml_SDL_CloseAudioDevice" 105 | 106 | -------------------------------------------------------------------------------- /src/sdlaudio.mli: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (** Audio *) 12 | 13 | (** API Doc: 14 | {{:http://wiki.libsdl.org/CategoryAudio}Audio category} *) 15 | 16 | type t 17 | 18 | type format = 19 | | AUDIO_U8 20 | | AUDIO_S8 21 | | AUDIO_U16LSB 22 | | AUDIO_S16LSB 23 | | AUDIO_U16MSB 24 | | AUDIO_S16MSB 25 | | AUDIO_U16 26 | | AUDIO_S16 27 | | AUDIO_S32LSB 28 | | AUDIO_S32MSB 29 | | AUDIO_S32 30 | | AUDIO_F32LSB 31 | | AUDIO_F32MSB 32 | | AUDIO_F32 33 | | AUDIO_U16SYS 34 | | AUDIO_S16SYS 35 | | AUDIO_S32SYS 36 | | AUDIO_F32SYS 37 | 38 | external get_drivers : 39 | unit -> string array 40 | = "caml_SDL_GetAudioDrivers" 41 | (** {{:http://wiki.libsdl.org/SDL_GetAudioDrivers}api doc} *) 42 | 43 | external init : driver_name:string -> unit 44 | = "caml_SDL_AudioInit" 45 | (** {{:http://wiki.libsdl.org/SDL_AudioInit}api doc} *) 46 | 47 | external quit : unit -> unit 48 | = "caml_SDL_AudioQuit" 49 | (** {{:http://wiki.libsdl.org/SDL_AudioQuit}api doc} *) 50 | 51 | external get_current_driver : unit -> string 52 | = "caml_SDL_GetCurrentAudioDriver" 53 | (** {{:http://wiki.libsdl.org/SDL_GetCurrentAudioDriver}api doc} *) 54 | 55 | type status = 56 | | Stopped 57 | | Playing 58 | | Paused 59 | 60 | external get_status : unit -> status 61 | = "caml_SDL_GetAudioStatus" 62 | (** {{:http://wiki.libsdl.org/SDL_GetAudioStatus}api doc} *) 63 | 64 | val string_of_status : status -> string 65 | 66 | external pause : pause_on:bool -> unit 67 | = "caml_SDL_PauseAudio" 68 | (** {{:http://wiki.libsdl.org/SDL_PauseAudio}api doc} *) 69 | 70 | external lock : unit -> unit 71 | = "caml_SDL_LockAudio" 72 | (** {{:http://wiki.libsdl.org/SDL_LockAudio}api doc} *) 73 | 74 | external unlock : unit -> unit 75 | = "caml_SDL_UnlockAudio" 76 | (** {{:http://wiki.libsdl.org/SDL_UnlockAudio}api doc} *) 77 | 78 | external close : unit -> unit 79 | = "caml_SDL_CloseAudio" 80 | (** {{:http://wiki.libsdl.org/SDL_CloseAudio}api doc} *) 81 | 82 | type audio_spec 83 | (** {{:http://wiki.libsdl.org/SDL_AudioSpec}api doc} *) 84 | 85 | external new_audio_spec : unit -> audio_spec 86 | = "caml_SDL_alloc_audio_spec" 87 | 88 | external free_audio_spec : audio_spec -> unit 89 | = "caml_SDL_free_audio_spec" 90 | 91 | type audio_buffer 92 | 93 | external load_wav : filename:string -> spec:audio_spec -> audio_buffer * int32 94 | = "caml_SDL_LoadWAV" 95 | (** {{:http://wiki.libsdl.org/SDL_LoadWAV}api doc} *) 96 | 97 | external free_wav : audio_buffer -> unit 98 | = "caml_SDL_FreeWAV" 99 | (** {{:http://wiki.libsdl.org/SDL_FreeWAV}api doc} *) 100 | 101 | type audio_device_id 102 | 103 | external open_audio_device_simple : audio_spec -> audio_device_id 104 | = "caml_SDL_OpenAudioDevice_simple" 105 | (** {{:http://wiki.libsdl.org/SDL_OpenAudioDevice}api doc} *) 106 | 107 | external queue_audio : audio_device_id -> audio_buffer -> int32 -> unit 108 | = "caml_SDL_QueueAudio" 109 | (** {{:http://wiki.libsdl.org/SDL_QueueAudio}api doc} *) 110 | 111 | external unpause_audio_device : audio_device_id -> unit 112 | = "caml_SDL_UnpauseAudioDevice" 113 | (** {{:http://wiki.libsdl.org/SDL_PauseAudioDevice}api doc} *) 114 | 115 | external pause_audio_device : audio_device_id -> unit 116 | = "caml_SDL_PauseAudioDevice" 117 | (** {{:http://wiki.libsdl.org/SDL_PauseAudioDevice}api doc} *) 118 | 119 | external close_audio_device : audio_device_id -> unit 120 | = "caml_SDL_CloseAudioDevice" 121 | (** {{:http://wiki.libsdl.org/SDL_CloseAudioDevice}api doc} *) 122 | 123 | -------------------------------------------------------------------------------- /src/sdlaudio_stub.h: -------------------------------------------------------------------------------- 1 | #ifndef _CAML_SDL_AUDIO_ 2 | #define _CAML_SDL_AUDIO_ 3 | 4 | #include 5 | 6 | value Val_SDL_AudioFormat(SDL_AudioFormat format); 7 | 8 | extern const SDL_AudioFormat ocaml_SDL_AudioFormat_table[]; 9 | 10 | #define SDL_AudioFormat_val(format) \ 11 | ocaml_SDL_AudioFormat_table[Long_val(format)] 12 | 13 | #endif /* _CAML_SDL_AUDIO_ */ 14 | 15 | /* vim: set ts=4 sw=4 et: */ 16 | /* Local Variables: */ 17 | /* c-basic-offset:4; tab-width:4; indent-tabs-mode:nil; */ 18 | /* End: */ 19 | -------------------------------------------------------------------------------- /src/sdlba.ml: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2014 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (** Prefixless modules, with Bigarray interactions *) 12 | 13 | module Surface_ba = struct 14 | include Sdlsurface_ba 15 | end 16 | 17 | module Texture_ba = struct 18 | include Sdltexture_ba 19 | end 20 | 21 | -------------------------------------------------------------------------------- /src/sdlblendMode.ml: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (* Blend Modes *) 12 | 13 | type t = 14 | | BNone 15 | | Blend 16 | | Add 17 | | Mod 18 | 19 | let to_string = function 20 | | BNone -> "blend_mode_none" 21 | | Blend -> "blend_mode_blend" 22 | | Add -> "blend_mode_add" 23 | | Mod -> "blend_mode_mod" 24 | 25 | let of_string s = 26 | match String.lowercase_ascii s with 27 | | "blend_mode_none" -> BNone 28 | | "blend_mode_blend" -> Blend 29 | | "blend_mode_add" -> Add 30 | | "blend_mode_mod" -> Mod 31 | | _ -> invalid_arg "SdlblendMode.of_string" 32 | 33 | -------------------------------------------------------------------------------- /src/sdlblendMode.mli: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (** Blend Modes *) 12 | 13 | (** API Doc: 14 | {{:http://wiki.libsdl.org/SDL_BlendMode}SDL_BlendMode} *) 15 | 16 | type t = 17 | | BNone 18 | | Blend 19 | | Add 20 | | Mod 21 | 22 | val to_string : t -> string 23 | val of_string : string -> t 24 | 25 | -------------------------------------------------------------------------------- /src/sdlblendMode_stub.c: -------------------------------------------------------------------------------- 1 | /* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | */ 11 | #define CAML_NAME_SPACE 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | 19 | #define Val_Sdl_BlendMode_None Val_int(0) 20 | #define Val_Sdl_BlendMode_Blend Val_int(1) 21 | #define Val_Sdl_BlendMode_Add Val_int(2) 22 | #define Val_Sdl_BlendMode_Mod Val_int(3) 23 | 24 | value 25 | Val_SDL_BlendMode(SDL_BlendMode blend_mode) 26 | { 27 | switch (blend_mode) { 28 | case SDL_BLENDMODE_NONE: return Val_Sdl_BlendMode_None; 29 | case SDL_BLENDMODE_BLEND: return Val_Sdl_BlendMode_Blend; 30 | case SDL_BLENDMODE_ADD: return Val_Sdl_BlendMode_Add; 31 | case SDL_BLENDMODE_MOD: return Val_Sdl_BlendMode_Mod; 32 | } 33 | caml_failwith("SdlblendMode.t"); 34 | } 35 | 36 | const SDL_BlendMode ocaml_SDL_BlendMode_table[] = { 37 | SDL_BLENDMODE_NONE, 38 | SDL_BLENDMODE_BLEND, 39 | SDL_BLENDMODE_ADD, 40 | SDL_BLENDMODE_MOD, 41 | }; 42 | 43 | /* vim: set ts=4 sw=4 et: */ 44 | -------------------------------------------------------------------------------- /src/sdlblendMode_stub.h: -------------------------------------------------------------------------------- 1 | #ifndef _CAML_SDL_BLENDMODE_ 2 | #define _CAML_SDL_BLENDMODE_ 3 | 4 | #include 5 | 6 | value Val_SDL_BlendMode(SDL_BlendMode blend_mode); 7 | 8 | extern const SDL_BlendMode ocaml_SDL_BlendMode_table[]; 9 | 10 | #define SDL_BlendMode_val(blend_mode) \ 11 | ocaml_SDL_BlendMode_table[Long_val(blend_mode)] 12 | 13 | #endif /* _CAML_SDL_BLENDMODE_ */ 14 | -------------------------------------------------------------------------------- /src/sdlclipboard.ml: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (* Clipboard Handling *) 12 | 13 | external set_text : text:string -> int 14 | = "caml_SDL_SetClipboardText" 15 | 16 | external get_text : unit -> string 17 | = "caml_SDL_GetClipboardText" 18 | 19 | external has_text : unit -> bool 20 | = "caml_SDL_HasClipboardText" 21 | -------------------------------------------------------------------------------- /src/sdlclipboard.mli: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (** Clipboard handling *) 12 | 13 | (** API Doc: 14 | {{:http://wiki.libsdl.org/CategoryClipboard}Clipboard category} *) 15 | 16 | external set_text : text:string -> int 17 | = "caml_SDL_SetClipboardText" 18 | (** {{:http://wiki.libsdl.org/SDL_SetClipboardText}api doc} *) 19 | 20 | external get_text : unit -> string 21 | = "caml_SDL_GetClipboardText" 22 | (** {{:http://wiki.libsdl.org/SDL_GetClipboardText}api doc} *) 23 | 24 | external has_text : unit -> bool 25 | = "caml_SDL_HasClipboardText" 26 | (** {{:http://wiki.libsdl.org/SDL_HasClipboardText}api doc} *) 27 | 28 | -------------------------------------------------------------------------------- /src/sdlclipboard_stub.c: -------------------------------------------------------------------------------- 1 | /* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | */ 11 | #define CAML_NAME_SPACE 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | 19 | CAMLprim value 20 | caml_SDL_SetClipboardText(value text) 21 | { 22 | int r = SDL_SetClipboardText(String_val(text)); 23 | return Val_int(r); 24 | } 25 | 26 | CAMLprim value 27 | caml_SDL_GetClipboardText(value unit) 28 | { 29 | char * txt = SDL_GetClipboardText(); 30 | return caml_copy_string(txt); 31 | } 32 | 33 | CAMLprim value 34 | caml_SDL_HasClipboardText(value unit) 35 | { 36 | SDL_bool b = SDL_HasClipboardText(); 37 | return Val_bool(b); 38 | } 39 | 40 | /* vim: set ts=4 sw=4 et: */ 41 | -------------------------------------------------------------------------------- /src/sdlcpuinfo.ml: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (** CPU feature detection *) 12 | 13 | external get_CPU_count : unit -> int 14 | = "caml_SDL_GetCPUCount" 15 | -------------------------------------------------------------------------------- /src/sdlcpuinfo.mli: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (** CPU feature detection *) 12 | 13 | (** API Doc: 14 | {{:http://wiki.libsdl.org/CategoryCPU}CPU category} *) 15 | 16 | external get_CPU_count : unit -> int 17 | = "caml_SDL_GetCPUCount" 18 | (** {{:http://wiki.libsdl.org/SDL_GetCPUCount}api doc} *) 19 | 20 | -------------------------------------------------------------------------------- /src/sdlcpuinfo_stub.c: -------------------------------------------------------------------------------- 1 | /* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | */ 11 | #define CAML_NAME_SPACE 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | 19 | CAMLprim value 20 | caml_SDL_GetCPUCount(value unit) 21 | { 22 | int n = SDL_GetCPUCount(); 23 | return Val_int(n); 24 | } 25 | 26 | /* vim: set ts=4 sw=4 et: */ 27 | -------------------------------------------------------------------------------- /src/sdlerror.ml: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (* Simple error message routines *) 12 | 13 | external get_error : unit -> string 14 | = "caml_SDL_GetError" 15 | 16 | external clear_error : unit -> unit 17 | = "caml_SDL_ClearError" 18 | -------------------------------------------------------------------------------- /src/sdlerror.mli: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (** Simple error message routines *) 12 | 13 | (** API Doc: 14 | {{:http://wiki.libsdl.org/CategoryError}Error category} *) 15 | 16 | external get_error : unit -> string 17 | = "caml_SDL_GetError" 18 | (** {{:http://wiki.libsdl.org/SDL_GetError}api doc} *) 19 | 20 | external clear_error : unit -> unit 21 | = "caml_SDL_ClearError" 22 | (** {{:http://wiki.libsdl.org/SDL_ClearError}api doc} *) 23 | 24 | -------------------------------------------------------------------------------- /src/sdlerror_stub.c: -------------------------------------------------------------------------------- 1 | /* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | */ 11 | #define CAML_NAME_SPACE 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | 19 | CAMLprim value 20 | caml_SDL_GetError(value unit) 21 | { 22 | const char *err = SDL_GetError(); 23 | return caml_copy_string(err); 24 | } 25 | 26 | CAMLprim value 27 | caml_SDL_ClearError(value unit) 28 | { 29 | SDL_ClearError(); 30 | return Val_unit; 31 | } 32 | 33 | /* vim: set ts=4 sw=4 et: */ 34 | -------------------------------------------------------------------------------- /src/sdlevent.mli: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (** Events handling *) 12 | 13 | (** API Doc: 14 | {{:http://wiki.libsdl.org/CategoryEvents}Events category} *) 15 | 16 | type state = 17 | | Released 18 | | Pressed 19 | 20 | val string_of_state : state -> string 21 | 22 | type keyboard_event = { 23 | ke_timestamp: int32; 24 | ke_window_id: int32; 25 | ke_state: state; 26 | ke_repeat: int; 27 | scancode: Sdlscancode.t; 28 | keycode: Sdlkeycode.t; 29 | keymod: Sdlkeymod.t list; 30 | } 31 | (** {{:http://wiki.libsdl.org/SDL_KeyboardEvent}api doc} *) 32 | 33 | type mouse_motion_event = { 34 | mm_timestamp: int32; 35 | mm_window_id: int32; 36 | mm_buttons: int list; 37 | mm_x: int; 38 | mm_y: int; 39 | mm_xrel: int; 40 | mm_yrel: int; 41 | } 42 | (** {{:http://wiki.libsdl.org/SDL_MouseMotionEvent}api doc} *) 43 | 44 | type mouse_button_event = { 45 | mb_timestamp: int32; 46 | mb_window_id: int32; 47 | mb_button: int; 48 | mb_state: state; 49 | mb_x: int; 50 | mb_y: int; 51 | } 52 | (** {{:http://wiki.libsdl.org/SDL_MouseButtonEvent}api doc} *) 53 | 54 | type mouse_wheel_event = { 55 | mw_timestamp: int32; 56 | mw_window_id: int32; 57 | mw_x: int; 58 | mw_y: int; 59 | } 60 | (** {{:http://wiki.libsdl.org/SDL_MouseWheelEvent}api doc} *) 61 | 62 | type joy_axis_event = { 63 | ja_timestamp: int32; 64 | ja_which: int; 65 | ja_axis: int; 66 | ja_value: int; 67 | } 68 | (** {{:http://wiki.libsdl.org/SDL_JoyAxisEvent}api doc} *) 69 | 70 | type joy_button_event = { 71 | jb_timestamp: int32; 72 | jb_which: int; 73 | jb_button: int; 74 | jb_state: state; 75 | } 76 | (** {{:http://wiki.libsdl.org/SDL_JoyButtonEvent}api doc} *) 77 | 78 | type joy_hat_event = { 79 | jh_timestamp: int32; 80 | jh_which: int; 81 | jh_hat: int; 82 | jh_dir: Sdlhat.direction; 83 | jh_pos: Sdlhat.positions; 84 | } 85 | (** {{:http://wiki.libsdl.org/SDL_JoyHatEvent}api doc} *) 86 | 87 | type joy_device_change = 88 | | JoyDevice_Added 89 | | JoyDevice_Removed 90 | 91 | val string_of_joy_device_change : 92 | joy_device_change -> string 93 | 94 | type joy_device_event = { 95 | jd_timestamp: int32; 96 | jd_which: int; 97 | jd_change: joy_device_change; 98 | } 99 | 100 | type window_event_xy = { 101 | win_x: int; 102 | win_y: int; 103 | } 104 | 105 | type window_event_kind = 106 | | WindowEvent_None 107 | | WindowEvent_Shown 108 | | WindowEvent_Hidden 109 | | WindowEvent_Exposed 110 | | WindowEvent_Moved of window_event_xy 111 | | WindowEvent_Resized of window_event_xy 112 | | WindowEvent_Size_Changed of window_event_xy 113 | | WindowEvent_Minimized 114 | | WindowEvent_Maximized 115 | | WindowEvent_Restored 116 | | WindowEvent_Enter 117 | | WindowEvent_Leave 118 | | WindowEvent_Focus_Gained 119 | | WindowEvent_Focus_Lost 120 | | WindowEvent_Close 121 | | WindowEvent_Take_Focus 122 | | WindowEvent_Hit_Test 123 | 124 | val string_of_window_event_kind : 125 | window_event_kind -> string 126 | 127 | type window_event = { 128 | we_timestamp: int32; 129 | window_ID: int32; 130 | kind : window_event_kind; 131 | } 132 | (** {{:http://wiki.libsdl.org/SDL_WindowEvent}api doc} *) 133 | 134 | type quit_event = { 135 | quit_timestamp: int32; 136 | } 137 | 138 | 139 | type text_editing_event = { 140 | te_timestamp: int32; 141 | te_window_ID: int32; 142 | te_text: string; 143 | te_begin: int; 144 | te_length: int; 145 | } 146 | 147 | type text_input_event = { 148 | ti_timestamp: int32; 149 | ti_window_ID: int32; 150 | ti_text: string; 151 | } 152 | 153 | type t = 154 | | Quit of quit_event 155 | | Mouse_Motion of mouse_motion_event 156 | | Mouse_Button_Down of mouse_button_event 157 | | Mouse_Button_Up of mouse_button_event 158 | | Mouse_Wheel of mouse_wheel_event 159 | | KeyDown of keyboard_event 160 | | KeyUp of keyboard_event 161 | | Text_Editing of text_editing_event 162 | | Text_Input of text_input_event 163 | | Joy_Axis_Motion of joy_axis_event 164 | | Joy_Ball_Motion 165 | | Joy_Hat_Motion of joy_hat_event 166 | | Joy_Button_Down of joy_button_event 167 | | Joy_Button_Up of joy_button_event 168 | | Joy_Device_Added of joy_device_event 169 | | Joy_Device_Removed of joy_device_event 170 | | Controller_Axis_Motion 171 | | Controller_Button_Down 172 | | Controller_Button_Up 173 | | Controller_Device_Added 174 | | Controller_Device_Removed 175 | | Controller_Device_Remapped 176 | | Finger_Down 177 | | Finger_Up 178 | | Finger_Motion 179 | | Dollar_Gesture 180 | | Dollar_Record 181 | | Multi_Gesture 182 | | Clipboard_Update 183 | | Drop_File 184 | | User_Event 185 | | Window_Event of window_event 186 | | SysWM_Event 187 | | APP_Terminating 188 | | APP_LowMemory 189 | | APP_Will_Enter_Background 190 | | APP_Did_Enter_Background 191 | | APP_Will_Enter_Foreground 192 | | APP_Did_Enter_Foreground 193 | | Display_Event 194 | | Keymap_Changed 195 | | Drop_Text 196 | | Drop_Begin 197 | | Drop_Complete 198 | | Audio_Device_Added 199 | | Audio_Device_Removed 200 | | Sensor_Update 201 | | Render_Targets_Reset 202 | | Render_Device_Reset 203 | 204 | 205 | external poll_event : unit -> t option 206 | = "caml_SDL_PollEvent" 207 | (** {{:http://wiki.libsdl.org/SDL_PollEvent}api doc} *) 208 | 209 | val to_string : t -> string 210 | 211 | -------------------------------------------------------------------------------- /src/sdlfilesystem.ml: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2014 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (* Filesystem Paths *) 12 | 13 | external get_base_path : unit -> string 14 | = "caml_SDL_GetBasePath" 15 | 16 | external get_pref_path : org:string -> app:string -> string 17 | = "caml_SDL_GetPrefPath" 18 | 19 | -------------------------------------------------------------------------------- /src/sdlfilesystem.mli: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2014 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (** Filesystem Paths *) 12 | 13 | (** API Doc: 14 | {{:http://wiki.libsdl.org/CategoryFilesystem}Filesystem category} *) 15 | 16 | external get_base_path : unit -> string = "caml_SDL_GetBasePath" 17 | (** {{:http://wiki.libsdl.org/SDL_GetBasePath}api doc} *) 18 | 19 | external get_pref_path : org:string -> app:string -> string 20 | = "caml_SDL_GetPrefPath" 21 | (** {{:http://wiki.libsdl.org/SDL_GetPrefPath}api doc} *) 22 | 23 | -------------------------------------------------------------------------------- /src/sdlfilesystem_stub.c: -------------------------------------------------------------------------------- 1 | /* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2014 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | */ 11 | #define CAML_NAME_SPACE 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | 19 | CAMLprim value 20 | caml_SDL_GetBasePath(value unit) 21 | { 22 | CAMLparam0(); 23 | CAMLlocal1(ret); 24 | char *base_path = SDL_GetBasePath(); 25 | if (base_path == NULL) 26 | caml_failwith("Sdlfilesystem.get_base_path"); 27 | ret = caml_copy_string(base_path); 28 | SDL_free(base_path); 29 | CAMLreturn(ret); 30 | } 31 | 32 | CAMLprim value 33 | caml_SDL_GetPrefPath(value org, value app) 34 | { 35 | CAMLparam0(); 36 | CAMLlocal1(ret); 37 | char *pref_path = SDL_GetPrefPath(String_val(org), String_val(app)); 38 | if (pref_path == NULL) 39 | caml_failwith("Sdlfilesystem.get_pref_path"); 40 | ret = caml_copy_string(pref_path); 41 | SDL_free(pref_path); 42 | CAMLreturn(ret); 43 | } 44 | 45 | /* vim: set ts=4 sw=4 et: */ 46 | -------------------------------------------------------------------------------- /src/sdlgl.ml: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (* OpenGL windowing *) 12 | 13 | type context 14 | 15 | external create_context : win:Sdlwindow.t -> context 16 | = "caml_SDL_GL_CreateContext" 17 | 18 | external make_current : 19 | win:Sdlwindow.t -> ctx:context -> int 20 | = "caml_SDL_GL_MakeCurrent" 21 | 22 | external unload_library : unit -> unit 23 | = "caml_SDL_GL_UnloadLibrary" 24 | 25 | external extension_supported : extension:string -> bool 26 | = "caml_SDL_GL_ExtensionSupported" 27 | 28 | external set_swap_interval : interval:int -> unit 29 | = "caml_SDL_GL_SetSwapInterval" 30 | 31 | external get_swap_interval : unit -> int 32 | = "caml_SDL_GL_GetSwapInterval" 33 | 34 | external swap_window : Sdlwindow.t -> unit 35 | = "caml_SDL_GL_SwapWindow" 36 | 37 | external delete_context : context -> unit 38 | = "caml_SDL_GL_DeleteContext" 39 | 40 | type gl_attr = 41 | | GL_RED_SIZE 42 | | GL_GREEN_SIZE 43 | | GL_BLUE_SIZE 44 | | GL_ALPHA_SIZE 45 | | GL_BUFFER_SIZE 46 | | GL_DOUBLEBUFFER 47 | | GL_DEPTH_SIZE 48 | | GL_STENCIL_SIZE 49 | | GL_ACCUM_RED_SIZE 50 | | GL_ACCUM_GREEN_SIZE 51 | | GL_ACCUM_BLUE_SIZE 52 | | GL_ACCUM_ALPHA_SIZE 53 | | GL_STEREO 54 | | GL_MULTISAMPLEBUFFERS 55 | | GL_MULTISAMPLESAMPLES 56 | | GL_ACCELERATED_VISUAL 57 | | GL_RETAINED_BACKING 58 | | GL_CONTEXT_MAJOR_VERSION 59 | | GL_CONTEXT_MINOR_VERSION 60 | | GL_CONTEXT_EGL 61 | | GL_CONTEXT_FLAGS 62 | | GL_CONTEXT_PROFILE_MASK 63 | | GL_SHARE_WITH_CURRENT_CONTEXT 64 | 65 | external set_attribute : gl_attr -> int -> unit 66 | = "caml_SDL_GL_SetAttribute" 67 | 68 | external get_attribute : gl_attr -> int 69 | = "caml_SDL_GL_GetAttribute" 70 | 71 | -------------------------------------------------------------------------------- /src/sdlgl.mli: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (** OpenGL windowing *) 12 | (** This module provides windowing for OpenGL applications *) 13 | 14 | (** API Doc: 15 | {{:http://wiki.libsdl.org/CategoryVideo}Video category} *) 16 | 17 | type context 18 | 19 | external create_context : win:Sdlwindow.t -> context 20 | = "caml_SDL_GL_CreateContext" 21 | (** {{:http://wiki.libsdl.org/SDL_GL_CreateContext}api doc} *) 22 | 23 | external make_current : 24 | win:Sdlwindow.t -> ctx:context -> int 25 | = "caml_SDL_GL_MakeCurrent" 26 | (** {{:http://wiki.libsdl.org/SDL_GL_MakeCurrent}api doc} *) 27 | 28 | external unload_library : unit -> unit 29 | = "caml_SDL_GL_UnloadLibrary" 30 | (** {{:http://wiki.libsdl.org/SDL_GL_UnloadLibrary}api doc} *) 31 | 32 | external extension_supported : extension:string -> bool 33 | = "caml_SDL_GL_ExtensionSupported" 34 | (** {{:http://wiki.libsdl.org/SDL_GL_ExtensionSupported}api doc} *) 35 | 36 | external set_swap_interval : interval:int -> unit 37 | = "caml_SDL_GL_SetSwapInterval" 38 | (** {{:http://wiki.libsdl.org/SDL_GL_SetSwapInterval}api doc} *) 39 | 40 | external get_swap_interval : unit -> int 41 | = "caml_SDL_GL_GetSwapInterval" 42 | (** {{:http://wiki.libsdl.org/SDL_GL_GetSwapInterval}api doc} *) 43 | 44 | external swap_window : Sdlwindow.t -> unit 45 | = "caml_SDL_GL_SwapWindow" 46 | (** {{:http://wiki.libsdl.org/SDL_GL_SwapWindow}api doc} *) 47 | 48 | external delete_context : context -> unit 49 | = "caml_SDL_GL_DeleteContext" 50 | (** {{:http://wiki.libsdl.org/SDL_GL_DeleteContext}api doc} *) 51 | 52 | (** {{:http://wiki.libsdl.org/SDL_GLattr}api doc} *) 53 | type gl_attr = 54 | | GL_RED_SIZE 55 | | GL_GREEN_SIZE 56 | | GL_BLUE_SIZE 57 | | GL_ALPHA_SIZE 58 | | GL_BUFFER_SIZE 59 | | GL_DOUBLEBUFFER 60 | | GL_DEPTH_SIZE 61 | | GL_STENCIL_SIZE 62 | | GL_ACCUM_RED_SIZE 63 | | GL_ACCUM_GREEN_SIZE 64 | | GL_ACCUM_BLUE_SIZE 65 | | GL_ACCUM_ALPHA_SIZE 66 | | GL_STEREO 67 | | GL_MULTISAMPLEBUFFERS 68 | | GL_MULTISAMPLESAMPLES 69 | | GL_ACCELERATED_VISUAL 70 | | GL_RETAINED_BACKING 71 | | GL_CONTEXT_MAJOR_VERSION 72 | | GL_CONTEXT_MINOR_VERSION 73 | | GL_CONTEXT_EGL 74 | | GL_CONTEXT_FLAGS 75 | | GL_CONTEXT_PROFILE_MASK 76 | | GL_SHARE_WITH_CURRENT_CONTEXT 77 | 78 | external set_attribute : gl_attr -> int -> unit 79 | = "caml_SDL_GL_SetAttribute" 80 | (** {{:http://wiki.libsdl.org/SDL_GL_SetAttribute}api doc} *) 81 | 82 | external get_attribute : gl_attr -> int 83 | = "caml_SDL_GL_GetAttribute" 84 | (** {{:http://wiki.libsdl.org/SDL_GL_GetAttribute}api doc} *) 85 | 86 | -------------------------------------------------------------------------------- /src/sdlgl_stub.c: -------------------------------------------------------------------------------- 1 | /* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | */ 11 | #define CAML_NAME_SPACE 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | #include "sdlwindow_stub.h" 19 | 20 | /* TODO 21 | int SDL_GL_LoadLibrary(const char *path); 22 | void * SDL_GL_GetProcAddress(const char *proc); 23 | */ 24 | 25 | CAMLprim value 26 | caml_SDL_GL_UnloadLibrary(value unit) 27 | { 28 | SDL_GL_UnloadLibrary(); 29 | return Val_unit; 30 | } 31 | 32 | CAMLprim value 33 | caml_SDL_GL_ExtensionSupported(value extension) 34 | { 35 | SDL_bool b = SDL_GL_ExtensionSupported(String_val(extension)); 36 | return Val_bool(b); 37 | } 38 | 39 | static const SDL_GLattr ocaml_sdl_glattr_table[] = { 40 | SDL_GL_RED_SIZE, 41 | SDL_GL_GREEN_SIZE, 42 | SDL_GL_BLUE_SIZE, 43 | SDL_GL_ALPHA_SIZE, 44 | SDL_GL_BUFFER_SIZE, 45 | SDL_GL_DOUBLEBUFFER, 46 | SDL_GL_DEPTH_SIZE, 47 | SDL_GL_STENCIL_SIZE, 48 | SDL_GL_ACCUM_RED_SIZE, 49 | SDL_GL_ACCUM_GREEN_SIZE, 50 | SDL_GL_ACCUM_BLUE_SIZE, 51 | SDL_GL_ACCUM_ALPHA_SIZE, 52 | SDL_GL_STEREO, 53 | SDL_GL_MULTISAMPLEBUFFERS, 54 | SDL_GL_MULTISAMPLESAMPLES, 55 | SDL_GL_ACCELERATED_VISUAL, 56 | SDL_GL_RETAINED_BACKING, 57 | SDL_GL_CONTEXT_MAJOR_VERSION, 58 | SDL_GL_CONTEXT_MINOR_VERSION, 59 | SDL_GL_CONTEXT_EGL, 60 | SDL_GL_CONTEXT_FLAGS, 61 | SDL_GL_CONTEXT_PROFILE_MASK, 62 | SDL_GL_SHARE_WITH_CURRENT_CONTEXT 63 | }; 64 | #define SDL_GLattr_val(v) \ 65 | ocaml_sdl_glattr_table[Long_val(v)] 66 | 67 | CAMLprim value 68 | caml_SDL_GL_SetAttribute( 69 | value attr, value val) 70 | { 71 | int r = 72 | SDL_GL_SetAttribute( 73 | SDL_GLattr_val(attr), 74 | Int_val(val)); 75 | if (r) caml_failwith("Sdlgl.set_attribute"); 76 | return Val_unit; 77 | } 78 | 79 | CAMLprim value 80 | caml_SDL_GL_GetAttribute( 81 | value attr) 82 | { 83 | int val; 84 | int r = 85 | SDL_GL_GetAttribute( 86 | SDL_GLattr_val(attr), 87 | &val); 88 | if (r) caml_failwith("Sdlgl.get_attribute"); 89 | return Val_int(val); 90 | } 91 | 92 | // SDL_GLContext is an alias for void* 93 | static value Val_SDL_GLContext(SDL_GLContext p) 94 | { 95 | return caml_copy_nativeint((intnat) p); 96 | } 97 | 98 | static SDL_GLContext SDL_GLContext_val(value v) 99 | { 100 | return (SDL_GLContext) Nativeint_val(v); 101 | } 102 | 103 | CAMLprim value 104 | caml_SDL_GL_CreateContext(value window) 105 | { 106 | SDL_GLContext ctx = SDL_GL_CreateContext(SDL_Window_val(window)); 107 | return Val_SDL_GLContext(ctx); 108 | } 109 | 110 | CAMLprim value 111 | caml_SDL_GL_MakeCurrent(value window, value context) 112 | { 113 | int r = SDL_GL_MakeCurrent( 114 | SDL_Window_val(window), SDL_GLContext_val(context)); 115 | return Val_int(r); 116 | } 117 | 118 | CAMLprim value 119 | caml_SDL_GL_SetSwapInterval(value interval) 120 | { 121 | int r = SDL_GL_SetSwapInterval(Int_val(interval)); 122 | if (r) caml_failwith("Sdlgl.set_swap_interval"); 123 | return Val_unit; 124 | } 125 | 126 | CAMLprim value 127 | caml_SDL_GL_GetSwapInterval(value unit) 128 | { 129 | int r = SDL_GL_GetSwapInterval(); 130 | return Val_int(r); 131 | } 132 | 133 | CAMLprim value 134 | caml_SDL_GL_SwapWindow(value window) 135 | { 136 | SDL_GL_SwapWindow(SDL_Window_val(window)); 137 | return Val_unit; 138 | } 139 | 140 | CAMLprim value 141 | caml_SDL_GL_DeleteContext(value context) 142 | { 143 | SDL_GL_DeleteContext(SDL_GLContext_val(context)); 144 | return Val_unit; 145 | } 146 | 147 | /* vim: set ts=4 sw=4 et: */ 148 | -------------------------------------------------------------------------------- /src/sdlhat.ml: -------------------------------------------------------------------------------- 1 | type positions = { 2 | left: bool; 3 | right: bool; 4 | up: bool; 5 | down: bool; 6 | } 7 | 8 | let string_of_pos p = 9 | let lst = [] in 10 | let lst = if p.down then "Down"::lst else lst in 11 | let lst = if p.up then "Up"::lst else lst in 12 | let lst = if p.right then "Right"::lst else lst in 13 | let lst = if p.left then "Left"::lst else lst in 14 | (String.concat " " lst) 15 | 16 | type direction = 17 | | Centered 18 | | Up 19 | | Right 20 | | Down 21 | | Left 22 | | Right_Up 23 | | Right_Down 24 | | Left_Up 25 | | Left_Down 26 | 27 | let string_of_dir = function 28 | | Centered -> "Centered" 29 | | Up -> "Up" 30 | | Right -> "Right" 31 | | Down -> "Down" 32 | | Left -> "Left" 33 | | Right_Up -> "Right_Up" 34 | | Right_Down -> "Right_Down" 35 | | Left_Up -> "Left_Up" 36 | | Left_Down -> "Left_Down" 37 | 38 | let dir_of_string s = 39 | match String.lowercase_ascii s with 40 | | "centered" -> Centered 41 | | "up" -> Up 42 | | "right" -> Right 43 | | "down" -> Down 44 | | "left" -> Left 45 | | "right_up" -> Right_Up 46 | | "right_down" -> Right_Down 47 | | "left_up" -> Left_Up 48 | | "left_down" -> Left_Down 49 | | _ -> invalid_arg "of_string" 50 | -------------------------------------------------------------------------------- /src/sdlhat.mli: -------------------------------------------------------------------------------- 1 | (** Joystick Hat *) 2 | 3 | type positions = { 4 | left: bool; 5 | right: bool; 6 | up: bool; 7 | down: bool; 8 | } 9 | 10 | val string_of_pos : positions -> string 11 | 12 | type direction = 13 | | Centered 14 | | Up 15 | | Right 16 | | Down 17 | | Left 18 | | Right_Up 19 | | Right_Down 20 | | Left_Up 21 | | Left_Down 22 | 23 | val string_of_dir : direction -> string 24 | val dir_of_string : string -> direction 25 | -------------------------------------------------------------------------------- /src/sdlhint.mli: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2022 Carsten Elton Sørensen 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | 12 | (** Hint kind *) 13 | 14 | (** {{:https://wiki.libsdl.org/CategoryHints}api doc} *) 15 | 16 | type t = 17 | | AccelerometerAsJoystick 18 | | AndroidApkExpansionMainFileVersion 19 | | AndroidApkExpansionPatchFileVersion 20 | | AndroidSeparateMouseAndTouch 21 | | AppleTvControllerUiEvents 22 | | AppleTvRemoteAllowRotation 23 | | BmpSaveLegacyFormat 24 | | EmscriptenAsyncify 25 | | EmscriptenKeyboardElement 26 | | FramebufferAcceleration 27 | | Gamecontrollerconfig 28 | | GrabKeyboard 29 | | IdleTimerDisabled 30 | | ImeInternalEditing 31 | | JoystickAllowBackgroundEvents 32 | | MacBackgroundApp 33 | | MacCtrlClickEmulateRightClick 34 | | MouseFocusClickthrough 35 | | MouseRelativeModeWarp 36 | | MouseRelativeScaling 37 | | NoSignalHandlers 38 | | Orientations 39 | | RenderDirect3d11Debug 40 | | RenderDirect3dThreadsafe 41 | | RenderDriver 42 | | RenderOpenglShaders 43 | | RenderScaleQuality 44 | | RenderVsync 45 | | RpiVideoLayer 46 | | ThreadStackSize 47 | | TimerResolution 48 | | VideoAllowScreensaver 49 | | VideoHighdpiDisabled 50 | | VideoMacFullscreenSpaces 51 | | VideoMinimizeOnFocusLoss 52 | | VideoWinD3dcompiler 53 | | VideoWindowSharePixelFormat 54 | | VideoX11NetWmPing 55 | | VideoX11Xinerama 56 | | VideoX11Xrandr 57 | | VideoX11Xvidmode 58 | | WindowFrameUsableWhileCursorHidden 59 | | WindowsDisableThreadNaming 60 | | WindowsEnableMessageloop 61 | | WindowsNoCloseOnAltF4 62 | | WinrtHandleBackButton 63 | | WinrtPrivacyPolicyLabel 64 | | WinrtPrivacyPolicyUrl 65 | | XinputEnabled 66 | | XinputUseOldJoystickMapping 67 | 68 | (** {{:http://wiki.libsdl.org/SDL_HintPriority}api doc} *) 69 | type priority = 70 | | Default 71 | | Normal 72 | | Override 73 | 74 | val to_string : t -> string 75 | val of_string : string -> t 76 | 77 | val set: t -> string -> bool 78 | (** {{:http://wiki.libsdl.org/SDL_SetHint}api doc} *) 79 | 80 | val set_with_priority: t -> string -> priority -> bool 81 | (** {{:http://wiki.libsdl.org/SDL_SetHintWithPriority}api doc} *) 82 | -------------------------------------------------------------------------------- /src/sdlhint_stub.c: -------------------------------------------------------------------------------- 1 | /* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2022 Carsten Elton Sørensen 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | */ 11 | #define CAML_NAME_SPACE 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | 19 | CAMLprim value 20 | caml_SDL_SetHint(value hint, value v) 21 | { 22 | SDL_bool r = 23 | SDL_SetHint( 24 | String_val(hint), 25 | String_val(v)); 26 | 27 | return Val_bool(r); 28 | } 29 | 30 | CAMLprim value 31 | caml_SDL_SetHintWithPriority(value hint, value v, value prio) 32 | { 33 | SDL_bool r = 34 | SDL_SetHintWithPriority( 35 | String_val(hint), 36 | String_val(v), 37 | Int_val(prio)); 38 | 39 | return Val_bool(r); 40 | } 41 | 42 | /* vim: set ts=4 sw=4 et: */ 43 | -------------------------------------------------------------------------------- /src/sdlinit.ml: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (** Initialisation *) 12 | 13 | type subsystem = [ 14 | | `TIMER 15 | | `AUDIO 16 | | `VIDEO 17 | | `JOYSTICK 18 | | `HAPTIC 19 | | `GAMECONTROLLER 20 | | `EVENTS 21 | ] 22 | 23 | external init : 24 | [< subsystem | `EVERYTHING | `NOPARACHUTE ] list -> unit 25 | = "caml_SDL_Init" 26 | 27 | external init_subsystem : subsystem list -> unit = "caml_SDL_InitSubSystem" 28 | -------------------------------------------------------------------------------- /src/sdlinit.mli: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (** Initialisation *) 12 | 13 | type subsystem = [ 14 | | `TIMER 15 | | `AUDIO 16 | | `VIDEO 17 | | `JOYSTICK 18 | | `HAPTIC 19 | | `GAMECONTROLLER 20 | | `EVENTS 21 | ] 22 | 23 | external init : 24 | [< subsystem | `EVERYTHING | `NOPARACHUTE ] list -> unit 25 | = "caml_SDL_Init" 26 | (** {{:https://wiki.libsdl.org/SDL_Init}api doc} *) 27 | 28 | 29 | external init_subsystem : subsystem list -> unit = "caml_SDL_InitSubSystem" 30 | (** {{:https://wiki.libsdl.org/SDL_InitSubSystem}api doc} *) 31 | 32 | -------------------------------------------------------------------------------- /src/sdlinit_stub.c: -------------------------------------------------------------------------------- 1 | /* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | */ 11 | #define CAML_NAME_SPACE 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | int main(int argc, char *argv[]) 20 | { 21 | caml_main(argv); 22 | return 0; 23 | } 24 | 25 | static inline Uint32 26 | sdlinit_val(value v) 27 | { 28 | if (v == caml_hash_variant("TIMER")) return SDL_INIT_TIMER; 29 | if (v == caml_hash_variant("AUDIO")) return SDL_INIT_AUDIO; 30 | if (v == caml_hash_variant("VIDEO")) return SDL_INIT_VIDEO; 31 | if (v == caml_hash_variant("JOYSTICK")) return SDL_INIT_JOYSTICK; 32 | if (v == caml_hash_variant("HAPTIC")) return SDL_INIT_HAPTIC; 33 | if (v == caml_hash_variant("GAMECONTROLLER")) return SDL_INIT_GAMECONTROLLER; 34 | if (v == caml_hash_variant("EVENTS")) return SDL_INIT_EVENTS; 35 | if (v == caml_hash_variant("EVERYTHING")) return SDL_INIT_EVERYTHING; 36 | if (v == caml_hash_variant("NOPARACHUTE")) return SDL_INIT_NOPARACHUTE; 37 | return 0x00000000; 38 | } 39 | 40 | static inline Uint32 41 | Sdl_init_val(value mask_list) 42 | { 43 | Uint32 c_mask = 0; 44 | while (mask_list != Val_emptylist) 45 | { 46 | value head = Field(mask_list, 0); 47 | c_mask |= sdlinit_val(head); 48 | mask_list = Field(mask_list, 1); 49 | } 50 | return c_mask; 51 | } 52 | 53 | CAMLprim value 54 | caml_SDL_Init(value init_flags) 55 | { 56 | int r = SDL_Init(Sdl_init_val(init_flags)); 57 | if (r < 0) caml_failwith("Sdl.init"); 58 | return Val_unit; 59 | } 60 | 61 | CAMLprim value 62 | caml_SDL_InitSubSystem(value init_flags) 63 | { 64 | int r = SDL_InitSubSystem(Sdl_init_val(init_flags)); 65 | if (r < 0) caml_failwith("Sdl.init_subsystem"); 66 | return Val_unit; 67 | } 68 | 69 | /* TODO 70 | Uint32 SDL_WasInit(Uint32 flags); 71 | */ 72 | 73 | /* vim: set ts=4 sw=4 et: */ 74 | -------------------------------------------------------------------------------- /src/sdljoystick.ml: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (* Joystick event handling *) 12 | 13 | type t 14 | 15 | external num_joysticks : unit -> int 16 | = "caml_SDL_NumJoysticks" 17 | 18 | external name_for_index : device_index:int -> string 19 | = "caml_SDL_JoystickNameForIndex" 20 | 21 | external j_open : device_index:int -> t 22 | = "caml_SDL_JoystickOpen" 23 | 24 | external close : t -> unit 25 | = "caml_SDL_JoystickClose" 26 | 27 | external num_axes : t -> int 28 | = "caml_SDL_JoystickNumAxes" 29 | 30 | external num_hats : t -> int 31 | = "caml_SDL_JoystickNumHats" 32 | 33 | external get_axis : t -> axis:int -> int 34 | = "caml_SDL_JoystickGetAxis" 35 | 36 | external get_button : t -> button:int -> int 37 | = "caml_SDL_JoystickGetButton" 38 | -------------------------------------------------------------------------------- /src/sdljoystick.mli: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (** Joystick event handling *) 12 | 13 | (** API Doc: 14 | {{:http://wiki.libsdl.org/CategoryJoystick}Joystick category} *) 15 | 16 | type t 17 | 18 | external num_joysticks : unit -> int 19 | = "caml_SDL_NumJoysticks" 20 | (** {{:http://wiki.libsdl.org/SDL_NumJoysticks}api doc} *) 21 | 22 | external name_for_index : device_index:int -> string 23 | = "caml_SDL_JoystickNameForIndex" 24 | (** {{:http://wiki.libsdl.org/SDL_JoystickNameForIndex}api doc} *) 25 | 26 | external j_open : device_index:int -> t 27 | = "caml_SDL_JoystickOpen" 28 | (** {{:http://wiki.libsdl.org/SDL_JoystickOpen}api doc} *) 29 | 30 | external close : t -> unit 31 | = "caml_SDL_JoystickClose" 32 | (** {{:http://wiki.libsdl.org/SDL_JoystickClose}api doc} *) 33 | 34 | external num_axes : t -> int 35 | = "caml_SDL_JoystickNumAxes" 36 | (** {{:http://wiki.libsdl.org/SDL_JoystickNumAxes}api doc} *) 37 | 38 | external num_hats : t -> int 39 | = "caml_SDL_JoystickNumHats" 40 | (** {{:http://wiki.libsdl.org/SDL_JoystickNumHats}api doc} *) 41 | 42 | external get_axis : t -> axis:int -> int 43 | = "caml_SDL_JoystickGetAxis" 44 | (** {{:http://wiki.libsdl.org/SDL_JoystickGetAxis}api doc} *) 45 | 46 | external get_button : t -> button:int -> int 47 | = "caml_SDL_JoystickGetButton" 48 | (** {{:http://wiki.libsdl.org/SDL_JoystickGetButton}api doc} *) 49 | 50 | -------------------------------------------------------------------------------- /src/sdljoystick_stub.c: -------------------------------------------------------------------------------- 1 | /* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | */ 11 | #define CAML_NAME_SPACE 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | 19 | CAMLprim value 20 | caml_SDL_NumJoysticks(value unit) 21 | { 22 | int num = SDL_NumJoysticks(); 23 | return Val_int(num); 24 | } 25 | 26 | CAMLprim value 27 | caml_SDL_JoystickNameForIndex(value device_index) 28 | { 29 | const char *name = SDL_JoystickNameForIndex(Int_val(device_index)); 30 | return caml_copy_string(name); 31 | } 32 | 33 | static value Val_SDL_Joystick(SDL_Joystick * p) 34 | { 35 | return caml_copy_nativeint((intnat) p); 36 | } 37 | 38 | static SDL_Joystick * SDL_Joystick_val(value v) 39 | { 40 | return (SDL_Joystick *) Nativeint_val(v); 41 | } 42 | 43 | CAMLprim value 44 | caml_SDL_JoystickOpen(value device_index) 45 | { 46 | SDL_Joystick *joy = SDL_JoystickOpen(Int_val(device_index)); 47 | return Val_SDL_Joystick(joy); 48 | } 49 | 50 | CAMLprim value 51 | caml_SDL_JoystickClose(value joystick) 52 | { 53 | SDL_JoystickClose(SDL_Joystick_val(joystick)); 54 | return Val_unit; 55 | } 56 | 57 | CAMLprim value 58 | caml_SDL_JoystickNumAxes(value joystick) 59 | { 60 | int num = SDL_JoystickNumAxes( 61 | SDL_Joystick_val(joystick)); 62 | return Val_int(num); 63 | } 64 | 65 | CAMLprim value 66 | caml_SDL_JoystickNumHats(value joystick) 67 | { 68 | int num = SDL_JoystickNumHats(SDL_Joystick_val(joystick)); 69 | return Val_int(num); 70 | } 71 | 72 | CAMLprim value 73 | caml_SDL_JoystickGetAxis(value joystick, value axis) 74 | { 75 | Sint16 state = SDL_JoystickGetAxis( 76 | SDL_Joystick_val(joystick), 77 | Int_val(axis)); 78 | return Val_int(state); 79 | } 80 | 81 | CAMLprim value 82 | caml_SDL_JoystickGetButton(value joystick, value button) 83 | { 84 | Uint8 state = SDL_JoystickGetButton( 85 | SDL_Joystick_val(joystick), 86 | Int_val(button)); 87 | return Val_int(state); 88 | } 89 | 90 | /* vim: set ts=4 sw=4 et: */ 91 | -------------------------------------------------------------------------------- /src/sdlkeyboard.ml: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (* Keyboard management *) 12 | 13 | external start_text_input : unit -> unit 14 | = "caml_SDL_StartTextInput" 15 | 16 | external stop_text_input : unit -> unit 17 | = "caml_SDL_StopTextInput" 18 | 19 | external is_text_input_active : unit -> bool 20 | = "caml_SDL_IsTextInputActive" 21 | 22 | external set_text_input_rect : Sdlrect.t -> unit 23 | = "caml_SDL_SetTextInputRect" 24 | 25 | external has_screen_keyboard_support : unit -> bool 26 | = "caml_SDL_HasScreenKeyboardSupport" 27 | -------------------------------------------------------------------------------- /src/sdlkeyboard.mli: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (** Keyboard management *) 12 | 13 | (** API Doc: 14 | {{:http://wiki.libsdl.org/CategoryKeyboard}Keyboard category} *) 15 | 16 | external start_text_input : unit -> unit 17 | = "caml_SDL_StartTextInput" 18 | (** {{:http://wiki.libsdl.org/SDL_StartTextInput}api doc} *) 19 | 20 | external stop_text_input : unit -> unit 21 | = "caml_SDL_StopTextInput" 22 | (** {{:http://wiki.libsdl.org/SDL_StopTextInput}api doc} *) 23 | 24 | external is_text_input_active : unit -> bool 25 | = "caml_SDL_IsTextInputActive" 26 | 27 | external set_text_input_rect : Sdlrect.t -> unit 28 | = "caml_SDL_SetTextInputRect" 29 | (** {{:http://wiki.libsdl.org/SDL_SetTextInputRect}api doc} *) 30 | 31 | external has_screen_keyboard_support : unit -> bool 32 | = "caml_SDL_HasScreenKeyboardSupport" 33 | (** {{:http://wiki.libsdl.org/SDL_HasScreenKeyboardSupport}api doc} *) 34 | 35 | -------------------------------------------------------------------------------- /src/sdlkeyboard_stub.c: -------------------------------------------------------------------------------- 1 | /* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | */ 11 | #define CAML_NAME_SPACE 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | #include "sdlrect_stub.h" 19 | 20 | CAMLprim value 21 | caml_SDL_StartTextInput(value unit) 22 | { 23 | SDL_StartTextInput(); 24 | return Val_unit; 25 | } 26 | 27 | CAMLprim value 28 | caml_SDL_StopTextInput(value unit) 29 | { 30 | SDL_StopTextInput(); 31 | return Val_unit; 32 | } 33 | 34 | CAMLprim value 35 | caml_SDL_IsTextInputActive(value unit) 36 | { 37 | SDL_bool b = SDL_IsTextInputActive(); 38 | return Val_bool(b); 39 | } 40 | 41 | CAMLprim value 42 | caml_SDL_SetTextInputRect(value _rect) 43 | { 44 | SDL_Rect rect; 45 | SDL_Rect_val(&rect, _rect); 46 | SDL_SetTextInputRect(&rect); 47 | return Val_unit; 48 | } 49 | 50 | CAMLprim value 51 | caml_SDL_HasScreenKeyboardSupport(value unit) 52 | { 53 | SDL_bool b = SDL_HasScreenKeyboardSupport(); 54 | return Val_bool(b); 55 | } 56 | 57 | /* vim: set ts=4 sw=4 et: */ 58 | -------------------------------------------------------------------------------- /src/sdlkeycode.mli: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (** Keyboard keys and modifiers *) 12 | 13 | (** API Doc: 14 | {{:http://wiki.libsdl.org/SDL_Keycode}SDL_Keycode} *) 15 | 16 | type t = 17 | | Unknown 18 | | Return 19 | | Escape 20 | | Backspace 21 | | Tab 22 | | Space 23 | | Exclaim 24 | | QuoteDBL 25 | | Hash 26 | | Percent 27 | | Dollar 28 | | Ampersand 29 | | Quote 30 | | LeftParen 31 | | RightParen 32 | | Asterisk 33 | | Plus 34 | | Comma 35 | | Minus 36 | | Period 37 | | Slash 38 | | Num0 39 | | Num1 40 | | Num2 41 | | Num3 42 | | Num4 43 | | Num5 44 | | Num6 45 | | Num7 46 | | Num8 47 | | Num9 48 | | Colon 49 | | SemiColon 50 | | Less 51 | | Equals 52 | | Greater 53 | | Question 54 | | At 55 | | LeftBracket 56 | | BackSlash 57 | | RightBracket 58 | | Caret 59 | | Underscore 60 | | BackQuote 61 | | A 62 | | B 63 | | C 64 | | D 65 | | E 66 | | F 67 | | G 68 | | H 69 | | I 70 | | J 71 | | K 72 | | L 73 | | M 74 | | N 75 | | O 76 | | P 77 | | Q 78 | | R 79 | | S 80 | | T 81 | | U 82 | | V 83 | | W 84 | | X 85 | | Y 86 | | Z 87 | | CapsLock 88 | | F1 89 | | F2 90 | | F3 91 | | F4 92 | | F5 93 | | F6 94 | | F7 95 | | F8 96 | | F9 97 | | F10 98 | | F11 99 | | F12 100 | | PrintScreen 101 | | ScrollLock 102 | | Pause 103 | | Insert 104 | | Home 105 | | PageUp 106 | | Delete 107 | | End 108 | | PageDown 109 | | Right 110 | | Left 111 | | Down 112 | | Up 113 | | NumLockClear 114 | | KP_Divide 115 | | KP_Multiply 116 | | KP_Minus 117 | | KP_Plus 118 | | KP_Enter 119 | | KP_1 120 | | KP_2 121 | | KP_3 122 | | KP_4 123 | | KP_5 124 | | KP_6 125 | | KP_7 126 | | KP_8 127 | | KP_9 128 | | KP_0 129 | | KP_Period 130 | | Application 131 | | Power 132 | | KP_Equals 133 | | F13 134 | | F14 135 | | F15 136 | | F16 137 | | F17 138 | | F18 139 | | F19 140 | | F20 141 | | F21 142 | | F22 143 | | F23 144 | | F24 145 | | Execute 146 | | Help 147 | | Menu 148 | | Select 149 | | Stop 150 | | Again 151 | | Undo 152 | | Cut 153 | | Copy 154 | | Paste 155 | | Find 156 | | Mute 157 | | VolumeUp 158 | | VolumeDown 159 | | KP_Comma 160 | | KP_EqualsAs400 161 | | ALTERASE 162 | | SYSREQ 163 | | CANCEL 164 | | CLEAR 165 | | PRIOR 166 | | RETURN2 167 | | SEPARATOR 168 | | OUT 169 | | OPER 170 | | CLEARAGAIN 171 | | CRSEL 172 | | EXSEL 173 | | KP_00 174 | | KP_000 175 | | ThousandsSeparator 176 | | DecimalSeparator 177 | | CurrencyUnit 178 | | CurrencySubunit 179 | | KP_LeftParen 180 | | KP_RightParen 181 | | KP_LeftBrace 182 | | KP_RightBrace 183 | | KP_Tab 184 | | KP_Backspace 185 | | KP_A 186 | | KP_B 187 | | KP_C 188 | | KP_D 189 | | KP_E 190 | | KP_F 191 | | KP_Xor 192 | | KP_Power 193 | | KP_Percent 194 | | KP_Less 195 | | KP_Greater 196 | | KP_Ampersand 197 | | KP_DBLAmpersand 198 | | KP_VerticalBar 199 | | KP_DBLVerticalBar 200 | | KP_Colon 201 | | KP_Hash 202 | | KP_Space 203 | | KP_At 204 | | KP_Exclam 205 | | KP_MemStore 206 | | KP_MemRecall 207 | | KP_MemClear 208 | | KP_MemAdd 209 | | KP_MemSubtract 210 | | KP_MemMultiply 211 | | KP_MemDivide 212 | | KP_PlusMinus 213 | | KP_Clear 214 | | KP_Clearentry 215 | | KP_Binary 216 | | KP_Octal 217 | | KP_Decimal 218 | | KP_Hexadecimal 219 | | LCtrl 220 | | LShift 221 | | LAlt 222 | | LGui 223 | | RCtrl 224 | | RShift 225 | | RAlt 226 | | RGUI 227 | | MODE 228 | | AudioNext 229 | | AudioPrev 230 | | AudioStop 231 | | AudioPlay 232 | | AudioMute 233 | | MediaSelect 234 | | WWW 235 | | Mail 236 | | Calculator 237 | | Computer 238 | | AC_Search 239 | | AC_Home 240 | | AC_Back 241 | | AC_Forward 242 | | AC_Stop 243 | | AC_Refresh 244 | | AC_Bookmarks 245 | | BrightnessDown 246 | | BrightnessUp 247 | | DisplaySwitch 248 | | KBDIllumToggle 249 | | KBDIllumDown 250 | | KBDIllumUp 251 | | Eject 252 | | Sleep 253 | 254 | val to_string : t -> string 255 | val of_string : string -> t 256 | 257 | -------------------------------------------------------------------------------- /src/sdlkeymod.ml: -------------------------------------------------------------------------------- 1 | type t = 2 | | LShift 3 | | RShift 4 | | LCtrl 5 | | RCtrl 6 | | LAlt 7 | | RAlt 8 | | LGUI 9 | | RGUI 10 | | NUM 11 | | CAPS 12 | | MODE 13 | 14 | let to_string = function 15 | | LShift -> "LShift" 16 | | RShift -> "RShift" 17 | | LCtrl -> "LCtrl" 18 | | RCtrl -> "RCtrl" 19 | | LAlt -> "LAlt" 20 | | RAlt -> "RAlt" 21 | | LGUI -> "LGUI" 22 | | RGUI -> "RGUI" 23 | | NUM -> "NUM" 24 | | CAPS -> "CAPS" 25 | | MODE -> "MODE" 26 | 27 | let of_string s = 28 | match String.lowercase_ascii s with 29 | | "lshift" -> LShift 30 | | "rshift" -> RShift 31 | | "lctrl" -> LCtrl 32 | | "rctrl" -> RCtrl 33 | | "lalt" -> LAlt 34 | | "ralt" -> RAlt 35 | | "lgui" -> LGUI 36 | | "rgui" -> RGUI 37 | | "num" -> NUM 38 | | "caps" -> CAPS 39 | | "mode" -> MODE 40 | | _ -> invalid_arg "Sdlkeymod.of_string" 41 | 42 | -------------------------------------------------------------------------------- /src/sdlkeymod.mli: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (** Key mods *) 12 | 13 | (** API Doc: 14 | {{:http://wiki.libsdl.org/SDL_Keymod}SDL_Keymod} *) 15 | 16 | type t = 17 | | LShift 18 | | RShift 19 | | LCtrl 20 | | RCtrl 21 | | LAlt 22 | | RAlt 23 | | LGUI 24 | | RGUI 25 | | NUM 26 | | CAPS 27 | | MODE 28 | 29 | val to_string : t -> string 30 | val of_string : string -> t 31 | 32 | -------------------------------------------------------------------------------- /src/sdlkeymod_stub.c: -------------------------------------------------------------------------------- 1 | /* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | */ 11 | #define CAML_NAME_SPACE 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | 19 | #define Val_LShift Val_int(0) 20 | #define Val_RShift Val_int(1) 21 | #define Val_LCtrl Val_int(2) 22 | #define Val_RCtrl Val_int(3) 23 | #define Val_LAlt Val_int(4) 24 | #define Val_RAlt Val_int(5) 25 | #define Val_LGUI Val_int(6) 26 | #define Val_RGUI Val_int(7) 27 | #define Val_NUM Val_int(8) 28 | #define Val_CAPS Val_int(9) 29 | #define Val_MODE Val_int(10) 30 | 31 | value 32 | Val_SDL_Keymod(SDL_Keymod kmod_mask) 33 | { 34 | CAMLparam0(); 35 | CAMLlocal2(li, cons); 36 | li = Val_emptylist; 37 | 38 | #define CONS_KMOD(KMOD_Mask, Val_keymod) \ 39 | if (kmod_mask & KMOD_Mask) { \ 40 | cons = caml_alloc(2, 0); \ 41 | Store_field(cons, 0, Val_keymod); \ 42 | Store_field(cons, 1, li); \ 43 | li = cons; \ 44 | } 45 | 46 | CONS_KMOD( KMOD_LSHIFT, Val_LShift ) 47 | CONS_KMOD( KMOD_RSHIFT, Val_RShift ) 48 | CONS_KMOD( KMOD_LCTRL, Val_LCtrl ) 49 | CONS_KMOD( KMOD_RCTRL, Val_RCtrl ) 50 | CONS_KMOD( KMOD_LALT, Val_LAlt ) 51 | CONS_KMOD( KMOD_RALT, Val_RAlt ) 52 | CONS_KMOD( KMOD_LGUI, Val_LGUI ) 53 | CONS_KMOD( KMOD_RGUI, Val_RGUI ) 54 | CONS_KMOD( KMOD_NUM, Val_NUM ) 55 | CONS_KMOD( KMOD_CAPS, Val_CAPS ) 56 | CONS_KMOD( KMOD_MODE, Val_MODE ) 57 | 58 | #undef CONS_KMOD 59 | CAMLreturn(li); 60 | } 61 | 62 | /* vim: set ts=4 sw=4 et: */ 63 | -------------------------------------------------------------------------------- /src/sdlkeymod_stub.h: -------------------------------------------------------------------------------- 1 | #ifndef _CAML_SDL_KEYMOD_ 2 | #define _CAML_SDL_KEYMOD_ 3 | 4 | value Val_SDL_Keymod(SDL_Keymod kmod_mask); 5 | 6 | #endif /* _CAML_SDL_KEYMOD_ */ 7 | -------------------------------------------------------------------------------- /src/sdlmouse.ml: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (* Mouse event handling *) 12 | 13 | type button = 14 | | Button_Left 15 | | Button_Middle 16 | | Button_Right 17 | | Button_X1 18 | | Button_X2 19 | | Button_X3 20 | | Button_X4 21 | | Button_X5 22 | 23 | type pos = int * int 24 | 25 | external get_state : unit -> pos * button list 26 | = "caml_SDL_GetMouseState" 27 | 28 | external get_buttons : unit -> button list 29 | = "caml_SDL_GetMouseButtons" 30 | 31 | external get_pos : unit -> pos 32 | = "caml_SDL_GetMousePos" 33 | 34 | external warp_in_window : Sdlwindow.t -> x:int -> y:int -> unit 35 | = "caml_SDL_WarpMouseInWindow" 36 | 37 | external set_relative_mode : enabled:bool -> unit 38 | = "caml_SDL_SetRelativeMouseMode" 39 | 40 | external show_cursor : toggle:bool -> unit 41 | = "caml_SDL_ShowCursor" 42 | 43 | external cursor_is_shown : unit -> bool 44 | = "caml_SDL_ShowCursor_Query" 45 | 46 | let to_string = function 47 | | Button_Left -> "Button_Left" 48 | | Button_Middle -> "Button_Middle" 49 | | Button_Right -> "Button_Right" 50 | | Button_X1 -> "Button_X1" 51 | | Button_X2 -> "Button_X2" 52 | | Button_X3 -> "Button_X3" 53 | | Button_X4 -> "Button_X4" 54 | | Button_X5 -> "Button_X5" 55 | 56 | let of_string s = 57 | match String.lowercase_ascii s with 58 | | "button_left" -> Button_Left 59 | | "button_middle" -> Button_Middle 60 | | "button_right" -> Button_Right 61 | | "button_x1" -> Button_X1 62 | | "button_x2" -> Button_X2 63 | | "button_x3" -> Button_X3 64 | | "button_x4" -> Button_X4 65 | | "button_x5" -> Button_X5 66 | | _ -> invalid_arg "Sdlmouse.of_string" 67 | 68 | -------------------------------------------------------------------------------- /src/sdlmouse.mli: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (** Mouse event handling *) 12 | 13 | (** API Doc: 14 | {{:http://wiki.libsdl.org/CategoryMouse}Mouse category} *) 15 | 16 | type button = 17 | | Button_Left 18 | | Button_Middle 19 | | Button_Right 20 | | Button_X1 21 | | Button_X2 22 | | Button_X3 23 | | Button_X4 24 | | Button_X5 25 | 26 | type pos = int * int 27 | 28 | external get_state : unit -> pos * button list 29 | = "caml_SDL_GetMouseState" 30 | (** {{:http://wiki.libsdl.org/SDL_GetMouseState}api doc} *) 31 | 32 | external get_buttons : unit -> button list 33 | = "caml_SDL_GetMouseButtons" 34 | 35 | external get_pos : unit -> pos 36 | = "caml_SDL_GetMousePos" 37 | 38 | external warp_in_window : Sdlwindow.t -> x:int -> y:int -> unit 39 | = "caml_SDL_WarpMouseInWindow" 40 | (** {{:http://wiki.libsdl.org/SDL_WarpMouseInWindow}api doc} *) 41 | 42 | external set_relative_mode : enabled:bool -> unit 43 | = "caml_SDL_SetRelativeMouseMode" 44 | (** {{:http://wiki.libsdl.org/SDL_SetRelativeMouseMode}api doc} *) 45 | 46 | external show_cursor : toggle:bool -> unit 47 | = "caml_SDL_ShowCursor" 48 | (** {{:http://wiki.libsdl.org/SDL_ShowCursor}api doc} *) 49 | 50 | external cursor_is_shown : unit -> bool 51 | = "caml_SDL_ShowCursor_Query" 52 | (** {{:http://wiki.libsdl.org/SDL_ShowCursor}api doc} *) 53 | 54 | val to_string : button -> string 55 | val of_string : string -> button 56 | 57 | -------------------------------------------------------------------------------- /src/sdlmouse_stub.c: -------------------------------------------------------------------------------- 1 | /* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | */ 11 | #define CAML_NAME_SPACE 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | #include "sdlwindow_stub.h" 19 | 20 | #define SDL_BUTTON_X3 (SDL_BUTTON_X2+1) 21 | #define SDL_BUTTON_X4 (SDL_BUTTON_X2+2) 22 | #define SDL_BUTTON_X5 (SDL_BUTTON_X2+3) 23 | #define SDL_BUTTON_X3MASK SDL_BUTTON(SDL_BUTTON_X3) 24 | #define SDL_BUTTON_X4MASK SDL_BUTTON(SDL_BUTTON_X4) 25 | #define SDL_BUTTON_X5MASK SDL_BUTTON(SDL_BUTTON_X5) 26 | 27 | #define Val_SDL_BUTTON_LEFT Val_int(0) 28 | #define Val_SDL_BUTTON_MIDDLE Val_int(1) 29 | #define Val_SDL_BUTTON_RIGHT Val_int(2) 30 | #define Val_SDL_BUTTON_X1 Val_int(3) 31 | #define Val_SDL_BUTTON_X2 Val_int(4) 32 | #define Val_SDL_BUTTON_X3 Val_int(5) 33 | #define Val_SDL_BUTTON_X4 Val_int(6) 34 | #define Val_SDL_BUTTON_X5 Val_int(7) 35 | 36 | static value 37 | Val_mouse_button(Uint32 state_mask) 38 | { 39 | CAMLparam0(); 40 | CAMLlocal2(li, cons); 41 | li = Val_emptylist; 42 | 43 | if (state_mask & SDL_BUTTON_LMASK) { 44 | cons = caml_alloc_small(2, Tag_cons); 45 | Store_field(cons, 0, Val_SDL_BUTTON_LEFT); 46 | Store_field(cons, 1, li); 47 | li = cons; 48 | } 49 | if (state_mask & SDL_BUTTON_MMASK) { 50 | cons = caml_alloc_small(2, Tag_cons); 51 | Store_field(cons, 0, Val_SDL_BUTTON_MIDDLE); 52 | Store_field(cons, 1, li); 53 | li = cons; 54 | } 55 | if (state_mask & SDL_BUTTON_RMASK) { 56 | cons = caml_alloc_small(2, Tag_cons); 57 | Store_field(cons, 0, Val_SDL_BUTTON_RIGHT); 58 | Store_field(cons, 1, li); 59 | li = cons; 60 | } 61 | if (state_mask & SDL_BUTTON_X1MASK) { 62 | cons = caml_alloc_small(2, Tag_cons); 63 | Store_field(cons, 0, Val_SDL_BUTTON_X1); 64 | Store_field(cons, 1, li); 65 | li = cons; 66 | } 67 | if (state_mask & SDL_BUTTON_X2MASK) { 68 | cons = caml_alloc_small(2, Tag_cons); 69 | Store_field(cons, 0, Val_SDL_BUTTON_X2); 70 | Store_field(cons, 1, li); 71 | li = cons; 72 | } 73 | if (state_mask & SDL_BUTTON_X3MASK) { 74 | cons = caml_alloc_small(2, Tag_cons); 75 | Store_field(cons, 0, Val_SDL_BUTTON_X3); 76 | Store_field(cons, 1, li); 77 | li = cons; 78 | } 79 | if (state_mask & SDL_BUTTON_X4MASK) { 80 | cons = caml_alloc_small(2, Tag_cons); 81 | Store_field(cons, 0, Val_SDL_BUTTON_X4); 82 | Store_field(cons, 1, li); 83 | li = cons; 84 | } 85 | if (state_mask & SDL_BUTTON_X5MASK) { 86 | cons = caml_alloc_small(2, Tag_cons); 87 | Store_field(cons, 0, Val_SDL_BUTTON_X5); 88 | Store_field(cons, 1, li); 89 | li = cons; 90 | } 91 | 92 | CAMLreturn(li); 93 | } 94 | 95 | CAMLprim value 96 | caml_SDL_GetMouseState(value unit) 97 | { 98 | CAMLparam0(); 99 | CAMLlocal2(ret, pos); 100 | int x, y; 101 | Uint32 state_mask = SDL_GetMouseState(&x, &y); 102 | 103 | pos = caml_alloc(2, 0); 104 | Store_field(pos, 0, Val_int(x)); 105 | Store_field(pos, 1, Val_int(y)); 106 | 107 | ret = caml_alloc(2, 0); 108 | Store_field(ret, 0, pos); 109 | Store_field(ret, 1, Val_mouse_button(state_mask)); 110 | CAMLreturn(ret); 111 | } 112 | 113 | CAMLprim value 114 | caml_SDL_GetMouseButtons(value unit) 115 | { 116 | CAMLparam0(); 117 | CAMLlocal1(buttons); 118 | Uint32 state_mask = SDL_GetMouseState(NULL, NULL); 119 | buttons = Val_mouse_button(state_mask); 120 | CAMLreturn(buttons); 121 | } 122 | 123 | CAMLprim value 124 | caml_SDL_GetMousePos(value unit) 125 | { 126 | CAMLparam0(); 127 | CAMLlocal1(pos); 128 | int x, y; 129 | (void) SDL_GetMouseState(&x, &y); 130 | pos = caml_alloc(2, 0); 131 | Store_field(pos, 0, Val_int(x)); 132 | Store_field(pos, 1, Val_int(y)); 133 | CAMLreturn(pos); 134 | } 135 | 136 | CAMLprim value 137 | caml_SDL_WarpMouseInWindow(value window, value x, value y) 138 | { 139 | SDL_WarpMouseInWindow( 140 | SDL_Window_val(window), 141 | Int_val(x), Int_val(y)); 142 | return Val_unit; 143 | } 144 | 145 | CAMLprim value 146 | caml_SDL_SetRelativeMouseMode(SDL_bool enabled) 147 | { 148 | int r = SDL_SetRelativeMouseMode(Bool_val(enabled)); 149 | if (r != 0) caml_failwith("Sdlmouse.set_relative_mode"); 150 | return Val_unit; 151 | } 152 | 153 | CAMLprim value 154 | caml_SDL_ShowCursor(value toggle) 155 | { 156 | int shown = SDL_ShowCursor(Int_val(toggle)); 157 | return Val_unit; 158 | } 159 | 160 | CAMLprim value 161 | caml_SDL_ShowCursor_Query(value unit) 162 | { 163 | int shown = SDL_ShowCursor(-1); 164 | return Val_bool(shown); 165 | } 166 | 167 | /* vim: set ts=4 sw=4 et: */ 168 | -------------------------------------------------------------------------------- /src/sdlpixel.ml: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (** Pixel format *) 12 | 13 | external get_pixel_format_name : SdlpixelFormat.t -> string 14 | = "caml_SDL_GetPixelFormatName" 15 | 16 | type pixel_format 17 | 18 | external alloc_format : SdlpixelFormat.t -> pixel_format 19 | = "caml_SDL_AllocFormat" 20 | 21 | external free_format : pixel_format -> unit 22 | = "caml_SDL_FreeFormat" 23 | 24 | type uint8 = int 25 | 26 | type rgb = uint8 * uint8 * uint8 27 | type rgba = uint8 * uint8 * uint8 * uint8 28 | 29 | external map_RGB : 30 | pixel_format -> rgb:rgb -> int32 31 | = "caml_SDL_MapRGB" 32 | 33 | external map_RGBA : 34 | pixel_format -> rgba:rgba -> int32 35 | = "caml_SDL_MapRGBA" 36 | 37 | external get_RGB : pixel:int32 -> fmt:pixel_format -> rgb 38 | = "caml_SDL_GetRGB" 39 | 40 | external get_RGBA : pixel:int32 -> fmt:pixel_format -> rgba 41 | = "caml_SDL_GetRGBA" 42 | -------------------------------------------------------------------------------- /src/sdlpixel.mli: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (** Pixel format *) 12 | 13 | (** API Doc: 14 | {{:http://wiki.libsdl.org/CategoryPixels}Pixels category} *) 15 | 16 | external get_pixel_format_name : SdlpixelFormat.t -> string 17 | = "caml_SDL_GetPixelFormatName" 18 | (** {{:http://wiki.libsdl.org/SDL_GetPixelFormatName}api doc} *) 19 | 20 | type pixel_format 21 | 22 | external alloc_format : SdlpixelFormat.t -> pixel_format 23 | = "caml_SDL_AllocFormat" 24 | (** {{:http://wiki.libsdl.org/SDL_AllocFormat}api doc} *) 25 | 26 | external free_format : pixel_format -> unit 27 | = "caml_SDL_FreeFormat" 28 | (** {{:http://wiki.libsdl.org/SDL_FreeFormat}api doc} *) 29 | 30 | type uint8 = int 31 | 32 | type rgb = uint8 * uint8 * uint8 33 | type rgba = uint8 * uint8 * uint8 * uint8 34 | 35 | external map_RGB : 36 | pixel_format -> rgb:rgb -> int32 37 | = "caml_SDL_MapRGB" 38 | (** {{:http://wiki.libsdl.org/SDL_MapRGB}api doc} *) 39 | 40 | external map_RGBA : 41 | pixel_format -> rgba:rgba -> int32 42 | = "caml_SDL_MapRGBA" 43 | (** {{:http://wiki.libsdl.org/SDL_MapRGBA}api doc} *) 44 | 45 | external get_RGB : pixel:int32 -> fmt:pixel_format -> rgb 46 | = "caml_SDL_GetRGB" 47 | (** {{:http://wiki.libsdl.org/SDL_GetRGB}api doc} *) 48 | 49 | external get_RGBA : pixel:int32 -> fmt:pixel_format -> rgba 50 | = "caml_SDL_GetRGBA" 51 | (** {{:http://wiki.libsdl.org/SDL_GetRGBA}api doc} *) 52 | 53 | -------------------------------------------------------------------------------- /src/sdlpixelFormat.mli: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (** Pixel format kind *) 12 | 13 | (** {{:http://wiki.libsdl.org/SDL_PixelFormatEnum}api doc} *) 14 | type t = 15 | | Unknown 16 | | Index1LSB 17 | | Index1MSB 18 | | Index4LSB 19 | | Index4MSB 20 | | Index8 21 | | RGB332 22 | | RGB444 23 | | RGB555 24 | | BGR555 25 | | ARGB4444 26 | | RGBA4444 27 | | ABGR4444 28 | | BGRA4444 29 | | ARGB1555 30 | | RGBA5551 31 | | ABGR1555 32 | | BGRA5551 33 | | RGB565 34 | | BGR565 35 | | RGB24 36 | | BGR24 37 | | RGB888 38 | | RGBX8888 39 | | BGR888 40 | | BGRX8888 41 | | ARGB8888 42 | | RGBA8888 43 | | ABGR8888 44 | | BGRA8888 45 | | ARGB2101010 46 | | YV12 47 | | IYUV 48 | | YUY2 49 | | UYVY 50 | | YVYU 51 | 52 | val to_string : t -> string 53 | val of_string : string -> t 54 | 55 | -------------------------------------------------------------------------------- /src/sdlpixelFormat_stub.c: -------------------------------------------------------------------------------- 1 | /* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | */ 11 | #define CAML_NAME_SPACE 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | #include 19 | 20 | const Uint32 caml_sdl_pixelformat_table[] = { 21 | SDL_PIXELFORMAT_UNKNOWN, 22 | SDL_PIXELFORMAT_INDEX1LSB, 23 | SDL_PIXELFORMAT_INDEX1MSB, 24 | SDL_PIXELFORMAT_INDEX4LSB, 25 | SDL_PIXELFORMAT_INDEX4MSB, 26 | SDL_PIXELFORMAT_INDEX8, 27 | SDL_PIXELFORMAT_RGB332, 28 | SDL_PIXELFORMAT_RGB444, 29 | SDL_PIXELFORMAT_RGB555, 30 | SDL_PIXELFORMAT_BGR555, 31 | SDL_PIXELFORMAT_ARGB4444, 32 | SDL_PIXELFORMAT_RGBA4444, 33 | SDL_PIXELFORMAT_ABGR4444, 34 | SDL_PIXELFORMAT_BGRA4444, 35 | SDL_PIXELFORMAT_ARGB1555, 36 | SDL_PIXELFORMAT_RGBA5551, 37 | SDL_PIXELFORMAT_ABGR1555, 38 | SDL_PIXELFORMAT_BGRA5551, 39 | SDL_PIXELFORMAT_RGB565, 40 | SDL_PIXELFORMAT_BGR565, 41 | SDL_PIXELFORMAT_RGB24, 42 | SDL_PIXELFORMAT_BGR24, 43 | SDL_PIXELFORMAT_RGB888, 44 | SDL_PIXELFORMAT_RGBX8888, 45 | SDL_PIXELFORMAT_BGR888, 46 | SDL_PIXELFORMAT_BGRX8888, 47 | SDL_PIXELFORMAT_ARGB8888, 48 | SDL_PIXELFORMAT_RGBA8888, 49 | SDL_PIXELFORMAT_ABGR8888, 50 | SDL_PIXELFORMAT_BGRA8888, 51 | SDL_PIXELFORMAT_ARGB2101010, 52 | SDL_PIXELFORMAT_YV12, 53 | SDL_PIXELFORMAT_IYUV, 54 | SDL_PIXELFORMAT_YUY2, 55 | SDL_PIXELFORMAT_UYVY, 56 | SDL_PIXELFORMAT_YVYU, 57 | }; 58 | 59 | value 60 | Val_Sdl_pixelformat_t(Uint32 pixel_format) 61 | { 62 | switch (pixel_format) { 63 | case SDL_PIXELFORMAT_UNKNOWN: return Val_int(0); 64 | case SDL_PIXELFORMAT_INDEX1LSB: return Val_int(1); 65 | case SDL_PIXELFORMAT_INDEX1MSB: return Val_int(2); 66 | case SDL_PIXELFORMAT_INDEX4LSB: return Val_int(3); 67 | case SDL_PIXELFORMAT_INDEX4MSB: return Val_int(4); 68 | case SDL_PIXELFORMAT_INDEX8: return Val_int(5); 69 | case SDL_PIXELFORMAT_RGB332: return Val_int(6); 70 | case SDL_PIXELFORMAT_RGB444: return Val_int(7); 71 | case SDL_PIXELFORMAT_RGB555: return Val_int(8); 72 | case SDL_PIXELFORMAT_BGR555: return Val_int(9); 73 | case SDL_PIXELFORMAT_ARGB4444: return Val_int(10); 74 | case SDL_PIXELFORMAT_RGBA4444: return Val_int(11); 75 | case SDL_PIXELFORMAT_ABGR4444: return Val_int(12); 76 | case SDL_PIXELFORMAT_BGRA4444: return Val_int(13); 77 | case SDL_PIXELFORMAT_ARGB1555: return Val_int(14); 78 | case SDL_PIXELFORMAT_RGBA5551: return Val_int(15); 79 | case SDL_PIXELFORMAT_ABGR1555: return Val_int(16); 80 | case SDL_PIXELFORMAT_BGRA5551: return Val_int(17); 81 | case SDL_PIXELFORMAT_RGB565: return Val_int(18); 82 | case SDL_PIXELFORMAT_BGR565: return Val_int(19); 83 | case SDL_PIXELFORMAT_RGB24: return Val_int(20); 84 | case SDL_PIXELFORMAT_BGR24: return Val_int(21); 85 | case SDL_PIXELFORMAT_RGB888: return Val_int(22); 86 | case SDL_PIXELFORMAT_RGBX8888: return Val_int(23); 87 | case SDL_PIXELFORMAT_BGR888: return Val_int(24); 88 | case SDL_PIXELFORMAT_BGRX8888: return Val_int(25); 89 | case SDL_PIXELFORMAT_ARGB8888: return Val_int(26); 90 | case SDL_PIXELFORMAT_RGBA8888: return Val_int(27); 91 | case SDL_PIXELFORMAT_ABGR8888: return Val_int(28); 92 | case SDL_PIXELFORMAT_BGRA8888: return Val_int(29); 93 | case SDL_PIXELFORMAT_ARGB2101010: return Val_int(30); 94 | case SDL_PIXELFORMAT_YV12: return Val_int(31); 95 | case SDL_PIXELFORMAT_IYUV: return Val_int(32); 96 | case SDL_PIXELFORMAT_YUY2: return Val_int(33); 97 | case SDL_PIXELFORMAT_UYVY: return Val_int(34); 98 | case SDL_PIXELFORMAT_YVYU: return Val_int(35); 99 | } 100 | caml_failwith("SdlPixelFormat.t"); 101 | } 102 | 103 | /* vim: set ts=4 sw=4 et: */ 104 | -------------------------------------------------------------------------------- /src/sdlpixelFormat_stub.h: -------------------------------------------------------------------------------- 1 | #ifndef _CAML_SDL_PIXELFORMAT_ 2 | #define _CAML_SDL_PIXELFORMAT_ 3 | 4 | #include 5 | 6 | value Val_Sdl_pixelformat_t(Uint32 pixel_format); 7 | 8 | extern const Uint32 caml_sdl_pixelformat_table[]; 9 | #define Sdl_pixelformat_t(v) \ 10 | caml_sdl_pixelformat_table[Long_val(v)] 11 | 12 | #endif /* _CAML_SDL_PIXELFORMAT_ */ 13 | -------------------------------------------------------------------------------- /src/sdlpixel_stub.c: -------------------------------------------------------------------------------- 1 | /* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | */ 11 | #define CAML_NAME_SPACE 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | #include 19 | #include "sdlpixelFormat_stub.h" 20 | 21 | CAMLprim value 22 | caml_SDL_GetPixelFormatName(value format) 23 | { 24 | const char * name = SDL_GetPixelFormatName(Sdl_pixelformat_t(format)); 25 | return caml_copy_string(name); 26 | } 27 | 28 | static value Val_SDL_PixelFormat(SDL_PixelFormat * p) 29 | { 30 | return caml_copy_nativeint((intnat) p); 31 | } 32 | 33 | static SDL_PixelFormat * SDL_PixelFormat_val(value v) 34 | { 35 | return (SDL_PixelFormat *) Nativeint_val(v); 36 | } 37 | 38 | CAMLprim value 39 | caml_SDL_AllocFormat(value pixel_format) 40 | { 41 | SDL_PixelFormat * px_fmt = SDL_AllocFormat(Sdl_pixelformat_t(pixel_format)); 42 | return Val_SDL_PixelFormat(px_fmt); 43 | } 44 | 45 | CAMLprim value 46 | caml_SDL_FreeFormat(value format) 47 | { 48 | SDL_FreeFormat(SDL_PixelFormat_val(format)); 49 | return Val_unit; 50 | } 51 | 52 | #define UInt32_val(v) Int32_val((v)) 53 | #define UInt8_val Int_val 54 | #define Val_uint8 Val_int 55 | 56 | CAMLprim value 57 | caml_SDL_MapRGB(value format, value rgb) 58 | { 59 | value r = Field(rgb,0); 60 | value g = Field(rgb,1); 61 | value b = Field(rgb,2); 62 | Uint32 px = SDL_MapRGB( 63 | SDL_PixelFormat_val(format), 64 | UInt8_val(r), 65 | UInt8_val(g), 66 | UInt8_val(b)); 67 | 68 | return caml_copy_int32(px); 69 | } 70 | 71 | CAMLprim value 72 | caml_SDL_MapRGBA(value format, value rgba) 73 | { 74 | value r = Field(rgba,0); 75 | value g = Field(rgba,1); 76 | value b = Field(rgba,2); 77 | value a = Field(rgba,3); 78 | Uint32 px = SDL_MapRGBA( 79 | SDL_PixelFormat_val(format), 80 | UInt8_val(r), 81 | UInt8_val(g), 82 | UInt8_val(b), 83 | UInt8_val(a)); 84 | 85 | return caml_copy_int32(px); 86 | } 87 | 88 | CAMLprim value 89 | caml_SDL_GetRGB(value pixel, value format) 90 | { 91 | CAMLparam2(pixel, format); 92 | CAMLlocal1(ret); 93 | 94 | Uint8 r, g, b; 95 | SDL_GetRGB( 96 | UInt32_val(pixel), 97 | SDL_PixelFormat_val(format), 98 | &r, &g, &b); 99 | 100 | ret = caml_alloc(3, 0); 101 | Store_field(ret, 0, Val_uint8(r)); 102 | Store_field(ret, 1, Val_uint8(g)); 103 | Store_field(ret, 2, Val_uint8(b)); 104 | CAMLreturn(ret); 105 | } 106 | 107 | CAMLprim value 108 | caml_SDL_GetRGBA(value pixel, value format) 109 | { 110 | CAMLparam2(pixel, format); 111 | CAMLlocal1(ret); 112 | 113 | Uint8 r, g, b, a; 114 | SDL_GetRGBA( 115 | UInt32_val(pixel), 116 | SDL_PixelFormat_val(format), 117 | &r, &g, &b, &a); 118 | 119 | ret = caml_alloc(4, 0); 120 | Store_field(ret, 0, Val_uint8(r)); 121 | Store_field(ret, 1, Val_uint8(g)); 122 | Store_field(ret, 2, Val_uint8(b)); 123 | Store_field(ret, 3, Val_uint8(a)); 124 | CAMLreturn(ret); 125 | } 126 | 127 | /* vim: set ts=4 sw=4 et: */ 128 | -------------------------------------------------------------------------------- /src/sdlpixel_stub.h: -------------------------------------------------------------------------------- 1 | #ifndef _CAML_SDL_PIXEL_ 2 | #define _CAML_SDL_PIXEL_ 3 | 4 | #include 5 | 6 | 7 | #endif /* _CAML_SDL_PIXEL_ */ 8 | -------------------------------------------------------------------------------- /src/sdlpoint_stub.h: -------------------------------------------------------------------------------- 1 | #ifndef _CAML_SDL_POINT_ 2 | #define _CAML_SDL_POINT_ 3 | 4 | #define SDL_Point_val(p, v) \ 5 | (p)->x = Int_val(Field(v, 0)); \ 6 | (p)->y = Int_val(Field(v, 1)); 7 | 8 | #define Val_SDL_Point(ret, p) \ 9 | ret = caml_alloc(2, 0); \ 10 | Store_field(ret, 0, Val_int((p)->x)); \ 11 | Store_field(ret, 1, Val_int((p)->y)); 12 | 13 | #endif /* _CAML_SDL_POINT_ */ 14 | -------------------------------------------------------------------------------- /src/sdlpower.ml: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (** Power management *) 12 | 13 | type power_state = [ 14 | | `powerstate_Unknown (** cannot determine power status *) 15 | | `powerstate_On_Battery (** Not plugged in, running on the battery *) 16 | | `powerstate_No_Battery (** Plugged in, no battery available *) 17 | | `powerstate_Charging (** Plugged in, charging battery *) 18 | | `powerstate_Charged (** Plugged in, battery charged *) 19 | ] 20 | 21 | external get_power_info : unit -> power_state * int * int 22 | = "caml_SDL_GetPowerInfo" 23 | -------------------------------------------------------------------------------- /src/sdlpower.mli: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (** Power management *) 12 | 13 | type power_state = [ 14 | | `powerstate_Unknown (** cannot determine power status *) 15 | | `powerstate_On_Battery (** Not plugged in, running on the battery *) 16 | | `powerstate_No_Battery (** Plugged in, no battery available *) 17 | | `powerstate_Charging (** Plugged in, charging battery *) 18 | | `powerstate_Charged (** Plugged in, battery charged *) 19 | ] 20 | 21 | external get_power_info : unit -> power_state * int * int 22 | = "caml_SDL_GetPowerInfo" 23 | 24 | -------------------------------------------------------------------------------- /src/sdlpower_stub.c: -------------------------------------------------------------------------------- 1 | /* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | */ 11 | #define CAML_NAME_SPACE 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | 19 | CAMLprim value 20 | caml_SDL_GetPowerInfo(value unit) 21 | { 22 | CAMLparam0(); 23 | CAMLlocal1(ret); 24 | 25 | int secs, pct; 26 | SDL_PowerState state = SDL_GetPowerInfo(&secs, &pct); 27 | 28 | ret = caml_alloc(3, 0); 29 | Store_field(ret, 0, Val_int(state)); 30 | Store_field(ret, 1, Val_int(secs)); 31 | Store_field(ret, 2, Val_int(pct)); 32 | CAMLreturn(ret); 33 | } 34 | 35 | /* vim: set ts=4 sw=4 et: */ 36 | -------------------------------------------------------------------------------- /src/sdlquit.ml: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (** Quit SDL *) 12 | 13 | external quit : unit -> unit = "caml_SDL_Quit" 14 | 15 | external quit_requested : unit -> bool 16 | = "caml_SDL_QuitRequested" 17 | -------------------------------------------------------------------------------- /src/sdlquit.mli: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (** Quit SDL *) 12 | 13 | external quit : unit -> unit = "caml_SDL_Quit" 14 | (** {{:http://wiki.libsdl.org/SDL_Quit}doc} *) 15 | 16 | external quit_requested : unit -> bool 17 | = "caml_SDL_QuitRequested" 18 | (** {{:http://wiki.libsdl.org/SDL_QuitRequested}doc} *) 19 | 20 | -------------------------------------------------------------------------------- /src/sdlquit_stub.c: -------------------------------------------------------------------------------- 1 | /* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | */ 11 | #define CAML_NAME_SPACE 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | #include 19 | 20 | CAMLprim value 21 | caml_SDL_Quit(value unit) 22 | { 23 | SDL_Quit(); 24 | return Val_unit; 25 | } 26 | 27 | /* TODO 28 | void SDL_QuitSubSystem(Uint32 flags); 29 | */ 30 | 31 | CAMLprim value 32 | caml_SDL_QuitRequested(value unit) 33 | { 34 | SDL_bool b = SDL_QuitRequested(); 35 | return Val_bool(b); 36 | } 37 | 38 | /* vim: set ts=4 sw=4 et: */ 39 | -------------------------------------------------------------------------------- /src/sdlrect.ml: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (** Rectangles *) 12 | 13 | (** A rectangle, with the origin at the upper left. *) 14 | type t = { 15 | x: int; 16 | y: int; 17 | w: int; 18 | h: int; 19 | } 20 | 21 | let make1 (x, y, w, h) = 22 | { x; y; w; h } 23 | 24 | let make2 ~pos:(x, y) ~dims:(w, h) = 25 | { x; y; w; h } 26 | 27 | let make4 ~x ~y ~w ~h = 28 | { x; y; w; h } 29 | 30 | let make = make2 31 | 32 | let move r ~x ~y = 33 | { r with x; y } 34 | 35 | external has_intersection : a:t -> b:t -> bool 36 | = "caml_SDL_HasIntersection" 37 | 38 | external intersect_rect_and_line : rect:t -> p1:int * int -> p2:int * int -> 39 | (int * int * int * int) option 40 | = "caml_SDL_IntersectRectAndLine" 41 | 42 | external point_in_rect : p:int * int -> r:t -> bool 43 | = "caml_SDL_PointInRect" 44 | -------------------------------------------------------------------------------- /src/sdlrect.mli: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (** Rectangles *) 12 | 13 | (** {{:http://wiki.libsdl.org/CategoryRect}Rect category} *) 14 | 15 | (** A rectangle, with the origin at the upper left. *) 16 | type t = { 17 | x: int; 18 | y: int; 19 | w: int; 20 | h: int; 21 | } 22 | 23 | val make : pos:int * int -> dims:int * int -> t 24 | (** currently an alias for [make2] *) 25 | 26 | val make1 : int * int * int * int -> t 27 | 28 | val make2 : pos:int * int -> dims:int * int -> t 29 | 30 | val make4 : x:int -> y:int -> w:int -> h:int -> t 31 | 32 | val move : t -> x:int -> y:int -> t 33 | 34 | external has_intersection : a:t -> b:t -> bool 35 | = "caml_SDL_HasIntersection" 36 | 37 | external intersect_rect_and_line : rect:t -> p1:int * int -> p2:int * int -> 38 | (int * int * int * int) option 39 | = "caml_SDL_IntersectRectAndLine" 40 | 41 | external point_in_rect : p:int * int -> r:t -> bool 42 | = "caml_SDL_PointInRect" 43 | 44 | -------------------------------------------------------------------------------- /src/sdlrect_stub.c: -------------------------------------------------------------------------------- 1 | /* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | */ 11 | #define CAML_NAME_SPACE 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include 19 | #include "sdlrect_stub.h" 20 | #include "sdlpoint_stub.h" 21 | 22 | #if OCAML_VERSION < 41200 23 | #define Val_none Val_int(0) 24 | 25 | static value 26 | Val_some(value v) 27 | { 28 | CAMLparam1(v); 29 | CAMLlocal1(some); 30 | some = caml_alloc(1, 0); 31 | Store_field(some, 0, v); 32 | CAMLreturn(some); 33 | } 34 | #else 35 | #define Val_some caml_alloc_some 36 | #endif 37 | 38 | CAMLprim value 39 | caml_SDL_HasIntersection(value a, value b) 40 | { 41 | SDL_Rect _a; 42 | SDL_Rect _b; 43 | SDL_Rect_val(&_a, a); 44 | SDL_Rect_val(&_b, b); 45 | 46 | SDL_bool r = 47 | SDL_HasIntersection(&_a, &_b); 48 | 49 | return Val_bool(r); 50 | } 51 | 52 | CAMLprim value 53 | caml_SDL_PointInRect(value pt, value rct) 54 | { 55 | SDL_Point _pt; 56 | SDL_Rect _rct; 57 | SDL_Rect_val(&_rct, rct); 58 | SDL_Point_val(&_pt, pt); 59 | 60 | SDL_bool r = 61 | SDL_PointInRect(&_pt, &_rct); 62 | 63 | return Val_bool(r); 64 | } 65 | 66 | CAMLprim value 67 | caml_SDL_IntersectRectAndLine(value rect, value p1, value p2) 68 | { 69 | CAMLparam3(rect, p1, p2); 70 | CAMLlocal2(ret, r); 71 | 72 | SDL_Rect _rect; 73 | SDL_Rect_val(&_rect, rect); 74 | 75 | int X1 = Int_val(Field(p1, 0)); 76 | int Y1 = Int_val(Field(p1, 1)); 77 | int X2 = Int_val(Field(p2, 0)); 78 | int Y2 = Int_val(Field(p2, 1)); 79 | 80 | SDL_bool res = 81 | SDL_IntersectRectAndLine( 82 | &_rect, 83 | &X1, &Y1, 84 | &X2, &Y2); 85 | 86 | if (res == SDL_TRUE) { 87 | r = caml_alloc(4, 0); 88 | 89 | Store_field(r, 0, Val_int(X1)); 90 | Store_field(r, 1, Val_int(Y1)); 91 | Store_field(r, 2, Val_int(X2)); 92 | Store_field(r, 3, Val_int(Y2)); 93 | 94 | ret = Val_some(r); 95 | } else { 96 | ret = Val_none; 97 | } 98 | 99 | CAMLreturn(ret); 100 | } 101 | 102 | /* vim: set ts=4 sw=4 et: */ 103 | -------------------------------------------------------------------------------- /src/sdlrect_stub.h: -------------------------------------------------------------------------------- 1 | #ifndef _CAML_SDL_RECT_ 2 | #define _CAML_SDL_RECT_ 3 | 4 | #define SDL_Rect_val(r, v) \ 5 | (r)->x = Int_val(Field(v, 0)); \ 6 | (r)->y = Int_val(Field(v, 1)); \ 7 | (r)->w = Int_val(Field(v, 2)); \ 8 | (r)->h = Int_val(Field(v, 3)) 9 | 10 | #define Val_SDL_Rect(ret, r) \ 11 | ret = caml_alloc(4, 0); \ 12 | Store_field(ret, 0, Val_int((r)->x)); \ 13 | Store_field(ret, 1, Val_int((r)->y)); \ 14 | Store_field(ret, 2, Val_int((r)->w)); \ 15 | Store_field(ret, 3, Val_int((r)->h)) 16 | 17 | #endif /* _CAML_SDL_RECT_ */ 18 | -------------------------------------------------------------------------------- /src/sdlrender.ml: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (* 2D rendering functions *) 12 | 13 | type t = Sdltype.renderer 14 | 15 | external create_window_and_renderer : 16 | width:int -> height:int -> 17 | flags:Sdlwindow.window_flags list -> 18 | Sdlwindow.t * t 19 | = "caml_SDL_CreateWindowAndRenderer" 20 | 21 | type renderer_flags = 22 | | Software 23 | | Accelerated 24 | | PresentVSync 25 | | TargetTexture 26 | 27 | let string_of_renderer_flags = function 28 | | Software -> "Software" 29 | | Accelerated -> "Accelerated" 30 | | PresentVSync -> "PresentVSync" 31 | | TargetTexture -> "TargetTexture" 32 | 33 | let renderer_flags_of_string s = 34 | match String.lowercase_ascii s with 35 | | "software" -> Software 36 | | "accelerated" -> Accelerated 37 | | "presentvsync" -> PresentVSync 38 | | "targettexture" -> TargetTexture 39 | | _ -> invalid_arg "Sdlrender.renderer_flags_of_string" 40 | 41 | external create_renderer : 42 | win:Sdlwindow.t -> index:int -> 43 | flags:renderer_flags list -> t 44 | = "caml_SDL_CreateRenderer" 45 | 46 | external get_output_size : t -> int * int 47 | = "caml_SDL_GetRendererOutputSize" 48 | 49 | external set_logical_size : t -> int * int -> unit 50 | = "caml_SDL_RenderSetLogicalSize" 51 | 52 | external set_logical_size2 : t -> width:int -> height:int -> unit 53 | = "caml_SDL_RenderSetLogicalSize2" 54 | 55 | external set_viewport : 56 | t -> Sdlrect.t -> unit 57 | = "caml_SDL_RenderSetViewport" 58 | 59 | external set_clip_rect : 60 | t -> Sdlrect.t -> unit 61 | = "caml_SDL_RenderSetClipRect" 62 | 63 | external set_draw_color : 64 | t -> rgb:(int * int * int) -> a:int -> unit 65 | = "caml_SDL_SetRenderDrawColor" 66 | 67 | external set_draw_color3 : 68 | t -> r:int -> g:int -> b:int -> a:int -> unit 69 | = "caml_SDL_SetRenderDrawColor3" 70 | 71 | external set_draw_blend_mode : t -> SdlblendMode.t -> unit 72 | = "caml_SDL_SetRenderDrawBlendMode" 73 | 74 | external draw_point : 75 | t -> int * int -> unit 76 | = "caml_SDL_RenderDrawPoint" 77 | 78 | external draw_point2 : 79 | t -> x:int -> y:int -> unit 80 | = "caml_SDL_RenderDrawPoint2" 81 | 82 | external draw_points : 83 | t -> points:(int * int) array -> unit 84 | = "caml_SDL_RenderDrawPoints" 85 | 86 | external draw_line : 87 | t -> ((int * int) * (int * int)) -> unit 88 | = "caml_SDL_RenderDrawLine" 89 | 90 | external draw_line2 : 91 | t -> p1:(int * int) -> p2:(int * int) -> unit 92 | = "caml_SDL_RenderDrawLine2" 93 | 94 | external draw_lines : 95 | t -> (int * int) array -> unit 96 | = "caml_SDL_RenderDrawLines" 97 | 98 | external draw_rect : 99 | t -> Sdlrect.t -> unit 100 | = "caml_SDL_RenderDrawRect" 101 | 102 | external draw_rects : 103 | t -> Sdlrect.t array -> unit 104 | = "caml_SDL_RenderDrawRects" 105 | 106 | external fill_rect : 107 | t -> Sdlrect.t -> unit 108 | = "caml_SDL_RenderFillRect" 109 | 110 | external fill_rects : 111 | t -> Sdlrect.t array -> unit 112 | = "caml_SDL_RenderFillRects" 113 | 114 | external copy : t -> 115 | texture:Sdltexture.t -> 116 | ?src_rect:Sdlrect.t -> 117 | ?dst_rect:Sdlrect.t -> unit -> unit 118 | = "caml_SDL_RenderCopy" 119 | 120 | type renderer_flip = 121 | | Flip_None 122 | | Flip_Horizontal 123 | | Flip_Vertical 124 | 125 | external copyEx : t -> 126 | texture:Sdltexture.t -> 127 | ?src_rect:Sdlrect.t -> 128 | ?dst_rect:Sdlrect.t -> 129 | ?angle:float -> 130 | ?center:int * int -> 131 | ?flip:renderer_flip -> 132 | unit -> unit 133 | = "caml_SDL_RenderCopyEx_bc" 134 | "caml_SDL_RenderCopyEx" 135 | 136 | external set_scale : t -> float * float -> unit 137 | = "caml_SDL_RenderSetScale" 138 | 139 | external render_present : t -> unit 140 | = "caml_SDL_RenderPresent" 141 | 142 | external clear : t -> unit 143 | = "caml_SDL_RenderClear" 144 | 145 | type renderer_info = { 146 | name: string; 147 | max_texture_width: int; 148 | max_texture_height: int; 149 | } 150 | 151 | external get_render_drivers : unit -> renderer_info array 152 | = "caml_SDL_GetRenderDrivers" 153 | 154 | external read_pixels : t -> ?rect:Sdlrect.t -> Sdlsurface.t -> unit 155 | = "caml_SDL_RenderReadPixels" 156 | 157 | external set_render_target : t -> Sdltexture.t option -> unit 158 | = "caml_SDL_SetRenderTarget" 159 | -------------------------------------------------------------------------------- /src/sdlrender_stub.h: -------------------------------------------------------------------------------- 1 | #ifndef _CAML_SDL_RENDERER_ 2 | #define _CAML_SDL_RENDERER_ 3 | 4 | static value Val_SDL_Renderer(SDL_Renderer * p) 5 | { 6 | return caml_copy_nativeint((intnat) p); 7 | } 8 | 9 | static SDL_Renderer * SDL_Renderer_val(value v) 10 | { 11 | return (SDL_Renderer *) Nativeint_val(v); 12 | } 13 | 14 | #endif /* _CAML_SDL_RENDERER_ */ 15 | -------------------------------------------------------------------------------- /src/sdlrwops.ml: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (* Read / Write operations *) 12 | 13 | type t 14 | 15 | external from_mem : bytes -> t 16 | = "caml_SDL_RWFromMem" 17 | 18 | external from_const_mem : string -> t 19 | = "caml_SDL_RWFromConstMem" 20 | 21 | external from_file : filename:string -> mode:string -> t 22 | = "caml_SDL_RWFromFile" 23 | 24 | type input = [ 25 | | `Filename of string (* provide the input by its filename *) 26 | | `Buffer of bytes (* provide the input data as a bytes buffer *) 27 | | `String of string (* provide the input data as a string buffer *) 28 | ] 29 | 30 | let from_input = function 31 | | `Filename(filename) -> from_file ~filename ~mode:"r" 32 | | `Buffer(mem) -> from_mem mem 33 | | `String(mem) -> from_const_mem mem 34 | 35 | let from_input_opt = function 36 | | `Filename(filename) -> Some(from_file ~filename ~mode:"r") 37 | | `Buffer(mem) -> Some(from_mem mem) 38 | | `String(mem) -> Some(from_const_mem mem) 39 | | _ -> None 40 | 41 | external alloc : unit -> t = "caml_SDL_AllocRW" 42 | external free : t -> unit = "caml_SDL_FreeRW" 43 | 44 | external close : t -> unit = "caml_SDL_CloseRW" 45 | 46 | external size : t -> int64 = "caml_SDL_RWsize" 47 | 48 | type seek = 49 | | SEEK_SET 50 | | SEEK_CUR 51 | | SEEK_END 52 | 53 | external seek : t -> offset:int64 -> seek -> int64 54 | = "caml_SDL_RWseek" 55 | 56 | external tell : t -> int64 57 | = "caml_SDL_RWtell" 58 | 59 | type uint8 = int 60 | 61 | type uint16 = int 62 | type uint32 = int32 63 | type uint64 = int64 64 | 65 | external readU8 : t -> uint8 = "caml_SDL_ReadU8" 66 | external writeU8 : t -> uint8 -> unit = "caml_SDL_WriteU8" 67 | 68 | module BigEndian = struct 69 | 70 | external read16 : t -> uint16 = "caml_SDL_ReadBE16" 71 | external read32 : t -> uint32 = "caml_SDL_ReadBE32" 72 | external read64 : t -> uint64 = "caml_SDL_ReadBE64" 73 | 74 | external write16 : t -> uint16 -> unit = "caml_SDL_WriteBE16" 75 | external write32 : t -> uint32 -> unit = "caml_SDL_WriteBE32" 76 | external write64 : t -> uint64 -> unit = "caml_SDL_WriteBE64" 77 | 78 | end 79 | 80 | module LittleEndian = struct 81 | 82 | external read16 : t -> uint16 = "caml_SDL_ReadLE16" 83 | external read32 : t -> uint32 = "caml_SDL_ReadLE32" 84 | external read64 : t -> uint64 = "caml_SDL_ReadLE64" 85 | 86 | external write16 : t -> uint16 -> unit = "caml_SDL_WriteLE16" 87 | external write32 : t -> uint32 -> unit = "caml_SDL_WriteLE32" 88 | external write64 : t -> uint64 -> unit = "caml_SDL_WriteLE64" 89 | 90 | end 91 | 92 | -------------------------------------------------------------------------------- /src/sdlrwops.mli: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (** Read / Write operations *) 12 | 13 | (** API Doc: 14 | {{:http://wiki.libsdl.org/CategoryIO}IO category} *) 15 | 16 | type t 17 | 18 | external from_mem : bytes -> t 19 | = "caml_SDL_RWFromMem" 20 | (** {{:http://wiki.libsdl.org/SDL_RWFromMem}api doc} *) 21 | 22 | external from_const_mem : string -> t 23 | = "caml_SDL_RWFromConstMem" 24 | (** {{:http://wiki.libsdl.org/SDL_RWFromConstMem}api doc} *) 25 | 26 | external from_file : filename:string -> mode:string -> t 27 | = "caml_SDL_RWFromFile" 28 | (** {{:http://wiki.libsdl.org/SDL_RWFromFile}api doc} *) 29 | 30 | type input = [ 31 | | `Filename of string (** provide the input by its filename *) 32 | | `Buffer of bytes (** provide the input data as a bytes buffer *) 33 | | `String of string (** provide the input data as a string buffer *) 34 | ] 35 | 36 | val from_input : 37 | [< `Buffer of bytes | `String of string | `Filename of string ] -> t 38 | 39 | val from_input_opt : 40 | [> `Buffer of bytes | `String of string | `Filename of string ] -> t option 41 | 42 | external alloc : unit -> t = "caml_SDL_AllocRW" 43 | external free : t -> unit = "caml_SDL_FreeRW" 44 | 45 | external close : t -> unit = "caml_SDL_CloseRW" 46 | (** {{:http://wiki.libsdl.org/SDL_RWclose}api doc} *) 47 | 48 | external size : t -> int64 = "caml_SDL_RWsize" 49 | (** {{:http://wiki.libsdl.org/SDL_RWsize}api doc} *) 50 | 51 | type seek = 52 | | SEEK_SET 53 | | SEEK_CUR 54 | | SEEK_END 55 | 56 | external seek : t -> offset:int64 -> seek -> int64 57 | = "caml_SDL_RWseek" 58 | (** {{:http://wiki.libsdl.org/SDL_RWseek}api doc} *) 59 | 60 | external tell : t -> int64 61 | = "caml_SDL_RWtell" 62 | (** {{:http://wiki.libsdl.org/SDL_RWtell}api doc} *) 63 | 64 | type uint8 = int 65 | 66 | type uint16 = int 67 | type uint32 = int32 68 | type uint64 = int64 69 | 70 | external readU8 : t -> uint8 = "caml_SDL_ReadU8" 71 | (** {{:http://wiki.libsdl.org/SDL_ReadU8}api doc} *) 72 | 73 | external writeU8 : t -> uint8 -> unit = "caml_SDL_WriteU8" 74 | (** {{:http://wiki.libsdl.org/SDL_WriteU8}api doc} *) 75 | 76 | module BigEndian : sig 77 | external read16 : t -> uint16 = "caml_SDL_ReadBE16" 78 | (** {{:http://wiki.libsdl.org/SDL_ReadBE16}api doc} *) 79 | 80 | external read32 : t -> uint32 = "caml_SDL_ReadBE32" 81 | (** {{:http://wiki.libsdl.org/SDL_ReadBE32}api doc} *) 82 | 83 | external read64 : t -> uint64 = "caml_SDL_ReadBE64" 84 | (** {{:http://wiki.libsdl.org/SDL_ReadBE64}api doc} *) 85 | 86 | external write16 : t -> uint16 -> unit = "caml_SDL_WriteBE16" 87 | (** {{:http://wiki.libsdl.org/SDL_WriteBE16}api doc} *) 88 | 89 | external write32 : t -> uint32 -> unit = "caml_SDL_WriteBE32" 90 | (** {{:http://wiki.libsdl.org/SDL_WriteBE32}api doc} *) 91 | 92 | external write64 : t -> uint64 -> unit = "caml_SDL_WriteBE64" 93 | (** {{:http://wiki.libsdl.org/SDL_WriteBE64}api doc} *) 94 | end 95 | 96 | module LittleEndian : sig 97 | external read16 : t -> uint16 = "caml_SDL_ReadLE16" 98 | (** {{:http://wiki.libsdl.org/SDL_ReadLE16}api doc} *) 99 | 100 | external read32 : t -> uint32 = "caml_SDL_ReadLE32" 101 | (** {{:http://wiki.libsdl.org/SDL_ReadLE32}api doc} *) 102 | 103 | external read64 : t -> uint64 = "caml_SDL_ReadLE64" 104 | (** {{:http://wiki.libsdl.org/SDL_ReadLE64}api doc} *) 105 | 106 | external write16 : t -> uint16 -> unit = "caml_SDL_WriteLE16" 107 | (** {{:http://wiki.libsdl.org/SDL_WriteLE16}api doc} *) 108 | 109 | external write32 : t -> uint32 -> unit = "caml_SDL_WriteLE32" 110 | (** {{:http://wiki.libsdl.org/SDL_WriteLE32}api doc} *) 111 | 112 | external write64 : t -> uint64 -> unit = "caml_SDL_WriteLE64" 113 | (** {{:http://wiki.libsdl.org/SDL_WriteLE64}api doc} *) 114 | end 115 | 116 | -------------------------------------------------------------------------------- /src/sdlrwops_stub.c: -------------------------------------------------------------------------------- 1 | /* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | */ 11 | #define CAML_NAME_SPACE 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include 19 | #include "sdlrwops_stub.h" 20 | 21 | #if OCAML_VERSION < 40600 22 | #define Bytes_val(x) String_val(x) 23 | #endif 24 | 25 | CAMLprim value 26 | caml_SDL_RWFromMem(value str) 27 | { 28 | SDL_RWops * rwo = 29 | SDL_RWFromMem( 30 | Bytes_val(str), 31 | caml_string_length(str)); 32 | return Val_SDL_RWops(rwo); 33 | } 34 | 35 | CAMLprim value 36 | caml_SDL_RWFromConstMem(value str) 37 | { 38 | SDL_RWops * rwo = 39 | SDL_RWFromConstMem( 40 | String_val(str), 41 | caml_string_length(str)); 42 | return Val_SDL_RWops(rwo); 43 | } 44 | 45 | CAMLprim value 46 | caml_SDL_RWFromFile(value file, value mode) 47 | { 48 | SDL_RWops * rwo = 49 | SDL_RWFromFile( 50 | String_val(file), 51 | String_val(mode)); 52 | if (rwo == NULL) caml_failwith("Sdlrwops.from_file"); 53 | return Val_SDL_RWops(rwo); 54 | } 55 | 56 | CAMLprim value 57 | caml_SDL_AllocRW(value unit) 58 | { 59 | SDL_RWops * rwo = SDL_AllocRW(); 60 | return Val_SDL_RWops(rwo); 61 | } 62 | 63 | CAMLprim value 64 | caml_SDL_FreeRW(value rwo) 65 | { 66 | SDL_FreeRW(SDL_RWops_val(rwo)); 67 | return Val_unit; 68 | } 69 | 70 | CAMLprim value 71 | caml_SDL_CloseRW(value rwo) 72 | { 73 | SDL_RWclose(SDL_RWops_val(rwo)); 74 | return Val_unit; 75 | } 76 | 77 | CAMLprim value 78 | caml_SDL_RWsize(value rwo) 79 | { 80 | Sint64 size = SDL_RWsize(SDL_RWops_val(rwo)); 81 | return caml_copy_int64(size); 82 | } 83 | 84 | static const int ocaml_SDL_RW_SEEK_table[] = { 85 | RW_SEEK_SET, 86 | RW_SEEK_CUR, 87 | RW_SEEK_END, 88 | }; 89 | #define SDL_RW_SEEK_val(seek) \ 90 | ocaml_SDL_RW_SEEK_table[Long_val(seek)] 91 | 92 | CAMLprim value 93 | caml_SDL_RWseek(value context, value offset, value whence) 94 | { 95 | // returns the final offset in the data stream, or -1 on error. 96 | Sint64 r = 97 | SDL_RWseek( 98 | SDL_RWops_val(context), 99 | Int64_val(offset), 100 | SDL_RW_SEEK_val(whence)); 101 | 102 | return caml_copy_int64(r); 103 | } 104 | 105 | CAMLprim value 106 | caml_SDL_RWtell(value context) 107 | { 108 | // returns the current offset in the data stream, or -1 on error. 109 | Sint64 r = SDL_RWtell(SDL_RWops_val(context)); 110 | return caml_copy_int64(r); 111 | } 112 | 113 | #define Uint8_val(d) (Int_val(d)) 114 | #define Val_Uint8(d) (Val_int(d)) 115 | 116 | #define Uint16_val(d) (Int_val(d)) 117 | #define Val_Uint16(d) (Val_int(d)) 118 | 119 | #define Uint32_val(d) (Int32_val(d)) 120 | #define Val_Uint32(d) (caml_copy_int32(d)) 121 | 122 | #define Uint64_val(d) (Int64_val(d)) 123 | #define Val_Uint64(d) (caml_copy_int64(d)) 124 | 125 | 126 | #define read_int_stub(IntT, SDL_ReadT) \ 127 | CAMLprim value \ 128 | caml_##SDL_ReadT(value rwo) { \ 129 | IntT d = SDL_ReadT(SDL_RWops_val(rwo)); \ 130 | return Val_##IntT(d); \ 131 | } 132 | 133 | read_int_stub(Uint8, SDL_ReadU8) 134 | 135 | read_int_stub(Uint16, SDL_ReadLE16) 136 | read_int_stub(Uint16, SDL_ReadBE16) 137 | read_int_stub(Uint32, SDL_ReadLE32) 138 | read_int_stub(Uint32, SDL_ReadBE32) 139 | read_int_stub(Uint64, SDL_ReadLE64) 140 | read_int_stub(Uint64, SDL_ReadBE64) 141 | 142 | 143 | #if 0 144 | CAMLprim value 145 | caml_SDL_WriteU8(value rwo, Uint8 d) 146 | { 147 | // Returns 1 on successful write, 0 on error. 148 | size_t s = SDL_WriteU8(SDL_RWops_val(rwo), Uint8_val(d)); 149 | if (s == 0) caml_failwith("Sdlrwops.writeU8"); 150 | return Val_unit; 151 | } 152 | #endif 153 | 154 | #define write_int_stub(IntT, SDL_WriteT, ml_writeT) \ 155 | CAMLprim value \ 156 | caml_##SDL_WriteT(value rwo, value d) { \ 157 | size_t s = \ 158 | SDL_WriteT(SDL_RWops_val(rwo), IntT##_val(d)); \ 159 | if (s == 0) caml_failwith("Sdlrwops." ml_writeT); \ 160 | return Val_unit; \ 161 | } 162 | 163 | write_int_stub(Uint8, SDL_WriteU8, "writeU8") 164 | 165 | write_int_stub(Uint16, SDL_WriteLE16, "LittleEndian.write16") 166 | write_int_stub(Uint16, SDL_WriteBE16, "BigEndian.write16") 167 | write_int_stub(Uint32, SDL_WriteLE32, "LittleEndian.write32") 168 | write_int_stub(Uint32, SDL_WriteBE32, "BigEndian.write32") 169 | write_int_stub(Uint64, SDL_WriteLE64, "LittleEndian.write64") 170 | write_int_stub(Uint64, SDL_WriteBE64, "BigEndian.write64") 171 | 172 | /* vim: set ts=4 sw=4 et: */ 173 | -------------------------------------------------------------------------------- /src/sdlrwops_stub.h: -------------------------------------------------------------------------------- 1 | #ifndef _CAML_SDL_RWOPS_ 2 | #define _CAML_SDL_RWOPS_ 3 | 4 | static value Val_SDL_RWops(SDL_RWops * p) 5 | { 6 | return caml_copy_nativeint((intnat) p); 7 | } 8 | 9 | static SDL_RWops * SDL_RWops_val(value v) 10 | { 11 | return (SDL_RWops *) Nativeint_val(v); 12 | } 13 | 14 | #endif /* _CAML_SDL_RWOPS_ */ 15 | -------------------------------------------------------------------------------- /src/sdlscancode.mli: -------------------------------------------------------------------------------- 1 | (** Keyboard scancodes *) 2 | 3 | (** API Doc: 4 | {{:http://wiki.libsdl.org/SDL_Scancode}SDL_Scancode} *) 5 | 6 | type t = 7 | | UNKNOWN 8 | | A 9 | | B 10 | | C 11 | | D 12 | | E 13 | | F 14 | | G 15 | | H 16 | | I 17 | | J 18 | | K 19 | | L 20 | | M 21 | | N 22 | | O 23 | | P 24 | | Q 25 | | R 26 | | S 27 | | T 28 | | U 29 | | V 30 | | W 31 | | X 32 | | Y 33 | | Z 34 | | Num1 35 | | Num2 36 | | Num3 37 | | Num4 38 | | Num5 39 | | Num6 40 | | Num7 41 | | Num8 42 | | Num9 43 | | Num0 44 | | RETURN 45 | | ESCAPE 46 | | BACKSPACE 47 | | TAB 48 | | SPACE 49 | | MINUS 50 | | EQUALS 51 | | LEFTBRACKET 52 | | RIGHTBRACKET 53 | | BACKSLASH 54 | | NONUSHASH 55 | | SEMICOLON 56 | | APOSTROPHE 57 | | GRAVE 58 | | COMMA 59 | | PERIOD 60 | | SLASH 61 | | CAPSLOCK 62 | | F1 63 | | F2 64 | | F3 65 | | F4 66 | | F5 67 | | F6 68 | | F7 69 | | F8 70 | | F9 71 | | F10 72 | | F11 73 | | F12 74 | | PRINTSCREEN 75 | | SCROLLLOCK 76 | | PAUSE 77 | | INSERT 78 | | HOME 79 | | PAGEUP 80 | | DELETE 81 | | END 82 | | PAGEDOWN 83 | | RIGHT 84 | | LEFT 85 | | DOWN 86 | | UP 87 | | NUMLOCKCLEAR 88 | | KP_DIVIDE 89 | | KP_MULTIPLY 90 | | KP_MINUS 91 | | KP_PLUS 92 | | KP_ENTER 93 | | KP_1 94 | | KP_2 95 | | KP_3 96 | | KP_4 97 | | KP_5 98 | | KP_6 99 | | KP_7 100 | | KP_8 101 | | KP_9 102 | | KP_0 103 | | KP_PERIOD 104 | | NONUSBACKSLASH 105 | | APPLICATION 106 | | POWER 107 | | KP_EQUALS 108 | | F13 109 | | F14 110 | | F15 111 | | F16 112 | | F17 113 | | F18 114 | | F19 115 | | F20 116 | | F21 117 | | F22 118 | | F23 119 | | F24 120 | | EXECUTE 121 | | HELP 122 | | MENU 123 | | SELECT 124 | | STOP 125 | | AGAIN 126 | | UNDO 127 | | CUT 128 | | COPY 129 | | PASTE 130 | | FIND 131 | | MUTE 132 | | VOLUMEUP 133 | | VOLUMEDOWN 134 | | KP_COMMA 135 | | KP_EQUALSAS400 136 | | INTERNATIONAL1 137 | | INTERNATIONAL2 138 | | INTERNATIONAL3 139 | | INTERNATIONAL4 140 | | INTERNATIONAL5 141 | | INTERNATIONAL6 142 | | INTERNATIONAL7 143 | | INTERNATIONAL8 144 | | INTERNATIONAL9 145 | | LANG1 146 | | LANG2 147 | | LANG3 148 | | LANG4 149 | | LANG5 150 | | LANG6 151 | | LANG7 152 | | LANG8 153 | | LANG9 154 | | ALTERASE 155 | | SYSREQ 156 | | CANCEL 157 | | CLEAR 158 | | PRIOR 159 | | RETURN2 160 | | SEPARATOR 161 | | OUT 162 | | OPER 163 | | CLEARAGAIN 164 | | CRSEL 165 | | EXSEL 166 | | KP_00 167 | | KP_000 168 | | THOUSANDSSEPARATOR 169 | | DECIMALSEPARATOR 170 | | CURRENCYUNIT 171 | | CURRENCYSUBUNIT 172 | | KP_LEFTPAREN 173 | | KP_RIGHTPAREN 174 | | KP_LEFTBRACE 175 | | KP_RIGHTBRACE 176 | | KP_TAB 177 | | KP_BACKSPACE 178 | | KP_A 179 | | KP_B 180 | | KP_C 181 | | KP_D 182 | | KP_E 183 | | KP_F 184 | | KP_XOR 185 | | KP_POWER 186 | | KP_PERCENT 187 | | KP_LESS 188 | | KP_GREATER 189 | | KP_AMPERSAND 190 | | KP_DBLAMPERSAND 191 | | KP_VERTICALBAR 192 | | KP_DBLVERTICALBAR 193 | | KP_COLON 194 | | KP_HASH 195 | | KP_SPACE 196 | | KP_AT 197 | | KP_EXCLAM 198 | | KP_MEMSTORE 199 | | KP_MEMRECALL 200 | | KP_MEMCLEAR 201 | | KP_MEMADD 202 | | KP_MEMSUBTRACT 203 | | KP_MEMMULTIPLY 204 | | KP_MEMDIVIDE 205 | | KP_PLUSMINUS 206 | | KP_CLEAR 207 | | KP_CLEARENTRY 208 | | KP_BINARY 209 | | KP_OCTAL 210 | | KP_DECIMAL 211 | | KP_HEXADECIMAL 212 | | LCTRL 213 | | LSHIFT 214 | | LALT 215 | | LGUI 216 | | RCTRL 217 | | RSHIFT 218 | | RALT 219 | | RGUI 220 | | MODE 221 | | AUDIONEXT 222 | | AUDIOPREV 223 | | AUDIOSTOP 224 | | AUDIOPLAY 225 | | AUDIOMUTE 226 | | MEDIASELECT 227 | | WWW 228 | | MAIL 229 | | CALCULATOR 230 | | COMPUTER 231 | | AC_SEARCH 232 | | AC_HOME 233 | | AC_BACK 234 | | AC_FORWARD 235 | | AC_STOP 236 | | AC_REFRESH 237 | | AC_BOOKMARKS 238 | | BRIGHTNESSDOWN 239 | | BRIGHTNESSUP 240 | | DISPLAYSWITCH 241 | | KBDILLUMTOGGLE 242 | | KBDILLUMDOWN 243 | | KBDILLUMUP 244 | | EJECT 245 | | SLEEP 246 | 247 | val to_string : t -> string 248 | val of_string : string -> t 249 | 250 | -------------------------------------------------------------------------------- /src/sdlsurface.ml: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (* Surface definition and management *) 12 | 13 | type t 14 | 15 | external create_rgb : 16 | width:int -> 17 | height:int -> 18 | depth:int -> t 19 | = "caml_SDL_CreateRGBSurface" 20 | 21 | external free : t -> unit 22 | = "caml_SDL_FreeSurface" 23 | 24 | external load_bmp : filename:string -> t 25 | = "caml_SDL_LoadBMP" 26 | 27 | external save_bmp : t -> filename:string -> unit 28 | = "caml_SDL_SaveBMP" 29 | 30 | external fill_rect : 31 | dst:t -> rect:Sdlrect.t -> 32 | color:int32 -> unit 33 | = "caml_SDL_FillRect" 34 | 35 | external blit_surface : 36 | src:t -> src_rect:Sdlrect.t -> 37 | dst:t -> dst_rect:Sdlrect.t -> 38 | Sdlrect.t 39 | = "caml_SDL_BlitSurface" 40 | 41 | external blit_surf : 42 | src:t -> dst:t -> dst_rect:Sdlrect.t -> 43 | Sdlrect.t 44 | = "caml_SDL_BlitSurf" 45 | 46 | external blit_surfs : 47 | src:t -> dst:t -> dst_rect:Sdlrect.t -> unit 48 | = "caml_SDL_BlitSurfs" 49 | 50 | external blit_pixels_unsafe : 51 | t -> string -> unit 52 | = "caml_SDL_Surface_Blit_Pixels" 53 | 54 | external set_color_key : t -> enable:bool -> key:int32 -> unit 55 | = "caml_SDL_SetColorKey" 56 | 57 | external set_color_key_map_rgb : t -> enable:bool -> 58 | rgb:(int * int * int) -> unit 59 | = "caml_SDL_SetColorKey_MapRGB" 60 | 61 | external get_width : t -> int = "caml_SDL_SurfaceGetWidth" 62 | external get_height : t -> int = "caml_SDL_SurfaceGetHeight" 63 | 64 | external get_dims : t -> int * int = "caml_SDL_SurfaceGetDims" 65 | 66 | external get_pitch : t -> int = "caml_SDL_SurfaceGetPitch" 67 | 68 | external get_pixel32_unsafe : t -> x:int -> y:int -> int32 69 | = "caml_SDL_SurfaceGetPixel32" 70 | 71 | external get_pixel16_unsafe : t -> x:int -> y:int -> int32 72 | = "caml_SDL_SurfaceGetPixel16" 73 | 74 | external get_pixel8_unsafe : t -> x:int -> y:int -> int32 75 | = "caml_SDL_SurfaceGetPixel8" 76 | 77 | external get_bits_per_pixel : t -> int 78 | = "caml_SDL_SurfaceGetBitsPerPixel" 79 | 80 | external has_palette : t -> bool 81 | = "caml_SDL_SurfaceHasPalette" 82 | 83 | external palette_num_colors : t -> int 84 | = "caml_SDL_SurfacePaletteColors" 85 | 86 | external set_blend_mode : t -> SdlblendMode.t -> unit 87 | = "caml_SDL_SetSurfaceBlendMode" 88 | 89 | external get_pixelformat_t : t -> SdlpixelFormat.t 90 | = "caml_SDL_Surface_get_pixelformat_t" 91 | 92 | external get_pixels : t -> string 93 | = "caml_SDL_Surface_get_pixels" 94 | 95 | -------------------------------------------------------------------------------- /src/sdlsurface.mli: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (** Surface definition and management *) 12 | 13 | (** API Doc: 14 | {{:http://wiki.libsdl.org/CategorySurface}Surface category} *) 15 | 16 | type t 17 | 18 | external create_rgb : 19 | width:int -> 20 | height:int -> 21 | depth:int -> t 22 | = "caml_SDL_CreateRGBSurface" 23 | (** {{:http://wiki.libsdl.org/SDL_CreateRGBSurface}api doc} *) 24 | 25 | external free : t -> unit 26 | = "caml_SDL_FreeSurface" 27 | (** {{:http://wiki.libsdl.org/SDL_FreeSurface}api doc} *) 28 | 29 | external load_bmp : filename:string -> t 30 | = "caml_SDL_LoadBMP" 31 | (** {{:http://wiki.libsdl.org/SDL_LoadBMP}api doc} *) 32 | 33 | external save_bmp : t -> filename:string -> unit 34 | = "caml_SDL_SaveBMP" 35 | (** {{:http://wiki.libsdl.org/SDL_SaveBMP}api doc} *) 36 | 37 | external fill_rect : 38 | dst:t -> rect:Sdlrect.t -> 39 | color:int32 -> unit 40 | = "caml_SDL_FillRect" 41 | (** {{:http://wiki.libsdl.org/SDL_FillRect}api doc} *) 42 | 43 | external blit_surface : 44 | src:t -> src_rect:Sdlrect.t -> 45 | dst:t -> dst_rect:Sdlrect.t -> 46 | Sdlrect.t 47 | = "caml_SDL_BlitSurface" 48 | (** {{:http://wiki.libsdl.org/SDL_BlitSurface}api doc} *) 49 | 50 | external blit_surf : 51 | src:t -> dst:t -> dst_rect:Sdlrect.t -> 52 | Sdlrect.t 53 | = "caml_SDL_BlitSurf" 54 | (** same than [blit_surface] but without the [src_rect] parameter *) 55 | 56 | external blit_surfs : 57 | src:t -> dst:t -> dst_rect:Sdlrect.t -> unit 58 | = "caml_SDL_BlitSurfs" 59 | (** same than [blit_surf] but returning [unit] *) 60 | 61 | external blit_pixels_unsafe : 62 | t -> string -> unit 63 | = "caml_SDL_Surface_Blit_Pixels" 64 | (** {{:http://wiki.libsdl.org/SDL_Surface}api doc} *) 65 | 66 | external set_color_key : t -> enable:bool -> key:int32 -> unit 67 | = "caml_SDL_SetColorKey" 68 | (** {{:http://wiki.libsdl.org/SDL_SetColorKey}api doc} *) 69 | 70 | external set_color_key_map_rgb : t -> enable:bool -> 71 | rgb:(int * int * int) -> unit 72 | = "caml_SDL_SetColorKey_MapRGB" 73 | 74 | external get_width : t -> int = "caml_SDL_SurfaceGetWidth" 75 | external get_height : t -> int = "caml_SDL_SurfaceGetHeight" 76 | external get_dims : t -> int * int = "caml_SDL_SurfaceGetDims" 77 | external get_pitch : t -> int = "caml_SDL_SurfaceGetPitch" 78 | 79 | external get_pixel32_unsafe : t -> x:int -> y:int -> int32 80 | = "caml_SDL_SurfaceGetPixel32" 81 | 82 | external get_pixel16_unsafe : t -> x:int -> y:int -> int32 83 | = "caml_SDL_SurfaceGetPixel16" 84 | 85 | external get_pixel8_unsafe : t -> x:int -> y:int -> int32 86 | = "caml_SDL_SurfaceGetPixel8" 87 | 88 | external get_bits_per_pixel : t -> int 89 | = "caml_SDL_SurfaceGetBitsPerPixel" 90 | 91 | external has_palette : t -> bool 92 | = "caml_SDL_SurfaceHasPalette" 93 | 94 | external palette_num_colors : t -> int 95 | = "caml_SDL_SurfacePaletteColors" 96 | (** number of colors in the palette, if any, [-1] otherwise *) 97 | 98 | external set_blend_mode : t -> SdlblendMode.t -> unit 99 | = "caml_SDL_SetSurfaceBlendMode" 100 | (** {{:http://wiki.libsdl.org/SDL_SetSurfaceBlendMode}api doc} *) 101 | 102 | external get_pixelformat_t : t -> SdlpixelFormat.t 103 | = "caml_SDL_Surface_get_pixelformat_t" 104 | 105 | external get_pixels : t -> string 106 | = "caml_SDL_Surface_get_pixels" 107 | (** {{:http://wiki.libsdl.org/SDL_Surface}api doc} *) 108 | 109 | -------------------------------------------------------------------------------- /src/sdlsurface_ba.ml: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2014 Piotr Mardziel 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (* Surface definition and management *) 12 | 13 | type t = Sdlsurface.t 14 | 15 | external get_pixels : 16 | t -> (int, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t 17 | = "caml_SDL_Surface_ba_get_pixels" 18 | 19 | external create_rgb_surface_from : 20 | pixels:(int, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t -> 21 | width:int -> height:int -> depth:int -> pitch:int -> 22 | r_mask:int32 -> 23 | g_mask:int32 -> 24 | b_mask:int32 -> 25 | a_mask:int32 -> t 26 | = "caml_SDL_CreateRGBSurfaceFrom_bytecode" 27 | "caml_SDL_CreateRGBSurfaceFrom" 28 | 29 | -------------------------------------------------------------------------------- /src/sdlsurface_ba.mli: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2014 Piotr Mardziel 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (** Surface access with Bigarrays *) 12 | 13 | (** API Doc: 14 | {{:http://wiki.libsdl.org/SDL_Surface}Surface Structure} *) 15 | 16 | type t = Sdlsurface.t 17 | 18 | external get_pixels : 19 | t -> (int, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t 20 | = "caml_SDL_Surface_ba_get_pixels" 21 | 22 | external create_rgb_surface_from : 23 | pixels:(int, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t -> 24 | width:int -> height:int -> depth:int -> pitch:int -> 25 | r_mask:int32 -> 26 | g_mask:int32 -> 27 | b_mask:int32 -> 28 | a_mask:int32 -> t 29 | = "caml_SDL_CreateRGBSurfaceFrom_bytecode" 30 | "caml_SDL_CreateRGBSurfaceFrom" 31 | 32 | -------------------------------------------------------------------------------- /src/sdlsurface_ba_stub.c: -------------------------------------------------------------------------------- 1 | /* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2014 Piotr Mardziel 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | */ 11 | #define CAML_NAME_SPACE 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include 19 | #include "sdlsurface_stub.h" 20 | 21 | CAMLprim value 22 | caml_SDL_Surface_ba_get_pixels(value surface) 23 | { 24 | SDL_Surface *surf = SDL_Surface_val(surface); 25 | 26 | int b_flag = 0; 27 | long dim = surf->h; 28 | 29 | dim *= surf->pitch; 30 | b_flag |= CAML_BA_UINT8; 31 | 32 | b_flag |= CAML_BA_C_LAYOUT | CAML_BA_EXTERNAL ; 33 | 34 | return caml_ba_alloc(b_flag, 1, surf->pixels, &dim); 35 | } 36 | 37 | #define Uint32_val(d) (Int32_val(d)) 38 | 39 | CAMLprim value 40 | caml_SDL_CreateRGBSurfaceFrom( 41 | value pixels, value width, value height, value depth, value pitch, 42 | value Rmask, value Gmask, value Bmask, value Amask) 43 | { 44 | SDL_Surface *surf = 45 | SDL_CreateRGBSurfaceFrom( 46 | (void *) Caml_ba_data_val(pixels), 47 | Int_val(width), 48 | Int_val(height), 49 | Int_val(depth), 50 | Int_val(pitch), 51 | Uint32_val(Rmask), 52 | Uint32_val(Gmask), 53 | Uint32_val(Bmask), 54 | Uint32_val(Amask)); 55 | 56 | return Val_SDL_Surface(surf); 57 | } 58 | 59 | CAMLprim value 60 | caml_SDL_CreateRGBSurfaceFrom_bytecode(value * argv, int argn) 61 | { 62 | return caml_SDL_CreateRGBSurfaceFrom( 63 | argv[0], argv[1], argv[2], 64 | argv[3], argv[4], argv[5], 65 | argv[6], argv[7], argv[8] ); 66 | } 67 | 68 | /* vim: set ts=4 sw=4 et: */ 69 | -------------------------------------------------------------------------------- /src/sdlsurface_stub.h: -------------------------------------------------------------------------------- 1 | #ifndef _CAML_SDL_SURFACE_ 2 | #define _CAML_SDL_SURFACE_ 3 | 4 | static value Val_SDL_Surface(SDL_Surface * p) 5 | { 6 | return caml_copy_nativeint((intnat) p); 7 | } 8 | 9 | static SDL_Surface * SDL_Surface_val(value v) 10 | { 11 | return (SDL_Surface *) Nativeint_val(v); 12 | } 13 | 14 | #endif /* _CAML_SDL_SURFACE_ */ 15 | -------------------------------------------------------------------------------- /src/sdltexture.ml: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (* Textures *) 12 | 13 | type t 14 | 15 | external create : 16 | Sdltype.renderer -> SdlpixelFormat.t -> SdltextureAccess.t -> int -> int -> t 17 | = "caml_SDL_CreateTexture" 18 | 19 | external create_from_surface : 20 | Sdltype.renderer -> Sdlsurface.t -> t 21 | = "caml_SDL_CreateTextureFromSurface" 22 | 23 | external destroy : t -> unit 24 | = "caml_SDL_DestroyTexture" 25 | 26 | external set_blend_mode : t -> SdlblendMode.t -> unit 27 | = "caml_SDL_SetTextureBlendMode" [@@noalloc] 28 | 29 | external get_blend_mode : t -> SdlblendMode.t 30 | = "caml_SDL_GetTextureBlendMode" 31 | 32 | external set_alpha_mod : t -> alpha:int -> unit 33 | = "caml_SDL_SetTextureAlphaMod" 34 | 35 | external get_alpha_mod : t -> int 36 | = "caml_SDL_GetTextureAlphaMod" 37 | 38 | external set_color_mod : t -> int * int * int -> unit 39 | = "caml_SDL_SetTextureColorMod" 40 | 41 | external set_color_mod3 : t -> r:int -> g:int -> b:int -> unit 42 | = "caml_SDL_SetTextureColorMod3" 43 | 44 | external get_color_mod : t -> int * int * int 45 | = "caml_SDL_GetTextureColorMod" 46 | 47 | -------------------------------------------------------------------------------- /src/sdltexture.mli: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (** Textures *) 12 | 13 | (** An efficient driver-specific representation of pixel data. *) 14 | 15 | type t 16 | 17 | external create : 18 | Sdltype.renderer -> SdlpixelFormat.t -> SdltextureAccess.t -> int -> int -> t 19 | = "caml_SDL_CreateTexture" 20 | (** {{:http://wiki.libsdl.org/SDL_CreateTexture}api doc} *) 21 | 22 | external create_from_surface : 23 | Sdltype.renderer -> Sdlsurface.t -> t 24 | = "caml_SDL_CreateTextureFromSurface" 25 | (** {{:http://wiki.libsdl.org/SDL_CreateTextureFromSurface}api doc} *) 26 | 27 | external destroy : t -> unit 28 | = "caml_SDL_DestroyTexture" 29 | (** {{:http://wiki.libsdl.org/SDL_DestroyTexture}api doc} *) 30 | 31 | external set_blend_mode : t -> SdlblendMode.t -> unit 32 | = "caml_SDL_SetTextureBlendMode" [@@noalloc] 33 | (** {{:http://wiki.libsdl.org/SDL_SetTextureBlendMode}api doc} *) 34 | 35 | external get_blend_mode : t -> SdlblendMode.t 36 | = "caml_SDL_GetTextureBlendMode" 37 | (** {{:http://wiki.libsdl.org/SDL_GetTextureBlendMode}api doc} *) 38 | 39 | external set_alpha_mod : t -> alpha:int -> unit 40 | = "caml_SDL_SetTextureAlphaMod" 41 | (** {{:http://wiki.libsdl.org/SDL_SetTextureAlphaMod}api doc} *) 42 | 43 | external get_alpha_mod : t -> int 44 | = "caml_SDL_GetTextureAlphaMod" 45 | (** {{:http://wiki.libsdl.org/SDL_GetTextureAlphaMod}api doc} *) 46 | 47 | external set_color_mod : t -> int * int * int -> unit 48 | = "caml_SDL_SetTextureColorMod" 49 | (** {{:http://wiki.libsdl.org/SDL_SetTextureColorMod}api doc} *) 50 | 51 | external set_color_mod3 : t -> r:int -> g:int -> b:int -> unit 52 | = "caml_SDL_SetTextureColorMod3" 53 | (** {{:http://wiki.libsdl.org/SDL_SetTextureColorMod}api doc} *) 54 | 55 | external get_color_mod : t -> int * int * int 56 | = "caml_SDL_GetTextureColorMod" 57 | (** {{:http://wiki.libsdl.org/SDL_GetTextureColorMod}api doc} *) 58 | 59 | -------------------------------------------------------------------------------- /src/sdltextureAccess.ml: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2022 Carsten Elton Sørensen 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (* Texture access kind *) 12 | 13 | type t = 14 | | Static 15 | | Streaming 16 | | Target 17 | 18 | 19 | let to_string = function 20 | | Static -> "SDL_TEXTUREACCESS_STATIC" 21 | | Streaming -> "SDL_TEXTUREACCESS_STREAMING" 22 | | Target -> "SDL_TEXTUREACCESS_TARGET" 23 | 24 | 25 | let of_string s = 26 | match String.uppercase_ascii s with 27 | | "SDL_TEXTUREACCESS_STATIC" -> Static 28 | | "SDL_TEXTUREACCESS_STREAMING" -> Streaming 29 | | "SDL_TEXTUREACCESS_TARGET" -> Target 30 | | _ -> invalid_arg "SdltextureAccess.of_string" 31 | 32 | -------------------------------------------------------------------------------- /src/sdltextureAccess.mli: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2022 Carsten Elton Sørensen 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (** Texture access kind *) 12 | 13 | (** {{:https://wiki.libsdl.org/SDL_TextureAccess}api doc} *) 14 | type t = 15 | | Static 16 | | Streaming 17 | | Target 18 | 19 | val to_string : t -> string 20 | val of_string : string -> t 21 | 22 | -------------------------------------------------------------------------------- /src/sdltexture_ba.ml: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2022 Carsten Elton Sørensen 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (** Texture access with Bigarrays *) 12 | 13 | 14 | type t = Sdltexture.t 15 | 16 | external ex_lock : 17 | t -> Sdlrect.t option -> ('a, 'b) Bigarray.kind -> int -> (('a, 'b, Bigarray.c_layout) Bigarray.Array1.t * int) option 18 | = "caml_SDL_Texture_ba_lock" 19 | (** {{:http://wiki.libsdl.org/SDL_LockTexture}api doc} *) 20 | 21 | let lock tex ?rect kind = 22 | ex_lock tex rect kind (Bigarray.kind_size_in_bytes kind) 23 | 24 | external unlock : 25 | t -> unit 26 | = "caml_SDL_Texture_ba_unlock" [@@noalloc] 27 | (** {{:http://wiki.libsdl.org/SDL_UnlockTexture}api doc} *) 28 | -------------------------------------------------------------------------------- /src/sdltexture_ba.mli: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2022 Carsten Elton Sørensen 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (** Texture access with Bigarrays *) 12 | 13 | 14 | type t = Sdltexture.t 15 | 16 | val lock : 17 | t -> ?rect:Sdlrect.t -> ('a, 'b) Bigarray.kind -> (('a, 'b, Bigarray.c_layout) Bigarray.Array1.t * int) option 18 | (** {{:http://wiki.libsdl.org/SDL_LockTexture}api doc} *) 19 | 20 | 21 | external unlock : 22 | t -> unit 23 | = "caml_SDL_Texture_ba_unlock" [@@noalloc] 24 | (** {{:http://wiki.libsdl.org/SDL_UnlockTexture}api doc} *) 25 | -------------------------------------------------------------------------------- /src/sdltexture_ba_stub.c: -------------------------------------------------------------------------------- 1 | /* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2022 Carsten Elton Sørensen 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | */ 11 | #define CAML_NAME_SPACE 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #include 20 | #include "sdltexture_stub.h" 21 | #include "sdlrect_stub.h" 22 | 23 | #if OCAML_VERSION < 41200 24 | #define Val_none Val_int(0) 25 | 26 | static value 27 | Val_some(value v) 28 | { 29 | CAMLparam1(v); 30 | CAMLlocal1(some); 31 | some = caml_alloc(1, 0); 32 | Store_field(some, 0, v); 33 | CAMLreturn(some); 34 | } 35 | #else 36 | #define Val_some caml_alloc_some 37 | #endif 38 | 39 | CAMLprim value 40 | caml_SDL_Texture_ba_lock(value texture, value rect, value kind, value kind_size) 41 | { 42 | CAMLparam4(texture, rect, kind, kind_size); 43 | CAMLlocal2(tuple, ba); 44 | 45 | SDL_Rect sdl_rect; 46 | SDL_Rect* p_rect = NULL; 47 | 48 | if (Is_some(rect)) 49 | { 50 | p_rect = &sdl_rect; 51 | SDL_Rect_val(p_rect, Some_val(rect)); 52 | } 53 | 54 | SDL_Texture* sdl_texture = SDL_Texture_val(texture); 55 | 56 | void* pixels; 57 | int pitch; 58 | 59 | int r = 60 | SDL_LockTexture( 61 | sdl_texture, 62 | p_rect, 63 | &pixels, 64 | &pitch); 65 | 66 | if (r != 0) 67 | { 68 | CAMLreturn(Val_none); 69 | } 70 | 71 | pitch /= Int_val(kind_size); 72 | 73 | int height; 74 | if (p_rect != NULL) { 75 | height = p_rect->h; 76 | } else { 77 | SDL_QueryTexture(sdl_texture, NULL, NULL, NULL, &height); 78 | } 79 | 80 | long dim = height * pitch; 81 | int b_flag = Caml_ba_kind_val(kind) | CAML_BA_C_LAYOUT | CAML_BA_EXTERNAL ; 82 | 83 | tuple = caml_alloc_tuple(2); 84 | ba = caml_ba_alloc_dims(b_flag, 1, pixels, dim); 85 | Store_field(tuple, 0, ba); 86 | Store_field(tuple, 1, Val_int(pitch)); 87 | 88 | CAMLreturn(Val_some(tuple)); 89 | } 90 | 91 | 92 | CAMLprim value 93 | caml_SDL_Texture_ba_unlock(value texture) 94 | { 95 | SDL_UnlockTexture(SDL_Texture_val(texture)); 96 | 97 | return Val_unit; 98 | } 99 | 100 | 101 | /* vim: set ts=4 sw=4 et: */ 102 | 103 | -------------------------------------------------------------------------------- /src/sdltexture_stub.c: -------------------------------------------------------------------------------- 1 | /* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | */ 11 | #define CAML_NAME_SPACE 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | #include "sdlrender_stub.h" 19 | #include "sdlpixelFormat_stub.h" 20 | #include "sdltexture_stub.h" 21 | #include "sdlsurface_stub.h" 22 | #include "sdlblendMode_stub.h" 23 | 24 | CAMLprim value 25 | caml_SDL_CreateTexture(value renderer, value format, value access, value w, value h) 26 | { 27 | SDL_Texture *tex = 28 | SDL_CreateTexture( 29 | SDL_Renderer_val(renderer), 30 | Sdl_pixelformat_t(format), 31 | Int_val(access), 32 | Int_val(w), 33 | Int_val(h)); 34 | if (!tex) 35 | caml_failwith("Sdltexture.create"); 36 | return Val_SDL_Texture(tex); 37 | } 38 | 39 | CAMLprim value 40 | caml_SDL_CreateTextureFromSurface(value renderer, value surface) 41 | { 42 | SDL_Texture *tex = 43 | SDL_CreateTextureFromSurface( 44 | SDL_Renderer_val(renderer), 45 | SDL_Surface_val(surface)); 46 | if (!tex) 47 | caml_failwith("Sdltexture.create_from_surface"); 48 | return Val_SDL_Texture(tex); 49 | } 50 | 51 | CAMLprim value 52 | caml_SDL_DestroyTexture(value texture) 53 | { 54 | SDL_DestroyTexture(SDL_Texture_val(texture)); 55 | return Val_unit; 56 | } 57 | 58 | #define Uint8_val Int_val 59 | #define Val_uint8(uc) Val_int((int)uc) 60 | 61 | CAMLprim value 62 | caml_SDL_SetTextureAlphaMod(value texture, value alpha) 63 | { 64 | int r = 65 | SDL_SetTextureAlphaMod( 66 | SDL_Texture_val(texture), 67 | Uint8_val(alpha)); 68 | if (r) 69 | caml_failwith("Sdltexture.set_alpha_mod"); 70 | return Val_unit; 71 | } 72 | 73 | CAMLprim value 74 | caml_SDL_GetTextureAlphaMod(value texture) 75 | { 76 | Uint8 alpha; 77 | int r = 78 | SDL_GetTextureAlphaMod( 79 | SDL_Texture_val(texture), 80 | &alpha); 81 | if (r) 82 | caml_failwith("Sdltexture.get_alpha_mod"); 83 | return Val_uint8(alpha); 84 | } 85 | 86 | CAMLprim value 87 | caml_SDL_SetTextureColorMod(value texture, value rgb) 88 | { 89 | value r = Field(rgb,0); 90 | value g = Field(rgb,1); 91 | value b = Field(rgb,2); 92 | int s = 93 | SDL_SetTextureColorMod( 94 | SDL_Texture_val(texture), 95 | Uint8_val(r), Uint8_val(g), Uint8_val(b)); 96 | if (s) 97 | caml_failwith("Sdltexture.set_color_mod"); 98 | return Val_unit; 99 | } 100 | 101 | CAMLprim value 102 | caml_SDL_SetTextureColorMod3( 103 | value texture, value r, value g, value b) 104 | { 105 | int s = 106 | SDL_SetTextureColorMod( 107 | SDL_Texture_val(texture), 108 | Uint8_val(r), Uint8_val(g), Uint8_val(b)); 109 | if (s) 110 | caml_failwith("Sdltexture.set_color_mod3"); 111 | return Val_unit; 112 | } 113 | 114 | CAMLprim value 115 | caml_SDL_SetTextureBlendMode(value texture, value blendMode) 116 | { 117 | int r = 118 | SDL_SetTextureBlendMode( 119 | SDL_Texture_val(texture), 120 | SDL_BlendMode_val(blendMode)); 121 | if (r) 122 | caml_failwith("Sdltexture.set_blend_mode"); 123 | return Val_unit; 124 | } 125 | 126 | CAMLprim value 127 | caml_SDL_GetTextureBlendMode(value texture) 128 | { 129 | SDL_BlendMode blendMode; 130 | int r = 131 | SDL_GetTextureBlendMode( 132 | SDL_Texture_val(texture), 133 | &blendMode); 134 | if (r) 135 | caml_failwith("Sdltexture.get_blend_mode"); 136 | return Val_SDL_BlendMode(blendMode); 137 | } 138 | 139 | CAMLprim value 140 | caml_SDL_GetTextureColorMod(value texture) 141 | { 142 | CAMLparam1(texture); 143 | CAMLlocal1(rgb); 144 | 145 | Uint8 r, g, b; 146 | int s = 147 | SDL_GetTextureColorMod( 148 | SDL_Texture_val(texture), 149 | &r, &g, &b); 150 | if (s) 151 | caml_failwith("Sdltexture.get_color_mod"); 152 | 153 | rgb = caml_alloc(3, 0); 154 | Store_field(rgb, 0, Val_uint8(r)); 155 | Store_field(rgb, 1, Val_uint8(g)); 156 | Store_field(rgb, 2, Val_uint8(b)); 157 | CAMLreturn(rgb); 158 | } 159 | 160 | #undef Val_uint8 161 | #undef Uint8_val 162 | 163 | /* vim: set ts=4 sw=4 et: */ 164 | -------------------------------------------------------------------------------- /src/sdltexture_stub.h: -------------------------------------------------------------------------------- 1 | #ifndef _CAML_SDL_TEXTURE_ 2 | #define _CAML_SDL_TEXTURE_ 3 | 4 | static value Val_SDL_Texture(SDL_Texture * p) 5 | { 6 | return caml_copy_nativeint((intnat) p); 7 | } 8 | 9 | static SDL_Texture * SDL_Texture_val(value v) 10 | { 11 | return (SDL_Texture *) Nativeint_val(v); 12 | } 13 | 14 | #endif /* _CAML_SDL_TEXTURE_ */ 15 | -------------------------------------------------------------------------------- /src/sdltimer.ml: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (** Time management *) 12 | 13 | external get_ticks : unit -> int 14 | = "caml_SDL_GetTicks" [@@noalloc] 15 | 16 | module D = struct 17 | external get_ticks : unit -> int * int 18 | = "caml_SDL_GetTicks_d" 19 | end 20 | 21 | external delay : ms:int -> unit 22 | = "caml_SDL_Delay" 23 | 24 | (* vim: set ts=2 sw=2 et: *) 25 | -------------------------------------------------------------------------------- /src/sdltimer.mli: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (** Time management *) 12 | 13 | (** API Doc: 14 | {{:http://wiki.libsdl.org/CategoryTimer}Timer category} *) 15 | 16 | external get_ticks : unit -> int = "caml_SDL_GetTicks" [@@noalloc] 17 | (** {{:http://wiki.libsdl.org/SDL_GetTicks}api doc} *) 18 | 19 | module D : sig 20 | external get_ticks : unit -> int * int = "caml_SDL_GetTicks_d" 21 | (** (seconds, milliseconds) *) 22 | end 23 | 24 | external delay : ms:int -> unit = "caml_SDL_Delay" 25 | (** {{:http://wiki.libsdl.org/SDL_Delay}api doc} *) 26 | 27 | (* vim: set ts=2 sw=2 et: *) 28 | -------------------------------------------------------------------------------- /src/sdltimer_stub.c: -------------------------------------------------------------------------------- 1 | /* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | */ 11 | #define CAML_NAME_SPACE 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | 19 | CAMLprim value 20 | caml_SDL_GetTicks(value unit) 21 | { 22 | Uint32 ticks = SDL_GetTicks(); 23 | return Val_long(ticks); 24 | } 25 | 26 | CAMLprim value 27 | caml_SDL_GetTicks_d(value unit) 28 | { 29 | CAMLparam1(unit); 30 | CAMLlocal1(ret); 31 | static const Uint32 th = 1000; 32 | Uint32 ticks = SDL_GetTicks(); 33 | Uint32 sec = ticks / th; 34 | Uint32 msec = ticks - sec * th; 35 | ret = caml_alloc(2, 0); 36 | Store_field(ret, 0, Val_int(sec)); 37 | Store_field(ret, 1, Val_int(msec)); 38 | CAMLreturn(ret); 39 | } 40 | 41 | CAMLprim value 42 | caml_SDL_Delay(value ms) 43 | { 44 | SDL_Delay(Long_val(ms)); 45 | return Val_unit; 46 | } 47 | 48 | /* vim: set ts=4 sw=4 et: */ 49 | -------------------------------------------------------------------------------- /src/sdltype.ml: -------------------------------------------------------------------------------- 1 | type renderer 2 | -------------------------------------------------------------------------------- /src/sdltype.mli: -------------------------------------------------------------------------------- 1 | type renderer 2 | -------------------------------------------------------------------------------- /src/sdlversion.ml: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (* SDL version used *) 12 | 13 | type version = int * int * int 14 | 15 | external get_runtime_version : unit -> version 16 | = "caml_SDL_GetRunTimeVersion" 17 | 18 | external get_compiled_version : unit -> version 19 | = "caml_SDL_GetCompiledVersion" 20 | 21 | external get_revision_string : unit -> string 22 | = "caml_SDL_GetRevisionString" 23 | 24 | external get_revision_number : unit -> int 25 | = "caml_SDL_GetRevisionNumber" 26 | 27 | module R = struct 28 | (* record version type *) 29 | type version = { 30 | major: int; 31 | minor: int; 32 | patch: int; 33 | } 34 | 35 | external get_runtime_version : unit -> version 36 | = "caml_SDL_GetRunTimeVersion" 37 | 38 | external get_compiled_version : unit -> version 39 | = "caml_SDL_GetCompiledVersion" 40 | end 41 | 42 | -------------------------------------------------------------------------------- /src/sdlversion.mli: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (** SDL version used *) 12 | 13 | (** API Doc: 14 | {{:http://wiki.libsdl.org/CategoryVersion}Version category} *) 15 | 16 | type version = int * int * int 17 | 18 | external get_runtime_version : unit -> version 19 | = "caml_SDL_GetRunTimeVersion" 20 | (** {{:http://wiki.libsdl.org/SDL_GetVersion}api doc} *) 21 | 22 | external get_compiled_version : unit -> version 23 | = "caml_SDL_GetCompiledVersion" 24 | (** {{:http://wiki.libsdl.org/SDL_VERSION}api doc} *) 25 | 26 | external get_revision_string : unit -> string 27 | = "caml_SDL_GetRevisionString" 28 | (** {{:http://wiki.libsdl.org/SDL_GetRevision}api doc} *) 29 | 30 | external get_revision_number : unit -> int 31 | = "caml_SDL_GetRevisionNumber" 32 | (** {{:http://wiki.libsdl.org/SDL_GetRevisionNumber}api doc} *) 33 | 34 | module R : sig 35 | (** record version type *) 36 | type version = { 37 | major: int; 38 | minor: int; 39 | patch: int; 40 | } 41 | 42 | external get_runtime_version : unit -> version 43 | = "caml_SDL_GetRunTimeVersion" 44 | (** {{:http://wiki.libsdl.org/SDL_GetVersion}api doc} *) 45 | 46 | external get_compiled_version : unit -> version 47 | = "caml_SDL_GetCompiledVersion" 48 | (** {{:http://wiki.libsdl.org/SDL_VERSION}api doc} *) 49 | end 50 | 51 | -------------------------------------------------------------------------------- /src/sdlversion_stub.c: -------------------------------------------------------------------------------- 1 | /* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | */ 11 | #define CAML_NAME_SPACE 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | 19 | CAMLprim value 20 | caml_SDL_GetCompiledVersion(value unit) 21 | { 22 | CAMLparam0(); 23 | CAMLlocal1(ret); 24 | 25 | SDL_version version; 26 | SDL_VERSION(&version); 27 | 28 | ret = caml_alloc(3, 0); 29 | Store_field(ret, 0, Val_int(version.major)); 30 | Store_field(ret, 1, Val_int(version.minor)); 31 | Store_field(ret, 2, Val_int(version.patch)); 32 | CAMLreturn(ret); 33 | } 34 | 35 | CAMLprim value 36 | caml_SDL_GetRunTimeVersion(value unit) 37 | { 38 | CAMLparam0(); 39 | CAMLlocal1(ret); 40 | 41 | SDL_version version; 42 | SDL_GetVersion(&version); 43 | 44 | ret = caml_alloc(3, 0); 45 | Store_field(ret, 0, Val_int(version.major)); 46 | Store_field(ret, 1, Val_int(version.minor)); 47 | Store_field(ret, 2, Val_int(version.patch)); 48 | CAMLreturn(ret); 49 | } 50 | 51 | CAMLprim value 52 | caml_SDL_GetRevisionString(value unit) 53 | { 54 | const char *rev = SDL_GetRevision(); 55 | return caml_copy_string(rev); 56 | } 57 | 58 | CAMLprim value 59 | caml_SDL_GetRevisionNumber(value unit) 60 | { 61 | int rev = SDL_GetRevisionNumber(); 62 | return Val_int(rev); 63 | } 64 | 65 | /* vim: set ts=4 sw=4 et: */ 66 | -------------------------------------------------------------------------------- /src/sdlwindow.ml: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (* Create and manage windows *) 12 | type t 13 | 14 | type window_flags = 15 | | FullScreen 16 | | OpenGL 17 | | Shown 18 | | Hidden 19 | | Borderless 20 | | Resizable 21 | | Minimized 22 | | Maximized 23 | | Input_Grabbed 24 | | Input_Focus 25 | | Mouse_Focus 26 | | FullScreen_Desktop 27 | | Foreign 28 | | Allow_HighDPI 29 | 30 | type window_pos = [ `centered | `undefined | `pos of int ] 31 | 32 | external create : 33 | title:string -> 34 | pos:window_pos * window_pos -> 35 | dims:int * int -> 36 | flags:window_flags list -> t 37 | = "caml_SDL_CreateWindow" 38 | 39 | external create2 : 40 | title:string -> 41 | x:window_pos -> 42 | y:window_pos -> 43 | width:int -> 44 | height:int -> 45 | flags:window_flags list -> t 46 | = "caml_SDL_CreateWindow2_bc" 47 | "caml_SDL_CreateWindow2" 48 | 49 | external set_title : window:t -> title:string -> unit 50 | = "caml_SDL_SetWindowTitle" 51 | 52 | external show : t -> unit = "caml_SDL_ShowWindow" 53 | external hide : t -> unit = "caml_SDL_HideWindow" 54 | external raise_win : t -> unit = "caml_SDL_RaiseWindow" 55 | external maximize : t -> unit = "caml_SDL_MaximizeWindow" 56 | external minimize : t -> unit = "caml_SDL_MinimizeWindow" 57 | external restore : t -> unit = "caml_SDL_RestoreWindow" 58 | 59 | external get_surface : 60 | t -> Sdlsurface.t 61 | = "caml_SDL_GetWindowSurface" 62 | 63 | external update_surface : t -> unit 64 | = "caml_SDL_UpdateWindowSurface" 65 | 66 | external set_brightness : t -> brightness:float -> unit 67 | = "caml_SDL_SetWindowBrightness" 68 | 69 | external get_brightness : t -> float 70 | = "caml_SDL_GetWindowBrightness" 71 | 72 | external destroy : t -> unit 73 | = "caml_SDL_DestroyWindow" 74 | 75 | external get_size : t -> (int * int) 76 | = "caml_SDL_GetWindowSize" 77 | -------------------------------------------------------------------------------- /src/sdlwindow.mli: -------------------------------------------------------------------------------- 1 | (* OCamlSDL2 - An OCaml interface to the SDL2 library 2 | Copyright (C) 2013 Florent Monnier 3 | 4 | This software is provided "AS-IS", without any express or implied warranty. 5 | In no event will the authors be held liable for any damages arising from 6 | the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it freely. 10 | *) 11 | (** Create and manage windows *) 12 | 13 | (** API Doc: 14 | {{:http://wiki.libsdl.org/CategoryVideo}Video category} *) 15 | 16 | type t 17 | 18 | (** {{:http://wiki.libsdl.org/SDL_WindowFlags}api doc} *) 19 | type window_flags = 20 | | FullScreen 21 | | OpenGL 22 | | Shown 23 | | Hidden 24 | | Borderless 25 | | Resizable 26 | | Minimized 27 | | Maximized 28 | | Input_Grabbed 29 | | Input_Focus 30 | | Mouse_Focus 31 | | FullScreen_Desktop 32 | | Foreign 33 | | Allow_HighDPI 34 | 35 | type window_pos = [ `centered | `undefined | `pos of int ] 36 | 37 | external create : 38 | title:string -> 39 | pos:window_pos * window_pos -> 40 | dims:int * int -> 41 | flags:window_flags list -> t 42 | = "caml_SDL_CreateWindow" 43 | (** {{:http://wiki.libsdl.org/SDL_CreateWindow}api doc} *) 44 | 45 | external create2 : 46 | title:string -> 47 | x:window_pos -> 48 | y:window_pos -> 49 | width:int -> 50 | height:int -> 51 | flags:window_flags list -> t 52 | = "caml_SDL_CreateWindow2_bc" 53 | "caml_SDL_CreateWindow2" 54 | (** {{:http://wiki.libsdl.org/SDL_CreateWindow}api doc} *) 55 | 56 | external set_title : window:t -> title:string -> unit 57 | = "caml_SDL_SetWindowTitle" 58 | (** {{:http://wiki.libsdl.org/SDL_SetWindowTitle}api doc} *) 59 | 60 | external show : t -> unit = "caml_SDL_ShowWindow" 61 | (** {{:http://wiki.libsdl.org/SDL_ShowWindow}api doc} *) 62 | 63 | external hide : t -> unit = "caml_SDL_HideWindow" 64 | (** {{:http://wiki.libsdl.org/SDL_HideWindow}api doc} *) 65 | 66 | external raise_win : t -> unit = "caml_SDL_RaiseWindow" 67 | (** {{:http://wiki.libsdl.org/SDL_RaiseWindow}api doc} *) 68 | 69 | external maximize : t -> unit = "caml_SDL_MaximizeWindow" 70 | (** {{:http://wiki.libsdl.org/SDL_MaximizeWindow}api doc} *) 71 | 72 | external minimize : t -> unit = "caml_SDL_MinimizeWindow" 73 | (** {{:http://wiki.libsdl.org/SDL_MinimizeWindow}api doc} *) 74 | 75 | external restore : t -> unit = "caml_SDL_RestoreWindow" 76 | (** {{:http://wiki.libsdl.org/SDL_RestoreWindow}api doc} *) 77 | 78 | external get_surface : t -> Sdlsurface.t = "caml_SDL_GetWindowSurface" 79 | (** {{:http://wiki.libsdl.org/SDL_GetWindowSurface}api doc} *) 80 | 81 | external update_surface : t -> unit = "caml_SDL_UpdateWindowSurface" 82 | (** {{:http://wiki.libsdl.org/SDL_UpdateWindowSurface}api doc} *) 83 | 84 | external set_brightness : t -> brightness:float -> unit = "caml_SDL_SetWindowBrightness" 85 | (** {{:http://wiki.libsdl.org/SDL_SetWindowBrightness}api doc} *) 86 | 87 | external get_brightness : t -> float = "caml_SDL_GetWindowBrightness" 88 | (** {{:http://wiki.libsdl.org/SDL_GetWindowBrightness}api doc} *) 89 | 90 | external destroy : t -> unit = "caml_SDL_DestroyWindow" 91 | (** {{:http://wiki.libsdl.org/SDL_DestroyWindow}api doc} *) 92 | 93 | external get_size : t -> (int * int) = "caml_SDL_GetWindowSize" 94 | (** {{:http://wiki.libsdl.org/SDL_GetWindowSize}api doc} *) 95 | -------------------------------------------------------------------------------- /src/sdlwindow_stub.h: -------------------------------------------------------------------------------- 1 | #ifndef _CAML_SDL_window_ 2 | #define _CAML_SDL_window_ 3 | 4 | static value Val_SDL_Window(SDL_Window * p) 5 | { 6 | return caml_copy_nativeint((intnat) p); 7 | } 8 | 9 | static SDL_Window * SDL_Window_val(value v) 10 | { 11 | return (SDL_Window *) Nativeint_val(v); 12 | } 13 | 14 | Uint32 Val_SDL_WindowFlags(value mask_list); 15 | 16 | #endif /* _CAML_SDL_window_ */ 17 | -------------------------------------------------------------------------------- /src/style1.dot: -------------------------------------------------------------------------------- 1 | digraph g { 2 | graph [ 3 | rankdir = LR 4 | bgcolor= grey40 5 | ] 6 | node [ 7 | fontsize = "10" 8 | fillcolor = grey60 9 | color = orange 10 | shape = box 11 | style = "rounded,filled" 12 | penwidth = 1.2 13 | ] 14 | -------------------------------------------------------------------------------- /src/variant.ml: -------------------------------------------------------------------------------- 1 | let input_line ic = 2 | try Some (input_line ic) 3 | with End_of_file -> close_in ic; None 4 | 5 | let load_lines fn = 6 | let ic = open_in fn in 7 | let rec aux acc = 8 | match input_line ic with 9 | | Some line -> aux (line::acc) 10 | | None -> List.rev acc 11 | in 12 | aux [] 13 | 14 | let pad s n = 15 | let len = String.length s in 16 | let p = max 0 (n - len) in 17 | (String.make p ' ') 18 | 19 | let () = 20 | let lst = load_lines Sys.argv.(1) in 21 | ListLabels.iteri lst ~f:(fun i enum -> 22 | Printf.printf 23 | " case %s:%sreturn Val_int(%d);\n" 24 | enum (pad enum 32) i 25 | ) 26 | -------------------------------------------------------------------------------- /tests/test_rect.ml: -------------------------------------------------------------------------------- 1 | let status = ref 0 2 | let err () = status := 1 3 | 4 | let check res should = 5 | if res = should 6 | then "OK" 7 | else (err (); "Failed") 8 | 9 | let () = 10 | let rect1 = Sdlrect.make4 10 10 100 60 in 11 | let rect2 = Sdlrect.make4 20 20 200 120 in 12 | let rect3 = Sdlrect.make4 220 220 20 20 in 13 | let should1, r1 = true, Sdlrect.has_intersection ~a:rect1 ~b:rect2 in 14 | let should2, r2 = false, Sdlrect.has_intersection ~a:rect1 ~b:rect3 in 15 | Printf.printf "test 1: %s\n%!" (check r1 should1); 16 | Printf.printf "test 2: %s\n%!" (check r2 should2); 17 | 18 | let rect4 = Sdlrect.make4 10 10 20 5 in 19 | let r3 = Sdlrect.intersect_rect_and_line rect4 (15, 0) (20, 30) in 20 | let r4 = Sdlrect.intersect_rect_and_line rect4 (50, 0) (60, 40) in 21 | let should3 = Some (16, 10, 16, 14) in 22 | let should4 = None in 23 | Printf.printf "test 3: %s\n%!" (check r3 should3); 24 | Printf.printf "test 4: %s\n%!" (check r4 should4); 25 | 26 | let r5 = Sdlrect.point_in_rect (5, 5) (Sdlrect.make4 0 0 10 10) in 27 | let r6 = Sdlrect.point_in_rect (2, 2) (Sdlrect.make4 5 5 10 10) in 28 | let should5 = true in 29 | let should6 = false in 30 | Printf.printf "test 5: %s\n%!" (check r5 should5); 31 | Printf.printf "test 6: %s\n%!" (check r6 should6); 32 | 33 | exit !status 34 | -------------------------------------------------------------------------------- /tests/test_surf_ba.ml: -------------------------------------------------------------------------------- 1 | open Sdl 2 | open Sdlba 3 | 4 | let color_of_rgb ~surf ~rgb = 5 | let fmt_kind = Surface.get_pixelformat_t surf in 6 | let fmt = Pixel.alloc_format fmt_kind in 7 | let color = Pixel.map_RGB fmt ~rgb in 8 | Pixel.free_format fmt; 9 | (color) 10 | 11 | let fill_rect surf x y w h ~rgb = 12 | let color = color_of_rgb ~surf ~rgb in 13 | let rect = Rect.make4 x y w h in 14 | Surface.fill_rect ~dst:surf ~rect ~color; 15 | ;; 16 | 17 | let output_ppm ~oc ~img ~width ~height = 18 | Printf.fprintf oc "P6\n%d %d\n255\n" width height; 19 | let n = Bigarray.Array1.dim img in 20 | for i = 0 to pred n do 21 | output_char oc (char_of_int img.{i}); 22 | done; 23 | output_char oc '\n'; 24 | flush oc; 25 | ;; 26 | 27 | let () = 28 | Sdl.init [`VIDEO]; 29 | let width, height = (320, 240) in 30 | let surf = Surface.create_rgb ~width ~height ~depth:24 in 31 | 32 | fill_rect surf 0 0 320 240 ~rgb:(0,0,0); 33 | fill_rect surf 20 20 200 120 ~rgb:(0,255,0); 34 | fill_rect surf 60 60 200 140 ~rgb:(255,0,0); 35 | fill_rect surf 0 0 100 100 ~rgb:(0,0,255); 36 | 37 | let ba = Surface_ba.get_pixels surf in 38 | 39 | let oc = open_out "test_surf_ba.ppm" in 40 | output_ppm ~oc ~img:ba ~width ~height; 41 | close_out oc; 42 | 43 | Sdl.quit () 44 | --------------------------------------------------------------------------------