chiark / gitweb /
sotextpit x11 red/blue
authorian <ian>
Sun, 3 Apr 2005 16:27:45 +0000 (16:27 +0000)
committerian <ian>
Sun, 3 Apr 2005 16:27:45 +0000 (16:27 +0000)
x11.cc
x11.hh

diff --git a/x11.cc b/x11.cc
index f689362..c8eb915 100644 (file)
--- a/x11.cc
+++ b/x11.cc
@@ -8,36 +8,32 @@
 
 static Parameter<int> x11size("x11size", "X11 window size", 500, 100, 10, 10000);
 
-static unsigned long colour_pixel(Display *display, Colormap cmap,
-                                 const char *name) {
+GC X11Output::gc(const char *colour_name) {
+  XGCValues gcvalues;
   XColor colour;
   Status st;
-  st= XAllocNamedColor(display,cmap,name,&colour,&colour);
+
+  st= XAllocNamedColor(display,cmap,colour_name,&colour,&colour);
   if (!st) {
-    cerr << "cannot allocate colour " << name << ", quitting\n";
+    cerr << "cannot allocate colour " << colour_name << ", quitting\n";
     exit(1);
   }
-  return colour.pixel;
+
+  gcvalues.foreground= gcvalues.background= colour.pixel;
+  return XCreateGC(display,window,GCForeground|GCBackground,&gcvalues);
 }
 
 X11Output::X11Output() {
-  XGCValues gcvalues;
-
   display= XOpenDisplay(0);
   window= XCreateSimpleWindow(display,
                               DefaultRootWindow(display),
                               0,0, x11size,x11size, 0,0,0);
+  cmap= DefaultColormap(display,DefaultScreen(display));
 
-  Colormap cmap= DefaultColormap(display,DefaultScreen(display));
-  black= colour_pixel(display,cmap,"black");
-  white= colour_pixel(display,cmap,"white");
-
-  gcvalues.foreground= gcvalues.background= black;
-  fabric= XCreateGC(display,window,GCForeground|GCBackground,&gcvalues);
-
-  gcvalues.foreground= gcvalues.background= white;
-
-  mesh= XCreateGC(display,window,GCForeground|GCBackground,&gcvalues);
+  black= gc("black");
+  white= gc("white");
+  blue= gc("blue");
+  red= gc("red");
 
   XSelectInput(display,window,0);
   XMapWindow(display,window);
@@ -57,8 +53,7 @@ X11Output::~X11Output() {
 }
 
 void X11Output::drawcell(const Point* list, int n, Colour colour) {
-  GC fill;
-  bool draw;
+  GC fill, draw;
   
   XPoint xp[n+1];
   for (int i=0; i<n; i++) {
@@ -67,14 +62,14 @@ void X11Output::drawcell(const Point* list, int n, Colour colour) {
     xp[i].y= (int)((-here.y+1.0)*(x11size*0.5));
   }
   switch (colour) {
-  case grid:       fill= fabric; draw= true;  break;
-  case solidblack: fill= fabric; draw= false; break;
-  case solidwhite: fill= mesh;   draw= false; break;
+  case grid:       fill= black;  draw= white;  break;
+  case solidblack: fill= red;    draw= 0;      break;
+  case solidwhite: fill= blue;   draw= 0;      break;
   default: abort();
   }
   XFillPolygon(display,window,fill,xp,n,Nonconvex,CoordModeOrigin);
   if (draw) {
     xp[n]= xp[0];
-    XDrawLines(display,window,mesh,xp,n+1,CoordModeOrigin);
+    XDrawLines(display,window,draw,xp,n+1,CoordModeOrigin);
   }
 }
diff --git a/x11.hh b/x11.hh
index 5fd626e..442bae7 100644 (file)
--- a/x11.hh
+++ b/x11.hh
@@ -19,9 +19,9 @@ struct X11Output : Output {
 private:
   Display *display;
   Window window;
-  unsigned long black, white;
-  GC fabric;
-  GC mesh;
+  Colormap cmap;
+  GC black, white, red, blue;
+  GC X11Output::gc(const char *colour_name);
 };
 
 #endif