2 # Pop up a "tip" dialog for a moment, then remove it. The delay in
3 # seconds can be specified as the second argument. The default is 1
4 # second. Note that the tip dialog is a shared resource. If
5 # someone else comes along and wants to pop a tip up before your delay
6 # is finished, you lose. :)
10 delay = if(size(arg) > 1) {arg[1]} else {DELAY};
11 labelNode.setValue(msg);
13 # The "width" value here is a hardcoded hack that assumes 9 pixels
14 # as a "typical" character width and adds some extra for the
15 # widgets to play with. Bah. Pui needs a layout engine...
16 width = 9 * size(msg) + 40;
17 popupNode.getNode("width").setIntValue(width);
18 popupNode.getNode("x").setIntValue((screenWProp.getValue() - width)/2);
19 popupNode.getNode("y").setIntValue(screenHProp.getValue() - 140);
22 fgcommand("dialog-new", popupNode);
23 fgcommand("dialog-show", tipArg);
25 currTimer = currTimer + 1;
26 thisTimer = currTimer;
27 settimer(func { if(currTimer == thisTimer) { popdown() } }, DELAY);
30 ########################################################################
32 ########################################################################
35 # Initialize property nodes via a timer, to insure the props module is
36 # loaded. See notes in view.nas
38 screenWProp = screenHProp = popupNode = labelNode = tipArg = nil;
40 screenWProp = props.globals.getNode("/sim/startup/xsize");
41 screenHProp = props.globals.getNode("/sim/startup/ysize");
43 # Set up the dialog property node:
44 tmpl = { name : "PopTip", modal : 0,
45 x : 100, y : 100, width : 120, height : 40,
46 text : { x : 10, y : 6, label : "NOTE" } };
47 popupNode = props.Node.new(tmpl);
48 labelNode = popupNode.getNode("text/label");
49 fgcommand("dialog-new", popupNode);
51 # Cache the command argument for popup/popdown
52 tipArg = props.Node.new({ "dialog-name" : "PopTip" });
57 # How many seconds do we show the tip?
62 # Pop down the tip dialog, if it is visible.
64 popdown = func { fgcommand("dialog-close", tipArg); }
66 # Marker for the "current" timer. This value gets stored in the
67 # closure of the timer function, and is used to check that there
68 # hasn't been a more recent timer set that should override.