stopwatch-dialog vbox false 8 -5 5 0.7 var p = "/sim/gui/dialogs/stopwatch-dialog/"; var display = props.globals.getNode(p ~ "display", 1); var time = props.globals.getNode("/sim/time/elapsed-sec"); var start_time = props.globals.getNode(p ~ "start-time", 1).getValue(); var accu = props.globals.getNode(p ~ "accu", 1).getValue(); if (start_time == nil) start_time = 0; if (accu == nil) accu = 0; var r = props.globals.getNode(p ~ "running"); var running = r != nil ? r.getBoolValue() : 0; var start = func { if (!running) { start_time = time.getValue(); running = 1; loop(); } } var stop = func { if (running) { running = 0; show(accu += time.getValue() - start_time); } } var reset = func { accu = 0; if (running) start_time = time.getValue(); else show(0); } var loop = func { if (running) { show(time.getValue() - start_time + accu); settimer(loop, 0.02); } } var show = func(s) { var hours = s / 3600; var minutes = int(math.mod(s / 60, 60)); var seconds = int(math.mod(s, 60)); var msec = int(math.mod(s * 1000, 1000) / 100); var d = sprintf("%3d : %02d : %02d.%d", hours, minutes, seconds, msec); display.setValue(d); } if (running) { loop(); } else { if (accu == nil) accu = 0; show(accu); } props.globals.getNode(p ~ "start-time", 1).setDoubleValue(start_time); props.globals.getNode(p ~ "running", 1).setBoolValue(running); props.globals.getNode(p ~ "accu", 1).setDoubleValue(accu); running = 0; # stop display loop center true /sim/gui/dialogs/stopwatch-dialog/display sim/gui/selected-style/fonts/gui-large 1 0.9 0 1 hbox 2