From: James Turner Date: Sun, 12 May 2013 12:30:48 +0000 (+0100) Subject: Make property-cycle usable with knobs/sliders. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=32834eb0b081b26f21fa7a0bbf14c2678bd5ac61;p=flightgear.git Make property-cycle usable with knobs/sliders. Add optional non-wrapping mode, and respect the 'offset' argument which knobs and sliders set, to control direction of stepping. --- diff --git a/src/Main/fg_commands.cxx b/src/Main/fg_commands.cxx index 4c3272916..8326aa77a 100644 --- a/src/Main/fg_commands.cxx +++ b/src/Main/fg_commands.cxx @@ -836,6 +836,11 @@ do_property_cycle (const SGPropertyNode * arg) { SGPropertyNode * prop = get_prop(arg); vector 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; }