diff --git a/Nasal/globals.nas b/Nasal/globals.nas index e4a71e865..710dbc316 100644 --- a/Nasal/globals.nas +++ b/Nasal/globals.nas @@ -20,8 +20,8 @@ isa = func { # tree. # fgcommand = func { - if(isa(arg[1], props.Node)) { _fgcommand(arg[0], arg[1]._g) } - _fgcommand(arg[0], propTree); + if(isa(arg[1], props.Node)) { arg[1] = arg[1]._g } + _fgcommand(arg[0], arg[1]); } ## diff --git a/Nasal/props.nas b/Nasal/props.nas index dfe483598..cee3defb4 100644 --- a/Nasal/props.nas +++ b/Nasal/props.nas @@ -30,14 +30,47 @@ Node = { }; -# Static constructor. Accepts a hash as an argument and duplicates -# its contents in the property node. ex: -# Node.new({ value : 1.0, units : "ms" }); +## +# Static constructor for a Node object. Accepts a Nasal hash +# expression to initialize the object a-la setValues(). +# Node.new = func { result = wrapNode(_new()); - if(typeof(arg[0]) == "hash") { - foreach(k; keys(arg[0])) { - result.getNode(k, 1).setValue(arg[0][k]); + if(size(arg) >= 0 and typeof(arg[0]) == "hash") { + result.setValues(arg[0]); + } + return result; +} + +## +# Useful utility. Sets a whole property tree from a Nasal hash +# object, such that scalars become leafs in the property tree, hashes +# become named subnodes, and vectors become indexed subnodes. This +# works recursively, so you can define whole property trees with +# syntax like: +# +# dialog = { +# name : "exit", width : 180, height : 100, modal : 0, +# text : { x : 10, y : 70, label : "Hello World!" } }; +# +Node.setValues = func { + foreach(k; keys(arg[0])) { me._setChildren(k, arg[0][k]); } +} + +## +# Private function to do the work of setValues(). +# The first argument is a child name, the second a nasal scalar, +# vector, or hash. +# +Node._setChildren = func { + name = arg[0]; val = arg[1]; + subnode = me.getNode(name, 1); + if(typeof(val) == "scalar") { subnode.setValue(val); } + elsif(typeof(val) == "hash") { subnode.setValues(val); } + elsif(typeof(val) == "vector") { + for(i=0; i max) { val = max } + fovProp.setDoubleValue(val); + popup(val); +} + +## +# Handler. Decrease FOV by one step +# +decrease = func { + calcMul(); + val = fovProp.getValue() / mul; + if(val == min) { return; } + if(val < min) { val = min } + fovProp.setDoubleValue(val); + popup(val); +} + +## +# Pop up the "fov" dialog for a moment. +# +popdown = func { fgcommand("dialog-close", fovDialog); } +popup = func { + fov = arg[0]; + fov = format(fov); + + labelNode.setValue("FOV: " ~ fov); + + # Create it, show it + popdown(); + fgcommand("dialog-show", fovDialog); + + # And kill it automatically after a second + settimer(popdown, 1); +} + diff --git a/keyboard.xml b/keyboard.xml index 967b93a54..93fe74786 100644 --- a/keyboard.xml +++ b/keyboard.xml @@ -557,22 +557,6 @@ calculated by adding 256 to the GLUT key value in glut.h. - - C - scripting test - - script - - - - G Gear down. @@ -638,9 +622,8 @@ calculated by adding 256 to the GLUT key value in glut.h. X Increase field of view. - property-multiply - /sim/current-view/field-of-view - 1.05 + nasal + @@ -885,9 +868,8 @@ calculated by adding 256 to the GLUT key value in glut.h. x Decrease field of view. - property-multiply - /sim/current-view/field-of-view - 0.952380952380 + nasal +