added TRANSPARENT flag for BITMAP fields

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@3881 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
kichik 2005-01-21 19:12:47 +00:00
parent 785e54440f
commit 31542c6ea4
3 changed files with 75 additions and 0 deletions

View file

@ -101,6 +101,7 @@ char *WINAPI STRDUP(const char *c)
// LBS_MULTIPLESEL 0x00000008 // LISTBOX // LBS_MULTIPLESEL 0x00000008 // LISTBOX
#define FLAG_READONLY 0x00000010 // TEXT/FILEREQUEST/DIRREQUEST #define FLAG_READONLY 0x00000010 // TEXT/FILEREQUEST/DIRREQUEST
// BS_LEFTTEXT 0x00000020 // CHECKBOX/RADIOBUTTON // BS_LEFTTEXT 0x00000020 // CHECKBOX/RADIOBUTTON
#define TRANSPARENT_BMP 0x00000020 // BITMAP
#define FLAG_PASSWORD 0x00000040 // TEXT/FILEREQUEST/DIRREQUEST #define FLAG_PASSWORD 0x00000040 // TEXT/FILEREQUEST/DIRREQUEST
#define FLAG_ONLYNUMBERS 0x00000080 // TEXT/FILEREQUEST/DIRREQUEST #define FLAG_ONLYNUMBERS 0x00000080 // TEXT/FILEREQUEST/DIRREQUEST
#define FLAG_MULTILINE 0x00000100 // TEXT/FILEREQUEST/DIRREQUEST #define FLAG_MULTILINE 0x00000100 // TEXT/FILEREQUEST/DIRREQUEST
@ -476,6 +477,7 @@ int WINAPI ReadSettings(void) {
{ "HSCROLL", WS_HSCROLL }, { "HSCROLL", WS_HSCROLL },
{ "VSCROLL", WS_VSCROLL }, { "VSCROLL", WS_VSCROLL },
{ "DISABLED", WS_DISABLED }, { "DISABLED", WS_DISABLED },
{ "TRANSPARENT", TRANSPARENT_BMP },
{ NULL, 0 } { NULL, 0 }
}; };
FieldType *pField = pFields + nIdx; FieldType *pField = pFields + nIdx;
@ -1191,6 +1193,7 @@ int WINAPI createCfgDlg()
{ {
WPARAM nImageType = pField->nType == FIELD_BITMAP ? IMAGE_BITMAP : IMAGE_ICON; WPARAM nImageType = pField->nType == FIELD_BITMAP ? IMAGE_BITMAP : IMAGE_ICON;
LPARAM nImage = 0; LPARAM nImage = 0;
if (pField->pszText) { if (pField->pszText) {
pField->hImage = LoadImage( pField->hImage = LoadImage(
m_hInstance, m_hInstance,
@ -1208,12 +1211,76 @@ int WINAPI createCfgDlg()
} }
else else
nImage = (LPARAM)LoadIcon(GetModuleHandle(0), MAKEINTRESOURCE(103)); nImage = (LPARAM)LoadIcon(GetModuleHandle(0), MAKEINTRESOURCE(103));
if ((pField->nFlags & TRANSPARENT_BMP) && nImageType == IMAGE_BITMAP)
{
// based on AdvSplash's SetTransparentRegion
BITMAP bm;
HBITMAP hBitmap = (HBITMAP) nImage;
if (GetObject(hBitmap, sizeof(bm), &bm))
{
HDC dc;
int x, y;
HRGN region, cutrgn;
BITMAPINFO bmi;
int size = bm.bmWidth * bm.bmHeight * sizeof(int);
int *bmp = (int *) MALLOC(size);
if (bmp)
{
bmi.bmiHeader.biBitCount = 32;
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biHeight = bm.bmHeight;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = bm.bmWidth;
bmi.bmiHeader.biClrUsed = 0;
bmi.bmiHeader.biClrImportant = 0;
dc = CreateCompatibleDC(NULL);
SelectObject(dc, hBitmap);
x = GetDIBits(dc, hBitmap, 0, bm.bmHeight, bmp, &bmi, DIB_RGB_COLORS);
region = CreateRectRgn(0, 0, bm.bmWidth, bm.bmHeight);
int keycolor = *bmp & 0xFFFFFF;
// Search for transparent pixels
for (y = bm.bmHeight - 1; y >= 0; y--) {
for (x = 0; x < bm.bmWidth;) {
if ((*bmp & 0xFFFFFF) == keycolor) {
int j = x;
while ((x < bm.bmWidth) && ((*bmp & 0xFFFFFF) == keycolor)) {
bmp++, x++;
}
// Cut transparent pixels from the original region
cutrgn = CreateRectRgn(j, y, x, y + 1);
CombineRgn(region, region, cutrgn, RGN_XOR);
DeleteObject(cutrgn);
} else {
bmp++, x++;
}
}
}
// Set resulting region.
SetWindowRgn(hwCtrl, region, TRUE);
DeleteObject(region);
DeleteObject(dc);
FREE(bmp);
}
}
}
mySendMessage( mySendMessage(
hwCtrl, hwCtrl,
STM_SETIMAGE, STM_SETIMAGE,
nImageType, nImageType,
nImage nImage
); );
if (pField->nType == FIELD_BITMAP) if (pField->nType == FIELD_BITMAP)
{ {
// Centre the image in the requested space. // Centre the image in the requested space.
@ -1226,6 +1293,7 @@ int WINAPI createCfgDlg()
SetWindowPos(hwCtrl, NULL, bmp_rect.left, bmp_rect.top, 0, 0, SetWindowPos(hwCtrl, NULL, bmp_rect.left, bmp_rect.top, 0, 0,
SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER); SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER);
} }
break; break;
} }

View file

@ -492,6 +492,13 @@ resize the image to the size of the control. Also useful to support
custom DPI settings. Without this, the image will be centered custom DPI settings. Without this, the image will be centered
within the specified area.</td> within the specified area.</td>
</tr> </tr>
<td class="righttable">TRANSPARENT</td>
<td class="righttable">Used by "<em>Bitmap</em>" controls. Hides
every pixel with the same color as of the top left pixel. This
allows to see-through to controls behind it. This flag doesn't
work well with a combination of the RESIZETOFIT flag and bitmaps
with more than 256 colors.</td>
</tr>
<tr> <tr>
<td class="righttable">GROUP</td> <td class="righttable">GROUP</td>
<td class="righttable">Add this flag to the first control of a <td class="righttable">Add this flag to the first control of a

Binary file not shown.