[Mono-list] Best way to convert Cairo.Color from/to Gdk.Color???
Francisco M. Marzoa
fmmarzoa at gmx.net
Mon Nov 22 09:32:16 EST 2010
Hello,
This is very useful for me. Thanks, Jonathan.
BTW, Does someone knows why Bule, Red and Green properties are ushort
typed but its constructor uses three byte values for initialize them????
Regards,
El 21/11/10 17:33, Jonathan Pobst escribió:
> Here are the extension methods I use to convert back and forth. Note
> that the range of a Cairo color value is 0.0-1.0 and the range for Gdk
> is 0-255.
>
> public static Cairo.Color ToCairoColor (this Gdk.Color color)
> {
> return new Cairo.Color ((double)color.Red / ushort.MaxValue,
> (double)color.Green / ushort.MaxValue, (double)color.Blue /
> ushort.MaxValue);
> }
>
>
> public static Gdk.Color ToGdkColor (this Cairo.Color color)
> {
> Gdk.Color c = new Gdk.Color ();
> c.Blue = (ushort)(color.B * ushort.MaxValue);
> c.Red = (ushort)(color.R * ushort.MaxValue);
> c.Green = (ushort)(color.G * ushort.MaxValue);
>
> return c;
> }
>
>
> Jonathan
>
> On 11/21/2010 6:40 AM, Francisco M. Marzoa wrote:
>> Hello,
>>
>> I'd like to know what's the best way to converting Cairo.Color into
>> Gdk.Color and viceversa, mainly for using Gtk.ColorSelection widget.
>> Currently I'm doing something like:
>>
>> Gdk.Color gcl;
>> Cairo.Color ccl;
>>
>> ...
>>
>> gcl = Gdk.Color ( (byte)ccl.R, (byte)ccl.G, (byte),cc.B);
>>
>> Although it seems to work, it does not looks neither clean nor robust,
>> as Cairo.Color uses a double for each color component, data may be lost
>> on the conversion though. I wonder if there's a better method for doing
>> this, and also for converting from Gdk.Color to Cairo.Color.
>>
>> Thanks a lot in advance.
>>
>> Best regards,
>>
>>
>>
>> _______________________________________________
>> Mono-list maillist - Mono-list at lists.ximian.com
>> http://lists.ximian.com/mailman/listinfo/mono-list
>>
>>
>
>
More information about the Mono-list
mailing list