(declare (integrate-external "geometry"))
-(define (make-terrain filename rows columns lat lng step color-function)
- (let ((widget (%make-terrain filename rows columns
- lat lng step color-function)))
+(define (make-terrain . options)
+ (let ((widget (%make-terrain options)))
(named-lambda (terrain command . args)
(define (check-flonum-args num description)
(if (not (= num (guarantee-list-of-type->length
args real? "a real number" 'TERRAIN)))
(error (string-append
- "The "(symbol-name command)" command requires"
+ "The "(symbol-name command)" command requires "
(number->string num '(int))" arguments: "description"."))))
(cond
(else
(error:wrong-type-argument command "a command name" 'TERRAIN))))))
-(define (%make-terrain filename rows columns lat lng step color-function)
- (let ((window (gtk-window-new 'toplevel))
- (grid (gtk-grid-new))
- (label (gtk-label-new ""))
- (matrix (make-heightmap-matrix filename rows columns)))
- (gtk-window-set-title window (string-append "Terrain: "
- (->namestring filename)))
- (gtk-container-set-border-width window 5)
- (gtk-widget-set-hexpand label #t)
- (let* ((min.max (matrix-min.max matrix rows columns))
- (widget (make-terrain-viewport
- matrix rows columns (car min.max) (cdr min.max)
- (make-latitude/longitude lat lng) step color-function
- label 300 300)))
- (gtk-widget-set-vexpand widget #t)
- (gtk-widget-set-hexpand widget #t)
- (gtk-grid-attach grid widget 0 0 1 1)
- (gtk-grid-attach grid label 0 1 1 1)
- (gtk-container-add window grid)
- (gtk-widget-show-all window)
- widget)))
+(define (%make-terrain options)
+
+ (define (get-keyword-value klist key default)
+ (let loop ((klist klist))
+ (if (pair? klist)
+ (if (eq? (car klist) key)
+ (car (cdr klist))
+ (loop (cdr (cdr klist))))
+ default)))
+
+ (define no-value "<none>")
+
+ (define (get-flonum-option name)
+ (let ((v (get-keyword-value options name no-value)))
+ (guarantee-real v name)
+ (->flonum v)))
+
+ (define (get-integer-option name default)
+ (let ((v (get-keyword-value options name no-value)))
+ (if (eq? v no-value)
+ default
+ (begin
+ (guarantee-integer v name)
+ v))))
+
+ (let ((filename (get-keyword-value options 'filename #f))
+ (rows (get-integer-option 'rows #f))
+ (columns (get-integer-option 'columns #f))
+ (latitude (get-flonum-option 'latitude))
+ (longitude (get-flonum-option 'longitude))
+ (step (get-flonum-option 'step))
+ (color-function
+ (let ((v (get-keyword-value options 'color-function #f)))
+ (and v (begin
+ (guarantee-procedure-of-arity
+ v 3 'make-terrain:color-function)
+ v))))
+ (width (get-integer-option 'width 300))
+ (height (get-integer-option 'height 300)))
+ (let ((matrix (make-heightmap-matrix filename rows columns))
+ (origin (make-latitude/longitude latitude longitude))
+ (title (if filename
+ (string-append "Terrain: "(->namestring filename))
+ "Terrain")))
+ (let ((window (gtk-window-new 'toplevel))
+ (grid (gtk-grid-new))
+ (label (gtk-label-new "")))
+ (gtk-window-set-title window title)
+ (gtk-container-set-border-width window 5)
+ (gtk-widget-set-hexpand label #t)
+ (let* ((min.max (matrix-min.max matrix rows columns))
+ (widget (make-terrain-viewport
+ matrix rows columns (car min.max) (cdr min.max)
+ origin step color-function
+ label width height)))
+ (gtk-widget-set-vexpand widget #t)
+ (gtk-widget-set-hexpand widget #t)
+ (gtk-grid-attach grid widget 0 0 1 1)
+ (gtk-grid-attach grid label 0 1 1 1)
+ (gtk-container-add window grid)
+ (gtk-widget-show-all window)
+ widget)))))
(define-class (<terrain-viewport>
(constructor make-terrain-viewport