Re: GdkColor quiestion.




Sergei Naumov <serge@astro.unc.edu> writes:

> Hi!
> I have problems with GdkColor. The goal is to draw a red line. So, I
> looked at the sources of Gdk/Gtk and conceived this piece:
> 
> 	GdkGC *draw;
> 	GdkColor drawColor;
> 
> 	draw = gdk_gc_new(widget->window);
> 	gdk_gc_copy(drawCross,widget->style->white_gc);
>         drawCrossColor.red = 255;
                               ^^^
Better make that 65535 or you'll get a black line. (Or almost
black). Color values range from 0 to 65535.

>         drawCrossColor.green = 0;
>         drawCrossColor.blue = 0;
> 	gdk_gc_set_foreground(drawCross,&drawCrossColor);
> 
> 	gdk_draw_line(widget->window,
> 	  	      draw,
> 		      x,10,
> 		      x,widget->allocation.height-10);
> 
> But. This thing still draws a white line. Can anyone explain what is wrong
> here? There is another question: what's the meaning of the "pixel" field
> in the GdkColor structure? The sources are very blurry on that.

The pixel value is the actual number that is drawn on the screen. For
a TrueColor display, it will be a combination of the RGB values. For
a PseudoColor (e.g., 8-bit color) display, it will be the index 
of the color in the colormap. This needs to be set up - which is
the cause of your problem.

Add a call:

    gdk_color_alloc (gtk_widget_get_colormap(widget), drawColor)

and things should work as you expect.

Regards,
                                        Owen



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]