From c6c63425f42a44e483b8676f562fa960e59c8777 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Tue, 18 Apr 2023 07:44:23 -0400 Subject: region: Use pushdown state. --- catbird/region.scm | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/catbird/region.scm b/catbird/region.scm index f1cc306..f42532a 100644 --- a/catbird/region.scm +++ b/catbird/region.scm @@ -25,6 +25,7 @@ #:use-module (catbird config) #:use-module (catbird mixins) #:use-module (catbird node) + #:use-module (catbird pushdown) #:use-module (catbird scene) #:use-module (chickadee) #:use-module (chickadee data array-list) @@ -53,8 +54,7 @@ (define-root-class ( ) (area #:accessor area #:init-keyword #:area) (camera #:accessor camera #:init-keyword #:camera #:init-value #f) - (scene #:accessor scene #:init-keyword #:scene #:init-value #f) - (scene-stack #:getter scene-stack #:init-thunk make-array-list) + (scene-state #:accessor scene-state #:init-thunk make-pushdown-state) (viewport #:accessor viewport)) (define-method (area-x (region )) @@ -99,23 +99,32 @@ (make-exception-with-message "region area exceeds window area"))) (make #:area area #:name name #:rank rank))) -(define-method (replace-scene (r ) (new-scene )) - (let ((old-scene (scene r))) +(define-method (scene (region )) + (state-current (scene-state region))) + +(define-method (replace-scene (region ) (new-scene )) + (let ((old-scene (scene region))) (when old-scene (on-exit old-scene)) - (set! (scene r) new-scene) - (set! (regions new-scene) (cons r (regions new-scene))) + (state-push! (scene-state region) new-scene) + (set! (regions new-scene) (cons region (regions new-scene))) (on-enter new-scene))) (define-method (push-scene (region ) (new-scene )) (let ((old-scene (scene region))) (when old-scene - (array-list-push! (scene-stack region) old-scene)) - (replace-scene region new-scene))) + (on-exit old-scene)) + (state-push! (scene-state region)) + (set! (regions new-scene) (cons region (regions new-scene))) + (on-enter new-scene))) (define-method (pop-scene (region )) - (let ((stack (scene-stack region))) - (unless (array-list-empty? stack) - (replace-scene (array-list-pop! stack))))) + (let ((old-scene (state-pop! (scene-state region)))) + (on-exit old-scene) + (set! (regions old-scene) + (delq region (regions old-scene)))) + (let ((restored-scene (scene region))) + (when restored-scene + (on-enter restored-scene)))) (define-method (update (region ) dt) (let ((s (scene region))) -- cgit v1.2.3