Fix 2 panels' toolbar icons display issue under high DPI

Improve Function list & Folder as Workspace toolbar icons display under high DPI.
This commit is contained in:
Don Ho 2021-07-30 15:59:27 +02:00
parent 2bb40b1ab5
commit 19f40fdeae
9 changed files with 35 additions and 35 deletions

View File

@ -368,8 +368,6 @@ IDI_FUNCLIST_LEAF BITMAP "icons/funcList_leaf.bmp"
IDI_FUNCLIST_SORTBUTTON BITMAP "icons/funclstSort.bmp"
IDI_FUNCLIST_RELOADBUTTON BITMAP "icons/funclstReload.bmp"
IDI_FUNCLIST_SORTBUTTON2 BITMAP "icons/funclstSort2.bmp"
IDI_FUNCLIST_RELOADBUTTON2 BITMAP "icons/funclstReload2.bmp"
IDI_FUNCLIST_SORTBUTTON_DM BITMAP "icons/darkMode/panels/funclstSort.bmp"
IDI_FUNCLIST_RELOADBUTTON_DM BITMAP "icons/darkMode/panels/funclstReload.bmp"

View File

@ -108,15 +108,23 @@ INT_PTR CALLBACK FileBrowser::run_dlgProc(UINT message, WPARAM wParam, LPARAM lP
NppDarkMode::setDarkTooltips(_hToolbarMenu, NppDarkMode::ToolTipsType::toolbar);
NppDarkMode::setDarkLineAbovePanelToolbar(_hToolbarMenu);
TBBUTTON tbButtons[3];
// Add the bmap image into toolbar's imagelist
TBADDBITMAP addbmp = { _hInst, 0 };
addbmp.nID = NppDarkMode::isEnabled() ? IDI_FB_SELECTCURRENTFILE_DM : IDI_FB_SELECTCURRENTFILE;
::SendMessage(_hToolbarMenu, TB_ADDBITMAP, 1, reinterpret_cast<LPARAM>(&addbmp));
addbmp.nID = NppDarkMode::isEnabled() ? IDI_FB_FOLDALL_DM : IDI_FB_FOLDALL;
::SendMessage(_hToolbarMenu, TB_ADDBITMAP, 1, reinterpret_cast<LPARAM>(&addbmp));
addbmp.nID = NppDarkMode::isEnabled() ? IDI_FB_EXPANDALL_DM : IDI_FB_EXPANDALL;
::SendMessage(_hToolbarMenu, TB_ADDBITMAP, 1, reinterpret_cast<LPARAM>(&addbmp));
int iconSizeDyn = nppParam._dpiManager.scaleX(16);
::SendMessage(_hToolbarMenu, TB_SETBITMAPSIZE, 0, MAKELPARAM(iconSizeDyn, iconSizeDyn));
TBADDBITMAP addbmp = { 0, 0 };
const int nbIcons = 3;
int iconIDs[nbIcons] = { IDI_FB_SELECTCURRENTFILE, IDI_FB_FOLDALL, IDI_FB_EXPANDALL};
int iconDarkModeIDs[nbIcons] = { IDI_FB_SELECTCURRENTFILE_DM, IDI_FB_FOLDALL_DM, IDI_FB_EXPANDALL_DM};
for (size_t i = 0; i < nbIcons; ++i)
{
int icoID = NppDarkMode::isEnabled() ? iconDarkModeIDs[i] : iconIDs[i];
HBITMAP hBmp = static_cast<HBITMAP>(::LoadImage(_hInst, MAKEINTRESOURCE(icoID), IMAGE_BITMAP, iconSizeDyn, iconSizeDyn, LR_LOADMAP3DCOLORS | LR_LOADTRANSPARENT));
addbmp.nID = reinterpret_cast<UINT_PTR>(hBmp);
::SendMessage(_hToolbarMenu, TB_ADDBITMAP, 1, reinterpret_cast<LPARAM>(&addbmp));
}
TBBUTTON tbButtons[nbIcons];
tbButtons[0].idCommand = FB_CMD_AIMFILE;
tbButtons[0].iBitmap = 0;
tbButtons[0].fsState = TBSTATE_ENABLED;
@ -141,7 +149,7 @@ INT_PTR CALLBACK FileBrowser::run_dlgProc(UINT message, WPARAM wParam, LPARAM lP
::SendMessage(_hToolbarMenu, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
::SendMessage(_hToolbarMenu, TB_SETBUTTONSIZE, 0, MAKELONG(nppParam._dpiManager.scaleX(20), nppParam._dpiManager.scaleY(20)));
::SendMessage(_hToolbarMenu, TB_SETPADDING, 0, MAKELONG(20, 0));
::SendMessage(_hToolbarMenu, TB_SETPADDING, 0, MAKELONG(nppParam._dpiManager.scaleX(10), 0));
::SendMessage(_hToolbarMenu, TB_ADDBUTTONS, sizeof(tbButtons) / sizeof(TBBUTTON), reinterpret_cast<LPARAM>(&tbButtons));
::SendMessage(_hToolbarMenu, TB_AUTOSIZE, 0, 0);

View File

@ -832,28 +832,26 @@ INT_PTR CALLBACK FunctionListPanel::run_dlgProc(UINT message, WPARAM wParam, LPA
NppDarkMode::setDarkLineAbovePanelToolbar(_hToolbarMenu);
oldFunclstToolbarProc = reinterpret_cast<WNDPROC>(::SetWindowLongPtr(_hToolbarMenu, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(funclstToolbarProc)));
TBBUTTON tbButtons[3];
// Add the bmap image into toolbar's imagelist
int icoID0 = IDI_FUNCLIST_SORTBUTTON;
int icoID1 = IDI_FUNCLIST_RELOADBUTTON;
if (NppDarkMode::isEnabled())
int iconSizeDyn = nppParams._dpiManager.scaleX(16);
::SendMessage(_hToolbarMenu, TB_SETBITMAPSIZE, 0, MAKELPARAM(iconSizeDyn, iconSizeDyn));
TBADDBITMAP addbmp = { 0, 0 };
const int nbIcons = 2;
int iconIDs[nbIcons] = { IDI_FUNCLIST_SORTBUTTON, IDI_FUNCLIST_RELOADBUTTON };
int iconDarkModeIDs[nbIcons] = { IDI_FUNCLIST_SORTBUTTON_DM, IDI_FUNCLIST_RELOADBUTTON_DM };
for (size_t i = 0; i < nbIcons; ++i)
{
icoID0 = IDI_FUNCLIST_SORTBUTTON_DM;
icoID1 = IDI_FUNCLIST_RELOADBUTTON_DM;
int icoID = NppDarkMode::isEnabled() ? iconDarkModeIDs[i] : iconIDs[i];
HBITMAP hBmp = static_cast<HBITMAP>(::LoadImage(_hInst, MAKEINTRESOURCE(icoID), IMAGE_BITMAP, iconSizeDyn, iconSizeDyn, LR_LOADMAP3DCOLORS | LR_LOADTRANSPARENT));
addbmp.nID = reinterpret_cast<UINT_PTR>(hBmp);
::SendMessage(_hToolbarMenu, TB_ADDBITMAP, 1, reinterpret_cast<LPARAM>(&addbmp));
}
else if (nppParams.getNppGUI()._toolBarStatus != TB_STANDARD)
{
icoID0 = IDI_FUNCLIST_SORTBUTTON2;
icoID1 = IDI_FUNCLIST_RELOADBUTTON2;
}
TBADDBITMAP addbmp = {_hInst, 0};
addbmp.nID = icoID0;
::SendMessage(_hToolbarMenu, TB_ADDBITMAP, 1, reinterpret_cast<LPARAM>(&addbmp));
addbmp.nID = icoID1;
::SendMessage(_hToolbarMenu, TB_ADDBITMAP, 1, reinterpret_cast<LPARAM>(&addbmp));
// Place holder of search text field
TBBUTTON tbButtons[1 + nbIcons];
tbButtons[0].idCommand = 0;
tbButtons[0].iBitmap = editWidthSep;
tbButtons[0].fsState = TBSTATE_ENABLED;
@ -873,7 +871,7 @@ INT_PTR CALLBACK FunctionListPanel::run_dlgProc(UINT message, WPARAM wParam, LPA
tbButtons[2].iString = reinterpret_cast<INT_PTR>(TEXT(""));
::SendMessage(_hToolbarMenu, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
::SendMessage(_hToolbarMenu, TB_SETBUTTONSIZE, 0, MAKELONG(16, 16));
::SendMessage(_hToolbarMenu, TB_SETBUTTONSIZE, 0, MAKELONG(nppParams._dpiManager.scaleX(16), nppParams._dpiManager.scaleY(16)));
::SendMessage(_hToolbarMenu, TB_ADDBUTTONS, sizeof(tbButtons) / sizeof(TBBUTTON), reinterpret_cast<LPARAM>(&tbButtons));
::SendMessage(_hToolbarMenu, TB_AUTOSIZE, 0, 0);

View File

@ -340,8 +340,6 @@ void ToolBar::reset(bool create)
int icoID = _toolBarIcons.getStdIconAt(static_cast<int32_t>(i));
HBITMAP hBmp = static_cast<HBITMAP>(::LoadImage(_hInst, MAKEINTRESOURCE(icoID), IMAGE_BITMAP, iconDpiDynamicalSize, iconDpiDynamicalSize, LR_LOADMAP3DCOLORS | LR_LOADTRANSPARENT));
addbmp.nID = reinterpret_cast<UINT_PTR>(hBmp);
//addbmp.nID = _toolBarIcons.getStdIconAt(i);
::SendMessage(_hSelf, TB_ADDBITMAP, 1, reinterpret_cast<LPARAM>(&addbmp));
}
if (_nbDynButtons > 0)
@ -357,7 +355,7 @@ void ToolBar::reset(bool create)
if (create)
{ //if the toolbar has been recreated, readd the buttons
_nbCurrentButtons = _nbTotalButtons;
WORD btnSize = (_state == TB_LARGE?32:16);
WORD btnSize = (_state == TB_LARGE ? 32 : 16);
::SendMessage(_hSelf, TB_SETBUTTONSIZE , 0, MAKELONG(btnSize, btnSize));
::SendMessage(_hSelf, TB_ADDBUTTONS, _nbTotalButtons, reinterpret_cast<LPARAM>(_pTBB));
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -280,10 +280,8 @@
#define IDI_FUNCLIST_SORTBUTTON 631
#define IDI_FUNCLIST_RELOADBUTTON 632
#define IDI_FUNCLIST_SORTBUTTON2 633
#define IDI_FUNCLIST_RELOADBUTTON2 634
#define IDI_FUNCLIST_SORTBUTTON_DM 635
#define IDI_FUNCLIST_RELOADBUTTON_DM 636
#define IDI_FUNCLIST_SORTBUTTON_DM 633
#define IDI_FUNCLIST_RELOADBUTTON_DM 634