chiark / gitweb /
rewrap parameters
[moebius.git] / x11.cc
1 /*
2  * X11 functions
3  */
4
5
6 #include "x11.hh"
7 #include "parameter.hh"
8
9 static Parameter<int> x11size("x11size", "X11 window size", 500, 100, 10, 10000);
10
11 static unsigned long colour_pixel(Display *display, Colormap cmap,
12                                   const char *name) {
13   XColor colour;
14   Status st;
15   st= XAllocNamedColor(display,cmap,name,&colour,&colour);
16   if (!st) {
17     cerr << "cannot allocate colour " << name << ", quitting\n";
18     exit(1);
19   }
20   return colour.pixel;
21 }
22
23 X11Output::X11Output() {
24   XGCValues gcvalues;
25   display= XOpenDisplay(0);
26   window= XCreateSimpleWindow(display,
27                               DefaultRootWindow(display),
28                               0,0, x11size,x11size, 0,0,0);
29   Colormap cmap= DefaultColormap(display,DefaultScreen(display));
30   gcvalues.background= colour_pixel(display,cmap,"black");
31   fabric= XCreateGC(display,window,GCBackground,&gcvalues);
32   gcvalues.foreground= gcvalues.background= colour_pixel(display,cmap,"white");
33   mesh= XCreateGC(display,window,GCForeground|GCBackground,&gcvalues);
34   XSelectInput(display,window,0);
35   XMapWindow(display,window);
36   XFlush(display);
37 }
38
39 void X11Output::startimage() {
40   XClearWindow(display,window);
41 }
42
43 void X11Output::endimage() {
44   XFlush(display);
45 }
46
47 X11Output::~X11Output() {
48   XCloseDisplay(display);
49 }
50
51 void X11Output::drawcell(const Point* list, int n) {
52   XPoint xp[n+1];
53   for (int i=0; i<n; i++) {
54     Onscreen here= Onscreen(list[i]);
55     xp[i].x= (int)((here.x+1.0)*(x11size*0.5));
56     xp[i].y= (int)((-here.y+1.0)*(x11size*0.5));
57   }
58   XFillPolygon(display,window,fabric,xp,n,Nonconvex,CoordModeOrigin);
59   xp[n]= xp[0];
60   XDrawLines(display,window,mesh,xp,n+1,CoordModeOrigin);
61 }