[gtkada] incoherent colors

briot at gnat.com briot at gnat.com
Fri Mar 10 16:49:59 CET 2000


 > the type returned by the choose_color_widget is Gdouble
 > and the type expected for GDK.COLOR is GUShort.

This is because they do not have the same meaning:
 - Gdouble is a value between 0.0 and 1.0, ie a percentage value.
   You can convert it to an absolute use than can be used in a Gdk_Color with
   the following code:
        Absolute_Value := Gushort ( Gdouble (Gushort'Last) * Gdouble_Value);

   (one of the few cases where you need more casts in GtkAda than in gtk+ :-)

 - Gushort is an absolute value for the Red, Green, Blue components of a color.


 > wouldn't it be more logicall to have only one type of color, or to offer
 > the proper conversion function (even if it isn't very complicated to write

No, because they do not have the same meaning. In fact, we could even have
created a completly new type.
But providing a conversion function makes sense, we will include one in a
future release.

 > B.T.W could anibody explain to me what exactly is a colormap ?
 > it isn't explained neither in the user guide nor in the RM.

You should probably have a quick look at a X11 book (or win32 book if you are
on windows). A colormap is one of the basic concepts to understand if you want
to be able to manipulate colors in graphical applications.
To be short: this is a way, on screen with small color depths (ie few bits per
pixel) to give access to a huge number of access, only a number of them being
available at a given time.
For instance, on a screen with a depth of 8, you can select 256 colors all the
possible colors, and reference them by an index. The colormap is used to
convert from that index to the real color definition.

This is potentially useless on screen with a depth of at least 16, I believe,
but even so it is better to use so that your application is more portable.

Emmanuel





More information about the gtkada mailing list