diff options
author | David Thompson <dthompson2@worcester.edu> | 2018-08-28 08:59:27 -0400 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2018-08-28 08:59:27 -0400 |
commit | 1ad377e3cde4011b9c2934c152335293261c3f1d (patch) | |
tree | 77752f479c36baa5381221140529f3ef26851874 | |
parent | 2eda5f3e5cc16ca9808d5a0e8326bcf1716796c6 (diff) |
Add sane default canvas view.
Cuts down on boilerplate that the user needs to write.
-rw-r--r-- | starling/node-2d.scm | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/starling/node-2d.scm b/starling/node-2d.scm index c0cb243..a0b2746 100644 --- a/starling/node-2d.scm +++ b/starling/node-2d.scm @@ -33,7 +33,9 @@ #:use-module (chickadee render texture) #:use-module (chickadee render viewport) #:use-module (chickadee scripting) + #:use-module (ice-9 match) #:use-module (oop goops) + #:use-module (sdl2 video) #:use-module (starling asset) #:use-module (starling kernel) #:use-module (starling node) @@ -175,8 +177,19 @@ ;; The canvas is the root of a 2D scene. It handles rendering one or ;; more views. +(define (make-default-views) + (match (window-size (window (current-kernel))) + ((width height) + (list + (make <view-2d> + #:camera (make <camera-2d> + #:width width + #:height height) + #:area (make-rect 0 0 width height)))))) + (define-class <canvas> (<node>) - (views #:accessor views #:init-form '() #:init-keyword #:views)) + (views #:accessor views #:init-thunk make-default-views + #:init-keyword #:views)) (define-method (update (canvas <canvas>) dt) (for-each (lambda (view) |