1
0
Fork 0
fgdata/gui/dialogs/stopwatch.xml
stuart 45754e544c Minor update to the Stopwatch:
- Place in bottom right of screen
- Enforce non-modal
- Remove space-bar start key assignment (clash with PTT).
2009-12-05 15:28:20 +00:00

142 lines
2.9 KiB
XML

<?xml version="1.0"?>
<PropertyList>
<name>stopwatch-dialog</name>
<layout>vbox</layout>
<modal>false</modal>
<default-padding>8</default-padding>
<x>-5</x>
<y>5</y>
<nasal>
<open>
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);
}
</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>
<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>