diff options
author | David Thompson <dthompson@member.fsf.org> | 2013-11-30 13:17:15 -0500 |
---|---|---|
committer | David Thompson <dthompson@member.fsf.org> | 2013-11-30 13:17:15 -0500 |
commit | a3d00293cbd731a86751b1f46d994bebab4bd655 (patch) | |
tree | be2c0d5da6f4432dc82fd5159c1a708b57eaf7ea /2d/window.scm | |
parent | d73ec673e3dfa2986e9fb6050dc54377a556b186 (diff) |
Add with-window form.
* 2d/window.scm (<window>): New record type.
(open-window): Use window object.
(close-window): Change docstring.
* 2d/game.scm (<game>, make-game): Remove window properties.
(run-game): Remove window logic.
Diffstat (limited to '2d/window.scm')
-rw-r--r-- | 2d/window.scm | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/2d/window.scm b/2d/window.scm index 094314b..4c967de 100644 --- a/2d/window.scm +++ b/2d/window.scm @@ -22,26 +22,46 @@ ;;; Code: (define-module (2d window) + #:use-module (srfi srfi-9) #:use-module (figl gl) #:use-module ((sdl sdl) #:prefix SDL:) #:use-module ((sdl mixer) #:prefix SDL:) #:use-module (2d vector2) - #:export (open-window - close-window)) + #:export (<window> + make-window + window? + window-title + window-resolution + window-fullscreen? + open-window + close-window + with-window)) -(define* (open-window title resolution fullscreen) - "Open the game window with the given TITLE and RESOLUTION. If -FULLSCREEN is #t, open a fullscreen window." - (let ((flags (if fullscreen '(opengl fullscreen) 'opengl)) - (width (vx resolution)) - (height (vy resolution))) +(define-record-type <window> + (%make-window title resolution fullscreen?) + window? + (title window-title) + (resolution window-resolution) + (fullscreen? window-fullscreen?)) + +(define* (make-window #:optional #:key + (title "Guile-2D Window") + (resolution (vector2 640 480)) + (fullscreen? #f)) + (%make-window title resolution fullscreen?)) + +(define* (open-window window) + "Open the game window using the settings in WINDOW." + (let ((flags (if (window-fullscreen? window) '(opengl fullscreen) 'opengl)) + (width (vx (window-resolution window))) + (height (vy (window-resolution window)))) ;; Initialize everything (SDL:enable-unicode #t) (SDL:init 'everything) (SDL:open-audio) ;; Open SDL window in OpenGL mode. (SDL:set-video-mode width height 24 flags) - (SDL:set-caption title) + (SDL:set-caption (window-title window)) ;; Initialize OpenGL orthographic view (gl-viewport 0 0 width height) (set-gl-matrix-mode (matrix-mode projection)) @@ -56,6 +76,12 @@ FULLSCREEN is #t, open a fullscreen window." (blending-factor-dest one-minus-src-alpha)))) (define (close-window) - "Close the game window and audio." + "Close the currently open window and audio." (SDL:close-audio) (SDL:quit)) + +(define-syntax-rule (with-window window body ...) + (begin + (open-window window) + body ... + (close-window))) |