彩色绘画
- 获取屏幕颜色空间
screen_colormap = DefaultColormap(display, DefaultScreen(display));
- 通过颜色名分配颜色结构体
rc = XAllocNamedColor(display, screen_colormap, "red", &red, &red); if (rc == 0) { fprintf(stderr, "XAllocNamedColor - failed to allocated 'red' color.\n"); exit(1); }
- 四个角落各画了一个小红点
XSetForeground(display, gc, red.pixel); XDrawPoint(display, win, gc, 5, 5); XDrawPoint(display, win, gc, 5, height-5); XDrawPoint(display, win, gc, width-5, 5); XDrawPoint(display, win, gc, width-5, height-5);
- 两条棕色的线条
XSetForeground(display, gc, brown.pixel); XDrawLine(display, win, gc, 50, 0, 50, 200); XDrawLine(display, win, gc, 0, 100, 200, 100);
- 花了一个蓝色的圆
XSetForeground(display, gc, blue.pixel); XDrawArc(display, win, gc, 50-(30/2), 100-(30/2), 30, 30, 0, 360*64);
- 通过相邻点画黄色的线条组
XSetForeground(display, gc, yellow.pixel); XDrawLines(display, win, gc, points, npoints, CoordModeOrigin);
- 画一个矩形
XSetForeground(display, gc, BlackPixel(display, screen_num)); XDrawRectangle(display, win, gc, 120, 150, 50, 60);
- 画一个填充的矩形
XSetForeground(display, gc, green.pixel); XFillRectangle(display, win, gc, 60, 150, 50, 60);