From bc12dbcbb827a1b0a8fec894578708d42723ebff Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Thu, 19 Jul 2007 12:34:20 -0400 Subject: [PATCH] short cut highlighting with colors works, but there's no sane defaults right now, so it just uses underlines --- render/font.c | 57 +++++++++++++++++++++++-------------------------- render/font.h | 8 ++++++- render/render.h | 9 +++++--- render/theme.c | 43 +++++++++++++++++++++++++++++++++++++ render/theme.h | 4 ++++ 5 files changed, 87 insertions(+), 34 deletions(-) diff --git a/render/font.c b/render/font.c index 8d389d8b..47c5f6aa 100644 --- a/render/font.c +++ b/render/font.c @@ -66,23 +66,19 @@ RrFont *RrFontOpen(const RrInstance *inst, const gchar *name, gint size, RrFont *out; PangoWeight pweight; PangoStyle pstyle; - PangoAttrList *attrlist; out = g_new(RrFont, 1); out->inst = inst; out->ref = 1; out->font_desc = pango_font_description_new(); out->layout = pango_layout_new(inst->pango); + out->shortcut_underline = pango_attr_underline_new(PANGO_UNDERLINE_LOW); out->shortcut_underline->start_index = 0; out->shortcut_underline->end_index = 0; - attrlist = pango_attr_list_new(); - /* shortcut_underline is owned by the attrlist */ - pango_attr_list_insert(attrlist, out->shortcut_underline); - /* the attributes are owned by the layout */ - pango_layout_set_attributes(out->layout, attrlist); - pango_attr_list_unref(attrlist); + out->underline_attrlist = pango_attr_list_new(); + pango_attr_list_insert(out->underline_attrlist, out->shortcut_underline); switch (weight) { case RR_FONTWEIGHT_LIGHT: pweight = PANGO_WEIGHT_LIGHT; break; @@ -131,6 +127,7 @@ void RrFontClose(RrFont *f) { if (f) { if (--f->ref < 1) { + pango_attr_list_unref(f->underline_attrlist); g_object_unref(f->layout); pango_font_description_free(f->font_desc); g_free(f); @@ -205,7 +202,6 @@ void RrFontDraw(XftDraw *d, RrTextureText *t, RrRect *area) XftColor c; gint mw; PangoRectangle rect; - PangoAttrList *attrlist; PangoEllipsizeMode ell; /* center the text vertically @@ -279,18 +275,28 @@ void RrFontDraw(XftDraw *d, RrTextureText *t, RrRect *area) if (t->shortcut) { const gchar *c = t->string + t->shortcut_pos; + PangoAttribute *pa; + PangoAttrList *al; + + if (t->shortcut_color) { + pa = pango_attr_foreground_new + (t->shortcut_color->r + (t->shortcut_color->r << 8), + t->shortcut_color->g + (t->shortcut_color->g << 8), + t->shortcut_color->b + (t->shortcut_color->b << 8)); + al = pango_attr_list_new(); + pango_attr_list_insert(al, pa); + } + else { + pa = t->font->shortcut_underline; + al = t->font->underline_attrlist; + pango_attr_list_ref(al); + } - t->font->shortcut_underline->start_index = t->shortcut_pos; - t->font->shortcut_underline->end_index = t->shortcut_pos + - (g_utf8_next_char(c) - c); - - /* the attributes are owned by the layout. - re-add the attributes to the layout after changing the - start and end index */ - attrlist = pango_layout_get_attributes(t->font->layout); - pango_attr_list_ref(attrlist); - pango_layout_set_attributes(t->font->layout, attrlist); - pango_attr_list_unref(attrlist); + pa->start_index = t->shortcut_pos; + pa->end_index = t->shortcut_pos + (g_utf8_next_char(c) - c); + + pango_layout_set_attributes(t->font->layout, al); + pango_attr_list_unref(al); } /* layout_line() uses y to specify the baseline @@ -299,15 +305,6 @@ void RrFontDraw(XftDraw *d, RrTextureText *t, RrRect *area) (d, &c, pango_layout_get_line(t->font->layout, 0), x * PANGO_SCALE, y * PANGO_SCALE); - if (t->shortcut) { - t->font->shortcut_underline->start_index = 0; - t->font->shortcut_underline->end_index = 0; - /* the attributes are owned by the layout. - re-add the attributes to the layout after changing the - start and end index */ - attrlist = pango_layout_get_attributes(t->font->layout); - pango_attr_list_ref(attrlist); - pango_layout_set_attributes(t->font->layout, attrlist); - pango_attr_list_unref(attrlist); - } + if (t->shortcut) + pango_layout_set_attributes(t->font->layout, NULL); } diff --git a/render/font.h b/render/font.h index 07d648d1..e548b75f 100644 --- a/render/font.h +++ b/render/font.h @@ -28,7 +28,8 @@ struct _RrFont { gint ref; PangoFontDescription *font_desc; PangoLayout *layout; /*!< Used for measuring and rendering strings */ - PangoAttribute *shortcut_underline; /*< For underlining the shortcut key */ + PangoAttribute *shortcut_underline; /*!< For underlining shortcuts */ + PangoAttrList *underline_attrlist; /*!< For underlining shortcuts */ gint ascent; /*!< The font's ascent in pango-units */ gint descent; /*!< The font's descent in pango-units */ }; @@ -39,4 +40,9 @@ void RrFontDraw(XftDraw *d, RrTextureText *t, RrRect *position); and then really close it */ void RrFontRef(RrFont *f); +void RrFontSetShortcutNormalColor(RrFont *f, RrColor *c); +void RrFontSetShortcutDisabledColor(RrFont *f, RrColor *c); +void RrFontSetShortcutSelectedColor(RrFont *f, RrColor *c); +void RrFontSetShortcutDisabledSelectedColor(RrFont *f, RrColor *c); + #endif /* __font_h */ diff --git a/render/render.h b/render/render.h index 1f87c6e0..311a70f8 100644 --- a/render/render.h +++ b/render/render.h @@ -25,6 +25,7 @@ #include "version.h" #include /* some platforms dont include this as needed for Xft */ +#include #include #include @@ -138,8 +139,9 @@ struct _RrTextureText { gint shadow_offset_y; RrColor *shadow_color; guchar shadow_alpha; - gboolean shortcut; /*!< Underline a character */ - guint shortcut_pos; /*!< Position in bytes of the character to underline */ + gboolean shortcut; /*!< Underline/hilight a character */ + guint shortcut_pos; /*!< Position in bytes of the character to hilight */ + RrColor *shortcut_color; /*!< Color for the hilighted character, or NULL */ RrEllipsizeMode ellipsize; }; @@ -247,7 +249,8 @@ void RrAppearanceFree (RrAppearance *a); void RrAppearanceAddTextures(RrAppearance *a, gint numtex); RrFont *RrFontOpen (const RrInstance *inst, const gchar *name, - gint size, RrFontWeight weight, RrFontSlant slant); + gint size, RrFontWeight weight, + RrFontSlant slant); RrFont *RrFontOpenDefault (const RrInstance *inst); void RrFontClose (RrFont *f); RrSize *RrFontMeasureString (const RrFont *f, const gchar *str, diff --git a/render/theme.c b/render/theme.c index a793ced7..9c2dc2b3 100644 --- a/render/theme.c +++ b/render/theme.c @@ -401,6 +401,37 @@ RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name, "menu.items.active.text.color", &theme->menu_selected_color)) theme->menu_selected_color = RrColorNew(inst, 0, 0, 0); + if (!read_color(db, inst, + "menu.items.text.shortcut.color", + &theme->menu_shortcut_color)) + theme->menu_shortcut_color = NULL; + if (!read_color(db, inst, + "menu.items.disabled.text.shortcut.color", + &theme->menu_disabled_shortcut_color)) + theme->menu_disabled_shortcut_color = + theme->menu_shortcut_color == NULL ? NULL : + RrColorNew(inst, + theme->menu_shortcut_color->r, + theme->menu_shortcut_color->g, + theme->menu_shortcut_color->b); + if (!read_color(db, inst, + "menu.items.disabled.text.shortcut.color", + &theme->menu_disabled_selected_shortcut_color)) + theme->menu_disabled_selected_shortcut_color = + theme->menu_shortcut_color == NULL ? NULL : + RrColorNew(inst, + theme->menu_shortcut_color->r, + theme->menu_shortcut_color->g, + theme->menu_shortcut_color->b); + if (!read_color(db, inst, + "menu.items.active.text.shortcut.color", + &theme->menu_selected_shortcut_color)) + theme->menu_selected_shortcut_color = + theme->menu_shortcut_color == NULL ? NULL : + RrColorNew(inst, + theme->menu_shortcut_color->r, + theme->menu_shortcut_color->g, + theme->menu_shortcut_color->b); /* load the image masks */ @@ -1034,12 +1065,20 @@ RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name, theme->a_menu_text_disabled_selected->texture[0].data.text.font = theme->menu_font; theme->a_menu_text_normal->texture[0].data.text.color = theme->menu_color; + theme->a_menu_text_normal->texture[0].data.text.shortcut_color = + theme->menu_shortcut_color; theme->a_menu_text_selected->texture[0].data.text.color = theme->menu_selected_color; + theme->a_menu_text_selected->texture[0].data.text.shortcut_color = + theme->menu_selected_shortcut_color; theme->a_menu_text_disabled->texture[0].data.text.color = theme->menu_disabled_color; + theme->a_menu_text_disabled->texture[0].data.text.shortcut_color = + theme->menu_disabled_shortcut_color; theme->a_menu_text_disabled_selected->texture[0].data.text.color = theme->menu_disabled_selected_color; + theme->a_menu_text_disabled_selected->texture[0].data.text.shortcut_color = + theme->menu_disabled_selected_shortcut_color; if (read_string(db, "menu.items.font", &str)) { char *p; @@ -1421,6 +1460,10 @@ void RrThemeFree(RrTheme *theme) RrColorFree(theme->menu_selected_color); RrColorFree(theme->menu_disabled_color); RrColorFree(theme->menu_disabled_selected_color); + RrColorFree(theme->menu_shortcut_color); + RrColorFree(theme->menu_selected_shortcut_color); + RrColorFree(theme->menu_disabled_shortcut_color); + RrColorFree(theme->menu_disabled_selected_shortcut_color); RrColorFree(theme->title_focused_shadow_color); RrColorFree(theme->title_unfocused_shadow_color); RrColorFree(theme->osd_color); diff --git a/render/theme.h b/render/theme.h index 2c35284f..25ae841d 100644 --- a/render/theme.h +++ b/render/theme.h @@ -87,6 +87,10 @@ struct _RrTheme { RrColor *menu_selected_color; RrColor *menu_disabled_color; RrColor *menu_disabled_selected_color; + RrColor *menu_shortcut_color; + RrColor *menu_selected_shortcut_color; + RrColor *menu_disabled_shortcut_color; + RrColor *menu_disabled_selected_shortcut_color; RrColor *title_focused_shadow_color; gchar title_focused_shadow_alpha; RrColor *title_unfocused_shadow_color; -- 2.34.1