Christian Kellermann avatar Christian Kellermann committed f1f9530

Add rotation keyword parameter to blit-image

This allows one to rotate the image resource before blitting
it. Thanks to Alaric Snell-Pym for the suggestion.

Comments (0)

Files changed (1)

          (else (error "Unkown resource type " type))))
-(define (blit-image name x y)
+(define (blit-image name x y #!key (rotation 0))
   (let ((img (alist-ref name *resources* equal?)))
     (unless img
       (error "No resource found with this name " name))
     (let* ((scale (img-res-scale-factor img))
            (scale (if scale scale 1))
+           (h (img-res-h img))
+           (w (img-res-w img))
            (t (/ (- 1 scale) 2))
-           (x (+ x (* t (img-res-w img))
+           (x (+ x (* t w)
                  (img-res-x-offset img)))
-           (y (+ y (* t (img-res-h img))
+           (y (+ y (* t h)
                  (img-res-y-offset img))))
+      (cairo-save *c*)
+      (if (zero? rotation)
+              (cairo-translate *c* x y)
+              (doto *c*
+                    (cairo-translate (+ (/ w 2) x)
+                                     (+ (/ h 2) y))
+                    (cairo-rotate (* (/ cairo-pi 180) rotation))
+                    (cairo-translate (- (/ w 2)) (- (/ h 2)))))
       (doto *c*
-            (cairo-save)
-            (cairo-translate x y)
             (cairo-scale scale scale)
             (cairo-set-source-surface (img-res-surface img) 0 0)
             (cairo-mask-surface (img-res-surface img) 0 0)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.