1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-22 14:08:06 +01:00

wmaker: Scale image to make them fit in the preview panel

Signed-off-by: Carlos R. Mafra <crmafra@gmail.com>
This commit is contained in:
Christophe CURIS
2014-04-06 00:11:57 +02:00
committed by Carlos R. Mafra
parent 050cae3bd2
commit 36159c614f
4 changed files with 27 additions and 5 deletions

View File

@@ -843,6 +843,11 @@ WMPixmap* WMCreateBlendedPixmapFromRImage(WMScreen *scrPtr, RImage *image,
WMPixmap* WMCreateBlendedPixmapFromFile(WMScreen *scrPtr, const char *fileName,
const RColor *color);
WMPixmap* WMCreateScaledBlendedPixmapFromFile(WMScreen *scrPtr, const char *fileName,
const RColor *color,
unsigned int width,
unsigned int height);
void WMDrawPixmap(WMPixmap *pixmap, Drawable d, int x, int y);
Pixmap WMGetPixmapXID(WMPixmap *pixmap);

View File

@@ -118,6 +118,12 @@ WMPixmap *WMCreateBlendedPixmapFromRImage(WMScreen * scrPtr, RImage * image, con
}
WMPixmap *WMCreateBlendedPixmapFromFile(WMScreen * scrPtr, const char *fileName, const RColor * color)
{
return WMCreateScaledBlendedPixmapFromFile(scrPtr, fileName, color, 0, 0);
}
WMPixmap *WMCreateScaledBlendedPixmapFromFile(WMScreen *scrPtr, const char *fileName, const RColor *color,
unsigned int width, unsigned int height)
{
WMPixmap *pixPtr;
RImage *image;
@@ -126,10 +132,20 @@ WMPixmap *WMCreateBlendedPixmapFromFile(WMScreen * scrPtr, const char *fileName,
if (!image)
return NULL;
/* scale it if needed to fit in the specified box */
if ((width > 0) && (height > 0) && ((image->width > width) || (image->height > height))) {
RImage *tmp;
tmp = image;
if (image->width > image->height)
image = RScaleImage(tmp, width, image->height * height / image->width);
else
image = RScaleImage(tmp, image->width * width / image->height, height);
RReleaseImage(tmp);
}
RCombineImageWithColor(image, color);
pixPtr = WMCreatePixmapFromRImage(scrPtr, image, 0);
RReleaseImage(image);
return pixPtr;

View File

@@ -619,7 +619,8 @@ static void setViewedImage(IconPanel *panel, const char *file)
color.green = 0xaa;
color.blue = 0xae;
color.alpha = 0;
pixmap = WMCreateBlendedPixmapFromFile(WMWidgetScreen(panel->win), file, &color);
pixmap = WMCreateScaledBlendedPixmapFromFile(WMWidgetScreen(panel->win), file, &color, 75, 75);
if (!pixmap) {
WMSetButtonEnabled(panel->okButton, False);
@@ -742,7 +743,7 @@ static void drawIconProc(WMList * lPtr, int index, Drawable d, char *text, int s
color.blue = WMBlueComponentOfColor(back) >> 8;
color.alpha = WMGetColorAlpha(back) >> 8;
pixmap = WMCreateBlendedPixmapFromFile(wmscr, file, &color);
pixmap = WMCreateScaledBlendedPixmapFromFile(wmscr, file, &color, width - 2, height - 2);
wfree(file);
if (!pixmap) {

View File

@@ -103,7 +103,7 @@ static void updateSettingsPanelIcon(AppSettingsPanel * panel)
color.green = 0xaa;
color.blue = 0xae;
color.alpha = 0;
pixmap = WMCreateBlendedPixmapFromFile(WMWidgetScreen(panel->win), path, &color);
pixmap = WMCreateScaledBlendedPixmapFromFile(WMWidgetScreen(panel->win), path, &color, 64, 64);
if (!pixmap) {
WMSetLabelImage(panel->iconLabel, NULL);
} else {