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 ++++++++++++----------- src/interactive/canvas.lisp | 5 +++-- 2 files changed, 15 insertions(+), 13 deletions(-) (limited to 'src') 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 diff --git a/src/interactive/canvas.lisp b/src/interactive/canvas.lisp index d870ae8..977e3ec 100644 --- a/src/interactive/canvas.lisp +++ b/src/interactive/canvas.lisp @@ -3,7 +3,7 @@ (in-package #:wheelwork) (defclass/std pixels () - ((pixel-width pixel-height :std (error "pixel-width and pixel-height are required")) + ((pixel-width pixel-height :std (error "pixel-width and pixel-height are required")) (data :a :with :doc "Array of RGBA data representing an image of pixel-width X pixel-height"))) (defmethod initialize-instance :after ((pixels pixels) &key) @@ -23,7 +23,8 @@ I.E. If you are are wanting to manipulate more than one pixel at a time, you should get those pixels with USE-CACHED set to NIL." - (with-slots (pixel-width pixel-height data) pixels + (let ((pixel-width (pixel-width pixels)) + (data (pixels-data pixels))) (cond ((and use-cached cached-pixel) (adjust-array cached-pixel 4 -- cgit v1.2.3