surface: Add SDL_BlitSurface binding.
authorDavid Thompson <dthompson2@worcester.edu>
Tue, 8 Jan 2019 03:53:13 +0000 (22:53 -0500)
committerDavid Thompson <dthompson2@worcester.edu>
Tue, 8 Jan 2019 03:53:13 +0000 (22:53 -0500)
* sdl2/bindings.scm (sdl-blit-surface): New procedure.
* sdl2/surface.scm (blit-surface): New procedure.

sdl2/bindings.scm
sdl2/surface.scm

index 84e49b8..7c16abb 100644 (file)
@@ -943,6 +943,9 @@ RETURN-TYPE and accept arguments of ARG-TYPES."
 (define-foreign sdl-convert-surface-format
   '* "SDL_ConvertSurfaceFormat" (list '* uint32 uint32))
 
+(define-foreign sdl-blit-surface
+  int "SDL_UpperBlit" '(* * * *))
+
 \f
 ;;;
 ;;; Audio
index bcdb588..a918bd7 100644 (file)
@@ -63,7 +63,8 @@
             surface-height
             surface-pitch
             surface-pixels
-            convert-surface-format))
+            convert-surface-format
+            blit-surface))
 
 \f
 ;;;
@@ -434,3 +435,17 @@ Valid format types are:
     (if (null-pointer? ptr)
         (sdl-error "convert-surface-format" "failed to convert surface format")
         (wrap-surface ptr))))
+
+(define (blit-surface src src-rect dst dst-rect)
+  "Blit the rectangle SRC-RECT from the surface SRC to DST-RECT of the
+surface DST."
+  (unless (zero?
+           (ffi:sdl-blit-surface (unwrap-surface src)
+                                 (if src-rect
+                                     ((@@ (sdl2 rect) unwrap-rect) src-rect)
+                                     %null-pointer)
+                                 (unwrap-surface dst)
+                                 (if dst-rect
+                                     ((@@ (sdl2 rect) unwrap-rect) dst-rect)
+                                     %null-pointer)))
+    (sdl-error "blit-surface" "failed to blit surface ~a to ~a" src dst)))