From 86eea20c7d00dfc223cf13217cf4dfc57202965e Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 9 Jul 2015 17:56:47 +0000 Subject: - various icon definition quirks; - code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@14520 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/AutoShutdown/src/utils.cpp | 17 ---- plugins/AutoShutdown/src/utils.h | 1 - plugins/CSList/src/cslist.cpp | 1 - plugins/Clist_modern/src/modern_clc.cpp | 1 - plugins/Clist_modern/src/modern_clui.cpp | 1 - plugins/FingerprintNG/src/fingerprint.cpp | 1 - plugins/HistoryStats/src/mu_common.cpp | 19 +---- plugins/HistoryStats/src/mu_common.h | 3 +- plugins/Popup/src/notifications.cpp | 1 - plugins/QuickMessages/src/Utils.cpp | 1 - plugins/UserInfoEx/src/Flags/svc_flagsicons.cpp | 107 +++++++----------------- plugins/UserInfoEx/src/classPsTreeItem.cpp | 2 - plugins/WhenWasIt/src/icons.cpp | 1 - protocols/MRA/src/MraIcons.cpp | 11 ++- 14 files changed, 37 insertions(+), 130 deletions(-) diff --git a/plugins/AutoShutdown/src/utils.cpp b/plugins/AutoShutdown/src/utils.cpp index 7fc7c6720a..d866eadd83 100644 --- a/plugins/AutoShutdown/src/utils.cpp +++ b/plugins/AutoShutdown/src/utils.cpp @@ -204,23 +204,6 @@ BOOL GetFormatedDateTime(TCHAR *pszOut,int nSize,time_t timestamp,BOOL fShowDate /************************* Skin ***********************************/ -HANDLE IcoLib_AddIconRes(const char *pszDbName,const TCHAR *pszSection,const TCHAR *pszDesc,HINSTANCE hInst,WORD idRes,BOOL fLarge) -{ - TCHAR szFileName[MAX_PATH]; - GetModuleFileName(hInst,szFileName,_countof(szFileName)); - - SKINICONDESC sid = { 0 }; - sid.pszName = (char*)pszDbName; - sid.section.t = (TCHAR*)pszSection; - sid.description.t = (TCHAR*)pszDesc; - sid.defaultFile.t = szFileName; - sid.iDefaultIndex = -idRes; - sid.cx = GetSystemMetrics(fLarge?SM_CXICON:SM_CXSMICON); - sid.cy = GetSystemMetrics(fLarge?SM_CYICON:SM_CYSMICON); - sid.flags = SIDF_SORTED | SIDF_ALL_TCHAR; - return IcoLib_AddIcon(&sid); -} - void AddHotkey() { HOTKEYDESC hkd = {0}; diff --git a/plugins/AutoShutdown/src/utils.h b/plugins/AutoShutdown/src/utils.h index 1c87078c92..02edb32dda 100644 --- a/plugins/AutoShutdown/src/utils.h +++ b/plugins/AutoShutdown/src/utils.h @@ -35,5 +35,4 @@ BOOL GetFormatedCountdown(TCHAR *pszOut,int nSize,time_t countdown); BOOL GetFormatedDateTime(TCHAR *pszOut,int nSize,time_t timestamp,BOOL fShowDateEvenToday); /* Skin */ -HANDLE IcoLib_AddIconRes(const char *pszDbName,const TCHAR *pszSection,const TCHAR *pszDesc,HINSTANCE hInst,WORD idRes,BOOL fLarge); void AddHotkey(); diff --git a/plugins/CSList/src/cslist.cpp b/plugins/CSList/src/cslist.cpp index 442d2ae86d..4ecc87bb24 100644 --- a/plugins/CSList/src/cslist.cpp +++ b/plugins/CSList/src/cslist.cpp @@ -130,7 +130,6 @@ extern "C" __declspec(dllexport) int Load() SKINICONDESC sid = { 0 }; sid.defaultFile.t = tszFile; sid.flags = SIDF_ALL_TCHAR; - sid.cx = sid.cy = 16; sid.section.t = _T(MODULENAME); for (int i = 0; i < _countof(forms); i++) { diff --git a/plugins/Clist_modern/src/modern_clc.cpp b/plugins/Clist_modern/src/modern_clc.cpp index 754055f7dd..2f31dc6777 100644 --- a/plugins/Clist_modern/src/modern_clc.cpp +++ b/plugins/Clist_modern/src/modern_clc.cpp @@ -1638,7 +1638,6 @@ static int clcHookModulesLoaded(WPARAM, LPARAM) GetModuleFileName(g_hInst, szMyPath, _countof(szMyPath)); SKINICONDESC sid = { 0 }; - sid.cx = sid.cy = 16; sid.defaultFile.t = szMyPath; sid.flags = SIDF_PATH_TCHAR; diff --git a/plugins/Clist_modern/src/modern_clui.cpp b/plugins/Clist_modern/src/modern_clui.cpp index 74fd4887ad..019e95db1a 100644 --- a/plugins/Clist_modern/src/modern_clui.cpp +++ b/plugins/Clist_modern/src/modern_clui.cpp @@ -1537,7 +1537,6 @@ HANDLE RegisterIcolibIconHandle(char *szIcoID, char *szSectionName, char *szDesc TCHAR fileFull[MAX_PATH] = { 0 }; SKINICONDESC sid = { 0 }; - sid.cx = sid.cy = 16; sid.section.a = szSectionName; sid.pszName = szIcoID; sid.flags |= SIDF_PATH_TCHAR; diff --git a/plugins/FingerprintNG/src/fingerprint.cpp b/plugins/FingerprintNG/src/fingerprint.cpp index fac865b3f9..096c9ff9ba 100644 --- a/plugins/FingerprintNG/src/fingerprint.cpp +++ b/plugins/FingerprintNG/src/fingerprint.cpp @@ -85,7 +85,6 @@ void __fastcall Prepare(KN_FP_MASK* mask, bool bEnable) sid.description.t = mask->szClientDescription; sid.defaultFile.t = destfile; sid.iDefaultIndex = -mask->iIconIndex; - sid.cx = sid.cy = 16; mask->hIcolibItem = IcoLib_AddIcon(&sid); } diff --git a/plugins/HistoryStats/src/mu_common.cpp b/plugins/HistoryStats/src/mu_common.cpp index f380b2a35e..812e0644e7 100644 --- a/plugins/HistoryStats/src/mu_common.cpp +++ b/plugins/HistoryStats/src/mu_common.cpp @@ -90,7 +90,7 @@ namespace mu return true; } - void addIcon(const TCHAR* szSection, const TCHAR* szDescription, const char* szIconName, const char* szDefaultFile, int iDefaultIndex, int cx /* = 16 */, int cy /* = 16 */) + void addIcon(const TCHAR* szSection, const TCHAR* szDescription, const char* szIconName, const char* szDefaultFile, int iDefaultIndex) { SKINICONDESC sid = { 0 }; sid.section.t = const_cast(szSection); @@ -98,23 +98,6 @@ namespace mu sid.pszName = const_cast(szIconName); sid.defaultFile.a = const_cast(szDefaultFile); sid.iDefaultIndex = iDefaultIndex; - sid.cx = cx; - sid.cy = cy; - sid.flags = SIDF_TCHAR; - IcoLib_AddIcon(&sid); - } - - void addIcon(const TCHAR* szSection, const TCHAR* szDescription, const char* szIconName, HICON hDefaultIcon, int cx /* = 16 */, int cy /* = 16 */) - { - SKINICONDESC sid = { 0 }; - sid.section.t = const_cast(szSection); - sid.description.t = const_cast(szDescription); - sid.pszName = const_cast(szIconName); - sid.defaultFile.a = NULL; - sid.iDefaultIndex = 0; - sid.hDefaultIcon = hDefaultIcon; - sid.cx = cx; - sid.cy = cy; sid.flags = SIDF_TCHAR; IcoLib_AddIcon(&sid); } diff --git a/plugins/HistoryStats/src/mu_common.h b/plugins/HistoryStats/src/mu_common.h index 6769414b0b..98bab3800e 100644 --- a/plugins/HistoryStats/src/mu_common.h +++ b/plugins/HistoryStats/src/mu_common.h @@ -45,8 +45,7 @@ namespace mu namespace icolib { bool _available(); - void addIcon(const TCHAR* szSection, const TCHAR* szDescription, const char* szIconName, const char* szDefaultFile, int iDefaultIndex, int cx = 16, int cy = 16); - void addIcon(const TCHAR* szSection, const TCHAR* szDescription, const char* szIconName, HICON hDefaultIcon, int cx = 16, int cy = 16); + void addIcon(const TCHAR* szSection, const TCHAR* szDescription, const char* szIconName, const char* szDefaultFile, int iDefaultIndex); HICON getIcon(const char* szIconName); } diff --git a/plugins/Popup/src/notifications.cpp b/plugins/Popup/src/notifications.cpp index a1e25be5f6..b42c5ac902 100644 --- a/plugins/Popup/src/notifications.cpp +++ b/plugins/Popup/src/notifications.cpp @@ -213,7 +213,6 @@ HANDLE RegisterNotification(POPUPNOTIFICATION *notification) SKINICONDESC sid = { 0 }; sid.section.a = section; - sid.cx = sid.cy = 16; sid.pszName = setting; sid.description.a = notification->lpzName; sid.hDefaultIcon = notification->lchIcon; diff --git a/plugins/QuickMessages/src/Utils.cpp b/plugins/QuickMessages/src/Utils.cpp index 23777ee2d2..17ce160dac 100644 --- a/plugins/QuickMessages/src/Utils.cpp +++ b/plugins/QuickMessages/src/Utils.cpp @@ -235,7 +235,6 @@ static HANDLE AddIcon(char* szIcoName) SKINICONDESC sid = { 0 }; sid.flags = SIDF_PATH_TCHAR; sid.section.a = "Quick Messages"; - sid.cx = sid.cy = 16; sid.description.a = szIcoName; sid.pszName = szIcoName; sid.defaultFile.t = tszPath; diff --git a/plugins/UserInfoEx/src/Flags/svc_flagsicons.cpp b/plugins/UserInfoEx/src/Flags/svc_flagsicons.cpp index 9710ee4f73..edc6e1718c 100644 --- a/plugins/UserInfoEx/src/Flags/svc_flagsicons.cpp +++ b/plugins/UserInfoEx/src/Flags/svc_flagsicons.cpp @@ -283,84 +283,41 @@ static INT_PTR ServiceCreateMergedFlagIcon(WPARAM wParam,LPARAM lParam) void InitIcons() { - /* all those flag icons storing in a large 24bit opaque bitmap to reduce file size */ + // all those flag icons storing in a large 24bit opaque bitmap to reduce file size FIBITMAP *dib = LoadResource(IDB_FLAGSPNG, _T("PNG")); if (dib == NULL) return; - UINT bit = ILC_COLOR32, bitDest = ILC_COLOR32; + if (FIP->FI_GetBPP(dib) != ILC_COLOR32) + if (NULL == (dib = ConvertTo(dib, ILC_COLOR32, 0))) + return; - if (FIP->FI_GetBPP(dib) != bit) - if (NULL == (dib = ConvertTo(dib, bit, 0))) - return; - - //create new dib - FIBITMAP *dib_ico = FIP->FI_Allocate(FIP->FI_GetWidth(dib), 16, bit, 0, 0, 0); + // create new dib + FIBITMAP *dib_ico = FIP->FI_Allocate(FIP->FI_GetWidth(dib), 16, ILC_COLOR32, 0, 0, 0); if (dib_ico == NULL) { FIP->FI_Unload(dib); return; } -/* - // res = FIP->FI_IsTransparent(dib_ico); - if (bit < 32) { - //disable transparency - FIP->FI_SetTransparent(dib, FALSE); - FIP->FI_SetTransparent(dib_ico, FALSE); - } -*/ - UINT h = FIP->FI_GetHeight(dib_ico); UINT w = FIP->FI_GetWidth(dib_ico); UINT t = ((h - FIP->FI_GetHeight(dib)) / 2) + 1; UINT b = t + FIP->FI_GetHeight(dib); - HBITMAP hbmMask = 0; - //copy dib to new dib_ico (centered) + // copy dib to new dib_ico (centered) if (FIP->FI_Paste(dib_ico, dib, 0, t - 1, 255 + 1)) { FIP->FI_Unload(dib); dib = NULL; - switch (bitDest) { - case 8: - case 16: - case 24: - {//transparency by 1bit monocrome icon mask (for bit < 32) - FIBITMAP *dib_mask; - if (NULL == (dib_mask = FIP->FI_Allocate(w, h, 1, 0, 0, 0))) { - FIP->FI_Unload(dib_ico); - return; - } - for(unsigned y = 0; y < h; y++) - for(unsigned x = 0; x < w; x++) { - BYTE value = ((y= b) ? 0 : 1); - FIP->FI_SetPixelIndex(dib_mask, x, y, &value); - } - hbmMask = FIP->FI_CreateHBITMAPFromDIB(dib_mask); - FIP->FI_Unload(dib_mask); - - //convert to target resolution - if (!hbmMask || !(dib_ico = ConvertTo(dib_ico, bitDest, 0))) { - FIP->FI_Unload(dib_ico); - if (hbmMask) DeleteObject(hbmMask); - return; - } - } break; - case 32: - {//transparency by alpha schannel - //Calculate the number of bytes per pixel (3 for 24-bit or 4 for 32-bit) - int bytespp = FIP->FI_GetLine(dib_ico) / w; - //set alpha schannel - for(unsigned y = 0; y < h; y++) { - BYTE *bits = FIP->FI_GetScanLine(dib_ico, y); - for(unsigned x = 0; x < w; x++) { - bits[FI_RGBA_ALPHA] = (y=b)? 0:255; - // jump to next pixel - bits += bytespp; - } - } - } break; - default: - FIP->FI_Unload(dib_ico); - return; + + // Calculate the number of bytes per pixel (3 for 24-bit or 4 for 32-bit) + int bytespp = FIP->FI_GetLine(dib_ico) / w; + // set alpha schannel + for (unsigned y = 0; y < h; y++) { + BYTE *bits = FIP->FI_GetScanLine(dib_ico, y); + for (unsigned x = 0; x < w; x++) { + bits[FI_RGBA_ALPHA] = (y < t || y >= b) ? 0 : 255; + // jump to next pixel + bits += bytespp; + } } } else { @@ -371,17 +328,14 @@ void InitIcons() HBITMAP hScrBM = FIP->FI_CreateHBITMAPFromDIB(dib_ico); FIP->FI_Unload(dib_ico); - - if (!hScrBM) { - DeleteObject(hbmMask); + if (!hScrBM) return; - } - //create ImageList - HIMAGELIST himl = ImageList_Create(16, 16, bitDest | ILC_MASK, 0, nCountriesCount); - ImageList_Add(himl, hScrBM, hbmMask); - DeleteObject(hScrBM); hScrBM = NULL; - DeleteObject(hbmMask); hbmMask = NULL; + // create ImageList + HIMAGELIST himl = ImageList_Create(16, 16, ILC_COLOR32 | ILC_MASK, 0, nCountriesCount); + ImageList_Add(himl, hScrBM, NULL); + DeleteObject(hScrBM); + hScrBM = NULL; if (himl != NULL) { phIconHandles = (HANDLE*)mir_alloc(nCountriesCount*sizeof(HANDLE)); @@ -389,9 +343,7 @@ void InitIcons() char szId[20]; SKINICONDESC sid = { 0 }; sid.section.t = LPGENT("Country flags"); - sid.pszName = szId; // name to refer to icon when playing and in db - sid.cx = GetSystemMetrics(SM_CXSMICON); - sid.cy = GetSystemMetrics(SM_CYSMICON); + sid.pszName = szId; // name to refer to icon when playing and in db sid.flags = SIDF_SORTED | SIDF_TCHAR; for (int i=0; i < nCountriesCount; i++) { @@ -404,14 +356,15 @@ void InitIcons() index = CountryNumberToIndex(countries[i].id); phIconHandles[index] = IcoLib_AddIcon(&sid); - if (sid.hDefaultIcon!=NULL) DestroyIcon(sid.hDefaultIcon); + if (sid.hDefaultIcon != NULL) + DestroyIcon(sid.hDefaultIcon); mir_free(sid.description.t); sid.description.t = NULL; } } ImageList_Destroy(himl); } - /* create services */ + // create services CreateServiceFunction(MS_FLAGS_LOADFLAGICON,ServiceLoadFlagIcon); CreateServiceFunction(MS_FLAGS_CREATEMERGEDFLAGICON,ServiceCreateMergedFlagIcon); } @@ -419,10 +372,10 @@ void InitIcons() void UninitIcons() { for(int i=0;i