Re: Setting *color_rgba properties



On Wed, 2009-02-04 at 09:27 +0000, charlie cucaera co uk wrote:

> The mere talk of bits makes me shudder! Thanks for explaining bit shifting,
> it seems I was on the right track but I thought I was missing something
> obvious (I think I need to re-read some basic programming texts; gtk is
> making me soft!)

I think this should convert a GdkColor to an RGBA 32-bit integer (this
code is actually from gtkcolorbutton.c):

  guint32 rgba;

  rgba = ((color->red & 0xff00) << 16) | 
         ((color->green & 0xff00) << 8) | 
          (color->blue & 0xff00);

We could add a convenience function for this.


> Is there a reason why a 32-bit integer is used, as opposed to an rgb
> triplet (+alpha) (although cairo itself uses doubles)?

It's easier to use a single integer as an object property. To use
separate red, green, blue and alpha values would mean 4 separate
properties or using a ref-counted struct, which is a bit of a pain.

Damon




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