]> git.mxchange.org Git - flightgear.git/commitdiff
Make property-cycle usable with knobs/sliders.
authorJames Turner <zakalawe@mac.com>
Sun, 12 May 2013 12:30:48 +0000 (13:30 +0100)
committerJames Turner <zakalawe@mac.com>
Sun, 12 May 2013 12:30:48 +0000 (13:30 +0100)
Add optional non-wrapping mode, and respect the 'offset' argument
which knobs and sliders set, to control direction of stepping.

src/Main/fg_commands.cxx

index 4c3272916f56a3180e29b9d8457e697bb71cfecb..8326aa77a2f2fcf787e67287ea6275a77c167ade 100644 (file)
@@ -836,6 +836,11 @@ do_property_cycle (const SGPropertyNode * arg)
 {
     SGPropertyNode * prop = get_prop(arg);
     vector<SGPropertyNode_ptr> values = arg->getChildren("value");
+    
+    bool wrap = arg->getBoolValue("wrap", true);
+    // compatible with knob/pick animations
+    int offset = arg->getIntValue("offset", 1);
+    
     int selection = -1;
     int nSelections = values.size();
 
@@ -847,15 +852,22 @@ do_property_cycle (const SGPropertyNode * arg)
                                 // Try to find the current selection
     for (int i = 0; i < nSelections; i++) {
         if (compare_values(prop, values[i])) {
-            selection = i + 1;
+            selection = i;
             break;
         }
     }
 
-                                // Default or wrap to the first selection
-    if (selection < 0 || selection >= nSelections)
+    if (selection < 0) { // default to first selection
         selection = 0;
-
+    } else {
+        selection += offset;
+        if (wrap) {
+            selection = (selection + nSelections) % nSelections;
+        } else {
+            SG_CLAMP_RANGE(selection, 0, nSelections - 1);
+        }
+    }
+    
     prop->setUnspecifiedValue(values[selection]->getStringValue());
     return true;
 }