From 4b440204887478ba9f4709bacbb01def3f20da5e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20D=C3=A9chelotte?= Date: Fri, 12 Apr 2013 01:42:31 +0200 Subject: [PATCH] WPrefs: consolidate the 2 createImages static functions into a global one --- WPrefs.app/Configurations.c | 41 +------------- WPrefs.app/WPrefs.c | 55 +++++++++++++++++++ WPrefs.app/WPrefs.h | 7 +++ WPrefs.app/Workspace.c | 126 +++++++++++++------------------------------- 4 files changed, 100 insertions(+), 129 deletions(-) diff --git a/WPrefs.app/Configurations.c b/WPrefs.app/Configurations.c index e64d8c11..55b15375 100644 --- a/WPrefs.app/Configurations.c +++ b/WPrefs.app/Configurations.c @@ -111,43 +111,6 @@ static void updateLabel(WMWidget *self, void *data) WMSetLabelText(panel->dithL, buffer); } -static void -createImages(WMScreen *scr, RContext *rc, RImage *xis, char *file, - WMPixmap **icon1, WMPixmap **icon2) -{ - RImage *icon; - char *path; - RColor gray = { 0xae, 0xaa, 0xae, 0 }; - - *icon1 = NULL; - *icon2 = NULL; - - path = LocateImage(file); - if (!path) - return; - - *icon1 = WMCreatePixmapFromFile(scr, path); - if (!*icon1) { - wwarning(_("could not load icon %s"), path); - wfree(path); - return; - } - icon = RLoadImage(rc, path, 0); - if (!icon) { - wwarning(_("could not load icon %s"), path); - wfree(path); - return; - } - RCombineImageWithColor(icon, &gray); - if (xis) { - RCombineImagesWithOpaqueness(icon, xis, 180); - if (!(*icon2 = WMCreatePixmapFromRImage(scr, icon, 127))) - wwarning(_("could not process icon %s: %s"), file, RMessageForError(RErrorCode)); - } - RReleaseImage(icon); - wfree(path); -} - static void createPanel(Panel *p) { _Panel *panel = (_Panel *) p; @@ -342,7 +305,7 @@ static void createPanel(Panel *p) WMSetButtonFont(panel->animB, font); WMSetButtonText(panel->animB, _("Animations")); WMSetButtonImagePosition(panel->animB, WIPAbove); - createImages(scr, rc, xis, ANIM_IMAGE, &altIcon, &icon); + CreateImages(scr, rc, xis, ANIM_IMAGE, &altIcon, &icon); if (icon) { WMSetButtonImage(panel->animB, icon); WMReleasePixmap(icon); @@ -360,7 +323,7 @@ static void createPanel(Panel *p) WMSetButtonFont(panel->supB, font); WMSetButtonText(panel->supB, _("Superfluous")); WMSetButtonImagePosition(panel->supB, WIPAbove); - createImages(scr, rc, xis, SUPERF_IMAGE, &altIcon, &icon); + CreateImages(scr, rc, xis, SUPERF_IMAGE, &altIcon, &icon); if (icon) { WMSetButtonImage(panel->supB, icon); WMReleasePixmap(icon); diff --git a/WPrefs.app/WPrefs.c b/WPrefs.app/WPrefs.c index 2b69b51f..17ef8640 100644 --- a/WPrefs.app/WPrefs.c +++ b/WPrefs.app/WPrefs.c @@ -392,6 +392,61 @@ char *LocateImage(char *name) return path; } +void CreateImages(WMScreen *scr, RContext *rc, RImage *xis, char *file, + WMPixmap **icon_normal, WMPixmap **icon_greyed) +{ + RImage *icon; + char *path; + RColor gray = { 0xae, 0xaa, 0xae, 0 }; + + path = LocateImage(file); + if (!path) + { + *icon_normal = NULL; + if (icon_greyed) + *icon_greyed = NULL; + return; + } + + *icon_normal = WMCreatePixmapFromFile(scr, path); + if (!*icon_normal) + { + wwarning(_("could not load icon %s"), path); + if (icon_greyed) + *icon_greyed = NULL; + wfree(path); + return; + } + + if (!icon_greyed) // Greyed-out version not requested, we are done + { + wfree(path); + return; + } + + icon = RLoadImage(rc, path, 0); + if (!icon) + { + wwarning(_("could not load icon %s"), path); + *icon_greyed = NULL; + wfree(path); + return; + } + RCombineImageWithColor(icon, &gray); + if (xis) + { + RCombineImagesWithOpaqueness(icon, xis, 180); + } + *icon_greyed = WMCreatePixmapFromRImage(scr, icon, 127); + if (!*icon_greyed) + { + wwarning(_("could not process icon %s: %s"), path, RMessageForError(RErrorCode)); + } + RReleaseImage(icon); + wfree(path); +} + + static WMPixmap *makeTitledIcon(WMScreen * scr, WMPixmap * icon, char *title1, char *title2) { return WMRetainPixmap(icon); diff --git a/WPrefs.app/WPrefs.h b/WPrefs.app/WPrefs.h index 900afdcb..5100ef66 100644 --- a/WPrefs.app/WPrefs.h +++ b/WPrefs.app/WPrefs.h @@ -76,6 +76,13 @@ char *LocateImage(char *name); void SetButtonAlphaImage(WMScreen *scr, WMButton *bPtr, char *file, char *title1, char *title2); +/* Loads `file' into `icon_normal'. If `icon_greyed' is not NULL, + * combine `icon_normal' with some grey and then optionally with image + * `xis', and store it in `icon_greyed' (typically to produce a + * greyed-out, red-crossed version of `icon_normal') */ +void CreateImages(WMScreen *scr, RContext *rc, RImage *xis, char *file, + WMPixmap **icon_normal, WMPixmap **icon_greyed); + WMWindow *GetWindow(Panel *panel); /* manipulate the dictionary for the WindowMaker domain */ diff --git a/WPrefs.app/Workspace.c b/WPrefs.app/Workspace.c index 6ba26fcd..83cdccdc 100644 --- a/WPrefs.app/Workspace.c +++ b/WPrefs.app/Workspace.c @@ -71,40 +71,6 @@ static char *WSNamePositions[] = { "bottomright" }; -static void -createImages(WMScreen * scr, RContext * rc, RImage * xis, char *file, WMPixmap ** icon1, WMPixmap ** icon2) -{ - RImage *icon; - RColor gray = { 0xae, 0xaa, 0xae, 0 }; - - *icon1 = WMCreatePixmapFromFile(scr, file); - if (!*icon1) { - wwarning(_("could not load icon %s"), file); - if (icon2) - *icon2 = NULL; - return; - } - - if (!icon2) - return; - - icon = RLoadImage(rc, file, 0); - if (!icon) { - wwarning(_("could not load icon %s"), file); - *icon2 = NULL; - return; - } - RCombineImageWithColor(icon, &gray); - if (xis) { - RCombineImagesWithOpaqueness(icon, xis, 180); - if (!(*icon2 = WMCreatePixmapFromRImage(scr, icon, 127))) { - wwarning(_("could not process icon %s: %s"), file, RMessageForError(RErrorCode)); - *icon2 = NULL; - } - } - RReleaseImage(icon); -} - static void showData(_Panel * panel) { int i, idx; @@ -170,14 +136,11 @@ static void createPanel(Panel * p) WMResizeWidget(panel->cyclL, 60, 60); WMMoveWidget(panel->cyclL, 10, 15); WMSetLabelImagePosition(panel->cyclL, WIPImageOnly); - path = LocateImage(CYCLE_FILE); - if (path) { - createImages(scr, rc, xis, path, &icon1, NULL); - if (icon1) { - WMSetLabelImage(panel->cyclL, icon1); - WMReleasePixmap(icon1); - } - wfree(path); + CreateImages(scr, rc, xis, CYCLE_FILE, &icon1, NULL); + if (icon1) + { + WMSetLabelImage(panel->cyclL, icon1); + WMReleasePixmap(icon1); } /**/ panel->linkB = WMCreateSwitchButton(panel->navF); @@ -189,14 +152,11 @@ static void createPanel(Panel * p) WMResizeWidget(panel->linkL, 60, 40); WMMoveWidget(panel->linkL, 10, 80); WMSetLabelImagePosition(panel->linkL, WIPImageOnly); - path = LocateImage(DONT_LINK_FILE); - if (path) { - createImages(scr, rc, xis, path, &icon1, NULL); - if (icon1) { - WMSetLabelImage(panel->linkL, icon1); - WMReleasePixmap(icon1); - } - wfree(path); + CreateImages(scr, rc, xis, DONT_LINK_FILE, &icon1, NULL); + if (icon1) + { + WMSetLabelImage(panel->linkL, icon1); + WMReleasePixmap(icon1); } /**/ panel->newB = WMCreateSwitchButton(panel->navF); @@ -208,14 +168,11 @@ static void createPanel(Panel * p) WMResizeWidget(panel->newL, 60, 20); WMMoveWidget(panel->newL, 10, 130); WMSetLabelImagePosition(panel->newL, WIPImageOnly); - path = LocateImage(ADVANCE_FILE); - if (path) { - createImages(scr, rc, xis, path, &icon1, NULL); - if (icon1) { - WMSetLabelImage(panel->newL, icon1); - WMReleasePixmap(icon1); - } - wfree(path); + CreateImages(scr, rc, xis, ADVANCE_FILE, &icon1, NULL); + if (icon1) + { + WMSetLabelImage(panel->newL, icon1); + WMReleasePixmap(icon1); } /**/ panel->posL = WMCreateLabel(panel->navF); @@ -228,14 +185,11 @@ static void createPanel(Panel * p) WMResizeWidget(panel->posiL, 60, 40); WMMoveWidget(panel->posiL, 10, 160); WMSetLabelImagePosition(panel->posiL, WIPImageOnly); - path = LocateImage(WSNAME_FILE); - if (path) { - createImages(scr, rc, xis, path, &icon1, NULL); - if (icon1) { - WMSetLabelImage(panel->posiL, icon1); - WMReleasePixmap(icon1); - } - wfree(path); + CreateImages(scr, rc, xis, WSNAME_FILE, &icon1, NULL); + if (icon1) + { + WMSetLabelImage(panel->posiL, icon1); + WMReleasePixmap(icon1); } panel->posP = WMCreatePopUpButton(panel->navF); @@ -262,18 +216,14 @@ static void createPanel(Panel * p) WMResizeWidget(panel->dockB, 64, 64); WMMoveWidget(panel->dockB, 25, 35); WMSetButtonImagePosition(panel->dockB, WIPImageOnly); - path = LocateImage(DOCK_FILE); - if (path) { - createImages(scr, rc, xis, path, &icon1, &icon2); - if (icon2) { - WMSetButtonImage(panel->dockB, icon2); - WMReleasePixmap(icon2); - } - if (icon1) { - WMSetButtonAltImage(panel->dockB, icon1); - WMReleasePixmap(icon1); - } - wfree(path); + CreateImages(scr, rc, xis, DOCK_FILE, &icon1, &icon2); + if (icon2) { + WMSetButtonImage(panel->dockB, icon2); + WMReleasePixmap(icon2); + } + if (icon1) { + WMSetButtonAltImage(panel->dockB, icon1); + WMReleasePixmap(icon1); } WMSetBalloonTextForView(_("Disable/enable the application Dock (the\n" "vertical icon bar in the side of the screen)."), WMWidgetView(panel->dockB)); @@ -282,18 +232,14 @@ static void createPanel(Panel * p) WMResizeWidget(panel->clipB, 64, 64); WMMoveWidget(panel->clipB, 25, 120); WMSetButtonImagePosition(panel->clipB, WIPImageOnly); - path = LocateImage(CLIP_FILE); - if (path) { - createImages(scr, rc, xis, path, &icon1, &icon2); - if (icon2) { - WMSetButtonImage(panel->clipB, icon2); - WMReleasePixmap(icon2); - } - if (icon1) { - WMSetButtonAltImage(panel->clipB, icon1); - WMReleasePixmap(icon1); - } - wfree(path); + CreateImages(scr, rc, xis, CLIP_FILE, &icon1, &icon2); + if (icon2) { + WMSetButtonImage(panel->clipB, icon2); + WMReleasePixmap(icon2); + } + if (icon1) { + WMSetButtonAltImage(panel->clipB, icon1); + WMReleasePixmap(icon1); } WMSetBalloonTextForView(_("Disable/enable the Clip (that thing with\n" "a paper clip icon)."), WMWidgetView(panel->clipB)); -- 2.11.4.GIT