stopwatch dialog
This commit is contained in:
parent
1bbdc9e42b
commit
bd28941f61
1 changed files with 139 additions and 0 deletions
139
gui/dialogs/stopwatch.xml
Normal file
139
gui/dialogs/stopwatch.xml
Normal file
|
@ -0,0 +1,139 @@
|
|||
<?xml version="1.0"?>
|
||||
|
||||
<PropertyList>
|
||||
<name>stopwatch-dialog</name>
|
||||
<layout>vbox</layout>
|
||||
<default-padding>8</default-padding>
|
||||
|
||||
<nasal>
|
||||
<open>
|
||||
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.001);
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
var d = sprintf("%3d : %02d : %02d.%03d", hours, minutes, seconds, msec);
|
||||
display.setValue(d);
|
||||
}
|
||||
|
||||
if (running) {
|
||||
loop();
|
||||
} else {
|
||||
if (accu == nil) {
|
||||
accu = 0;
|
||||
}
|
||||
show(accu);
|
||||
}
|
||||
</open>
|
||||
|
||||
<close>
|
||||
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
|
||||
</close>
|
||||
</nasal>
|
||||
|
||||
<text>
|
||||
<label>xxxxx000 : 00 : 00.000</label>
|
||||
<halign>center</halign>
|
||||
<live>true</live>
|
||||
<property>/sim/gui/dialogs/stopwatch-dialog/display</property>
|
||||
<font>
|
||||
<name>TIMES_24</name>
|
||||
</font>
|
||||
<color>
|
||||
<red>1</red>
|
||||
<green>0.9</green>
|
||||
<blue>0</blue>
|
||||
<alpha>1</alpha>
|
||||
</color>
|
||||
</text>
|
||||
|
||||
<group>
|
||||
<layout>hbox</layout>
|
||||
<default-padding>2</default-padding>
|
||||
|
||||
<button>
|
||||
<legend>Start</legend>
|
||||
<equal>true</equal>
|
||||
<key>Space</key>
|
||||
<pref-width>47</pref-width>
|
||||
<binding>
|
||||
<command>nasal</command>
|
||||
<script>start()</script>
|
||||
</binding>
|
||||
</button>
|
||||
|
||||
<button>
|
||||
<legend>Stop</legend>
|
||||
<default>true</default>
|
||||
<pref-width>47</pref-width>
|
||||
<binding>
|
||||
<command>nasal</command>
|
||||
<script>stop()</script>
|
||||
</binding>
|
||||
</button>
|
||||
|
||||
<button>
|
||||
<legend>Reset</legend>
|
||||
<key>Delete</key>
|
||||
<pref-width>47</pref-width>
|
||||
<binding>
|
||||
<command>nasal</command>
|
||||
<script>reset()</script>
|
||||
</binding>
|
||||
</button>
|
||||
|
||||
<button>
|
||||
<legend>Close</legend>
|
||||
<key>Esc</key>
|
||||
<pref-width>47</pref-width>
|
||||
<binding>
|
||||
<command>dialog-close</command>
|
||||
</binding>
|
||||
</button>
|
||||
</group>
|
||||
</PropertyList>
|
Loading…
Reference in a new issue