/********************************************************************** * To compile: * gcc -o simple-x simple-x.c -lm -lXm -lXt -lX11 * * Usage: simple-x -bg white -fg black -geometry 300x300+10+10 * * From another window you may run xv which allows you to grab your simple-x * window and print it or save it in some other format. **********************************************************************/ #include #include void redraw(Widget w, XtPointer client_data, XtPointer call_data); main(int argc, char *argv[]) { XtAppContext app_context; Widget toplevel, canvas; GC gc; XColor color; XGCValues values; Arg wargs[2]; int n; /* Create the top level window shell */ toplevel = XtAppInitialize(&app_context,argv[0], NULL, 0, &argc, argv, NULL, NULL, 0); /* Create the drawing area widget within the toplevel shell. */ n = 0; XtSetArg(wargs[n], XmNwidth, 300); n++; XtSetArg(wargs[n], XmNheight, 300); n++; canvas = XtCreateManagedWidget("canvas", xmDrawingAreaWidgetClass, toplevel,wargs,n); /* * Create a gc to draw with. Make sure it's foreground color is the * default foreground color of the widget, so it can be changed on the * command line. */ n = 0; XtSetArg(wargs[n], XmNforeground, &(color.pixel)); n++; XtGetValues(canvas, wargs, n); values.foreground = color.pixel; gc = XCreateGC(XtDisplay(canvas), DefaultRootWindow(XtDisplay(canvas)), GCForeground, &values); /* Tell X the name of the function that redraws the picture. */ XtAddCallback(canvas, XmNexposeCallback, redraw, gc); /* Make the widget real. */ XtRealizeWidget(toplevel); /* Enter the infinite loop for processing X events. */ XtAppMainLoop(app_context); } /********************************************************************** * This function draws the whole figure. It is called anytime the * window needs to be redrawn. **********************************************************************/ void redraw(Widget w, XtPointer client_data, XtPointer call_data) { int i; GC gc; gc = (GC)client_data; for (i = 10; i < 200; i++) XDrawPoint(XtDisplay(w), XtWindow(w), gc, i, i); for (i = 10; i < 200; i++) XDrawPoint(XtDisplay(w), XtWindow(w), gc, 210-i, i); }