0
0
mirror of https://github.com/vim/vim.git synced 2025-09-29 04:34:16 -04:00

patch 7.4.2089

Problem:    Color handling of X11 GUIs is too complicated.
Solution:   Simplify the code.  Use RGBA where appropriate. (Kazunobu
            Kuriyama)
This commit is contained in:
Bram Moolenaar
2016-07-21 22:10:12 +02:00
parent f36213597d
commit 36edf0685c
5 changed files with 125 additions and 197 deletions

View File

@@ -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;