1
0
mirror of https://github.com/gryf/wmaker.git synced 2026-01-09 07:14:18 +01:00

WPrefs: consolidate the 2 createImages static functions into a global one

This commit is contained in:
Daniel Déchelotte
2013-04-12 01:42:31 +02:00
committed by Carlos R. Mafra
parent 9548c42b71
commit 4b44020488
4 changed files with 100 additions and 129 deletions

View File

@@ -111,43 +111,6 @@ static void updateLabel(WMWidget *self, void *data)
WMSetLabelText(panel->dithL, buffer); 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) static void createPanel(Panel *p)
{ {
_Panel *panel = (_Panel *) p; _Panel *panel = (_Panel *) p;
@@ -342,7 +305,7 @@ static void createPanel(Panel *p)
WMSetButtonFont(panel->animB, font); WMSetButtonFont(panel->animB, font);
WMSetButtonText(panel->animB, _("Animations")); WMSetButtonText(panel->animB, _("Animations"));
WMSetButtonImagePosition(panel->animB, WIPAbove); WMSetButtonImagePosition(panel->animB, WIPAbove);
createImages(scr, rc, xis, ANIM_IMAGE, &altIcon, &icon); CreateImages(scr, rc, xis, ANIM_IMAGE, &altIcon, &icon);
if (icon) { if (icon) {
WMSetButtonImage(panel->animB, icon); WMSetButtonImage(panel->animB, icon);
WMReleasePixmap(icon); WMReleasePixmap(icon);
@@ -360,7 +323,7 @@ static void createPanel(Panel *p)
WMSetButtonFont(panel->supB, font); WMSetButtonFont(panel->supB, font);
WMSetButtonText(panel->supB, _("Superfluous")); WMSetButtonText(panel->supB, _("Superfluous"));
WMSetButtonImagePosition(panel->supB, WIPAbove); WMSetButtonImagePosition(panel->supB, WIPAbove);
createImages(scr, rc, xis, SUPERF_IMAGE, &altIcon, &icon); CreateImages(scr, rc, xis, SUPERF_IMAGE, &altIcon, &icon);
if (icon) { if (icon) {
WMSetButtonImage(panel->supB, icon); WMSetButtonImage(panel->supB, icon);
WMReleasePixmap(icon); WMReleasePixmap(icon);

View File

@@ -392,6 +392,61 @@ char *LocateImage(char *name)
return path; 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) static WMPixmap *makeTitledIcon(WMScreen * scr, WMPixmap * icon, char *title1, char *title2)
{ {
return WMRetainPixmap(icon); return WMRetainPixmap(icon);

View File

@@ -76,6 +76,13 @@ char *LocateImage(char *name);
void SetButtonAlphaImage(WMScreen *scr, WMButton *bPtr, char *file, void SetButtonAlphaImage(WMScreen *scr, WMButton *bPtr, char *file,
char *title1, char *title2); 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); WMWindow *GetWindow(Panel *panel);
/* manipulate the dictionary for the WindowMaker domain */ /* manipulate the dictionary for the WindowMaker domain */

View File

@@ -71,40 +71,6 @@ static char *WSNamePositions[] = {
"bottomright" "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) static void showData(_Panel * panel)
{ {
int i, idx; int i, idx;
@@ -170,14 +136,11 @@ static void createPanel(Panel * p)
WMResizeWidget(panel->cyclL, 60, 60); WMResizeWidget(panel->cyclL, 60, 60);
WMMoveWidget(panel->cyclL, 10, 15); WMMoveWidget(panel->cyclL, 10, 15);
WMSetLabelImagePosition(panel->cyclL, WIPImageOnly); WMSetLabelImagePosition(panel->cyclL, WIPImageOnly);
path = LocateImage(CYCLE_FILE); CreateImages(scr, rc, xis, CYCLE_FILE, &icon1, NULL);
if (path) { if (icon1)
createImages(scr, rc, xis, path, &icon1, NULL); {
if (icon1) { WMSetLabelImage(panel->cyclL, icon1);
WMSetLabelImage(panel->cyclL, icon1); WMReleasePixmap(icon1);
WMReleasePixmap(icon1);
}
wfree(path);
} }
/**/ panel->linkB = WMCreateSwitchButton(panel->navF); /**/ panel->linkB = WMCreateSwitchButton(panel->navF);
@@ -189,14 +152,11 @@ static void createPanel(Panel * p)
WMResizeWidget(panel->linkL, 60, 40); WMResizeWidget(panel->linkL, 60, 40);
WMMoveWidget(panel->linkL, 10, 80); WMMoveWidget(panel->linkL, 10, 80);
WMSetLabelImagePosition(panel->linkL, WIPImageOnly); WMSetLabelImagePosition(panel->linkL, WIPImageOnly);
path = LocateImage(DONT_LINK_FILE); CreateImages(scr, rc, xis, DONT_LINK_FILE, &icon1, NULL);
if (path) { if (icon1)
createImages(scr, rc, xis, path, &icon1, NULL); {
if (icon1) { WMSetLabelImage(panel->linkL, icon1);
WMSetLabelImage(panel->linkL, icon1); WMReleasePixmap(icon1);
WMReleasePixmap(icon1);
}
wfree(path);
} }
/**/ panel->newB = WMCreateSwitchButton(panel->navF); /**/ panel->newB = WMCreateSwitchButton(panel->navF);
@@ -208,14 +168,11 @@ static void createPanel(Panel * p)
WMResizeWidget(panel->newL, 60, 20); WMResizeWidget(panel->newL, 60, 20);
WMMoveWidget(panel->newL, 10, 130); WMMoveWidget(panel->newL, 10, 130);
WMSetLabelImagePosition(panel->newL, WIPImageOnly); WMSetLabelImagePosition(panel->newL, WIPImageOnly);
path = LocateImage(ADVANCE_FILE); CreateImages(scr, rc, xis, ADVANCE_FILE, &icon1, NULL);
if (path) { if (icon1)
createImages(scr, rc, xis, path, &icon1, NULL); {
if (icon1) { WMSetLabelImage(panel->newL, icon1);
WMSetLabelImage(panel->newL, icon1); WMReleasePixmap(icon1);
WMReleasePixmap(icon1);
}
wfree(path);
} }
/**/ panel->posL = WMCreateLabel(panel->navF); /**/ panel->posL = WMCreateLabel(panel->navF);
@@ -228,14 +185,11 @@ static void createPanel(Panel * p)
WMResizeWidget(panel->posiL, 60, 40); WMResizeWidget(panel->posiL, 60, 40);
WMMoveWidget(panel->posiL, 10, 160); WMMoveWidget(panel->posiL, 10, 160);
WMSetLabelImagePosition(panel->posiL, WIPImageOnly); WMSetLabelImagePosition(panel->posiL, WIPImageOnly);
path = LocateImage(WSNAME_FILE); CreateImages(scr, rc, xis, WSNAME_FILE, &icon1, NULL);
if (path) { if (icon1)
createImages(scr, rc, xis, path, &icon1, NULL); {
if (icon1) { WMSetLabelImage(panel->posiL, icon1);
WMSetLabelImage(panel->posiL, icon1); WMReleasePixmap(icon1);
WMReleasePixmap(icon1);
}
wfree(path);
} }
panel->posP = WMCreatePopUpButton(panel->navF); panel->posP = WMCreatePopUpButton(panel->navF);
@@ -262,18 +216,14 @@ static void createPanel(Panel * p)
WMResizeWidget(panel->dockB, 64, 64); WMResizeWidget(panel->dockB, 64, 64);
WMMoveWidget(panel->dockB, 25, 35); WMMoveWidget(panel->dockB, 25, 35);
WMSetButtonImagePosition(panel->dockB, WIPImageOnly); WMSetButtonImagePosition(panel->dockB, WIPImageOnly);
path = LocateImage(DOCK_FILE); CreateImages(scr, rc, xis, DOCK_FILE, &icon1, &icon2);
if (path) { if (icon2) {
createImages(scr, rc, xis, path, &icon1, &icon2); WMSetButtonImage(panel->dockB, icon2);
if (icon2) { WMReleasePixmap(icon2);
WMSetButtonImage(panel->dockB, icon2); }
WMReleasePixmap(icon2); if (icon1) {
} WMSetButtonAltImage(panel->dockB, icon1);
if (icon1) { WMReleasePixmap(icon1);
WMSetButtonAltImage(panel->dockB, icon1);
WMReleasePixmap(icon1);
}
wfree(path);
} }
WMSetBalloonTextForView(_("Disable/enable the application Dock (the\n" WMSetBalloonTextForView(_("Disable/enable the application Dock (the\n"
"vertical icon bar in the side of the screen)."), WMWidgetView(panel->dockB)); "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); WMResizeWidget(panel->clipB, 64, 64);
WMMoveWidget(panel->clipB, 25, 120); WMMoveWidget(panel->clipB, 25, 120);
WMSetButtonImagePosition(panel->clipB, WIPImageOnly); WMSetButtonImagePosition(panel->clipB, WIPImageOnly);
path = LocateImage(CLIP_FILE); CreateImages(scr, rc, xis, CLIP_FILE, &icon1, &icon2);
if (path) { if (icon2) {
createImages(scr, rc, xis, path, &icon1, &icon2); WMSetButtonImage(panel->clipB, icon2);
if (icon2) { WMReleasePixmap(icon2);
WMSetButtonImage(panel->clipB, icon2); }
WMReleasePixmap(icon2); if (icon1) {
} WMSetButtonAltImage(panel->clipB, icon1);
if (icon1) { WMReleasePixmap(icon1);
WMSetButtonAltImage(panel->clipB, icon1);
WMReleasePixmap(icon1);
}
wfree(path);
} }
WMSetBalloonTextForView(_("Disable/enable the Clip (that thing with\n" WMSetBalloonTextForView(_("Disable/enable the Clip (that thing with\n"
"a paper clip icon)."), WMWidgetView(panel->clipB)); "a paper clip icon)."), WMWidgetView(panel->clipB));