Add the capacity to customize the color of Notepad++ (not only dark)

1. Customizable colors easily handled now by tweaking a few custom drawing implementations.
2. make dark mode less intense by default.

Close #9848
This commit is contained in:
Adam D. Walling 2021-05-09 22:32:35 -04:00 committed by Don HO
parent 4aa459ef47
commit 1089e239ba
6 changed files with 128 additions and 96 deletions

View File

@ -1622,7 +1622,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
{ {
if (NppDarkMode::isEnabled()) if (NppDarkMode::isEnabled())
{ {
FillRect(nmtbcd->nmcd.hdc, &nmtbcd->nmcd.rc, NppDarkMode::getPureBackgroundBrush()); FillRect(nmtbcd->nmcd.hdc, &nmtbcd->nmcd.rc, NppDarkMode::getDarkerBackgroundBrush());
nmtbcd->clrText = NppDarkMode::getTextColor(); nmtbcd->clrText = NppDarkMode::getTextColor();
SetTextColor(nmtbcd->nmcd.hdc, NppDarkMode::getTextColor()); SetTextColor(nmtbcd->nmcd.hdc, NppDarkMode::getTextColor());
return CDRF_SKIPDEFAULT; return CDRF_SKIPDEFAULT;

View File

@ -15,6 +15,73 @@
namespace NppDarkMode namespace NppDarkMode
{ {
struct Colors
{
COLORREF background = 0;
COLORREF softerBackground = 0;
COLORREF hotBackground = 0;
COLORREF pureBackground = 0;
COLORREF errorBackground = 0;
COLORREF text = 0;
COLORREF darkerText = 0;
COLORREF edge = 0;
};
struct Brushes
{
HBRUSH background = nullptr;
HBRUSH softerBackground = nullptr;
HBRUSH hotBackground = nullptr;
HBRUSH pureBackground = nullptr;
HBRUSH errorBackground = nullptr;
Brushes(const Colors& colors)
: background(::CreateSolidBrush(colors.background))
, softerBackground(::CreateSolidBrush(colors.softerBackground))
, hotBackground(::CreateSolidBrush(colors.hotBackground))
, pureBackground(::CreateSolidBrush(colors.pureBackground))
, errorBackground(::CreateSolidBrush(colors.errorBackground))
{}
~Brushes()
{
::DeleteObject(background); background = nullptr;
::DeleteObject(softerBackground); softerBackground = nullptr;
::DeleteObject(hotBackground); hotBackground = nullptr;
::DeleteObject(pureBackground); pureBackground = nullptr;
::DeleteObject(errorBackground); errorBackground = nullptr;
}
};
static const Colors darkColors{
HEXRGB(0x202020), // background
HEXRGB(0x282828), // softerBackground
HEXRGB(0x404040), // hotBackground
HEXRGB(0x000000), // pureBackground
HEXRGB(0xB00000), // errorBackground
HEXRGB(0xE0E0E0), // textColor
HEXRGB(0xC0C0C0), // darkerTextColor
HEXRGB(0x808080), // edgeColor
};
struct Theme
{
Colors colors;
Brushes brushes;
Theme(const Colors& colors)
: colors(colors)
, brushes(colors)
{}
};
Theme& getTheme()
{
static Theme g_theme(darkColors);
return g_theme;
}
static Options _options; // actual runtime options static Options _options; // actual runtime options
const Options& configuredOptions() const Options& configuredOptions()
@ -121,75 +188,20 @@ namespace NppDarkMode
return invert_c; return invert_c;
} }
COLORREF getBackgroundColor() COLORREF getBackgroundColor() { return getTheme().colors.background; }
{ COLORREF getSofterBackgroundColor() { return getTheme().colors.softerBackground; }
return RGB(0x20, 0x20, 0x20); COLORREF getHotBackgroundColor() { return getTheme().colors.hotBackground; }
} COLORREF getDarkerBackgroundColor() { return getTheme().colors.pureBackground; }
COLORREF getErrorBackgroundColor() { return getTheme().colors.errorBackground; }
COLORREF getTextColor() { return getTheme().colors.text; }
COLORREF getDarkerTextColor() { return getTheme().colors.darkerText; }
COLORREF getEdgeColor() { return getTheme().colors.edge; }
COLORREF getSofterBackgroundColor() HBRUSH getBackgroundBrush() { return getTheme().brushes.background; }
{ HBRUSH getSofterBackgroundBrush() { return getTheme().brushes.softerBackground; }
return RGB(0x2B, 0x2B, 0x2B); HBRUSH getHotBackgroundBrush() { return getTheme().brushes.hotBackground; }
} HBRUSH getDarkerBackgroundBrush() { return getTheme().brushes.pureBackground; }
HBRUSH getErrorBackgroundBrush() { return getTheme().brushes.errorBackground; }
COLORREF getHotBackgroundColor()
{
return RGB(0x4D, 0x4D, 0x4D);
}
COLORREF getPureBackgroundColor()
{
return RGB(0, 0, 0);
}
COLORREF getTextColor()
{
return RGB(0xE0, 0xE0, 0xE0);
}
COLORREF getDarkerTextColor()
{
return RGB(0xC0, 0xC0, 0xC0);
}
COLORREF getEdgeColor()
{
return RGB(0x80, 0x80, 0x80);
}
COLORREF getErrorBackgroundColor()
{
return RGB(0xB0, 0x00, 0x00);
}
HBRUSH getBackgroundBrush()
{
static HBRUSH g_hbrBackground = ::CreateSolidBrush(getBackgroundColor());
return g_hbrBackground;
}
HBRUSH getSofterBackgroundBrush()
{
static HBRUSH g_hbrSofterBackground = ::CreateSolidBrush(getSofterBackgroundColor());
return g_hbrSofterBackground;
}
HBRUSH getHotBackgroundBrush()
{
static HBRUSH g_hbrHotBackground = ::CreateSolidBrush(getHotBackgroundColor());
return g_hbrHotBackground;
}
HBRUSH getPureBackgroundBrush()
{
static HBRUSH g_hbrPureBackground = (HBRUSH)::GetStockObject(BLACK_BRUSH);
return g_hbrPureBackground;
}
HBRUSH getErrorBackgroundBrush()
{
static HBRUSH g_hbrErrorBackground = ::CreateSolidBrush(getErrorBackgroundColor());
return g_hbrErrorBackground;
}
// handle events // handle events
@ -237,7 +249,7 @@ namespace NppDarkMode
rc.top -= 1; rc.top -= 1;
} }
FillRect(pUDM->hdc, &rc, NppDarkMode::getPureBackgroundBrush()); FillRect(pUDM->hdc, &rc, NppDarkMode::getDarkerBackgroundBrush());
*lr = 0; *lr = 0;
@ -301,7 +313,7 @@ namespace NppDarkMode
if (iBackgroundStateID == MPI_NORMAL || iBackgroundStateID == MPI_DISABLED) if (iBackgroundStateID == MPI_NORMAL || iBackgroundStateID == MPI_DISABLED)
{ {
FillRect(pUDMI->um.hdc, &pUDMI->dis.rcItem, NppDarkMode::getPureBackgroundBrush()); FillRect(pUDMI->um.hdc, &pUDMI->dis.rcItem, NppDarkMode::getDarkerBackgroundBrush());
} }
else if (iBackgroundStateID == MPI_HOT || iBackgroundStateID == MPI_DISABLEDHOT) else if (iBackgroundStateID == MPI_HOT || iBackgroundStateID == MPI_DISABLEDHOT)
{ {
@ -824,7 +836,7 @@ namespace NppDarkMode
PAINTSTRUCT ps; PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps); HDC hdc = BeginPaint(hWnd, &ps);
FillRect(hdc, &ps.rcPaint, NppDarkMode::getPureBackgroundBrush()); FillRect(hdc, &ps.rcPaint, NppDarkMode::getBackgroundBrush());
static HPEN g_hpen = CreatePen(PS_SOLID, 1, NppDarkMode::getEdgeColor()); static HPEN g_hpen = CreatePen(PS_SOLID, 1, NppDarkMode::getEdgeColor());
@ -870,7 +882,7 @@ namespace NppDarkMode
SetTextColor(hdc, (bHot || (i == nSelTab) ) ? NppDarkMode::getTextColor() : NppDarkMode::getDarkerTextColor()); SetTextColor(hdc, (bHot || (i == nSelTab) ) ? NppDarkMode::getTextColor() : NppDarkMode::getDarkerTextColor());
FillRect(hdc, &rcItem, (i == nSelTab) ? NppDarkMode::getPureBackgroundBrush() : NppDarkMode::getBackgroundBrush()); FillRect(hdc, &rcItem, (i == nSelTab) ? NppDarkMode::getBackgroundBrush() : NppDarkMode::getSofterBackgroundBrush());
SetBkMode(hdc, TRANSPARENT); SetBkMode(hdc, TRANSPARENT);

View File

@ -2,6 +2,15 @@
#include <Windows.h> #include <Windows.h>
constexpr COLORREF HEXRGB(DWORD rrggbb) {
// from 0xRRGGBB like natural #RRGGBB
// to the little-endian 0xBBGGRR
return
((rrggbb & 0xFF0000) >> 16) |
((rrggbb & 0x00FF00) ) |
((rrggbb & 0x0000FF) << 16);
}
namespace NppDarkMode namespace NppDarkMode
{ {
struct Options struct Options
@ -26,14 +35,15 @@ namespace NppDarkMode
COLORREF getBackgroundColor(); COLORREF getBackgroundColor();
COLORREF getSofterBackgroundColor(); COLORREF getSofterBackgroundColor();
COLORREF getHotBackgroundColor(); COLORREF getHotBackgroundColor();
COLORREF getPureBackgroundColor(); COLORREF getDarkerBackgroundColor();
COLORREF getErrorBackgroundColor();
COLORREF getTextColor(); COLORREF getTextColor();
COLORREF getDarkerTextColor(); COLORREF getDarkerTextColor();
COLORREF getEdgeColor(); COLORREF getEdgeColor();
COLORREF getErrorBackgroundColor();
HBRUSH getBackgroundBrush(); HBRUSH getBackgroundBrush();
HBRUSH getPureBackgroundBrush(); HBRUSH getDarkerBackgroundBrush();
HBRUSH getSofterBackgroundBrush(); HBRUSH getSofterBackgroundBrush();
HBRUSH getHotBackgroundBrush(); HBRUSH getHotBackgroundBrush();
HBRUSH getErrorBackgroundBrush(); HBRUSH getErrorBackgroundBrush();

View File

@ -859,8 +859,8 @@ INT_PTR CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
} }
SetTextColor((HDC)wParam, NppDarkMode::getTextColor()); SetTextColor((HDC)wParam, NppDarkMode::getTextColor());
SetBkColor((HDC)wParam, NppDarkMode::getPureBackgroundColor()); SetBkColor((HDC)wParam, NppDarkMode::getBackgroundColor());
return (LRESULT)GetStockObject(BLACK_BRUSH); return (LRESULT)NppDarkMode::getBackgroundBrush();
} }
case WM_PRINTCLIENT: case WM_PRINTCLIENT:
case WM_ERASEBKGND: case WM_ERASEBKGND:
@ -871,7 +871,7 @@ INT_PTR CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
} }
RECT rc = { 0 }; RECT rc = { 0 };
getClientRect(rc); getClientRect(rc);
FillRect((HDC)wParam, &rc, NppDarkMode::getPureBackgroundBrush()); FillRect((HDC)wParam, &rc, NppDarkMode::getBackgroundBrush());
SetWindowLongPtr(_hSelf, DWLP_MSGRESULT, TRUE); SetWindowLongPtr(_hSelf, DWLP_MSGRESULT, TRUE);
return TRUE; return TRUE;
} }
@ -3683,7 +3683,7 @@ void FindReplaceDlg::drawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
} }
else if (_statusbarFindStatus == FSMessage) else if (_statusbarFindStatus == FSMessage)
{ {
fgColor = RGB(0x50, 0x50, 0xFF); // blue fgColor = RGB(0x70, 0x70, 0xFF); // blue
} }
else if (_statusbarFindStatus == FSTopReached || _statusbarFindStatus == FSEndReached) else if (_statusbarFindStatus == FSTopReached || _statusbarFindStatus == FSEndReached)
{ {
@ -4430,8 +4430,8 @@ INT_PTR CALLBACK FindIncrementDlg::run_dlgProc(UINT message, WPARAM wParam, LPAR
if (FSNotFound != getFindStatus()) if (FSNotFound != getFindStatus())
{ {
SetTextColor((HDC)wParam, NppDarkMode::getTextColor()); SetTextColor((HDC)wParam, NppDarkMode::getTextColor());
SetBkColor((HDC)wParam, NppDarkMode::getPureBackgroundColor()); SetBkColor((HDC)wParam, NppDarkMode::getBackgroundColor());
return (LRESULT)NppDarkMode::getPureBackgroundBrush(); return (LRESULT)NppDarkMode::getBackgroundBrush();
} }
else // text not found else // text not found
{ {
@ -4462,8 +4462,8 @@ INT_PTR CALLBACK FindIncrementDlg::run_dlgProc(UINT message, WPARAM wParam, LPAR
} }
SetTextColor((HDC)wParam, NppDarkMode::getTextColor()); SetTextColor((HDC)wParam, NppDarkMode::getTextColor());
SetBkColor((HDC)wParam, NppDarkMode::getPureBackgroundColor()); SetBkColor((HDC)wParam, NppDarkMode::getBackgroundColor());
return (LRESULT)GetStockObject(BLACK_BRUSH); return (LRESULT)NppDarkMode::getBackgroundBrush();
} }
case NPPM_INTERNAL_REFRESHDARKMODE: case NPPM_INTERNAL_REFRESHDARKMODE:
@ -4577,15 +4577,25 @@ INT_PTR CALLBACK FindIncrementDlg::run_dlgProc(UINT message, WPARAM wParam, LPAR
case WM_ERASEBKGND: case WM_ERASEBKGND:
{ {
HWND hParent = ::GetParent(_hSelf); if (NppDarkMode::isEnabled())
HDC winDC = (HDC)wParam; {
//RTL handling RECT rcClient = { 0 };
POINT pt = {0, 0}, ptOrig = {0, 0}; GetClientRect(_hSelf, &rcClient);
::MapWindowPoints(_hSelf, hParent, &pt, 1); FillRect((HDC)wParam, &rcClient, NppDarkMode::getBackgroundBrush());
::OffsetWindowOrgEx((HDC)wParam, pt.x, pt.y, &ptOrig); return TRUE;
LRESULT lResult = SendMessage(hParent, WM_ERASEBKGND, reinterpret_cast<WPARAM>(winDC), 0); }
::SetWindowOrgEx(winDC, ptOrig.x, ptOrig.y, NULL); else
return (BOOL)lResult; {
HWND hParent = ::GetParent(_hSelf);
HDC winDC = (HDC)wParam;
//RTL handling
POINT pt = { 0, 0 }, ptOrig = { 0, 0 };
::MapWindowPoints(_hSelf, hParent, &pt, 1);
::OffsetWindowOrgEx((HDC)wParam, pt.x, pt.y, &ptOrig);
LRESULT lResult = SendMessage(hParent, WM_ERASEBKGND, reinterpret_cast<WPARAM>(winDC), 0);
::SetWindowOrgEx(winDC, ptOrig.x, ptOrig.y, NULL);
return (BOOL)lResult;
}
} }
} }
return DefWindowProc(getHSelf(), message, wParam, lParam); return DefWindowProc(getHSelf(), message, wParam, lParam);

View File

@ -710,7 +710,7 @@ void FileBrowser::notified(LPNMHDR notification)
{ {
if (NppDarkMode::isEnabled()) if (NppDarkMode::isEnabled())
{ {
FillRect(nmtbcd->nmcd.hdc, &nmtbcd->nmcd.rc, NppDarkMode::getPureBackgroundBrush()); FillRect(nmtbcd->nmcd.hdc, &nmtbcd->nmcd.rc, NppDarkMode::getBackgroundBrush());
nmtbcd->clrText = NppDarkMode::getTextColor(); nmtbcd->clrText = NppDarkMode::getTextColor();
SetTextColor(nmtbcd->nmcd.hdc, NppDarkMode::getTextColor()); SetTextColor(nmtbcd->nmcd.hdc, NppDarkMode::getTextColor());
SetWindowLongPtr(_hSelf, DWLP_MSGRESULT, CDRF_SKIPDEFAULT); SetWindowLongPtr(_hSelf, DWLP_MSGRESULT, CDRF_SKIPDEFAULT);

View File

@ -866,7 +866,7 @@ LRESULT TabBarPlus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPara
RECT rc = { 0 }; RECT rc = { 0 };
GetClientRect(hwnd, &rc); GetClientRect(hwnd, &rc);
FillRect((HDC)wParam, &rc, NppDarkMode::getPureBackgroundBrush()); FillRect((HDC)wParam, &rc, NppDarkMode::getDarkerBackgroundBrush());
return 1; return 1;
} }
@ -886,7 +886,7 @@ LRESULT TabBarPlus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPara
PAINTSTRUCT ps; PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps); HDC hdc = BeginPaint(hwnd, &ps);
FillRect(hdc, &ps.rcPaint, NppDarkMode::getPureBackgroundBrush()); FillRect(hdc, &ps.rcPaint, NppDarkMode::getDarkerBackgroundBrush());
UINT id = ::GetDlgCtrlID(hwnd); UINT id = ::GetDlgCtrlID(hwnd);