kwo pushed a commit to branch master. http://git.enlightenment.org/e16/e16.git/commit/?id=00c261652ed39824fa21d884c1687c196969ecfa
commit 00c261652ed39824fa21d884c1687c196969ecfa Author: Kim Woelders <[email protected]> Date: Tue Dec 12 18:59:48 2017 +0100 Do proper rendering of transparent icons in menus --- src/menus-misc.c | 26 ++++++------------- src/menus.c | 77 ++++++++++++++++++++++++++++---------------------------- src/menus.h | 4 +-- 3 files changed, 49 insertions(+), 58 deletions(-) diff --git a/src/menus-misc.c b/src/menus-misc.c index 5dc7be3a..3ff09a3d 100644 --- a/src/menus-misc.c +++ b/src/menus-misc.c @@ -1,6 +1,6 @@ /* * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors - * Copyright (C) 2004-2015 Kim Woelders + * Copyright (C) 2004-2017 Kim Woelders * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -33,7 +33,6 @@ #include "ewins.h" #include "file.h" #include "groups.h" -#include "iclass.h" #include "menus.h" #include "parse.h" #include "progress.h" @@ -49,18 +48,15 @@ MenuItemCreateFromBackground(const char *bgid, const char *file) { MenuItem *mi; Background *bg; - ImageClass *ic; char thumb[1024], buf[1024]; bg = BrackgroundCreateFromImage(bgid, file, thumb, sizeof(thumb)); if (!bg) return NULL; - ic = ImageclassCreateSimple("`", thumb); - Esnprintf(buf, sizeof(buf), "bg use %s", bgid); - mi = MenuItemCreate(NULL, ic, buf, NULL); + mi = MenuItemCreate(NULL, thumb, buf, NULL); return mi; } @@ -309,7 +305,6 @@ FillFlatFileMenu(Menu * m, const char *file) char *txt, *icon, *act, *params; char wd[4096]; MenuItem *mi; - ImageClass *icc = NULL; Menu *mm; txt = icon = act = params = NULL; @@ -318,21 +313,14 @@ FillFlatFileMenu(Menu * m, const char *file) if (icon) icon = FindFile(icon, NULL, FILE_TYPE_ICON); - if (icon) - { - Esnprintf(wd, sizeof(wd), "__FM.%s", icon); - icc = ImageclassFind(wd, 0); - if (!icc) - icc = ImageclassCreateSimple(wd, icon); - Efree(icon); - } + if ((act) && (!strcmp(act, "exec")) && (params)) { sscanf(params, "%4000s", wd); if (path_canexec(wd)) { Esnprintf(wd, sizeof(wd), "exec %s", params); - mi = MenuItemCreate(txt, icc, wd, NULL); + mi = MenuItemCreate(txt, icon, wd, NULL); MenuAddItem(m, mi); } } @@ -341,15 +329,17 @@ FillFlatFileMenu(Menu * m, const char *file) mm = MenuFind(params, NULL); if (mm) { - mi = MenuItemCreate(txt, icc, NULL, mm); + mi = MenuItemCreate(txt, icon, NULL, mm); MenuAddItem(m, mi); } } else if (act) { - mi = MenuItemCreate(txt, icc, act, NULL); + mi = MenuItemCreate(txt, icon, act, NULL); MenuAddItem(m, mi); } + + Efree(icon); } } fclose(f); diff --git a/src/menus.c b/src/menus.c index 82038882..622fee06 100644 --- a/src/menus.c +++ b/src/menus.c @@ -1,6 +1,6 @@ /* * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors - * Copyright (C) 2004-2015 Kim Woelders + * Copyright (C) 2004-2017 Kim Woelders * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -80,16 +80,17 @@ struct _menustyle { struct _menuitem { Menu *menu; - ImageClass *icon_iclass; char *text; + char *icon; char *params; Menu *child; char state; PmapMask pmm[3]; Win win; - Win icon_win; short icon_w; short icon_h; + short icon_x; + short icon_y; short text_w; short text_h; short text_x; @@ -411,15 +412,15 @@ MenuStyleCreate(const char *name) } MenuItem * -MenuItemCreate(const char *text, ImageClass * iclass, +MenuItemCreate(const char *text, const char *icon, const char *action_params, Menu * child) { MenuItem *mi; mi = ECALLOC(MenuItem, 1); - mi->icon_iclass = iclass; mi->text = (text) ? Estrdup((text[0]) ? text : "?!?") : NULL; + mi->icon = Estrdup(icon); mi->params = Estrdup(action_params); mi->child = child; if (child) @@ -625,6 +626,7 @@ MenuEmpty(Menu * m, int destroying) MenuDestroy(mi->child); } Efree(mi->text); + Efree(mi->icon); Efree(mi->params); for (j = 0; j < 3; j++) PmapMaskFree(&(mi->pmm[j])); @@ -632,7 +634,6 @@ MenuEmpty(Menu * m, int destroying) EDestroyWindow(mi->win); else EventCallbackUnregister(mi->win, MenuItemHandleEvents, mi); - ImageclassFree(mi->icon_iclass); Efree(mi); } Efree(m->items); @@ -740,9 +741,9 @@ MenuRealize(Menu * m) m->items[i]->text_w = w; m->items[i]->text_h = h; } - if (m->items[i]->icon_iclass && Conf.menus.show_icons) + if (m->items[i]->icon && Conf.menus.show_icons) { - im = ImageclassGetImage(m->items[i]->icon_iclass, 0, 0, 0); + im = EImageLoad(m->items[i]->icon); if (im) { w = h = 0; @@ -754,9 +755,6 @@ MenuRealize(Menu * m) EImageGetSize(im, &w, &h); m->items[i]->icon_w = w; m->items[i]->icon_h = h; - m->items[i]->icon_win = - ECreateWindow(m->items[i]->win, 0, 0, w, h, 0); - EMapWindow(m->items[i]->icon_win); if (h > maxh) maxh = h; if (w > maxx2) @@ -764,7 +762,10 @@ MenuRealize(Menu * m) EImageFree(im); } else - m->items[i]->icon_iclass = NULL; + { + Efree(m->items[i]->icon); + m->items[i]->icon = NULL; + } } } @@ -831,27 +832,18 @@ MenuRealize(Menu * m) m->items[i]->text_x = pad_item->left + maxx2; m->items[i]->text_w = maxx1; m->items[i]->text_y = (maxh - m->items[i]->text_h) / 2; - if (m->items[i]->icon_win) - EMoveWindow(m->items[i]->icon_win, - pad_item->left + - ((maxx2 - m->items[i]->icon_w) / 2), - ((maxh - m->items[i]->icon_h) / 2)); + m->items[i]->icon_x = pad_item->left + + (maxx2 - m->items[i]->icon_w) / 2; + m->items[i]->icon_y = (maxh - m->items[i]->icon_h) / 2; } else { m->items[i]->text_x = pad_item->left; m->items[i]->text_w = maxx1; m->items[i]->text_y = (maxh - m->items[i]->text_h) / 2; - if (m->items[i]->icon_win) - EMoveWindow(m->items[i]->icon_win, - maxw - pad_item->right - maxx2 + - ((maxx2 - m->items[i]->icon_w) / 2), - ((maxh - m->items[i]->icon_h) / 2)); - } - if (m->items[i]->icon_iclass && Conf.menus.show_icons) - { - ImageclassApply(m->items[i]->icon_iclass, m->items[i]->icon_win, - 0, 0, STATE_NORMAL, ST_MENU_ITEM); + m->items[i]->icon_x = maxw - pad_item->right - maxx2 + + (maxx2 - m->items[i]->icon_w) / 2; + m->items[i]->icon_y = (maxh - m->items[i]->icon_h) / 2; } if (x + maxw > mmw) mmw = x + maxw; @@ -953,6 +945,7 @@ MenuDrawItem(Menu * m, MenuItem * mi, char shape, int state) int item_type; ImageClass *ic; PmapMask pmm; + EImage *im; EGetGeometry(mi->win, NULL, &x, &y, &w, &h, NULL, NULL); @@ -991,6 +984,14 @@ MenuDrawItem(Menu * m, MenuItem * mi, char shape, int state) mi->text_h, 17, TextclassGetJustification(m->style->tclass)); } + if (mi->icon && Conf.menus.show_icons) + { + im = EImageLoad(mi->icon); + EImageRenderOnDrawable(im, mi->win, mi_pmm->pmap, EIMAGE_BLEND, + mi->icon_x, mi->icon_y, + mi->icon_w, mi->icon_h); + EImageFree(im); + } } ESetWindowBackgroundPixmap(mi->win, mi_pmm->pmap, 1); @@ -1750,11 +1751,11 @@ MenuConfigLoad(FILE * fs) char s5[FILEPATH_LEN_MAX]; char *p2, *p3; char *txt = NULL; + char *icon = NULL; const char *params; int i1, i2, len; Menu *m = NULL, *mm; MenuItem *mi; - ImageClass *ic = NULL; while (GetLine(s, sizeof(s), fs)) { @@ -1773,8 +1774,8 @@ MenuConfigLoad(FILE * fs) if (i2 != CONFIG_OPEN) goto done; m = NULL; - ic = NULL; _EFREE(txt); + _EFREE(icon); continue; case CONFIG_CLOSE: err = 0; @@ -1801,10 +1802,10 @@ MenuConfigLoad(FILE * fs) continue; case MENU_ITEM: - ic = NULL; - if (strcmp("NULL", s2)) - ic = ImageclassFind(s2, 0); _EFREE(txt); + _EFREE(icon); + if (strcmp("NULL", s2)) + icon = Estrdup(s2); if (p3 && *p3) txt = Estrdup(p3); continue; @@ -1826,7 +1827,7 @@ MenuConfigLoad(FILE * fs) MenuSetTitle(m, p2); break; case MENU_ACTION: - if ((txt) || (ic)) + if (txt || icon) { char ok = 1; @@ -1839,21 +1840,21 @@ MenuConfigLoad(FILE * fs) } if (ok) { - mi = MenuItemCreate(txt, ic, p2, NULL); + mi = MenuItemCreate(txt, icon, p2, NULL); MenuAddItem(m, mi); } - ic = NULL; _EFREE(txt); + _EFREE(icon); } break; case MENU_SUBMENU: len = 0; sscanf(p3, "%s %n", s3, &len); - ic = NULL; + _EFREE(icon); if (strcmp("NULL", s3)) - ic = ImageclassFind(s3, 1); + icon = Estrdup(s3); mm = MenuFind(s2, NULL); - mi = MenuItemCreate(p3 + len, ic, NULL, mm); + mi = MenuItemCreate(p3 + len, icon, NULL, mm); MenuAddItem(m, mi); break; default: diff --git a/src/menus.h b/src/menus.h index e6807b52..46378243 100644 --- a/src/menus.h +++ b/src/menus.h @@ -1,6 +1,6 @@ /* * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors - * Copyright (C) 2004-2007 Kim Woelders + * Copyright (C) 2004-2017 Kim Woelders * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -42,7 +42,7 @@ Menu *MenuCreate(const char *name, const char *title, void MenuEmpty(Menu * m, int destroying); int MenuLoad(Menu * m); Menu *MenuFind(const char *name, const char *param); -MenuItem *MenuItemCreate(const char *text, ImageClass * ic, +MenuItem *MenuItemCreate(const char *text, const char *icon, const char *action_params, Menu * child); void MenuSetInternal(Menu * m); void MenuSetDynamic(Menu * m); --
