summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Prikler <leo.prikler@student.tugraz.at>2020-12-01 15:16:50 +0100
committerDavid Thompson <dthompson2@worcester.edu>2020-12-02 10:04:45 -0500
commit0e627ad72df828882664b87293f9fec3602c5ceb (patch)
treefeb1ccb89d942d0f14742f1d70fc41cba232c8d9
parentdf05f9d1494d3a62a5b301f6f2db3410f21be458 (diff)
render: Add more bindings.
* sdl2/bindings.scm (sdl-render-get-integer-scale, sdl-render-get-scale) (sdl-render-get-logical-size, sdl-render-get-viewport) (sdl-render-set-integer-scale, sdl-render-set-scale) (sdl-render-set-logical-size, sdl-render-set-viewport): New procedures. * sdl2/render.scm (render-get-integer-scale, render-get-logical-size) (render-get-scale, render-get-viewport, render-set-integer-scale) (render-set-logical-size, render-set-scale, render-set-viewport): New procedures. * doc/api.texi: Document new (sdl2 render) bindings.
-rw-r--r--doc/api.texi39
-rw-r--r--sdl2/bindings.scm24
-rw-r--r--sdl2/render.scm62
3 files changed, 125 insertions, 0 deletions
diff --git a/doc/api.texi b/doc/api.texi
index 9620f87..a158795 100644
--- a/doc/api.texi
+++ b/doc/api.texi
@@ -1048,6 +1048,45 @@ Clear the rendering target @var{renderer} with the current drawing color.
Display @var{renderer}.
@end deffn
+@deffn {Procedure} renderer-integer-scale renderer
+Returns @code{#t} if @var{renderer} currently uses integer scaling and
+@code{#f} otherwise. Integer scaling can be used together with
+logical size to effectively restrict the drawing region to an area
+even if the window is larger than that.
+@end deffn
+
+@deffn {Procedure} set-renderer-integer-scale! renderer enable?
+If @var{enable?} is @code{#t}, enable integer scaling, otherwise
+disable it.
+@end deffn
+
+@deffn {Procedure} renderer-logical-size renderer
+Return the current logical size used by @var{renderer}.
+@end deffn
+
+@deffn {Procedure} set-renderer-logical-size! renderer width height
+Set the logical size of @var{renderer} to @var{width} x @var{height}.
+@end deffn
+
+@deffn {Procedure} renderer-scale renderer
+Return the scaling factors @code{(X Y)} used by @var{renderer} to
+scale coordinates.
+@end deffn
+
+@deffn {Procedure} set-renderer-scale! renderer scale-x scale-y
+Set the factors by which @var{renderer} scales coordinates according
+to the scaling factors @var{scale-x} and @var{scale-y}.
+@end deffn
+
+@deffn {Procedure} renderer-viewport renderer
+Return the rectangle that @var{renderer} currently draws on. If the
+entire region is used, all values of that rectangle will be 0.
+@end deffn
+
+@deffn {Procedure} set-renderer-viewport! renderer rect
+Set the drawing area for @var{renderer} to @var{rect}.
+@end deffn
+
@deffn {Procedure} render-copy renderer @
texture @
[#:angle 0] @
diff --git a/sdl2/bindings.scm b/sdl2/bindings.scm
index d2f3bbe..586011e 100644
--- a/sdl2/bindings.scm
+++ b/sdl2/bindings.scm
@@ -333,6 +333,30 @@ RETURN-TYPE and accept arguments of ARG-TYPES."
(define-foreign sdl-render-fill-rects
int "SDL_RenderFillRects" (list '* '* int))
+(define-foreign sdl-render-get-integer-scale
+ sdl-bool "SDL_RenderGetIntegerScale" (list '*))
+
+(define-foreign sdl-render-get-logical-size
+ void "SDL_RenderGetLogicalSize" (list '* '* '*))
+
+(define-foreign sdl-render-get-scale
+ void "SDL_RenderGetScale" (list '* '* '*))
+
+(define-foreign sdl-render-get-viewport
+ void "SDL_RenderGetViewport" (list '* '*))
+
+(define-foreign sdl-render-set-integer-scale
+ int "SDL_RenderSetIntegerScale" (list '* sdl-bool))
+
+(define-foreign sdl-render-set-logical-size
+ int "SDL_RenderSetLogicalSize" (list '* int int))
+
+(define-foreign sdl-render-set-scale
+ int "SDL_RenderSetScale" (list '* float float))
+
+(define-foreign sdl-render-set-viewport
+ int "SDL_RenderSetViewport" (list '* '*))
+
;;;
;;; Events
diff --git a/sdl2/render.scm b/sdl2/render.scm
index 6a9c0b2..4cf0a28 100644
--- a/sdl2/render.scm
+++ b/sdl2/render.scm
@@ -122,6 +122,68 @@ color."
"Display RENDERER."
(ffi:sdl-render-present (unwrap-renderer renderer)))
+(define (renderer-logical-size renderer)
+ "Return the logical size used by RENDERER."
+ (let ((bv (make-bytevector (* 2 (sizeof int)) 0)))
+ (ffi:sdl-render-get-logical-size (unwrap-renderer renderer)
+ (bytevector->pointer bv)
+ (bytevector->pointer (sizeof int)))
+ (bytevector->sint-list bv (native-endianness) (sizeof int))))
+
+(define (set-renderer-logical-size! renderer width height)
+ "Set the logical size of RENDERER to WIDTH x HEIGHT."
+ (unless (zero? (ffi:sdl-render-set-logical-size
+ (unwrap-renderer renderer)
+ width height))
+ (sdl-error "set-renderer-logical-size!" "Failed to set logical size")))
+
+(define (renderer-scale renderer)
+ "Return the scale used by RENDERER."
+ (let ((bv (make-bytevector (* 2 (sizeof float)) 0)))
+ (ffi:sdl-render-get-scale (unwrap-renderer renderer)
+ (bytevector->pointer bv)
+ (bytevector->pointer (sizeof float)))
+ (list (bytevector-ieee-single-native-ref bv 0)
+ (bytevector-ieee-single-native-ref bv 1))))
+
+(define (set-renderer-scale! renderer scale-x scale-y)
+ "Set the drawing scale of RENDERER according to SCALE-X and SCALE-Y
+scaling factors."
+ (unless (zero? (ffi:sdl-render-set-logical-size (unwrap-renderer renderer)
+ scale-x scale-y))
+ (sdl-error "set-renderer-scale!" "Failed to set scale")))
+
+(define (renderer-integer-scale renderer)
+ "Returns #t if integer scaling is forced on RENDERER."
+ (not
+ (zero?
+ (ffi:sdl-render-get-integer-scale
+ (unwrap-renderer renderer)))))
+
+(define (set-renderer-integer-scale! renderer enabled?)
+ "If ENABLED? is #t, enable integer scaling for RENDERER, otherwise
+disable it."
+ (unless (zero? (ffi:sdl-render-set-integer-scale
+ (unwrap-renderer renderer)
+ (ffi:boolean->sdl-bool enabled?)))
+ (sdl-error "set-renderer-integer-scale!" "Failed to set integer scale")))
+
+(define (renderer-viewport renderer)
+ "Return the drawing area used by RENDERER."
+ (let ((rect ((@@ (sdl2 rect) make-rect) 0 0 0 0)))
+ (ffi:sdl-render-get-viewport (unwrap-renderer renderer)
+ ((@@ (sdl2 rect) unwrap-rect) rect))
+ rect))
+
+(define (set-renderer-viewport! renderer rect)
+ "Set the drawing area for RENDERER to RECT."
+ (unless (zero? (ffi:sdl-render-set-viewport
+ (unwrap-renderer renderer)
+ (if rect
+ ((@@ (sdl2 rect) unwrap-rect) rect)
+ %null-pointer)))
+ (sdl-error "set-renderer-viewport!" "Failed to set viewport")))
+
(define (set-render-draw-blend-mode renderer blend-mode)
"Set blend mode of RENDERER to BLEND-MODE."
(ffi:sdl-set-render-draw-blend-mode