render: Add srcrect and dstrect arguments to render-copy.
authorJona <saikyun@gmail.com>
Fri, 5 May 2017 08:36:07 +0000 (10:36 +0200)
committerDavid Thompson <dthompson2@worcester.edu>
Wed, 7 Jun 2017 01:12:14 +0000 (21:12 -0400)
* sdl2/bindings.scm (sdl-rect): New variable.
* sdl2/render.scm (render-copy): Add srcrect and dstrect arguments.

sdl2/bindings.scm
sdl2/render.scm

index d69e737..dd0a619 100644 (file)
@@ -49,6 +49,9 @@ RETURN-TYPE and accept arguments of ARG-TYPES."
 (define-public sdl-color
   (list uint8 uint8 uint8 uint8))
 
+(define-public sdl-rect
+  (list int int int int))
+
 (define sdl-bool int)
 
 (define-public (boolean->sdl-bool b)
index 8c34d60..5b27990 100644 (file)
@@ -122,12 +122,15 @@ color."
         (sdl-error "surface->texture" "failed to convert surface to texture")
         (wrap-texture ptr))))
 
-;; TODO: Add srcrect and dstrect.
-(define (render-copy renderer texture)
+(define (render-copy renderer texture srcrect dstrect)
   "Copy TEXTURE to the rendering target of RENDERER."
   (let ((result (ffi:sdl-render-copy (unwrap-renderer renderer)
                                      (unwrap-texture texture)
-                                     %null-pointer
-                                     %null-pointer)))
+                                     (if (nil? srcrect)
+                                         %null-pointer
+                                         (make-c-struct ffi:sdl-rect srcrect))
+                                     (if (nil? dstrect)
+                                         %null-pointer
+                                         (make-c-struct ffi:sdl-rect dstrect)))))
     (unless (zero? result)
       (sdl-error "render-copy" "failed to copy texture"))))