commit f4a1c9b

chld  ·  2026-07-12 13:43:24 +0000 UTC
parent 89babb3
add pixmap
1 files changed,  +14, -7
M xd.c
M xd.c
+14, -7
 1@@ -20,14 +20,14 @@ int main(void)
 2 			100, 100, 640, 480, 0, BlackPixel(d,s), 
 3 			WhitePixel(d, s));
 4 	XStoreName(d, w, "xd");
 5-	/*
 6-	 * exposure mask redraws lost parts on window manipulation
 7-	 */
 8 	XSelectInput(d, w, ExposureMask|KeyPressMask|
 9 			ButtonPressMask|ButtonReleaseMask|
10 			PointerMotionMask);
11 	XMapWindow(d, w);
12 	GC gc=XCreateGC(d, w, 0, NULL);
13+	Pixmap p=XCreatePixmap(d,w,640,480,DefaultDepth(d,s));
14+	XSetForeground(d, gc, WhitePixel(d,s));
15+	XFillRectangle(d, p,gc,0,0,640,480);
16 	XSetForeground(d, gc, BlackPixel(d,s));
17 
18 	int z=20;
19@@ -44,7 +44,9 @@ int main(void)
20 
21 		switch(ev.type)
22 		{
23-			case Expose: break;
24+			case Expose:
25+				XCopyArea(d,p,w,gc,0,0,640,480,0,0);
26+				break;
27 			case ButtonPress:
28 				if(ev.xbutton.button==Button1)
29 				{
30@@ -64,18 +66,23 @@ int main(void)
31 				if (dr)
32 				{
33 					XSetForeground(d, gc, er ? WhitePixel(d,s) : BlackPixel(d,s));
34-					XDrawLine(d,w,gc,lx,ly,
35+					XDrawLine(d,p,gc,lx,ly,
36 							ev.xmotion.x,
37 							ev.xmotion.y);
38+					XCopyArea(d,p,w,gc,0,0,640,480,0,0);
39 					lx=ev.xmotion.x;
40 					ly=ev.xmotion.y;
41-					XFlush(d);
42 				}
43 				break;
44 			case KeyPress: {
45 				KeySym k=XLookupKeysym(&ev.xkey, 0);
46 				if (k==XK_q||k==XK_Escape) goto q;
47-				if (k==XK_c) XClearWindow(d,w);
48+				if (k==XK_c) {
49+					XSetForeground(d, gc, WhitePixel(d,s));
50+					XFillRectangle(d, p,gc,0,0,640,480);
51+					XClearWindow(d,w);
52+					XCopyArea(d,p,w,gc,0,0,640,480,0,0);
53+				}
54 				if (k==XK_e) er=!er;
55 				if (k==XK_i) z+=5;
56 				if (k==XK_o) z-=5;