stopwatch-dialog
vbox
8
mod = func(x, y) { x - int(x / y) * y }
p = "/sim/gui/dialogs/stopwatch-dialog/";
display = props.globals.getNode(p ~ "display", 1);
time = props.globals.getNode("/sim/time/elapsed-sec");
start_time = props.globals.getNode(p ~ "start-time", 1).getValue();
accu = props.globals.getNode(p ~ "accu", 1).getValue();
r = props.globals.getNode(p ~ "running");
running = r != nil ? r.getBoolValue() : 0;
start = func {
if (!running) {
start_time = time.getValue();
running = 1;
loop();
}
}
stop = func {
if (running) {
running = 0;
show(accu += time.getValue() - start_time);
}
}
reset = func {
accu = 0;
if (running) {
start_time = time.getValue();
} else {
show(0);
}
}
loop = func {
if (running) {
show(time.getValue() - start_time + accu);
settimer(loop, 0.02);
}
}
show = func(s) {
var hours = s / 3600;
var minutes = int(mod(s / 60, 60));
var seconds = int(mod(s, 60));
var msec = int(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
TIMES_24
1
0.9
0
1
hbox
2