chiark / gitweb /
new gui-plan seems to work
authorian <ian>
Sun, 26 Jun 2005 01:37:51 +0000 (01:37 +0000)
committerian <ian>
Sun, 26 Jun 2005 01:37:51 +0000 (01:37 +0000)
hostside/.cvsignore
hostside/Makefile
hostside/gui-plan.c
layout/Makefile
layout/plan-to-gui-data

index 889d7ba83da4871acc6c91e765866fecb84564ad..9f85dda07fa40869167aee1c60fb27cdb0749fb8 100644 (file)
@@ -6,4 +6,4 @@ layoutinfo.h
 *.d
 proto-expanded
 auproto-*
-gui-plan
+gui-plan-bot
index 97a1a13f55c38d293165557d9d5d9d4fed5df858..c097ed4ba2239fc2c08096ba1bfbaa8fdd667ccd 100644 (file)
@@ -3,7 +3,7 @@
 include ../common.make
 include ../cprogs.make
 
-TARGETS=       hostside hostside-old gui-plan
+TARGETS=       hostside hostside-old gui-plan-bot
 
 all:           $(TARGETS)
 
@@ -19,7 +19,8 @@ hostside:     hostside.o serialio.o client.o obc.o commands.o utils.o \
 proto-expanded:        ../cebpic/README.protocol
                expand <$< $o
 
-gui-plan:      gui-plan.o utils.o parseutils.o ../layout/ui-plan-bot.o \
+gui-plan-bot: gui-plan-%: gui-plan.o utils.o parseutils.o \
+                ../layout/ours.dgram-%.plandata.o \
                 __oop-read-copy.o -loop
                $(LINK) -L/usr/X11R6/lib -lXpm -lX11
 
index baf0da7d64463ebbd150f8a18736bf90b239ab94..1f0b62ece0e839f9c9f1a1627cf07c15c29acf67 100644 (file)
 #include <oop.h>
 #include <oop-read.h>
 
+typedef struct PosnState PosnState;
+struct PosnState {
+  int x, y, width, height;
+  Pixmap pm;
+};
+
+typedef struct MaskState MaskState;
+struct MaskState {
+  int x, y, width, height;
+  GC gc;
+};
+
 typedef struct SegmovfeatState SegmovfeatState;
 struct SegmovfeatState {
   SegmovfeatState *next;
-  int invert, det, posn, x, y, width, height, redraw_needed;
-  GC gc;
-  Pixmap (*posns)[2/*i*/][2/*det*/];
+  int invert, det, posn, redraw_needed;
+  MaskState mask;
+  PosnState (*posns)[2/*i*/][2/*det*/];
+    /* posns[n_posns]=unknown if n_posns>1 */
 };
 
 oop_source *events;
@@ -36,6 +49,7 @@ static Display *d;
 static oop_source_sys *sys_events;
 static Window w;
 static int redraw_needed_count, expose_count;
+static Pixmap bg_pixmap;
 
 static void diex(const char *fn, const char *w) __attribute__((noreturn));
 static void diex(const char *fn, const char *w) {
@@ -124,9 +138,9 @@ static void xlib_expose(XExposeEvent *ev) {
        fs= fs->next) {
     if (fs->redraw_needed)
       continue;
-    if (!range_overlap(fs->x, fs->width,
+    if (!range_overlap(fs->mask.x, fs->mask.width,
                       ev->x, ev->width)) continue;
-    if (!range_overlap(fs->y, fs->height,
+    if (!range_overlap(fs->mask.y, fs->mask.height,
                       ev->y, ev->height)) continue;
     fs->redraw_needed= 1;
     redraw_needed_count++;
@@ -134,23 +148,24 @@ static void xlib_expose(XExposeEvent *ev) {
 }
 
 static void redraw(SegmovfeatState *fs) {
-  Pixmap src;
+  PosnState *src;
   
   if (fs->redraw_needed) {
     fs->redraw_needed= 0;
     redraw_needed_count--;
   }
   if (fs->invert < 0) {
-    XCALL( XFillRectangle, "redraw",
-          (d,w, fs->gc,
-           fs->x, fs->y,
-           fs->width, fs->height) );
+    XCALL( XCopyArea, "redraw",
+          (d, bg_pixmap, w, fs->mask.gc,
+           fs->mask.x, fs->mask.y,
+           fs->mask.width, fs->mask.height,
+           fs->mask.x, fs->mask.y) );
   } else {
-    src= fs->posns[fs->posn][fs->invert][fs->det];
+    src= &fs->posns[fs->posn][fs->invert][fs->det];
     XCALL( XCopyArea, "redraw",
-          (d, src, w, fs->gc,
-           0,0, fs->width, fs->height,
-           fs->x, fs->y) );
+          (d, src->pm, w, fs->mask.gc,
+           0,0, src->width, src->height,
+           src->x, src->y) );
   }
 }
 
@@ -251,8 +266,11 @@ static void *stdin_ifok(oop_source *evts, oop_read *cl_read,
     if (invert<0) badcmd(0,"off may not take movfeatpos");
     ps_neednumber(&ps, &posn, 0, movfeat_d->n_posns-1, "movfeatpos");
   } else {
-    if (invert>=0 && movfeat_d->n_posns > 1) badcmd(0,"movfeatpos needed");
-    posn= 0;
+    if (invert>=0 && movfeat_d->n_posns > 1) {
+      posn= movfeat_d->n_posns;
+    } else {
+      posn= 0;
+    }
   }
 
   ps_neednoargs(&ps);
@@ -276,11 +294,9 @@ int main(int argc, const char *const *argv) {
   
   oop_read *rd;
   const char *arg;
-  Pixmap bg_pixmap;
   Pixmap mask;
   XpmAttributes mattribs;
   XWindowAttributes wattribs;
-  XColor background_colour;
   int segment_ix, movfeat_ix, posn, invert, det, oor;
   SegmovfeatState *fs;
   const PlanSegmentData *segment_d;
@@ -315,11 +331,6 @@ int main(int argc, const char *const *argv) {
           (d,w, (char**)ui_plan_data.background, &bg_pixmap,0,0) );
 
   XCALL( XSetWindowBackgroundPixmap, 0, (d,w,bg_pixmap) );
-  XCALL( XFreePixmap, "background", (d,bg_pixmap) );
-
-  XCALL( XAllocNamedColor, "background",
-        (d, wattribs.colormap, ui_plan_colour_off,
-         &background_colour, &background_colour) );
 
   state= mmalloc(sizeof(*state) * ui_plan_data.n_segments);
   for (segment_ix= 0, segment_d= ui_plan_data.segments;
@@ -332,38 +343,48 @@ int main(int argc, const char *const *argv) {
         movfeat_ix++, movfeat_d++, fs++) {
       fs->next= states_head;  states_head= fs;
       fs->invert= -1;
-      fs->det= fs->posn= 0;
-      fs->x= movfeat_d->x;
-      fs->y= movfeat_d->y;
+      fs->det= 0;
+      fs->posn= movfeat_d->n_posns;
+      if (fs->posn==1) fs->posn= 0;
+      fs->mask.x= movfeat_d->mask.x;
+      fs->mask.y= movfeat_d->mask.y;
       fs->redraw_needed= 0;
+      
       mattribs.valuemask= XpmDepth | XpmColorSymbols;
       mattribs.depth= 1;
       mattribs.colorsymbols= coloursymbols;
       mattribs.numsymbols= sizeof(coloursymbols) / sizeof(*coloursymbols);
       XPMCALL( XpmCreatePixmapFromData, "mask",
-              (d,w, (char**)movfeat_d->off, &mask,0, &mattribs) );
-      fs->width= mattribs.width;
-      fs->height= mattribs.height;
+              (d,w, (char**)movfeat_d->mask.d, &mask,0, &mattribs) );
+      fs->mask.width= mattribs.width;
+      fs->mask.height= mattribs.height;
 
-      gcv.clip_x_origin= fs->x;
-      gcv.clip_y_origin= fs->y;
+      gcv.clip_x_origin= fs->mask.x;
+      gcv.clip_y_origin= fs->mask.y;
       gcv.clip_mask= mask;
-      gcv.foreground= background_colour.pixel;
-      fs->gc= XCreateGC(d,w,
-                       GCClipXOrigin | GCClipYOrigin
-                       | GCClipMask | GCForeground,
-                       &gcv);
+      fs->mask.gc= XCreateGC(d,w,
+                            GCClipXOrigin | GCClipYOrigin | GCClipMask,
+                            &gcv);
       XCALL( XFreePixmap, "mask", (d,mask) );
 
-      fs->posns= mmalloc(sizeof(*fs->posns)*movfeat_d->n_posns);
-      for (posn= 0; posn < movfeat_d->n_posns; posn++)
+      fs->posns= mmalloc(sizeof(*fs->posns)*(fs->posn+1));
+      for (posn= 0; posn <= fs->posn; posn++)
        for (invert=0; invert<2; invert++)
          for (det=0; det<2; det++) {
+           PosnState *ps= &fs->posns[posn][invert][det];
+           const PlanPixmapDataRef *ppdr= posn < movfeat_d->n_posns
+             ? &movfeat_d->posns[posn].on[invert][det]
+             : &movfeat_d->unknown[invert][det];
+           ps->x= ppdr->x;
+           ps->y= ppdr->y;
+           mattribs.valuemask= 0;
            XPMCALL( XpmCreatePixmapFromData, "main",
                     (d,w,
-                     (char**)(movfeat_d->posns[posn].a[invert][det]),
-                     &fs->posns[posn][invert][det],
-                     0,0) );
+                     (char**)ppdr->d,
+                     &ps->pm,
+                     0, &mattribs) );
+           ps->width= mattribs.width;
+           ps->height= mattribs.height;
          }
     }
   }
index 165ffd8b2b5551589cb47a9547ff95af9e2cd17c..025b630221ae8bc75cc312c779cc2ea8c3ae6f40 100644 (file)
@@ -25,7 +25,8 @@ default:      $(CPROGS) for-test-ui
 all:           default lpages layers extras
 for-test-ui:   ours.graph.c ours.redactgraph ours.raw.neato.ps \
                ours.redacted.neato.ps ours.layout-data.o \
-               ours.dgram-bot.segcmap ours.dgram-bot.plandata.c
+               ours.dgram-bot.segcmap ours.dgram-bot.plandata.c \
+               ours.dgram-bot.plandata.o
 
 layers:                $(LAYERS)
 lpages:                $(LPAGES)
index 7b6af4c669cc46344998e18b6c7b2b085b44f345..bd1fed4f2f83a5ab23f3e05c3e4feee74700564f 100755 (executable)
@@ -70,6 +70,17 @@ sub xpmdata_setup ($$$) {
        };
 }
 
+#---------- parse args ----------
+
+our $gvarname= 'ui_plan_data';
+
+die unless @ARGV;
+die if $ARGV[0] =~ m/^\-/;
+if ($ARGV[$#ARGV] =~ s/^\-g//) {
+    $gvarname= pop @ARGV;
+    $gvarname =~ s/\W/_/g;
+}
+
 #---------- read segcmap ----------
 
 our (%datum_numbits,%datum_basebit);
@@ -387,6 +398,8 @@ cmaps_define();
 
 #---------- output ----------
 
+our ($backgd);
+
 sub cmapdata_output_all () {
     my ($cmapname, $stuff, $cmap, $sname, $pixchars);
 
@@ -418,6 +431,7 @@ sub cmapdata_output_all () {
 sub xpmdata_output_all () {
     my ($style, $namerhs, $xp, $row, $pp, $xy, $pixel);
     my ($y, $cmap_data, $header_data, $cmapname);
+    $backgd= $xpmdata{'background'}{''};
     foreach $style (sort keys %xpmdata) {
        foreach $namerhs (sort keys %{ $xpmdata{$style} }) {
            $xp= $xpmdata{$style}{$namerhs};
@@ -466,9 +480,8 @@ sub xpmdata_output_all () {
 
 sub ppdr ($$$) {
     my ($style,$cmap,$namerhs) = @_;
-    my ($xpmd, $backgd);
+    my ($xpmd);
     $xpmd= $xpmdata{$style}{$namerhs};
-    $backgd= $xpmdata{'background'}{''};
 defined $xpmd or die "$style $cmap $namerhs ?";
     return sprintf("{ %d-%d,%d-%d, p_%s_%s }",
                   (map { $xpmd->{$_}{Min}, $backgd->{$_}{Min} } qw(X Y)),
@@ -533,8 +546,9 @@ sub plandata_output_all () {
     }
 
     oods('ui_plan_data',
-        "const PlanData ui_plan_data= {\n".
-        "  $sz{X}, $sz{Y},\n".
+        "const PlanData $gvarname= {\n".
+        "  $backgd->{X}{Max}-$backgd->{X}{Min},".
+        "  $backgd->{Y}{Max}-$backgd->{Y}{Min},".
         "  p_background_,\n".
         "  ".scalar(@segnames).", segments\n".
         "};\n");