Add SDL_GetTicks binding.
[guile-sdl2.git] / sdl2 / bindings.scm
1 ;;; guile-sdl2 --- FFI bindings for SDL2
2 ;;; Copyright © 2015 David Thompson <davet@gnu.org>
3 ;;;
4 ;;; This file is part of guile-sdl2.
5 ;;;
6 ;;; Guile-sdl2 is free software; you can redistribute it and/or modify
7 ;;; it under the terms of the GNU Lesser General Public License as
8 ;;; published by the Free Software Foundation; either version 3 of the
9 ;;; License, or (at your option) any later version.
10 ;;;
11 ;;; Guile-sdl2 is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ;;; General Public License for more details.
15 ;;;
16 ;;; You should have received a copy of the GNU Lesser General Public
17 ;;; License along with guile-sdl2. If not, see
18 ;;; <http://www.gnu.org/licenses/>.
19
20 ;;; Commentary:
21 ;;
22 ;; Low-level FFI bindings.
23 ;;
24 ;;; Code:
25
26 (define-module (sdl2 bindings)
27 #:use-module (system foreign)
28 #:use-module (sdl2 config)
29 #:export (boolean->sdl-bool
30
31 SDL_INIT_TIMER
32 SDL_INIT_AUDIO
33 SDL_INIT_VIDEO
34 SDL_INIT_HAPTIC
35 SDL_INIT_GAMECONTROLLER
36 SDL_INIT_EVENTS
37 SDL_INIT_NOPARACHUTE
38
39 SDL_WINDOW_FULLSCREEN
40 SDL_WINDOW_OPENGL
41 SDL_WINDOW_SHOWN
42 SDL_WINDOW_HIDDEN
43 SDL_WINDOW_BORDERLESS
44 SDL_WINDOW_RESIZABLE
45 SDL_WINDOW_MINIMIZED
46 SDL_WINDOW_MAXIMIZED
47 SDL_WINDOW_INPUT_GRABBED
48 SDL_WINDOW_INPUT_FOCUS
49 SDL_WINDOW_MOUSE_FOCUS
50 SDL_WINDOW_FULLSCREEN_DESKTOP
51 SDL_WINDOW_FOREIGN
52 SDL_WINDOW_ALLOW_HIGHDPI
53 SDL_WINDOW_MOUSE_CAPTURE))
54
55 (define sdl-func
56 (let ((lib (dynamic-link %libsdl2)))
57 (lambda (return-type function-name arg-types)
58 "Return a procedure for the foreign function FUNCTION-NAME in
59 the SDL2 shared library. That function must return a value of
60 RETURN-TYPE and accept arguments of ARG-TYPES."
61 (pointer->procedure return-type
62 (dynamic-func function-name lib)
63 arg-types))))
64
65 (define-syntax-rule (define-foreign name return-type func-name arg-types)
66 (define-public name
67 (sdl-func return-type func-name arg-types)))
68
69 \f
70 ;;;
71 ;;; Foreign Types
72 ;;;
73
74 (define sdl-bool int)
75
76 (define (boolean->sdl-bool b)
77 "Convert the boolean B to an SDL_bool."
78 (if b 1 0))
79
80 \f
81 ;;;
82 ;;; Errors
83 ;;;
84
85 (define-foreign sdl-get-error
86 '* "SDL_GetError" '())
87
88 \f
89 ;;;
90 ;;; Initialization
91 ;;;
92
93 (define SDL_INIT_TIMER #x00000001)
94 (define SDL_INIT_AUDIO #x00000010)
95 (define SDL_INIT_VIDEO #x00000020)
96 (define SDL_INIT_HAPTIC #x00001000)
97 (define SDL_INIT_GAMECONTROLLER #x00002000)
98 (define SDL_INIT_EVENTS #x00004000)
99
100 (define-foreign sdl-init
101 int "SDL_Init" (list uint32))
102
103 (define-foreign sdl-quit
104 void "SDL_Quit" '())
105
106 \f
107 ;;;
108 ;;; Version
109 ;;;
110
111 (define-foreign sdl-get-version
112 void "SDL_GetVersion" '(*))
113
114 \f
115 ;;;
116 ;;; Video
117 ;;;
118
119 (define SDL_WINDOW_FULLSCREEN #x00000001)
120 (define SDL_WINDOW_OPENGL #x00000002)
121 (define SDL_WINDOW_SHOWN #x00000004)
122 (define SDL_WINDOW_HIDDEN #x00000008)
123 (define SDL_WINDOW_BORDERLESS #x00000010)
124 (define SDL_WINDOW_RESIZABLE #x00000020)
125 (define SDL_WINDOW_MINIMIZED #x00000040)
126 (define SDL_WINDOW_MAXIMIZED #x00000080)
127 (define SDL_WINDOW_INPUT_GRABBED #x00000100)
128 (define SDL_WINDOW_INPUT_FOCUS #x00000200)
129 (define SDL_WINDOW_MOUSE_FOCUS #x00000400)
130 (define SDL_WINDOW_FULLSCREEN_DESKTOP (logior SDL_WINDOW_FULLSCREEN
131 #x00001000))
132 (define SDL_WINDOW_FOREIGN #x00000800)
133 (define SDL_WINDOW_ALLOW_HIGHDPI #x00002000)
134 (define SDL_WINDOW_MOUSE_CAPTURE #x00004000)
135
136 (define-foreign sdl-create-window
137 '* "SDL_CreateWindow" (list '* int int int int uint32))
138
139 (define-foreign sdl-destroy-window
140 void "SDL_DestroyWindow" '(*))
141
142 (define-foreign sdl-get-window-title
143 '* "SDL_GetWindowTitle" '(*))
144
145 (define-foreign sdl-get-window-size
146 void "SDL_GetWindowSize" '(* * *))
147
148 (define-foreign sdl-get-window-position
149 void "SDL_GetWindowPosition" '(* * *))
150
151 (define-foreign sdl-get-window-id
152 uint32 "SDL_GetWindowID" '(*))
153
154 (define-foreign sdl-get-window-from-id
155 '* "SDL_GetWindowFromID" (list uint32))
156
157 (define-foreign sdl-hide-window
158 void "SDL_HideWindow" '(*))
159
160 (define-foreign sdl-show-window
161 void "SDL_ShowWindow" '(*))
162
163 (define-foreign sdl-maximize-window
164 void "SDL_MaximizeWindow" '(*))
165
166 (define-foreign sdl-minimize-window
167 void "SDL_MinimizeWindow" '(*))
168
169 (define-foreign sdl-raise-window
170 void "SDL_RaiseWindow" '(*))
171
172 (define-foreign sdl-restore-window
173 void "SDL_RestoreWindow" '(*))
174
175 (define-foreign sdl-set-window-bordered
176 void "SDL_SetWindowBordered" (list '* sdl-bool))
177
178 (define-foreign sdl-set-window-title
179 void "SDL_SetWindowTitle" '(* *))
180
181 (define-foreign sdl-set-window-position
182 void "SDL_SetWindowPosition" (list '* int int))
183
184 (define-foreign sdl-set-window-size
185 void "SDL_SetWindowSize" (list '* int int))
186
187 (define-foreign sdl-gl-create-context
188 '* "SDL_GL_CreateContext" '(*))
189
190 (define-foreign sdl-gl-delete-context
191 void "SDL_GL_DeleteContext" '(*))
192
193 (define-foreign sdl-gl-swap-window
194 void "SDL_GL_SwapWindow" '(*))
195
196 \f
197 ;;;
198 ;;; Timer
199 ;;;
200
201 (define-foreign sdl-get-ticks
202 uint32 "SDL_GetTicks" '())