beckman@iuvax.cs.indiana.edu (Peter Beckman) (01/21/89)
I am trying to use Xlib call to draw within a widget. Sorry for the confusion, I have tried lots of things, The one I thought had the most promise is listed below. After 8 hours, I started grasping at straws. Yes, the widget is realized before I draw to it. Any help would be appreciated. -Pete XtGCMask valuemask; XGCValues myXGCV; Display *dpy; Drawable win; GC gc; dpy = XtDisplay(Widget); myXGCV.foreground = WhitePixel(dpy, DefaultScreen(dpy)); myXGCV.background = BlackPixel(dpy, DefaultScreen(dpy)); valuemask = GCForeground | GCBackground; gc = XtGetGC(Widget, valuemask, &myXGCV); win = XtWindow(Widget); XFillRectangle(dpy,win,gc,0,0,400,400);
coltoff@PRC.Unisys.COM (Joel Coltoff) (01/21/89)
In article <16672@iuvax.cs.indiana.edu> beckman@iuvax.cs.indiana.edu (Peter Beckman) writes: >dpy = XtDisplay(Widget); >myXGCV.foreground = WhitePixel(dpy, DefaultScreen(dpy)); >myXGCV.background = BlackPixel(dpy, DefaultScreen(dpy)); >valuemask = GCForeground | GCBackground; >gc = XtGetGC(Widget, valuemask, &myXGCV); >win = XtWindow(Widget); > >XFillRectangle(dpy,win,gc,0,0,400,400); Having just been down that road I'll take a shot at this. First of all you are changing entries in the values structure when you call XtGetGC(). This is a definite NO NO. Here is the code that works for me in my text widget. The copyMask is set to all values that XFillRectangle() uses minus those I'm going to change anyway. gc = XtGetGC(w, 0L, &values); gcCopy = XCreateGC(XtDisplay(w), XtWindow(w), 0L, &valuesCopy); copyMask = GCFillStyle | GCSubwindowMode | GCClipXOrigin | GCClipYOrigin | GCClipMask | GCTile | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin; XCopyGC(XtDisplay(w), gc, copyMask, gcCopy); /* * Modify the values in the writable version of the GC */ XSetFunction(XtDisplay(w), gcCopy, GXinvert); XSetPlaneMask(XtDisplay(w), gcCopy, foreground ^ background); XSetForeground(XtDisplay(w), gcCopy, AllPlanes); XFillRectangle(XtDisplay(w), XtWindow(w), gcCopy, X_pos, Y_pos, width, height ); /* * Free up the GCs */ XFreeGC(XtDisplay(w), gcCopy); XtDestroyGC(gc); Good Luck. -- - Joel {psuvax1,sdcrdcf}!burdvax!coltoff (UUCP) coltoff@burdvax.prc.unisys.com (ARPA)
kit@ATHENA.MIT.EDU (Chris D. Peterson) (01/27/89)
> From: coltoff@burdvax.prc.unisys.com (Joel Coltoff) > In article <16672@iuvax.cs.indiana.edu> beckman@iuvax.cs.indiana.edu (Peter > Beckman) writes: > >dpy = XtDisplay(Widget); > >myXGCV.foreground = WhitePixel(dpy, DefaultScreen(dpy)); > >myXGCV.background = BlackPixel(dpy, DefaultScreen(dpy)); > >valuemask = GCForeground | GCBackground; > >gc = XtGetGC(Widget, valuemask, &myXGCV); > >win = XtWindow(Widget); > > > >XFillRectangle(dpy,win,gc,0,0,400,400); > Having just been down that road I'll take a shot at this. First of all > you are changing entries in the values structure when you call XtGetGC(). > This is a definite NO NO. Here is the code that works for me in my text > widget. The copyMask is set to all values that XFillRectangle() uses > minus those I'm going to change anyway. [code deleted] There is nothing wrong with the call to XtGetCG above, As we have discussed before Joel you cannot change the attributes in a GC created with XtGetGC. (e.g. XSetForground() is a NO NO). But there is nothing wrong with specifying values in the call to XtGetGC(). Right: myXGCV.foreground = WhitePixel(dpy, DefaultScreen(dpy)); myXGCV.background = BlackPixel(dpy, DefaultScreen(dpy)); valuemask = GCForeground | GCBackground; gc = XtGetGC(Widget, valuemask, &myXGCV); Right: gc = XCreateGC(XtDisplay(w), XtWindow(w), 0L, &values); XSetFunction(XtDisplay(w), gcCopy, GXinvert); XSetPlaneMask(XtDisplay(w), gcCopy, foreground ^ background); XSetForeground(XtDisplay(w), gcCopy, AllPlanes); Wrong: gc = XtGetGC(w, 0L, &values); XSetFunction(XtDisplay(w), gcCopy, GXinvert); XSetPlaneMask(XtDisplay(w), gcCopy, foreground ^ background); XSetForeground(XtDisplay(w), gcCopy, AllPlanes); I hope this clears up any confusion. Chris D. Peterson MIT X Consortium / Project Athena Net: kit@athena.mit.edu Phone: (617) 253 - 1326 USMail: MIT - Room E40-321 77 Massachusetts Ave. Cambridge, MA 02139