diff options
author | Bram Moolenaar <Bram@vim.org> | 2016-07-21 22:10:12 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2016-07-21 22:10:12 +0200 |
commit | 36edf0685c8b55ee3ce709058d83ada8027fec1e (patch) | |
tree | 06e655f23ec2b4c9b4be5acf22b0869506bddd6b /src/gui_beval.c | |
parent | f36213597d737ab500771e87edcf121acd55e277 (diff) | |
download | vim-git-36edf0685c8b55ee3ce709058d83ada8027fec1e.tar.gz |
patch 7.4.2089v7.4.2089
Problem: Color handling of X11 GUIs is too complicated.
Solution: Simplify the code. Use RGBA where appropriate. (Kazunobu
Kuriyama)
Diffstat (limited to 'src/gui_beval.c')
-rw-r--r-- | src/gui_beval.c | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/src/gui_beval.c b/src/gui_beval.c index 4525dde7a..74da90893 100644 --- a/src/gui_beval.c +++ b/src/gui_beval.c @@ -1044,7 +1044,12 @@ set_printable_label_text(GtkLabel *label, char_u *text) attrentry_T *aep; PangoAttribute *attr; guicolor_T pixel; +#if GTK_CHECK_VERSION(3,0,0) + GdkRGBA color = { 0.0, 0.0, 0.0, 1.0 }; + PangoAttribute *attr_alpha; +#else GdkColor color = { 0, 0, 0, 0 }; +#endif /* Look up the RGB values of the SpecialKey foreground color. */ aep = syn_gui_attr2entry(hl_attr(HLF_8)); @@ -1052,30 +1057,10 @@ set_printable_label_text(GtkLabel *label, char_u *text) if (pixel != INVALCOLOR) # if GTK_CHECK_VERSION(3,0,0) { - GdkVisual * const visual = gtk_widget_get_visual(gui.drawarea); - - if (visual == NULL) - { - color.red = 0; - color.green = 0; - color.blue = 0; - } - else - { - guint32 r_mask, g_mask, b_mask; - gint r_shift, g_shift, b_shift; - - gdk_visual_get_red_pixel_details(visual, &r_mask, &r_shift, - NULL); - gdk_visual_get_green_pixel_details(visual, &g_mask, &g_shift, - NULL); - gdk_visual_get_blue_pixel_details(visual, &b_mask, &b_shift, - NULL); - - color.red = ((pixel & r_mask) >> r_shift) / 255.0 * 65535; - color.green = ((pixel & g_mask) >> g_shift) / 255.0 * 65535; - color.blue = ((pixel & b_mask) >> b_shift) / 255.0 * 65535; - } + color.red = ((pixel & 0xff0000) >> 16) / 255.0; + color.green = ((pixel & 0xff00) >> 8) / 255.0; + color.blue = (pixel & 0xff) / 255.0; + color.alpha = 1.0; } # else gdk_colormap_query_color(gtk_widget_get_colormap(gui.drawarea), @@ -1124,11 +1109,27 @@ set_printable_label_text(GtkLabel *label, char_u *text) } if (pixel != INVALCOLOR) { +#if GTK_CHECK_VERSION(3,0,0) +# define DOUBLE2UINT16(val) ((guint16)((val) * 65535 + 0.5)) + attr = pango_attr_foreground_new( + DOUBLE2UINT16(color.red), + DOUBLE2UINT16(color.green), + DOUBLE2UINT16(color.blue)); + attr_alpha = pango_attr_foreground_alpha_new( + DOUBLE2UINT16(color.alpha)); +# undef DOUBLE2UINT16 +#else attr = pango_attr_foreground_new( color.red, color.green, color.blue); +#endif attr->start_index = pdest - buf; attr->end_index = pdest - buf + outlen; pango_attr_list_insert(attr_list, attr); +#if GTK_CHECK_VERSION(3,0,0) + attr_alpha->start_index = pdest - buf; + attr_alpha->end_index = pdest - buf + outlen; + pango_attr_list_insert(attr_list, attr_alpha); +#endif } pdest += outlen; p += charlen; |