diff --git a/whalesong/image/private/image.rkt b/whalesong/image/private/image.rkt index 490e551..f5d9231 100644 --- a/whalesong/image/private/image.rkt +++ b/whalesong/image/private/image.rkt @@ -1,13 +1,15 @@ #lang s-exp "../../lang/base.rkt" ;; Image functions that be implemented using racket based on primitives +;; NOTE: Modifications here may require rebuilding of Whalesong (require "main.rkt" "../../lang/for.rkt" "../../lang/posn.rkt") (provide place-images - place-images/align) + place-images/align + empty-image) ; place-images : (listof image?) (listof posn?) image? -> image? (define (place-images images posns scene) @@ -20,3 +22,5 @@ (for/fold ([acc scene]) ([img images] [posn posns]) (place-image/align img (posn-x posn) (posn-y posn) x-place y-place acc))) + +(define empty-image (rectangle 0 0 "solid" "black")) diff --git a/whalesong/image/private/js-impl.js b/whalesong/image/private/js-impl.js index ac1c00d..473243b 100644 --- a/whalesong/image/private/js-impl.js +++ b/whalesong/image/private/js-impl.js @@ -474,6 +474,22 @@ EXPORTS['overlay/xy'] = jsnums.toFixnum(deltaY)); }); +EXPORTS['overlay/offset'] = + makePrimitiveProcedure( + 'overlay/offset', + 4, + function(MACHINE) { + var img1 = checkImage(MACHINE, "overlay/offset", 0); + var deltaX = checkReal(MACHINE, "overlay/offset", 1); + var deltaY = checkReal(MACHINE, "overlay/offset", 2); + var img2 = checkImage(MACHINE, "overlay/offset", 3); + var middleX = (img1.getWidth() - img2.getWidth()) / 2; + var middleY = (img1.getHeight() - img2.getHeight()) / 2; + return makeOverlayImage(img1, + img2, + jsnums.toFixnum(middleX + deltaX), + jsnums.toFixnum(middleY + deltaY)); + }); EXPORTS['overlay/align'] = @@ -540,6 +556,23 @@ EXPORTS['underlay/xy'] = -(jsnums.toFixnum(deltaY))); }); +EXPORTS['underlay/offset'] = + makePrimitiveProcedure( + 'underlay/offset', + 4, + function(MACHINE) { + var img1 = checkImage(MACHINE, "underlay/offset", 0); + var deltaX = checkReal(MACHINE, "underlay/offset", 1); + var deltaY = checkReal(MACHINE, "underlay/offset", 2); + var img2 = checkImage(MACHINE, "underlay/offset", 3); + var middleX = (img1.getWidth() - img2.getWidth()) / 2; + var middleY = (img1.getHeight() - img2.getHeight()) / 2; + return makeOverlayImage(img2, + img1, + -jsnums.toFixnum(middleX + deltaX), + -jsnums.toFixnum(middleY + deltaY)); + }); + EXPORTS['underlay/align'] = makePrimitiveProcedure( 'underlay/align', diff --git a/whalesong/image/private/main.rkt b/whalesong/image/private/main.rkt index 0e71a16..d78e851 100644 --- a/whalesong/image/private/main.rkt +++ b/whalesong/image/private/main.rkt @@ -19,9 +19,11 @@ video/url play-sound overlay + overlay/offset overlay/xy overlay/align underlay + underlay/offset underlay/xy underlay/align beside diff --git a/whalesong/image/private/racket-impl.rkt b/whalesong/image/private/racket-impl.rkt index e3e57b8..362556a 100644 --- a/whalesong/image/private/racket-impl.rkt +++ b/whalesong/image/private/racket-impl.rkt @@ -5,9 +5,11 @@ (provide text text/font overlay + overlay/offset overlay/xy overlay/align underlay + underlay/offset underlay/xy underlay/align beside @@ -101,9 +103,11 @@ text text/font overlay + overlay/offset overlay/xy overlay/align underlay + underlay/offset underlay/xy underlay/align beside