From eae5e5b611d308bc5374409f88ab24301a3ea76a Mon Sep 17 00:00:00 2001 From: erg Date: Sat, 12 Feb 2005 05:01:35 +0000 Subject: [PATCH] Add fix to lefty to support background color --- cmd/dotty/dotty.lefty | 22 ++++++++++++++-------- cmd/dotty/dotty_draw.lefty | 20 ++++++++++++++++++++ cmd/dotty/dotty_ui.lefty | 1 + cmd/lefty/ws/x11/gcanvas.c | 9 +++++++++ 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/cmd/dotty/dotty.lefty b/cmd/dotty/dotty.lefty index 3d7b65aa0..bb81900c1 100644 --- a/cmd/dotty/dotty.lefty +++ b/cmd/dotty/dotty.lefty @@ -317,9 +317,9 @@ dotty.protogt.savegraph = function (gt, name, type, savecoord) { graph.rect[1].y = node.pos.y + node.size.y / 2; } } - graph.graphattr.bb = concat (graph.rect[0].x, ',', - graph.rect[0].y, ',', graph.rect[1].x, ',', - graph.rect[1].y); + graph.graphattr.bb = concat (graph.rect[0].x, ',', + graph.rect[0].y, ',', graph.rect[1].x, ',', + graph.rect[1].y); if (graph.lp & tablesize (graph.lp) > 0) graph.graphattr.lp = concat (graph.lp.x, ',', graph.lp.y); } else @@ -465,7 +465,9 @@ dotty.protogt.createview = function (gt, protovt) { dotty.views[vt.view] = vt; if (protovt.colors & tablesize (protovt.colors) > 0) { for (id in protovt.colors) - if (setwidgetattr (vt.canvas, ['color' = [ + if (id == '_bgcolor_') + setwidgetattr (vt.canvas, ['color' = [0 = protovt.colors[id];];]); + else if (setwidgetattr (vt.canvas, ['color' = [ protovt.colors[id] = id; ];]) ~= 1) { t = split (id, ' '); @@ -486,7 +488,9 @@ dotty.protogt.createview = function (gt, protovt) { break; ovt = gt.views[id]; for (id in ovt.colors) - if (setwidgetattr (vt.canvas, ['color' = [ + if (id == '_bgcolor_') + setwidgetattr (vt.canvas, ['color' = [0 = ovt.colors[id];];]); + else if (setwidgetattr (vt.canvas, ['color' = [ ovt.colors[id] = id; ];]) ~= 1) { t = split (id, ' '); @@ -729,7 +733,9 @@ dotty.protogt.printorsave = function (gt, vt, otype, name, mode, ptype) { } for (cname in vt.colors) { cid = vt.colors[cname]; - if (setwidgetattr (pscanvas, ['color' = [cid = cname;];]) ~= 1) { + if (cname == '_bgcolor_') + setwidgetattr (pscanvas, ['color' = [0 = cid;];]); + else if (setwidgetattr (pscanvas, ['color' = [cid = cname;];]) ~= 1) { t = split (cname, ' '); if (tablesize (t) ~= 3 | setwidgetattr (pscanvas, ['color' = [cid = [ @@ -762,8 +768,8 @@ dotty.protogt.printorsave = function (gt, vt, otype, name, mode, ptype) { sgraph.fontname = fontmap[sgraph.graphattr.fontname]; gt.drawsgraph (gt, [0 = vt;], sgraph); } - graph.fontname = fontmap[graph.graphattr.fontname]; - gt.drawsgraph (gt, [0 = vt;], graph); + graph.fontname = fontmap[graph.graphattr.fontname]; + gt.drawsgraph (gt, [0 = vt;], graph); gt.edgehandles = edgehandles; vt.canvas = canvas; destroywidget (pscanvas); diff --git a/cmd/dotty/dotty_draw.lefty b/cmd/dotty/dotty_draw.lefty index 5e0276cbb..6dff234f1 100644 --- a/cmd/dotty/dotty_draw.lefty +++ b/cmd/dotty/dotty_draw.lefty @@ -649,6 +649,24 @@ dotty.protogt.getcolor = function (views, name) { } return color; }; +dotty.protogt.setbgcolor = function (views, name) { + local vid, vt, t; + + for (vid in views) { + vt = views[vid]; + if (setwidgetattr (vt.canvas, ['color' = [0 = name;];]) ~= 1) { + t = split (name, ' '); + if (tablesize (t) ~= 3 | + setwidgetattr (vt.canvas, ['color' = [0 = [ + 'h' = ston (t[0]); 's' = ston (t[1]); 'v' = ston (t[2]); + ];];]) ~= 1) { + dotty.message (0, concat ('unknown bgcolor ', name)); + return; + } + } + vt.colors['_bgcolor_'] = name; + } +}; dotty.protogt.unpacksgraphattr = function (gt, sgraph) { local attr; @@ -721,6 +739,8 @@ dotty.protogt.unpackattr = function (gt) { graph[dotty.keys.color] = gt.getcolor (gt.views, 'grey'); else graph[dotty.keys.color] = gt.getcolor (gt.views, attr.color); + if (attr.bgcolor ~= '') + gt.setbgcolor (gt.views, attr.bgcolor); for (gid in graph.graphdict) { sgraph = graph.graphs[graph.graphdict[gid]]; attr = sgraph.graphattr; diff --git a/cmd/dotty/dotty_ui.lefty b/cmd/dotty/dotty_ui.lefty index 7f6f9dae2..cf456241d 100644 --- a/cmd/dotty/dotty_ui.lefty +++ b/cmd/dotty/dotty_ui.lefty @@ -6,6 +6,7 @@ dotty.protogt.doaction = function (data, s) { vt = dotty.views[data.widget]; gt = dotty.graphs[vt.gtid]; + data.menuitem = s; if (data.obj.nid >= 0) { if (gt.actions.node[s]) { gt.actions.node[s] (gt, vt, data.obj, data); diff --git a/cmd/lefty/ws/x11/gcanvas.c b/cmd/lefty/ws/x11/gcanvas.c index 72c876613..036bc632c 100644 --- a/cmd/lefty/ws/x11/gcanvas.c +++ b/cmd/lefty/ws/x11/gcanvas.c @@ -386,6 +386,15 @@ int GCsetwidgetattr(Gwidget_t * widget, int attrn, Gwattr_t * attrp) } /* XAllocColor may change the rgb values */ cp->red = r, cp->green = g, cp->blue = b; + if (color == 0) { + XSetBackground (Gdisplay, GC, WCU->colors[0].color.pixel); + ADD2ARGS (XtNbackground, WCU->colors[0].color.pixel); + } else if (color == 1) { + XSetForeground (Gdisplay, GC, WCU->colors[1].color.pixel); + ADD2ARGS (XtNforeground, WCU->colors[1].color.pixel); + } + XtSetValues (widget->w, argp, argn); + RESETARGS; if (color == WCU->gattr.color) WCU->gattr.color = -1; break; -- 2.40.0