Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!att!cbnews!jec From: jec@cbnews.att.com (John Collier) Newsgroups: comp.windows.x Subject: How do I use a read/write color cell? Keywords: read,write,alloc,SetColor Message-ID: <1990Sep26.190951.21408@cbnews.att.com> Date: 26 Sep 90 19:09:51 GMT Distribution: na Organization: AT&T Bell Laboratories Lines: 69 I've been fiddling around with a "paint mixer" program, mostly just to learn how things work (those of you who've already done this may smile and nod your heads knowingly...:-). This is the "traditional" paint mixer where I show three sliders, one each for red, green, and blue intensities, with the idea that when I move one of the sliders, the background color inside a window will change dynamically. This would be really nice; I just can't seem to make it work. I made a call to XAllocColorCells to allocate one read/write color cell. The call looks like: unsigned long *plane_masks = 0 ; int rtn = XAllocColorCells (dsp, cmap, True, plane_masks, 0, &pixel, 1) ; This seems to yield a valid value for "pixel" usually something "25". I also check the return code and it never comes back "0", so it seems like this part works okay. Later I call XStoreColor to initialize the color cell to "black": XColor xc ; xc.pixel = pixel ; xc.red = 0 ; xc.green = 0 ; xc.blue = 0 ; xc.flags = DoRed | DoGreen | DoBlue ; XStoreColor (dsp, cmap, &xc) ; As far as I can tell, this works. My Xlib Reference Manual doesn't mention a return code, so I don't know if I can check one to see it the call worked. Also, my test area shows black, which may or may not mean anything under the circumstances. Once I've allocated this, I assign the background color of an OpenLook Static Text widget to use the "pixel" I got from the previous call. This looks like: XFreeColors (dsp, cmap, old_pixel_value, 1, 0) ; /* Free previous color */ XColor xc ; xc.pixel = new_pixel ; /* Pixel value obtained from XAllocColorCells */ int rtn = XAllocColor (dsp, cmap, &xc) ; /* Build an Xt Args list with XtNbackground set to "new_pixel" */ /* Use XtSetValues to set the widget background color to "new_pixel" */ I check the return code from "XAllocColor", but it is never zero, so I assume this call worked as well. Later, in the callback function for the slider, I call XStoreColor again to set a new RGB value for the "pixel". It is identical to the one above except only one field is set and "flags" is set correspondingly. I also left-shift the color by 8 (<< 8) before I call XStoreColor. Now, with all of that, when I run the program and move the sliders, the window background never changes color. If someone could tell me what I'm doing wrong or, conversely, a better way to do it right, I would really appreciate it. The explanation can deal with what I want to do on the Xlib level; I can translate it into my "stuff" from there. Any ideas, help, or suggestions would be appreciated. -- ------------------------------------------------------------------------------- Working around here is like going into a swamp | John Collier, AT&T Bell Labs full of alligators...you'll either be eaten | ARPA: jec@cbnea.ATT.COM alive or wind up with some really nice luggage!| uucp/e-mail: att!cbnea!jec