Re: GtkColorButton Deprecation




On 13/04/13 05:54, Matthew Brush wrote:
On 13-04-12 03:51 PM, Lanoxx wrote:
Hi,

i was migration some code from GtkColorButton to the GtkColorChooser
interface today. I was storing a color palette of 3x16 colors (R + G +
B) as 16bit integers before which looked something like this:

         "{"\
         0x2e2e, 0x3434, 0x3636,\
         0xcccc, 0x0000, 0x0000,\
         0x4e4e, 0x9a9a, 0x0606,\
         ...
         0xadad, 0x7f7f, 0xa8a8,\
         0x3434, 0xe2e2, 0xe2e2,\
         0xeeee, 0xeeee, 0xecec}"

However with the new ColorChooser interface I now have to store doubles
instead of ints. If I convert the values to doubles and then store them
in the same way, it doesnt' look like a very clean solution to me. So I
was wondering if there isn't any cleaner and easier solution for this?

         "{"\
         0.180392156863, 0.203921568627, 0.211764705882,\
         ...
         ...}"


Hi,

You could do something like this:

    #define RGB(r,g,b) { (r) / (gdouble)G_MAXUINT16, \
                         (g) / (gdouble)G_MAXUINT16, \
                         (b) / (gdouble)G_MAXUINT16, 1. }

    static GdkRGBA palette[] = {
      RGB(0x2e2e, 0x3434, 0x3636),
      RGB(0xcccc, 0x0000, 0x0000),
      // ...
    };
Hi Matthew,

thanks a lot for that suggestion, that was very useful. I am now using this macro to initialize the paletts standard paletts, and I have added two more macros to convert to and from int. I decided to continue to store the values as int in the config files, because I think its easier to edit by hand, and it will also save me some trouble with libconfuse. The problem with libconfuse was that the values are initialized from strings and thus I cannot use macros there.

#define GUINT16_TO_FLOAT(color) (color / (double) 0xFFFF)
#define GUINT16_FROM_FLOAT(value) ((int) (value * 0xFFFF + 0.5d))

The code now looks like this in many places:

    fg.red   =    GUINT16_TO_FLOAT(config_getint ("text_red"));
    ...
current_palette[i].red = GUINT16_TO_FLOAT(config_getnint ("palette", i*3));
    ...
    config_setint ("back_red",   GUINT16_FROM_FLOAT(gdk_back.red));
    ...

Just for the record if anyone comes across the same problem, here is my solution:
https://github.com/lanoxx/tilda/commit/66653d60cb91d368908e24b55360cbfae98ed02d

Regards
Sebastian

Cheers,
Matthew Brush

_______________________________________________
gtk-devel-list mailing list
gtk-devel-list gnome org
https://mail.gnome.org/mailman/listinfo/gtk-devel-list



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