#include #include #include #include #include #include typedef unsigned long ulong; #define SIZEX 400 #define SIZEX2 (SIZEX/2) #define SIZEY 400 #define SIZEY2 (SIZEY/2) static int SCANSCALE =64; static Display *display; static Window window,root; static XImage *src,*dest; static XEvent ev; static ulong black,white; static int width,height,cx,cy; static int shrink=False; static GC gc; int main(int argc, char *argv[]) { void ScaleImg(XImage *dest, XImage *src); char str[180]; Window rw,cw; int rx,ry,cx,cy,bmask; int f; if (argc>1) if (!strcmp(argv[1],"-help")) { fprintf(stderr,"Keys :\n"); fprintf(stderr,"LMB - Lower viewing angle\n"); fprintf(stderr,"MMB - Raise viewing angle\n"); fprintf(stderr,"RMB - Quit\n"); } if (!(display=XOpenDisplay(NULL))) { fprintf(stderr,"%s: couldn't open display\n",argv[0]); exit(1); } root=DefaultRootWindow(display); root=RootWindow(display,DefaultScreen(display)); width=DisplayWidth(display,DefaultScreen(display)); height=DisplayHeight(display,DefaultScreen(display)); window=XCreateSimpleWindow (display,root,0,800,SIZEX,SIZEY,0,0,0); gc=XCreateGC(display,window,0L,NULL); XSetBackground(display,gc,white=WhitePixel(display,0)); XSetForeground(display,gc,black=BlackPixel(display,0)); XSetPlaneMask(display,gc,AllPlanes); XSelectInput (display,window,ButtonPressMask); XMapWindow(display,window); while(True) { if (XCheckTypedWindowEvent(display,window,ButtonPress,&ev)) switch(ev.xbutton.button) { case 1: SCANSCALE=SCANSCALE>>1; if (SCANSCALE<1) SCANSCALE=1; break; case 2: SCANSCALE=SCANSCALE<<1; break; case 3: XCloseDisplay(display); exit(0); break; } XQueryPointer(display,window,&rw,&cw,&rx,&ry,&cx,&cy,&bmask); rx-=SIZEX/2; ry-=SIZEY/2; if (rx<0) rx=0; if (ry<0) ry=0; if ((rx+SIZEX)>=width) rx=width-SIZEX; if ((ry+SIZEY)>=height) ry=height-SIZEY; src=XGetImage(display,root,rx,ry,SIZEX,SIZEY,AllPlanes,ZPixmap); /* Cheat to create an image we know will be the same as the source... */ dest=XGetImage(display,root,0,0,SIZEX,SIZEY,AllPlanes,ZPixmap); ScaleImg(src,dest); XPutImage(display,window,gc,dest,0,0,0,0,SIZEX,SIZEY); XDestroyImage (src); XDestroyImage (dest); /* XSync(display,False); */ } } int ScaleX (double n, double sc) { return SIZEX2-(int)((SIZEX2-n)/sc); } int ScaleY (double n, double sc) { return SIZEY2-(int)((SIZEY2-n)/sc); } void ScaleImg(XImage *src, XImage *dest) { int x,y; double sc; sc=1.0; for(y=0;y