diff options
author | Hugo Hörnquist <hugo@hornquist.se> | 2019-06-04 20:16:08 +0200 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2019-06-04 15:45:46 -0400 |
commit | 895180d78f951d92b7888f134da426ad606d043d (patch) | |
tree | de29912b7dd0e97ea2ec5af3c46c7577675176b5 /sdl2/render.scm | |
parent | 84e59980a606f54ea96bb1932ff9a6474a5aaf45 (diff) |
render: Add SDL_RenderDrawRect and SDL_RenderFillRect bindings.
* sdl2/bindings.scm (sdl-render-draw-rect, sdl-render-draw-rects,
sdl-render-fill-rect, sdl-render-fill-rects): New procedures.
* sdl2/render.scm (render-draw-rect, render-draw-rects,
render-fill-rect, render-fill-rects): New procedures.
* doc/api.texi: Document new procedures.
Diffstat (limited to 'sdl2/render.scm')
-rw-r--r-- | sdl2/render.scm | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/sdl2/render.scm b/sdl2/render.scm index 0b92bc4..6504ce9 100644 --- a/sdl2/render.scm +++ b/sdl2/render.scm @@ -28,6 +28,7 @@ #:use-module (ice-9 format) #:use-module (ice-9 match) #:use-module (system foreign) + #:use-module (rnrs bytevectors) #:use-module (sdl2) #:use-module ((sdl2 bindings) #:prefix ffi:) #:export (make-renderer @@ -42,6 +43,10 @@ render-draw-lines render-draw-point render-draw-points + render-draw-rect + render-draw-rects + render-fill-rect + render-fill-rects delete-texture! surface->texture)) @@ -150,6 +155,42 @@ color." (bytevector->pointer bv) count))) +(define (render-draw-rect renderer rect) + "Draw RECT on RENDERER." + (ffi:sdl-render-draw-rect + (unwrap-renderer renderer) + ((@@ (sdl2 rect) unwrap-rect) rect))) + +(define (render-draw-rects renderer rects) + "Draw RECTS on RENDERER." + (let* ((count (length rects)) + (bv (make-s32vector (* count 4)))) + (for-each (lambda (rect i) + (bytevector-copy! ((@@ (sdl2 rect) rect-bv) rect) 0 + bv (* i 4 4) (* 4 4))) + rects (iota count)) + (ffi:sdl-render-draw-rects (unwrap-renderer renderer) + (bytevector->pointer bv) + count))) + +(define (render-fill-rect renderer rect) + "Fill RECT on RENDERER." + (ffi:sdl-render-fill-rect + (unwrap-renderer renderer) + ((@@ (sdl2 rect) unwrap-rect) rect))) + +(define (render-fill-rects renderer rects) + "Fill RECTS on RENDERER." + (let* ((count (length rects)) + (bv (make-s32vector (* count 4)))) + (for-each (lambda (rect i) + (bytevector-copy! ((@@ (sdl2 rect) rect-bv) rect) 0 + bv (* i 4 4) (* 4 4))) + rects (iota count)) + (ffi:sdl-render-fill-rects (unwrap-renderer renderer) + (bytevector->pointer bv) + count))) + ;;; ;;; Texture |