surface: Add SDL_FillRect binding.
authorDavid Thompson <dthompson2@worcester.edu>
Wed, 9 Jan 2019 02:29:58 +0000 (21:29 -0500)
committerDavid Thompson <dthompson2@worcester.edu>
Wed, 9 Jan 2019 02:29:58 +0000 (21:29 -0500)
* sdl2/bindings.scm (sdl-fill-rect): New procedure.
* sdl2/surface.scm (fill-rect): New procedure.
* doc/api.texi (Surfaces): Document it.

doc/api.texi
sdl2/bindings.scm
sdl2/surface.scm

index 7e47fd7..57e92d3 100644 (file)
@@ -1000,6 +1000,10 @@ Blit the rectangle @var{src-rect} from the surface @var{src} to
 destination.
 @end deffn
 
 destination.
 @end deffn
 
+@deffn {Procedure} fill-rect @var{dst} @var{rect} @var{color}
+Fill @var{rect} with @var{color}, a 32-bit color encoded as an integer
+value, in the surface @var{dst}.
+@end deffn
 
 @node Rendering
 @section Rendering
 
 @node Rendering
 @section Rendering
index 1f97186..c314a23 100644 (file)
@@ -949,6 +949,9 @@ RETURN-TYPE and accept arguments of ARG-TYPES."
 (define-foreign sdl-blit-scaled
   int "SDL_UpperBlitScaled" '(* * * *))
 
 (define-foreign sdl-blit-scaled
   int "SDL_UpperBlitScaled" '(* * * *))
 
+(define-foreign sdl-fill-rect
+  int "SDL_FillRect" (list '* '* uint32))
+
 \f
 ;;;
 ;;; Audio
 \f
 ;;;
 ;;; Audio
index 3770a17..1350fa3 100644 (file)
@@ -65,7 +65,8 @@
             surface-pixels
             convert-surface-format
             blit-surface
             surface-pixels
             convert-surface-format
             blit-surface
-            blit-scaled))
+            blit-scaled
+            fill-rect))
 
 \f
 ;;;
 
 \f
 ;;;
@@ -464,3 +465,13 @@ surface DST, scaling the source to fit the destination."
                                      ((@@ (sdl2 rect) unwrap-rect) dst-rect)
                                      %null-pointer)))
     (sdl-error "blit-scaled" "failed to blit surface ~a to ~a" src dst)))
                                      ((@@ (sdl2 rect) unwrap-rect) dst-rect)
                                      %null-pointer)))
     (sdl-error "blit-scaled" "failed to blit surface ~a to ~a" src dst)))
+
+(define (fill-rect dst rect color)
+  "Fill RECT with COLOR in the surface DST."
+  (unless (zero?
+           (ffi:sdl-fill-rect (unwrap-surface dst)
+                              (if rect
+                                  ((@@ (sdl2 rect) unwrap-rect) rect)
+                                  %null-pointer)
+                              color))
+    (sdl-error "fill-rect" "failed to fill rect in ~a" dst)))