Annotation of OpenXM/src/ox_toolkit/glib.c, Revision 1.4
1.4 ! ohara 1: /* $OpenXM: OpenXM/src/ox_toolkit/glib.c,v 1.3 2000/01/18 12:24:18 takayama Exp $ */
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: {
1.4 ! ohara 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();
1.1 ohara 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: {
1.4 ! ohara 42: glib_d = XOpenDisplay(NULL);
! 43: glib_w = XCreateSimpleWindow(glib_d,RootWindow(glib_d,0),100,100,
! 44: XSIZE,YSIZE,2,0,BlackPixel(glib_d,0));
! 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);
1.1 ohara 49:
1.4 ! ohara 50: XSetBackground(glib_d, glib_gc, BlackPixel(glib_d, 0));
! 51: XSetForeground(glib_d, glib_gc, WhitePixel(glib_d, 0));
1.1 ohara 52:
1.4 ! ohara 53: /* intialize line attributes */
! 54: XSetLineAttributes(glib_d,glib_gc,1,LineSolid,CapButt,JoinMiter);
1.1 ohara 55: }
56:
57: int gclose()
58: {
1.4 ! ohara 59: XFlush(glib_d);
1.1 ohara 60: }
61:
62: int gFlush()
63: {
1.4 ! ohara 64: XFlush(glib_d);
1.1 ohara 65: }
66:
67:
68: int moveto(int x, int y)
69: {
1.4 ! ohara 70: glib_x = x;
! 71: glib_y = y;
1.1 ohara 72: }
73:
74: int lineto(int x, int y)
75: {
1.4 ! ohara 76: XDrawLine(glib_d,glib_w,glib_gc,glib_x,glib_y,x,y);
! 77: glib_x = x; glib_y = y;
1.1 ohara 78: }
79:
80: int setpixel(int x, int y)
81: {
1.4 ! ohara 82: XDrawPoint(glib_d,glib_w,glib_gc,x,y);
1.1 ohara 83: }
84:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>