chiark / gitweb /
cin.get(buf,100,'\n') fails on blank lines nowadays, bah - use getline
[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 X11Output::X11Output() {
12   XGCValues gcvalues;
13   display= XOpenDisplay(0);
14   window= XCreateSimpleWindow(display,
15                               DefaultRootWindow(display),
16                               0,0, x11size,x11size, 0,0,0);
17   gcvalues.background= 0;
18   fabric= XCreateGC(display,window,GCBackground,&gcvalues);
19   gcvalues.foreground= 1;
20   gcvalues.background= 1;
21   mesh= XCreateGC(display,window,GCForeground|GCBackground,&gcvalues);
22   XSelectInput(display,window,0);
23   XMapWindow(display,window);
24   XFlush(display);
25 }
26
27 void X11Output::startimage() {
28   XClearWindow(display,window);
29 }
30
31 void X11Output::endimage() {
32   XFlush(display);
33 }
34
35 X11Output::~X11Output() {
36   XCloseDisplay(display);
37 }
38
39 void X11Output::drawcell(const Point* list, int n) {
40   XPoint xp[n+1];
41   for (int i=0; i<n; i++) {
42     Onscreen here= Onscreen(list[i]);
43     xp[i].x= (int)((here.x+1.0)*(x11size*0.5));
44     xp[i].y= (int)((-here.y+1.0)*(x11size*0.5));
45   }
46   XFillPolygon(display,window,fabric,xp,n,Nonconvex,CoordModeOrigin);
47   xp[n]= xp[0];
48   XDrawLines(display,window,mesh,xp,n+1,CoordModeOrigin);
49 }