diff options
Diffstat (limited to 'catbird/region.scm')
-rw-r--r-- | catbird/region.scm | 74 |
1 files changed, 52 insertions, 22 deletions
diff --git a/catbird/region.scm b/catbird/region.scm index 7e9f9df..a117a2e 100644 --- a/catbird/region.scm +++ b/catbird/region.scm @@ -36,31 +36,32 @@ #:use-module (ice-9 exceptions) #:use-module (oop goops) #:export (<region> - make-region + <full-region> area area-x area-y area-width area-height camera + set-camera freeze frozen? scene replace-scene push-scene pop-scene - unfreeze) + unfreeze + on-window-resize) #:re-export (name rank render update)) (define-root-class <region> (<renderable> <updatable> <nameable> <rankable>) - (area #:accessor area #:init-keyword #:area) + (area #:getter area #:init-keyword #:area) (camera #:accessor camera #:init-keyword #:camera #:init-value #f) (scene-state #:accessor scene-state #:init-thunk make-pushdown-state) (framebuffer #:accessor framebuffer) - (framebuffer-rect #:accessor framebuffer-rect) ;; Regions can be frozen for debugging purposes, so that the scene ;; they contain isn't updated or rendered. (frozen? #:accessor frozen? #:init-value #f)) @@ -88,26 +89,37 @@ (define-method (initialize (region <region>) args) (next-method) + (refresh-framebuffer region) + (refresh-camera region)) + +(define-method (set-camera (region <region>) new-camera) + (set! (camera region) new-camera) + (refresh-camera region)) + +(define-method (refresh-camera (region <region>)) + (let ((c (camera region))) + (when c (resize c (width region) (height region))))) + +(define-method (refresh-framebuffer (region <region>)) (let ((r (area region))) (set! (framebuffer region) (make-framebuffer (float->int (rect-width r)) - (float->int (rect-height r)))) - (set! (framebuffer-rect region) - (make-rect 0.0 0.0 - (float->int (rect-width r)) - (float->int (rect-height r)))))) - -(define (make-region area name rank) - (let* ((window (current-window)) - (w (window-width window)) - (h (window-height window))) - (when (or (< (rect-left area) 0.0) - (< (rect-bottom area) 0.0) - (> (rect-right area) w) - (> (rect-top area) h)) - (raise-exception - (make-exception-with-message "region area exceeds window area"))) - (make <region> #:area area #:name name #:rank rank))) + (float->int (rect-height r)))))) + +(define-method (resize (region <region>) width height) + (let ((r (area region)) + (c (camera region)) + (s (scene region))) + (set-rect-width! r width) + (set-rect-height! r height) + (refresh-framebuffer region) + (refresh-camera region) + (when s (on-region-resize s)))) + +(define-method (move (region <region>) x y) + (let ((r (area region))) + (set-rect-x! r x) + (set-rect-y! r y ))) (define-method (freeze (region <region>)) (set! (frozen? region) #t)) @@ -161,5 +173,23 @@ (with-projection (projection-matrix (camera region)) (render/around s alpha)))) (draw-sprite* (framebuffer-texture fb) - (framebuffer-rect region) + (area region) %identity-matrix))))) + +(define-method (on-window-resize (region <region>) width height) + #t) + + +;;; +;;; Full region +;;; + +(define (current-window-area) + (let ((window (current-window))) + (make-rect 0.0 0.0 (window-width window) (window-height window)))) + +(define-class <full-region> (<region>) + (area #:getter area #:init-thunk current-window-area)) + +(define-method (on-window-resize (region <full-region>) width height) + (resize region width height)) |