2006-02-02 23:34:16 +00:00
|
|
|
# $Id$
|
|
|
|
#
|
|
|
|
# screen log window
|
|
|
|
# =================
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# simple use:
|
|
|
|
#
|
|
|
|
# foo = screen.window.new()
|
|
|
|
# foo.write("message in the middle of the screen");
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# advanced use:
|
|
|
|
#
|
|
|
|
# bar = screen.window.new(nil, -100, 3, 10);
|
|
|
|
# bar.fg = [1, 1, 1, 1]; # choose white color
|
|
|
|
# bar.align = "left";
|
|
|
|
#
|
|
|
|
# bar.write("first line");
|
|
|
|
# bar.write("second line (red)", 1, 0, 0);
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# arguments:
|
|
|
|
# x ... x coordinate
|
|
|
|
# y ... y coordinate
|
|
|
|
# positive coords position relative to the left/lower corner,
|
|
|
|
# negative coords from the right/upper corner, nil centers
|
|
|
|
# maxlines ... max number of displayed lines; if more are pushed into the
|
|
|
|
# screen, then the ones on top fall off
|
|
|
|
# autoscroll ... seconds that each line should be shown; can be less if
|
|
|
|
# a message falls off; if 0 then don't scroll at all
|
|
|
|
#
|
|
|
|
|
|
|
|
dialog_id = 0;
|
2006-02-04 13:31:16 +00:00
|
|
|
theme_font = nil;
|
2006-02-02 23:34:16 +00:00
|
|
|
|
|
|
|
window = {
|
|
|
|
new : func(x = nil, y = nil, maxlines = 10, autoscroll = 10) {
|
|
|
|
m = { parents : [window] };
|
|
|
|
#
|
|
|
|
# "public"
|
|
|
|
m.x = x;
|
|
|
|
m.y = y;
|
|
|
|
m.maxlines = maxlines;
|
|
|
|
m.autoscroll = autoscroll; # display time in seconds
|
2006-02-04 13:31:16 +00:00
|
|
|
m.font = nil;
|
2006-02-02 23:34:16 +00:00
|
|
|
m.bg = [0, 0, 0, 0]; # background color
|
2006-02-04 13:31:16 +00:00
|
|
|
m.fg = [0.9, 0.4, 0.2, 1]; # default foreground color
|
2006-02-03 00:02:26 +00:00
|
|
|
m.align = "center"; # "left", "right", "center"
|
2006-02-02 23:34:16 +00:00
|
|
|
#
|
|
|
|
# "private"
|
|
|
|
m.name = "__screen_window_" ~ (dialog_id += 1) ~ "__";
|
|
|
|
m.lines = [];
|
|
|
|
m.skiptimer = 0;
|
|
|
|
m.dialog = nil;
|
|
|
|
m.namenode = props.Node.new({ "dialog-name" : m.name });
|
|
|
|
setlistener("/sim/startup/xsize", func { m._redraw_() });
|
|
|
|
setlistener("/sim/startup/ysize", func { m._redraw_() });
|
|
|
|
return m;
|
|
|
|
},
|
|
|
|
|
|
|
|
write : func(msg, r = nil, g = nil, b = nil, a = nil) {
|
|
|
|
if (me.namenode == nil) { return }
|
|
|
|
if (r == nil) { r = me.fg[0] }
|
|
|
|
if (g == nil) { g = me.fg[1] }
|
|
|
|
if (b == nil) { b = me.fg[2] }
|
|
|
|
if (a == nil) { a = me.fg[3] }
|
|
|
|
append(me.lines, [msg, r, g, b, a]);
|
|
|
|
if (size(me.lines) > me.maxlines) {
|
|
|
|
me.lines = subvec(me.lines, 1);
|
|
|
|
if (me.autoscroll) {
|
|
|
|
me.skiptimer += 1;
|
|
|
|
}
|
|
|
|
}
|
2006-02-05 20:43:14 +00:00
|
|
|
me.show();
|
2006-02-02 23:34:16 +00:00
|
|
|
if (me.autoscroll) {
|
|
|
|
settimer(func { me._timeout_() }, me.autoscroll, 1);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2006-02-05 20:43:14 +00:00
|
|
|
show : func {
|
|
|
|
if (me.dialog != nil) {
|
|
|
|
me.close();
|
|
|
|
}
|
2006-02-02 23:34:16 +00:00
|
|
|
|
|
|
|
me.dialog = gui.Widget.new();
|
|
|
|
me.dialog.set("name", me.name);
|
|
|
|
if (me.x != nil) { me.dialog.set("x", me.x) }
|
|
|
|
if (me.y != nil) { me.dialog.set("y", me.y) }
|
|
|
|
me.dialog.set("layout", "vbox");
|
|
|
|
me.dialog.set("default-padding", 2);
|
2006-02-04 13:31:16 +00:00
|
|
|
if (me.font != nil) {
|
|
|
|
me.dialog.setFont(me.font);
|
|
|
|
} elsif (theme_font != nil) {
|
|
|
|
me.dialog.setFont(theme_font);
|
|
|
|
}
|
2006-02-02 23:34:16 +00:00
|
|
|
me.dialog.setColor(me.bg[0], me.bg[1], me.bg[2], me.bg[3]);
|
|
|
|
|
2006-02-05 20:43:14 +00:00
|
|
|
foreach (line; me.lines) {
|
2006-02-02 23:34:16 +00:00
|
|
|
var w = me.dialog.addChild("text");
|
2006-02-05 20:43:14 +00:00
|
|
|
w.set("halign", me.align);
|
|
|
|
w.set("label", line[0]);
|
|
|
|
w.setColor(line[1], line[2], line[3], line[4]);
|
2006-02-02 23:34:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fgcommand("dialog-new", me.dialog.prop());
|
|
|
|
fgcommand("dialog-show", me.namenode);
|
|
|
|
},
|
|
|
|
|
2006-02-04 13:31:16 +00:00
|
|
|
close : func {
|
|
|
|
fgcommand("dialog-close", me.namenode);
|
|
|
|
if (me.dialog != nil) {
|
|
|
|
#me.x = me.dialog.prop().getNode("lastx").getValue();
|
|
|
|
#me.y = me.dialog.prop().getNode("lasty").getValue();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2006-02-02 23:34:16 +00:00
|
|
|
_timeout_ : func {
|
|
|
|
if (me.skiptimer > 0) {
|
|
|
|
me.skiptimer -= 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (size(me.lines) > 1) {
|
|
|
|
me.lines = subvec(me.lines, 1);
|
2006-02-05 20:43:14 +00:00
|
|
|
me.show();
|
2006-02-02 23:34:16 +00:00
|
|
|
} else {
|
2006-02-04 13:31:16 +00:00
|
|
|
me.close();
|
2006-02-02 23:34:16 +00:00
|
|
|
dialog = nil;
|
|
|
|
me.lines = [];
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_redraw_ : func {
|
|
|
|
if (me.dialog != nil) {
|
2006-02-04 13:31:16 +00:00
|
|
|
me.close();
|
2006-02-05 20:43:14 +00:00
|
|
|
me.show();
|
2006-02-02 23:34:16 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log = nil;
|
|
|
|
|
|
|
|
INIT = func {
|
2006-02-04 13:31:16 +00:00
|
|
|
setlistener("/sim/current-gui", func {
|
|
|
|
var theme = getprop("/sim/current-gui");
|
|
|
|
theme_font = getprop("/sim/gui[" ~ theme ~ "]/fonts/message-display/name");
|
|
|
|
}, 1);
|
|
|
|
|
|
|
|
|
2006-02-02 23:34:16 +00:00
|
|
|
log = window.new(nil, -40, 10, 10);
|
2006-02-03 00:02:26 +00:00
|
|
|
|
|
|
|
var b = "/sim/screen/";
|
|
|
|
setlistener(b ~ "black", func { log.write(cmdarg().getValue(), 0, 0, 0) });
|
|
|
|
setlistener(b ~ "white", func { log.write(cmdarg().getValue(), 1, 1, 1) });
|
|
|
|
setlistener(b ~ "red", func { log.write(cmdarg().getValue(), 0.8, 0, 0) });
|
|
|
|
setlistener(b ~ "green", func { log.write(cmdarg().getValue(), 0, 0.6, 0) });
|
|
|
|
setlistener(b ~ "blue", func { log.write(cmdarg().getValue(), 0, 0, 0.8) });
|
|
|
|
setlistener(b ~ "yellow", func { log.write(cmdarg().getValue(), 0.8, 0.8, 0) });
|
|
|
|
setlistener(b ~ "magenta", func { log.write(cmdarg().getValue(), 0.7, 0, 0.7) });
|
|
|
|
setlistener(b ~ "cyan", func { log.write(cmdarg().getValue(), 0, 0.6, 0.6) });
|
2006-02-02 23:34:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
settimer(INIT, 0);
|
2006-02-04 13:31:16 +00:00
|
|
|
|