chiark / gitweb /
5c40ba2ea2d93c683f52f4829c06a3895dfb4a1f
[moebius.git] / dualx11.cc
1 /*
2  * X11 functions
3  */
4
5 #include "dualx11.hh"
6 #include "parameter.hh"
7
8 static Parameter<int> dualx11size("dualx11size", "Dual X11 window size",
9                                   500, 100, 10, 10000);
10
11 DualX11Output::DualX11Output() {
12   display= XOpenDisplay(0);
13   Colormap cmap= DefaultColormap(display,DefaultScreen(display));
14
15   XAllocColorCells(display,cmap,
16                    False, // contig
17                    planemasks,
18                    2, // nplanes
19                    &pixelbase,
20                    1); // ncolors
21   XColor colours[4], *cp= colours;
22   for (int i=0; i<2; i++)
23     for (int j=0; j<2; j++, cp++) {
24       cp->pixel= pixelbase + (i? planemasks[0] :0) + (j? planemasks[1] :0);
25       cp->red= i?65535:0;  cp->green= j?/*65535*/32000:0;  cp->blue= 0;
26       cp->flags= DoRed|DoGreen|DoBlue;
27     }
28   XStoreColors(display,cmap,colours,4);
29   
30   window= XCreateSimpleWindow(display,
31                               DefaultRootWindow(display),
32                               0,0, dualx11size,dualx11size, 0,0, pixelbase);
33
34   XGCValues gcvalues;
35   int i;
36   for (i=0; i<2; i++) {
37     gcvalues.plane_mask= planemasks[i];
38     // First, the fabric
39     gcvalues.function= GXclear;
40     fabric[i]= XCreateGC(display,window,
41                          GCFunction|GCPlaneMask,
42                          &gcvalues);
43     // Then, the mesh
44     gcvalues.function= GXset;
45     mesh[i]= XCreateGC(display,window,
46                        GCFunction|GCPlaneMask,
47                        &gcvalues);
48   }
49   XSelectInput(display,window,0);
50   XMapWindow(display,window);
51   XFlush(display);
52 }
53
54 void DualX11Output::startimage() {
55   XClearWindow(display,window);
56 }
57
58 void DualX11Output::endimage() {
59   XFlush(display);
60 }
61
62 DualX11Output::~DualX11Output() {
63   XCloseDisplay(display);
64 }
65
66 void DualX11Output::drawcell(const Point* list, int n) {
67   static Parameter<double> eyeseparation("eyesep",
68                                          "Distance from projection eye to origin", 
69                                          0.3, .1, 0., 100.);
70   for (int i=0; i<2; i++) {
71     Point::seteyex(eyeseparation*(i-0.5));
72     XPoint xp[n+1];
73     for (int j=0; j<n; j++) {
74       Onscreen here= Onscreen(list[j]);
75       xp[j].x= (int)((here.x+1.0)*(dualx11size*0.5));
76       xp[j].y= (int)((-here.y+1.0)*(dualx11size*0.5));
77     }
78     XFillPolygon(display,window,fabric[i],xp,n,Nonconvex,CoordModeOrigin);
79     xp[n]= xp[0];
80     XDrawLines(display,window,mesh[i],xp,n+1,CoordModeOrigin);
81   }
82   Point::seteyex(0);
83 }