Annotation of OpenXM/src/ox_toolkit/glib.c, Revision 1.2
1.2 ! ohara 1: /* $OpenXM$ */
1.1 ohara 2: #include <X11/Xlib.h>
3: #include <X11/Xutil.h>
4: #include <stdio.h>
5:
6: #ifdef TEST
7: int main()
8: {
9: int k;
10: gopen();
11: for (k=10; k<=500; k++) {
12: setpixel(k,k);
13: }
14: moveto(100,50);
15: lineto(400,50);
16: for (k=10; k<=300; k += 20) {
17: lineto(k,2*k);
18: }
19: gFlush();
20: gclose();
21: getchar();
22: }
23:
24: #endif
25:
26: /* -------------------- main code of glib.c ---------------- */
27: #define XSIZE 640
28: #define YSIZE 400
29:
30: /* global variables */
31: Display *glib_d;
32: Window glib_w;
33: GC glib_gc;
34: XSetWindowAttributes glib_a;
35:
36: static int glib_x = 0;
37: static int glib_y = 0;
38:
39: /* functions exported */
40: int gopen()
41: {
42: glib_d = XOpenDisplay(NULL);
43: glib_w = XCreateSimpleWindow(glib_d,RootWindow(glib_d,0),100,100,
44: XSIZE,YSIZE,2,0,1);
45: glib_a.override_redirect = 1;
46: XChangeWindowAttributes(glib_d,glib_w,CWOverrideRedirect, &glib_a);
47: XMapWindow(glib_d,glib_w);
48: glib_gc = XCreateGC(glib_d,glib_w,0,0);
49:
50: XSetBackground(glib_d, glib_gc, BlackPixel(glib_d, 0));
51: XSetForeground(glib_d, glib_gc, WhitePixel(glib_d, 0));
52:
53: /* intialize line attributes */
54: XSetLineAttributes(glib_d,glib_gc,1,LineSolid,CapButt,JoinMiter);
55: }
56:
57: int gclose()
58: {
59: XFlush(glib_d);
60: }
61:
62: int gFlush()
63: {
64: XFlush(glib_d);
65: }
66:
67:
68: int moveto(int x, int y)
69: {
70: glib_x = x;
71: glib_y = y;
72: }
73:
74: int lineto(int x, int y)
75: {
76: XDrawLine(glib_d,glib_w,glib_gc,glib_x,glib_y,x,y);
77: glib_x = x; glib_y = y;
78: }
79:
80: int setpixel(int x, int y)
81: {
82: XDrawPoint(glib_d,glib_w,glib_gc,x,y);
83: }
84:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>