static Pixmap pixmap, doublebuffers[2];
static Window window;
static GC linegc, fillgc;
-static int wwidth=WSZ, wheight=WSZ, wmaxdim=WSZ, currentbuffer;
-static int ncut;
+static int wwidth=WSZ, wheight=WSZ, wmindim=WSZ, wmaxdim=WSZ;
+static int ncut, currentbuffer, x11depth, x11screen;
-static double scale= WSZ * 0.3;
+static double scale= 0.3;
static double eye_z= -10, eye_x= 0;
static double cut_z= -9;
if (z < cut_z) { ncut++; return; }
double zezezp= eye_z / (eye_z - z);
- points[i].x= scale * (zezezp * (x - eye_x) + eye_x) + WSZ/2;
- points[i].y= scale * (zezezp * y ) + WSZ/2;
+ points[i].x= scale * wmindim * (zezezp * (x - eye_x) + eye_x) + wwidth/2;
+ points[i].y= scale * wmindim * (zezezp * y ) + wheight/2;
}
points[3]= points[0];
static const unsigned long core_event_mask=
ButtonPressMask|ButtonReleaseMask|StructureNotifyMask|ButtonMotionMask;
+static void mkpixmaps(void) {
+ for (currentbuffer=0; currentbuffer<2; currentbuffer++) {
+ XA( pixmap= XCreatePixmap(display,window,wwidth,wheight,x11depth) );
+ doublebuffers[currentbuffer]= pixmap;
+ }
+ currentbuffer= 0;
+}
+
static void display_prepare(void) {
XGCValues gcv;
XSetWindowAttributes wa;
- int screen, depth;
XVisualInfo vinfo;
XSizeHints hints;
XA( display= XOpenDisplay(0) );
- screen= DefaultScreen(display);
- depth= DefaultDepth(display,screen);
- XA( XMatchVisualInfo(display,screen,depth, TrueColor,&vinfo) );
+ x11screen= DefaultScreen(display);
+ x11depth= DefaultDepth(display,x11screen);
+ XA( XMatchVisualInfo(display,x11screen,x11depth, TrueColor,&vinfo) );
wa.event_mask= core_event_mask;
XA( window= XCreateWindow(display, DefaultRootWindow(display),
- 0,0, wwidth,wheight, 0,depth,
+ 0,0, wwidth,wheight, 0,x11depth,
InputOutput, vinfo.visual,
CWEventMask, &wa) );
hints.x= 10;
hints.y= 10;
XSetWMNormalHints(display,window,&hints);
-
- for (currentbuffer=0; currentbuffer<2; currentbuffer++) {
- XA( pixmap= XCreatePixmap(display,window,wwidth,wheight,depth) );
- doublebuffers[currentbuffer]= pixmap;
- }
+
+ mkpixmaps();
gcv.function= GXcopy;
gcv.plane_mask= ~0UL;
- gcv.foreground= WhitePixel(display,screen);
+ gcv.foreground= WhitePixel(display,x11screen);
linegc= XCreateGC(display,pixmap, GCFunction|GCPlaneMask|GCForeground, &gcv);
gcv.function= GXclear;
gcv.plane_mask= ~0UL;
fillgc= XCreateGC(display,pixmap, GCFunction|GCPlaneMask, &gcv);
-
- currentbuffer= 0;
}
static void display_conformation(void) {
drag_position(x,y);
}
-static void event_config(XConfigureEvent *e) { printf("configure\n"); }
+static void event_config(XConfigureEvent *e) {
+ if (e->width == wwidth && e->height == wheight)
+ return;
+
+ wwidth= e->width; wheight= e->height;
+ wmaxdim= wwidth > wheight ? wwidth : wheight;
+ wmindim= wwidth < wheight ? wwidth : wheight;
+
+ XA( XSetWindowBackground(display,window,BlackPixel(display,x11screen)) );
+ for (currentbuffer=0; currentbuffer<2; currentbuffer++)
+ XA( XFreePixmap(display, doublebuffers[currentbuffer]) );
+
+ mkpixmaps();
+ show();
+}
int main(int argc, const char *const *argv) {
XEvent event;