#include "x11.hh"
+#include "parameter.hh"
+
+static Parameter<int> x11size("x11size", "X11 window size", 500, 100, 10, 10000);
+
+static unsigned long colour_pixel(Display *display, Colormap cmap,
+ const char *name) {
+ XColor colour;
+ Status st;
+ st= XAllocNamedColor(display,cmap,name,&colour,&colour);
+ if (!st) {
+ cerr << "cannot allocate colour " << name << ", quitting\n";
+ exit(1);
+ }
+ return colour.pixel;
+}
X11Output::X11Output() {
XGCValues gcvalues;
+
display= XOpenDisplay(0);
window= XCreateSimpleWindow(display,
DefaultRootWindow(display),
- 0,0, 500,500, 0,0,0);
- gcvalues.background= 0;
- fabric= XCreateGC(display,window,GCBackground,&gcvalues);
- gcvalues.foreground= 1;
- gcvalues.background= 1;
+ 0,0, x11size,x11size, 0,0,0);
+
+ 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);
+
XSelectInput(display,window,0);
XMapWindow(display,window);
XFlush(display);
XCloseDisplay(display);
}
-void X11Output::drawcell(const Point* list, int n) {
+void X11Output::drawcell(const Point* list, int n, Colour colour) {
+ GC fill;
+ bool draw;
+
XPoint xp[n+1];
for (int i=0; i<n; i++) {
Onscreen here= Onscreen(list[i]);
- xp[i].x= (int)((here.x+1.0)*250.0);
- xp[i].y= (int)((-here.y+1.0)*250.0);
+ xp[i].x= (int)((here.x+1.0)*(x11size*0.5));
+ 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;
+ default: abort();
+ }
+ XFillPolygon(display,window,fill,xp,n,Nonconvex,CoordModeOrigin);
+ if (draw) {
+ xp[n]= xp[0];
+ XDrawLines(display,window,mesh,xp,n+1,CoordModeOrigin);
}
- XFillPolygon(display,window,fabric,xp,n,Nonconvex,CoordModeOrigin);
- xp[n]= xp[0];
- XDrawLines(display,window,mesh,xp,n+1,CoordModeOrigin);
}