From 81d51af6e0ac022d1e96b2bcd45909b75d855675 Mon Sep 17 00:00:00 2001 From: Frank Duncan Date: Wed, 20 Apr 2016 00:33:51 -0500 Subject: [PATCH] Parse widgets v1 - slider --- src/main/interface.lisp | 31 ++++++++++++++++--------------- src/main/main.lisp | 11 ++++++++--- src/main/model.lisp | 19 ++++++++++++++++++- src/main/nvm/base.lisp | 2 +- src/main/nvm/nvm.lisp | 13 +++++++++---- src/main/nvm/utils.lisp | 8 ++++---- 6 files changed, 56 insertions(+), 28 deletions(-) diff --git a/src/main/interface.lisp b/src/main/interface.lisp index f59a242..dd6c4ce 100644 --- a/src/main/interface.lisp +++ b/src/main/interface.lisp @@ -6,7 +6,7 @@ ; It may be useful to keep windows around (defvar *glut-window-opened* nil) -(defvar *model* nil) +(defvar *dimensions* nil) (defvar *colors* '((140 140 140) ; gray (5) @@ -84,13 +84,18 @@ (gl:vertex 260 250 0) (gl:end))) -(defun initialize (model) - "INITIALIZE MODEL => RESULT +(defun initialize (&key dims) + "INITIALIZE &key DIMS => RESULT + + DIMS: (:xmin XMIN :xmax XMAX :ymin YMIN :ymax YMAX) ARGUMENTS AND VALUES: - MODEL: A clnl-model:model to use to initialize the interface RESULT: undefined + XMIN: An integer representing the minimum patch coord in X + XMAX: An integer representing the maximum patch coord in X + YMIN: An integer representing the minimum patch coord in Y + YMAX: An integer representing the maximum patch coord in Y DESCRIPTION: @@ -98,7 +103,7 @@ DESCRIPTION: the interface lives. From here, one can go into headless or running mode, but for certain things this interface will still need to act, and also allows for bringing up and taking down of visual elements." - (setf *model* model)) + (setf *dimensions* dims)) (defun run () "RUN => RESULT @@ -119,12 +124,8 @@ DESCRIPTION: (sb-int:with-float-traps-masked (:invalid) (cl-glut:init) (cl-glut:init-window-size - (floor - (* *patch-size* - (1+ (- (getf (clnl-model:world-dimensions *model*) :xmax) (getf (clnl-model:world-dimensions *model*) :xmin))))) - (floor - (* *patch-size* - (1+ (- (getf (clnl-model:world-dimensions *model*) :ymax) (getf (clnl-model:world-dimensions *model*) :ymin)))))) + (floor (* *patch-size* (1+ (- (getf *dimensions* :xmax) (getf *dimensions* :xmin))))) + (floor (* *patch-size* (1+ (- (getf *dimensions* :ymax) (getf *dimensions* :ymin)))))) (cl-glut:init-display-mode :double :rgba) (cl-glut:create-window "CLNL Test Window") (setf *glut-window-opened* t) @@ -166,13 +167,13 @@ DESCRIPTION: (render-buf (first (gl:gen-renderbuffers 1))) ;(width ; (floor (* *patch-size* (1+ (- - ; (getf (clnl-model:world-dimensions *model*) :ymax) - ; (getf (clnl-model:world-dimensions *model*) :ymin)))))) + ; (getf *dimensions* :ymax) + ; (getf *dimensions* :ymin)))))) ;(height ; (floor (* *patch-size* (1+ (- (getf *world-dims* :xmax) (getf *world-dims* :xmin)))))) ; (floor (* *patch-size* (1+ (- - ; (getf (clnl-model:world-dimensions *model*) :xmax) - ; (getf (clnl-model:world-dimensions *model*) :xmin))))) + ; (getf *dimensions* :xmax) + ; (getf *dimensions* :xmin))))) (width 143) ; Hard coded for now, yay v1 (if you see this comment in a year, please cry for me) (height 143)) (gl:bind-framebuffer :framebuffer fbo) diff --git a/src/main/main.lisp b/src/main/main.lisp index 70be24d..b6cce46 100644 --- a/src/main/main.lisp +++ b/src/main/main.lisp @@ -43,7 +43,12 @@ DESCRIPTION: is set so that multiple runs will evaluate to the same. When FILE is not provided, a default model is used." - (eval (model->lisp (if file (with-open-file (str file) (clnl-model:read-from-nlogo str)) (clnl-model:default-model))))) + (let + ((netlogoed-lisp + (model->lisp + (if file (with-open-file (str file) (clnl-model:read-from-nlogo str)) (clnl-model:default-model)))) + (*package* (find-package :cl))) + (eval netlogoed-lisp))) (defun run-commands (cmds) "RUN-COMMANDS CMDS => RESULT @@ -79,5 +84,5 @@ DESCRIPTION: (defun model->lisp (model) `(progn (clnl-random:set-seed 15) ; should the seed always be 15? - (clnl-nvm:create-world ,model) - (clnl-interface:initialize ,model))) + (clnl-nvm:create-world :dims ',(clnl-model:world-dimensions model)) + (clnl-interface:initialize :dims ',(clnl-model:world-dimensions model)))) diff --git a/src/main/model.lisp b/src/main/model.lisp index 3812ac2..a919120 100644 --- a/src/main/model.lisp +++ b/src/main/model.lisp @@ -78,7 +78,7 @@ DESCRIPTION: (defstruct ,type ,@(remove nil (mapcar - (lambda (def) (when (find (car def) (list :int :double :boolean :choice :string)) (second def))) + (lambda (def) (when (find (car def) (list :int :double :boolean :choice :string :option)) (second def))) definitions))) (push (list @@ -110,6 +110,7 @@ DESCRIPTION: (:double `(coerce (read-from-string ,line) 'double-float)) (:boolean `(string= "1" ,line)) (:choice `(cadr (find ,line ',(third def) :key #'car :test #'string=))) + (:option `(when (string/= ,line ,(third def)) ,line)) (:string line)))) (when val-getter (list (intern (symbol-name (cadr def)) :keyword) val-getter)))) definitions @@ -144,6 +145,22 @@ DESCRIPTION: (:string tick-counter-label) (:double frame-rate 30)) +(defwidget-definition slider + (:specified "SLIDER") + (:int left) + (:int top) + (:int right) + (:int bottom) + (:string display) + (:string varname) + (:string min) + (:string max) + (:double default) + (:string step) + (:reserved) + (:option units "NIL") + (:choice direction (("HORIZONTAL" :horizontal) ("VERTICAL" :vertical)))) + (defun parse-interface (interface-as-strings) (let ((widgets-as-strings diff --git a/src/main/nvm/base.lisp b/src/main/nvm/base.lisp index ea427fa..dfd3fc2 100644 --- a/src/main/nvm/base.lisp +++ b/src/main/nvm/base.lisp @@ -5,7 +5,7 @@ (defvar *turtles* nil) (defvar *myself* nil) (defvar *self* nil) -(defvar *model* nil) +(defvar *dimensions* nil) (defvar *topology* :torus) (defstruct turtle who color heading xcor ycor) diff --git a/src/main/nvm/nvm.lisp b/src/main/nvm/nvm.lisp index b18faf1..287513e 100644 --- a/src/main/nvm/nvm.lisp +++ b/src/main/nvm/nvm.lisp @@ -173,13 +173,18 @@ DESCRIPTION: See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#create-turtles" (loop :for i :from 1 :to n :do (create-turtle))) -(defun create-world (model) - "CREATE-WORLD MODEL => RESULT +(defun create-world (&key dims) + "CREATE-WORLD &key DIMS => RESULT + + DIMS: (:xmin XMIN :xmax XMAX :ymin YMIN :ymax YMAX) ARGUMENTS AND VALUES: - MODEL: A clnl-model:model to use to initialize the vm RESULT: undefined + XMIN: An integer representing the minimum patch coord in X + XMAX: An integer representing the maximum patch coord in X + YMIN: An integer representing the minimum patch coord in Y + YMAX: An integer representing the maximum patch coord in Y DESCRIPTION: @@ -187,7 +192,7 @@ DESCRIPTION: This should be called before using the engine in any real capacity. If called when an engine is already running, it may do somethign weird." - (setf *model* model) + (setf *dimensions* dims) (setf *turtles* nil) (setf *current-id* 0)) diff --git a/src/main/nvm/utils.lisp b/src/main/nvm/utils.lisp index 06941f5..22242f5 100644 --- a/src/main/nvm/utils.lisp +++ b/src/main/nvm/utils.lisp @@ -1,6 +1,6 @@ (in-package #:clnl-nvm) -(defun min-pxcor () (getf (clnl-model:world-dimensions *model*) :xmin)) -(defun max-pxcor () (getf (clnl-model:world-dimensions *model*) :xmax)) -(defun min-pycor () (getf (clnl-model:world-dimensions *model*) :ymin)) -(defun max-pycor () (getf (clnl-model:world-dimensions *model*) :ymax)) +(defun min-pxcor () (getf *dimensions* :xmin)) +(defun max-pxcor () (getf *dimensions* :xmax)) +(defun min-pycor () (getf *dimensions* :ymin)) +(defun max-pycor () (getf *dimensions* :ymax)) -- 2.25.1