render: Add SDL_RenderCopyEx binding.
authorPierre-Antoine Rouby <contact@parouby.fr>
Mon, 20 May 2019 16:03:18 +0000 (18:03 +0200)
committerDavid Thompson <dthompson@vistahigherlearning.com>
Tue, 21 May 2019 12:05:35 +0000 (08:05 -0400)
* sdl2/bindings.scm (sdl-point): New variable.
  (sdl-render-copy-ex): New procedure.
* sdl2/render.scm (render-copy): Add optional arguments, angle and
  center.
* doc/api.texi (Rendering): Document it.

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

index 57e92d3..5be763c 100644 (file)
@@ -1049,8 +1049,10 @@ Display @var{renderer}.
 
 @deffn {Procedure} render-copy renderer @
                                       texture @
-                                      [#:srcrect]
-                                      [#:dstrect]
+                                      [#:angle 0] @
+                                      [#:srcrect] @
+                                      [#:dstrect] @
+                                      [#:center]
 Copy @var{texture} to the rendering target of @var{renderer}.
 @end deffn
 
index c314a23..854bdc9 100644 (file)
@@ -53,6 +53,9 @@ RETURN-TYPE and accept arguments of ARG-TYPES."
 (define-public sdl-rect
   (list int int int int))
 
+(define-public sdl-point
+  (list int int))
+
 (define sdl-bool int)
 
 (define-public (boolean->sdl-bool b)
@@ -233,6 +236,9 @@ RETURN-TYPE and accept arguments of ARG-TYPES."
 (define-foreign sdl-render-copy
   int "SDL_RenderCopy" '(* * * *))
 
+(define-foreign sdl-render-copy-ex
+  int "SDL_RenderCopyEx" (list '* '* '* '* double '* int))
+
 (define-foreign sdl-create-texture-from-surface
   '* "SDL_CreateTextureFromSurface" '(* *))
 
index e2fb05c..c91699d 100644 (file)
@@ -127,15 +127,23 @@ color."
         (sdl-error "surface->texture" "failed to convert surface to texture")
         (wrap-texture ptr))))
 
-(define* (render-copy renderer texture #:key srcrect dstrect)
+
+(define* (render-copy renderer texture
+                      #:key (angle 0) srcrect dstrect center)
   "Copy TEXTURE to the rendering target of RENDERER."
-  (let ((result (ffi:sdl-render-copy (unwrap-renderer renderer)
-                                     (unwrap-texture texture)
-                                     (if srcrect
-                                         (make-c-struct ffi:sdl-rect srcrect)
-                                         %null-pointer)
-                                     (if dstrect
-                                         (make-c-struct ffi:sdl-rect dstrect)
-                                         %null-pointer))))
+  (let ((result (ffi:sdl-render-copy-ex
+                 (unwrap-renderer renderer)
+                 (unwrap-texture texture)
+                 (if srcrect
+                     (make-c-struct ffi:sdl-rect srcrect)
+                     %null-pointer)
+                 (if dstrect
+                     (make-c-struct ffi:sdl-rect dstrect)
+                     %null-pointer)
+                 angle
+                 (if center
+                     (make-c-struct ffi:sdl-point center)
+                     %null-pointer)
+                 0)))
     (unless (zero? result)
       (sdl-error "render-copy" "failed to copy texture"))))