displaying multiple colors

This forum is read only. No new submissions are accepted.

Questions about motif? Contact us

3 posts / 0 new
Last post
displaying multiple colors

Submitted by Anonymous on Tue, 07/22/2003 - 14:44.

hi,

I have created a notebook widget (using XmCreateNotebook) and I draw images to each of the pages (using the XDrawRectangle, XFillRectangle, and XDrawline commands). Each of the rectangles that are drawn are assigned an ID (usually between 0-100) and need to be drawn in a different color. I first tried XAllocColor and supplied my own rgb values, but could not come up with a suitable method to assign each ID it`s own unique color... So, then I read about the rgb.txt file, and copied a list of colors from that file into the directory that has the program I created, and then I read from this list and call XAllocNamedColor with the names from that file... My problem is that not all the colors appear as I think they should appear (i.e. orange appears white, and other colors appear to be modified when their neighboring colors (or the background) changes color). I have read about the different types of Visuals that exist (i.e. PsuedoColor, GrayScale, TrueColor) but I have yet to find out how to use these (or set them). So, part of my question is, how do you go about displaying multiple colors in a widget (i.e. is there anything special I need to do/ be aware of?). I hope this all makes sense, if not, feel free to ask me any questions, as I would really like to figure this problem out!

Thanks in Advance for your help!

P.S. In case in helps, I am working on a Sun Solaris machine, using SunOS Release 5.7 Generic_106541-07, and the CDE desktop environment

Wed, 07/23/2003 - 18:33#1

Wed, 07/23/2003 - 18:33#1

Anonymous

displaying multiple colors

Ok,

I think that my problem *may* lie in how I am using the colormap. From suing the xdpyinfo utility, I found out that there are 256 available entries for the colormap. However, I call XAllocColor many more times than that (Note some of these are repeat calls for the same color). So, I think I need to figure out how to only allocate the colors to the colormap once, and then retrieve the proper colors from the colormap.

Finally, never mind about the questions I had about the Visual structure from my previous post. I think I have figured that part out...

Thanks,

Fri, 08/15/2003 - 15:17#2

Fri, 08/15/2003 - 15:17#2

Anonymous

displaying multiple colors

For the benefit of future visitors to this site who may have the same question... I finally figured out a way to have the widget show multiple colors... If you don`t care which colors are shown on the screen (as long as the screen shows different colors), then all you need to do is create a color structure, and set the pixel value... From what I have read about, the pixel value can be just about any number (at least from 0-256, and maybe even more), and then set the foreground to that color... For example, the following code will create rectangles, with each one having a different color

int i,w,h;
XColor lines, white, black, color;

w=10;
h = 10;
for (i=0; i < NUM_RECTANGLES; i++)
{
color.pixel = i;

XSetForeground(display[currentPage], gc[currentPage], color.pixel);

XDrawRectangle(display[currentPage], pixmap[currentPage], gc[currentPage], i, i+5, w, h);
XFillRectangle(display[currentPage], pixmap[currentPage], gc[currentPage], i, i+5, w, h);
}

As an additional side note, I would like to point out that I believe my previous problem was that I was continuously allocating colors, and my colormap was filling up, and, once when it was full, the colors got messed up...

Hope this helps someone someday!