From 1829fe9b78343d41fd7c3618e43ea17721b1cd0d Mon Sep 17 00:00:00 2001 From: Julian Squires Date: Tue, 28 Oct 2008 20:00:30 -0400 Subject: [PATCH] Added more utilities: WITH-INIT, WIDTH-OF, HEIGHT-OF, and WITH-BOUND-IMAGE. --- package.lisp | 4 ++++ utilities.lisp | 25 ++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/package.lisp b/package.lisp index 81d663b..10e3d46 100644 --- a/package.lisp +++ b/package.lisp @@ -4,7 +4,11 @@ (:use #:cl #:cffi :anaphora) (:shadow #:load #:error) (:export + #:with-bound-image #:with-images + #:with-init + #:width-of + #:height-of ;; bindings #:BIND-IMAGE #:BLIT diff --git a/utilities.lisp b/utilities.lisp index c89890e..093eff5 100644 --- a/utilities.lisp +++ b/utilities.lisp @@ -11,6 +11,9 @@ (t 'il:load-f)) args)))) +;;; XXX I don't like the potential confusion between WITH-BOUND-IMAGE +;;; and WITH-IMAGES, but WITH-NEW-IMAGES and WITH-LOADED-IMAGES all +;;; give the wrong impression, alas. (defmacro with-images ((&rest images) &body body) "Generates an IL image for each of IMAGES, binding and loading if a parameter is supplied. BODY is executed, and the images are freed thereafter." (let ((ids (gensym)) @@ -26,4 +29,24 @@ ,@body) (il:delete-images ,count ,ids))))) -(il:with-images (urp arp (exit "/home/julian/exit.pcx")) (format t "~&~A ~A ~A" urp arp exit)) \ No newline at end of file +(defmacro with-init (&body body) + `(progn (init) + (unwind-protect (progn ,@body) + (shutdown)))) + +(defun width-of (id) + (bind-image id) + (get-integer :image-width)) + +(defun height-of (id) + (bind-image id) + (get-integer :image-height)) + + +(defmacro with-bound-image ((id) &body body) + "Binds ID for the duration of BODY, returning to the previously bound image thereafter." + (let ((old-image (gensym))) + `(let ((,old-image (il:get-integer :cur-image))) + (il:bind-image ,id) + (unwind-protect (progn ,@body) + (il:bind-image ,old-image))))) \ No newline at end of file -- 2.11.4.GIT