From fdfee6053fb8430566eb7a9960b77cf28826aa01 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Thu, 28 Jul 2022 09:38:35 -0500 Subject: [add] canvas-paint example; [refactor] with-current-pen --- src/canvas-language.lisp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'src/canvas-language.lisp') diff --git a/src/canvas-language.lisp b/src/canvas-language.lisp index 8188e53..b90e22d 100644 --- a/src/canvas-language.lisp +++ b/src/canvas-language.lisp @@ -24,17 +24,18 @@ "Like WITH-CURRENT-PEN, but lets you set the state of the pen EXECUTION BODY. After BODY executes, the state is restored to whatever it was before WITH-PEN-STATE was evaluated." - `(let ((*current-pen-position* ,(if position nil '*current-pen-position*)) - (*current-pen-color* ,(if color-supplied-p nil '*current-pen-color*)) - (*current-pen-width* ,(if width nil '*current-pen-width*))) - ,(when position - `(move-to ,@position)) - ,(when color-supplied-p - `(canvas-pen-color ,color)) - ,(when width - `(canvas-pen-width ,width)) - (with-current-pen - ,@body))) + (with-gensyms (newpos) + `(let ((*current-pen-position* ,(if position nil '*current-pen-position*)) + (*current-pen-color* ,(if color-supplied-p nil '*current-pen-color*)) + (*current-pen-width* ,(if width nil '*current-pen-width*))) + ,(when position + `(let ((,newpos ,position)) (apply 'move-pen-to ,newpos))) + ,(when color-supplied-p + `(canvas-pen-color ,color)) + ,(when width + `(canvas-pen-width ,width)) + (with-current-pen + ,@body)))) (defmacro with-canvas (canvas &body body) "Perform drawing commands in BODY using the value of CANVAS as the -- cgit v1.2.3