X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=moebius2.git;a=blobdiff_plain;f=project.c;fp=project.c;h=521af66786895c6b7f5a51603a689cfe4db46b6a;hp=0921edfb52291b4c0f8addb866e920b026bf6b8c;hb=a990bb85e8f41a0a60272546ecf04b45b2a2709c;hpb=2e8e765ae894f9921fa97db2f21915662f162224 diff --git a/project.c b/project.c index 0921edf..521af66 100644 --- a/project.c +++ b/project.c @@ -91,10 +91,10 @@ static Display *display; 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; @@ -117,8 +117,8 @@ static void drawtriangle(const Triangle *t) { 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]; @@ -129,21 +129,28 @@ static void drawtriangle(const Triangle *t) { 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) ); @@ -151,22 +158,17 @@ static void display_prepare(void) { 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) { @@ -305,7 +307,21 @@ static void event_motion(int x, int y) { 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;