Correction de moverect.c
/* deplacement de rectangle */
#include <stdio.h>
#include <X11/Xlib.h>
GC gc1, gc2;
Display *display;
int screen;
Window win, root;
unsigned long white_pixel, black_pixel,
val_gc_masq;
XGCValues gc_valeurs;
int x1, x2, y1, y2;
main() {
display = XOpenDisplay ("");
screen = DefaultScreen (display);
root = RootWindow (display, screen);
white_pixel = WhitePixel (display, screen);
black_pixel = BlackPixel (display, screen);
win = XCreateSimpleWindow (display, root, 0, 0, 200, 200, 2,
black_pixel, white_pixel);
XSelectInput (display, win, ExposureMask | ButtonPressMask);
XStoreName (display, win, "moverect");
XMapWindow (display, win);
val_gc_masq = 0;
gc_valeurs.background = white_pixel;
val_gc_masq = val_gc_masq | GCBackground ;
gc_valeurs.foreground = black_pixel;
val_gc_masq = val_gc_masq | GCForeground ;
gc_valeurs.line_width = 3;
val_gc_masq = val_gc_masq | GCLineWidth ;
gc_valeurs.plane_mask = black_pixel ^ white_pixel;
val_gc_masq = val_gc_masq | GCPlaneMask ;
gc1 = XCreateGC (display, win, val_gc_masq, &gc_valeurs);
gc2 = XCreateGC (display, win, val_gc_masq, &gc_valeurs);
XSetFunction (display, gc1, GXcopy);
XSetFunction (display, gc2, GXinvert);
x1 = y1 = 10;
for (;;) {
XEvent ev;
XNextEvent (display, &ev);
switch (ev.type) {
case Expose :
XDrawRectangle (display, win, gc1, x1, y1, 20, 20);
break;
case ButtonPress :
x2 = ev.xbutton.x ;
y2 = ev.xbutton.y ;
XDrawRectangle (display, win, gc2, x1, y1, 20, 20);
x1 = x2;
y1 = y2;
XDrawRectangle (display, win, gc1, x1, y1, 20, 20);
break;
default :
break;
}
}
}