Menu

[r760]: / trunk / lispbuilder-sdl / base / sdl-util.lisp  Maximize  Restore  History

Download this file

62 lines (50 with data), 2.2 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
;; SDL (Simple Media Layer) library using CFFI for foreign function interfacing...
;; (C)2006 Justin Heyes-Jones <justinhj@gmail.com> and Luke Crook <luke@balooga.com>
;; Thanks to Frank Buss and Surendra Singh
;; see COPYING for license
;; This file contains some useful functions for using SDL from Common lisp
;; using sdl.lisp (the CFFI wrapper)
(in-package #:lispbuilder-sdl-base)
;;; w
(defmacro with-init (init-flags &body body)
"Attempts to initialize the SDL subsystems using SDL-Init.
Automatically shuts down the SDL subsystems using SDL-Quit upon normal application termination or
if any fatal error occurs within &body.
init-flags can be any combination of SDL-INIT-TIMER, SDL-INIT-AUDIO, SDL-INIT-VIDEO, SDL-INIT-CDROM,
SDL-INIT-JOYSTICK, SDL-INIT-NOPARACHUTE, SDL-INIT-EVENTTHREAD or SDL-INIT-EVERYTHING."
`(block nil
(unwind-protect
(when (init-sdl ,@(when init-flags
`(:flags (list ,@init-flags))))
,@body)
(sdl-cffi::SDL-Quit))))
(defun init-sdl (&key (flags sdl-cffi::SDL-INIT-VIDEO))
(if (equal 0 (sdl-cffi::SDL-Init (set-flags flags)))
t
nil))
(defun was-init? (&key (flags sdl-cffi::SDL-INIT-VIDEO))
(if (equal (set-flags flags)
(sdl-cffi::sdl-was-init (set-flags flags)))
t
nil))
(defun key= (key1 key2)
(eq key1 key2))
(defun modifier= (mod key)
"Returns t if the keypress modifier 'mod' is equal to the specified 'key'.
(cffi:foreign-enum-value 'SDLMod key)."
(equal mod (cffi:foreign-enum-value 'sdl-cffi::SDL-Mod key)))
(defun set-flags (&rest keyword-args)
(if (listp (first keyword-args))
(let ((keywords
(mapcar #'(lambda (x)
(eval x))
(first keyword-args))))
(apply #'logior keywords))
(apply #'logior keyword-args)))
(defun load-image (filename)
"load in the supplied filename, must be a bmp file"
; (format t "loading ~a~%" filename)
(let ((file (namestring filename)))
(if (and (stringp file) (probe-file file)) ; LJC: Make sure filename is a string and the filename exists.
(sdl-cffi::SDL-Load-BMP-RW (sdl-cffi::sdl-RW-From-File file "rb") 1)
(error "File ~A does not exist." file))))
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.