[gtkada] Problem with color

Emmanuel Briot briot at gnat.com
Wed Dec 27 16:10:53 CET 2000


Christophe Baillon writes:
 > I have made a procedure putpixel who is drawing a point in a drawing object i
 > have created before.
 > It give in argument the color of the pixel, using the parse function (for
 > rgb.txt).
 > The procedure is working except i obtain a bad color on the screen.
 > Sometimes the pixel is blue, sometime it is red, instead of being yellow for
 > example.
 > What is the problem ?

 >       G_Color := Parse(color);
 >       Set_Foreground(Gc, G_Color);



You need to allocate the color as well.
Parse simply gets the Red, Green, Blue components, but doesn't reserve an
entry in the colormap for that color.
If you are using a 24bits or 32bits video mode (true color), you might get
away with it, since these components are directly the color itself.
However, if you have less bits (or to make your application indeed portable),
the colormap is in fact a palette, where each color is referenced by an index
in a table. Each entry in the table then contains the RGB components.

As a result, you always need to call Alloc for that color.

Your code becomes:

  G_Color := Parse (Color);
  Alloc (Gtk.Widget.Get_Default_Colormap, G_Color);
  Set_Foreground (GC, G_Color);


regards,
Emmanuel




More information about the gtkada mailing list