Skip to content

Commit

Permalink
Preparing dark mode for 8.4.1 support.
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonard-The-Wise committed May 7, 2022
1 parent 8ac523b commit dc52870
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 28 deletions.
71 changes: 48 additions & 23 deletions src/DarkMode/PluginDarkMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@

#define BKLUMINANCE_BRIGHTER 140
#define BKLUMINANCE_SOFTER 80
#define TEXTLUMINANCE_MAX 240
#define EDGELUMINANCE_BRIGHTER 220
#define EDGELUMINANCE_DARKER 60

Expand Down Expand Up @@ -80,9 +81,9 @@ namespace PluginDarkMode
HBRUSH softlightBackground = nullptr;
HBRUSH textColorBrush = nullptr;
HBRUSH darkerTextColorBrush = nullptr;
HBRUSH edgeBackground = nullptr;
HBRUSH hotEdgeBackground = nullptr;
HBRUSH disabledEdgeBackground = nullptr;
HBRUSH edgeBrush = nullptr;
HBRUSH hotEdgeBrush = nullptr;
HBRUSH disabledEdgeBrush = nullptr;

Brushes(const Colors& colors)
: background(::CreateSolidBrush(colors.background))
Expand All @@ -94,9 +95,9 @@ namespace PluginDarkMode
, softlightBackground(::CreateSolidBrush(lightColor(colors.background, BKLUMINANCE_SOFTER)))
, textColorBrush(::CreateSolidBrush(colors.text))
, darkerTextColorBrush(::CreateSolidBrush(colors.darkerText))
, edgeBackground(::CreateSolidBrush(colors.edge))
, hotEdgeBackground(::CreateSolidBrush(lightColor(colors.edge, EDGELUMINANCE_BRIGHTER)))
, disabledEdgeBackground(::CreateSolidBrush(lightColor(colors.edge, EDGELUMINANCE_DARKER)))
, edgeBrush(::CreateSolidBrush(colors.edge))
, hotEdgeBrush(::CreateSolidBrush(colors.hotEdge))
, disabledEdgeBrush(::CreateSolidBrush(lightColor(colors.edge, EDGELUMINANCE_DARKER)))
{}

~Brushes()
Expand All @@ -110,6 +111,10 @@ namespace PluginDarkMode
::DeleteObject(softlightBackground); softlightBackground = nullptr;
::DeleteObject(textColorBrush); textColorBrush = nullptr;
::DeleteObject(darkerTextColorBrush); darkerTextColorBrush = nullptr;
::DeleteObject(edgeBrush); edgeBrush = nullptr;
::DeleteObject(hotEdgeBrush); hotEdgeBrush = nullptr;
::DeleteObject(disabledEdgeBrush); disabledEdgeBrush = nullptr;

}

void change(const Colors& colors)
Expand All @@ -123,6 +128,9 @@ namespace PluginDarkMode
::DeleteObject(softlightBackground);
::DeleteObject(textColorBrush);
::DeleteObject(darkerTextColorBrush);
::DeleteObject(edgeBrush);
::DeleteObject(hotEdgeBrush);
::DeleteObject(disabledEdgeBrush);

background = ::CreateSolidBrush(colors.background);
softerBackground = ::CreateSolidBrush(colors.softerBackground);
Expand All @@ -133,9 +141,9 @@ namespace PluginDarkMode
softlightBackground = ::CreateSolidBrush(lightColor(colors.background, BKLUMINANCE_SOFTER));
textColorBrush = ::CreateSolidBrush(colors.text);
darkerTextColorBrush = ::CreateSolidBrush(colors.darkerText);
edgeBackground = ::CreateSolidBrush(colors.edge);
hotEdgeBackground = ::CreateSolidBrush(lightColor(colors.edge, EDGELUMINANCE_BRIGHTER));
disabledEdgeBackground = ::CreateSolidBrush(lightColor(colors.edge, EDGELUMINANCE_DARKER));
edgeBrush = ::CreateSolidBrush(colors.edge);
hotEdgeBrush = ::CreateSolidBrush(colors.hotEdge);
disabledEdgeBrush = ::CreateSolidBrush(lightColor(colors.edge, EDGELUMINANCE_DARKER));
}
};

Expand All @@ -149,7 +157,7 @@ namespace PluginDarkMode
Pens(const Colors& colors)
: darkerTextPen(::CreatePen(PS_SOLID, 1, colors.darkerText))
, edgePen(::CreatePen(PS_SOLID, 1, colors.edge))
, hotEdgePen(::CreatePen(PS_SOLID, 1, lightColor(colors.edge, EDGELUMINANCE_BRIGHTER)))
, hotEdgePen(::CreatePen(PS_SOLID, 1, colors.hotEdge))
, disabledEdgePen(::CreatePen(PS_SOLID, 1, lightColor(colors.edge, EDGELUMINANCE_DARKER)))
{}

Expand All @@ -170,7 +178,7 @@ namespace PluginDarkMode

darkerTextPen = ::CreatePen(PS_SOLID, 1, colors.darkerText);
edgePen = ::CreatePen(PS_SOLID, 1, colors.edge);
hotEdgePen = ::CreatePen(PS_SOLID, 1, lightColor(colors.edge, EDGELUMINANCE_BRIGHTER));
hotEdgePen = ::CreatePen(PS_SOLID, 1, colors.hotEdge);
disabledEdgePen = ::CreatePen(PS_SOLID, 1, lightColor(colors.edge, EDGELUMINANCE_DARKER));
}

Expand All @@ -187,7 +195,8 @@ namespace PluginDarkMode
HEXRGB(0xC0C0C0), // darkerTextColor
HEXRGB(0x808080), // disabledTextColor
HEXRGB(0xFFFF00), // linkTextColor
HEXRGB(0x646464) // edgeColor
HEXRGB(0x646464), // edgeColor
HEXRGB(0x9B9B9B) // hotEdgeColor
};

// red tone
Expand All @@ -201,7 +210,8 @@ namespace PluginDarkMode
HEXRGB(0xC0C0C0), // darkerTextColor
HEXRGB(0x808080), // disabledTextColor
HEXRGB(0xFFFF00), // linkTextColor
HEXRGB(0x908080) // edgeColor
HEXRGB(0x908080), // edgeColor
HEXRGB(0xBBABAB) // hotEdgeColor
};

// green tone
Expand All @@ -215,7 +225,8 @@ namespace PluginDarkMode
HEXRGB(0xC0C0C0), // darkerTextColor
HEXRGB(0x808080), // disabledTextColor
HEXRGB(0xFFFF00), // linkTextColor
HEXRGB(0x809080) // edgeColor
HEXRGB(0x809080), // edgeColor
HEXRGB(0xABBBAB) // hotEdgeColor
};

// blue tone
Expand All @@ -229,7 +240,8 @@ namespace PluginDarkMode
HEXRGB(0xC0C0C0), // darkerTextColor
HEXRGB(0x808080), // disabledTextColor
HEXRGB(0xFFFF00), // linkTextColor
HEXRGB(0x8080A0) // edgeColor
HEXRGB(0x8080A0), // edgeColor
HEXRGB(0xABABCB) // hotEdgeColor
};

// purple tone
Expand All @@ -243,7 +255,8 @@ namespace PluginDarkMode
HEXRGB(0xC0C0C0), // darkerTextColor
HEXRGB(0x808080), // disabledTextColor
HEXRGB(0xFFFF00), // linkTextColor
HEXRGB(0x9080A0) // edgeColor
HEXRGB(0x9080A0), // edgeColor
HEXRGB(0xBBABCB) // hotEdgeColor
};

// cyan tone
Expand All @@ -257,7 +270,8 @@ namespace PluginDarkMode
HEXRGB(0xC0C0C0), // darkerTextColor
HEXRGB(0x808080), // disabledTextColor
HEXRGB(0xFFFF00), // linkTextColor
HEXRGB(0x8090A0) // edgeColor
HEXRGB(0x8090A0), // edgeColor
HEXRGB(0xBBBBCB) // hotEdgeColor
};

// olive tone
Expand All @@ -271,7 +285,8 @@ namespace PluginDarkMode
HEXRGB(0xC0C0C0), // darkerTextColor
HEXRGB(0x808080), // disabledTextColor
HEXRGB(0xFFFF00), // linkTextColor
HEXRGB(0x909080) // edgeColor
HEXRGB(0x909080), // edgeColor
HEXRGB(0xBBBBAB) // hotEdgeColor
};

// customized
Expand All @@ -285,7 +300,8 @@ namespace PluginDarkMode
HEXRGB(0xC0C0C0), // darkerTextColor
HEXRGB(0x808080), // disabledTextColor
HEXRGB(0xFFFF00), // linkTextColor
HEXRGB(0x646464) // edgeColor
HEXRGB(0x646464), // edgeColor
HEXRGB(0x9B9B9B) // hotEdgeColor
};

void setDarkTone(ColorTone colorToneChoice)
Expand Down Expand Up @@ -555,11 +571,12 @@ namespace PluginDarkMode
COLORREF getDarkerBackgroundColor() { return getTheme()._colors.pureBackground; }
COLORREF getErrorBackgroundColor() { return getTheme()._colors.errorBackground; }
COLORREF getTextColor() { return getTheme()._colors.text; }
COLORREF getHotTextColor() { return lightColor(getTheme()._colors.text, 240); }
COLORREF getHotTextColor() { return lightColor(getTheme()._colors.text, TEXTLUMINANCE_MAX); }
COLORREF getDarkerTextColor() { return getTheme()._colors.darkerText; }
COLORREF getDisabledTextColor() { return getTheme()._colors.disabledText; }
COLORREF getLinkTextColor() { return getTheme()._colors.linkText; }
COLORREF getEdgeColor() { return getTheme()._colors.edge; }
COLORREF getHotEdgeColor() { return getTheme()._colors.hotEdge; }

HBRUSH getBackgroundBrush() { return getTheme()._brushes.background; }
HBRUSH getSofterBackgroundBrush() { return getTheme()._brushes.softerBackground; }
Expand All @@ -570,15 +587,16 @@ namespace PluginDarkMode
HBRUSH getSoftlightBackgroundBrush() { return getTheme()._brushes.softlightBackground; }
HBRUSH getTextBrush() { return getTheme()._brushes.textColorBrush; }
HBRUSH getDarkerTextBrush() { return getTheme()._brushes.darkerTextColorBrush; }
HBRUSH getEdgeBrush() { return getTheme()._brushes.edgeBackground; }
HBRUSH getHotEdgeBrush() { return getTheme()._brushes.hotEdgeBackground; }
HBRUSH getDisabledEdgeBrush() { return getTheme()._brushes.disabledEdgeBackground; }
HBRUSH getEdgeBrush() { return getTheme()._brushes.edgeBrush; }
HBRUSH getHotEdgeBrush() { return getTheme()._brushes.hotEdgeBrush; }
HBRUSH getDisabledEdgeBrush() { return getTheme()._brushes.disabledEdgeBrush; }

HPEN getDarkerTextPen() { return getTheme()._pens.darkerTextPen; }
HPEN getEdgePen() { return getTheme()._pens.edgePen; }
HPEN getHotEdgePen() { return getTheme()._pens.hotEdgePen; }
HPEN getDisabledEdgePen() { return getTheme()._pens.disabledEdgePen; }


void setThemeColors(Colors& newColors)
{
assert(g_initialized);
Expand Down Expand Up @@ -665,6 +683,13 @@ namespace PluginDarkMode
getTheme().change(clrs);
}

void setHotEdgeColor(COLORREF c)
{
Colors clrs = getTheme()._colors;
clrs.hotEdge = c;
getTheme().change(clrs);
}

Colors getDarkModeDefaultColors()
{
assert(g_initialized);
Expand Down
2 changes: 2 additions & 0 deletions src/DarkMode/PluginDarkMode.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace PluginDarkMode
COLORREF disabledText = 0;
COLORREF linkText = 0;
COLORREF edge = 0;
COLORREF hotEdge = 0;
};

struct Options
Expand Down Expand Up @@ -128,6 +129,7 @@ namespace PluginDarkMode
void setDisabledTextColor(COLORREF c);
void setLinkTextColor(COLORREF c);
void setEdgeColor(COLORREF c);
void setHotEdgeColor(COLORREF c);

Colors getDarkModeDefaultColors();
void changeCustomTheme(const Colors& colors);
Expand Down
5 changes: 5 additions & 0 deletions src/Plugin Controls/AboutDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ void AboutDialog::LoadAboutTextEditor(int resourceID)
rawText.assign((char*)ptr, _size);

// Replace %VARIABLE% strings from raw text
// HACK: change Bk Color of dark mode without messages
_replaceStrings.insert({ L"4210752", std::to_wstring(PluginDarkMode::getSofterBackgroundColor()) });
generic_string rawTextW = replaceStringsW(str2wstr(rawText), _replaceStrings);

// Free memory allocated for resource
Expand Down Expand Up @@ -141,6 +143,9 @@ void AboutDialog::LoadAboutTextEditor(int resourceID)
_aboutText.resize(SendMessage(editControl, EM_GETTEXTLENGTHEX, reinterpret_cast<WPARAM>(&tl), 0) + 1);
GETTEXTEX tex = { (DWORD)_aboutText.size() * sizeof(TCHAR), GT_RAWTEXT, 1200, NULL, NULL};
SendMessage(editControl, EM_GETTEXTEX, reinterpret_cast<LPARAM>(&tex), reinterpret_cast<LPARAM>(_aboutText.data()));

if (PluginDarkMode::isEnabled())
SendMessage(editControl, EM_SETBKGNDCOLOR, 0, PluginDarkMode::getSofterBackgroundColor());
}

// Free memory allocated for resource again
Expand Down
23 changes: 22 additions & 1 deletion src/Plugin Interface/Notepad_plus_msgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,28 @@ struct toolbarIconsWithDarkMode {
// - cbSize must be filled with sizeof(NppDarkMode::Colors).
// - returnColors must be a pre-allocated NppDarkMode::Colors struct.
// Returns true when successful, false otherwise.

// You need to uncomment the following code to use NppDarkMode::Colors structure:
//
// 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 disabledText = 0;
// COLORREF linkText = 0;
// COLORREF edge = 0;
// COLORREF hotEdge = 0;
// };
// }
//
// Note: in the case of calling failure ("false" is returned), you may need to change NppDarkMode::Colors structure to:
// https://github.com/notepad-plus-plus/notepad-plus-plus/blob/master/PowerEditor/src/NppDarkMode.h#L32


#define VAR_NOT_RECOGNIZED 0
Expand Down
7 changes: 5 additions & 2 deletions src/PluginMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,8 @@ void Plugin::RefreshDarkMode(bool ForceUseDark, bool UseDark)
if (ForceUseDark)
isDarkModeEnabled = UseDark;

// Normal support overrides legacy
if (_NppSupportDarkModeMessages)
// Non-legacy support
if (_NppSupportDarkModeMessages && !ForceUseDark)
{
isDarkModeEnabled = Messenger().SendNppMessage<bool>(NPPM_ISDARKMODEENABLED);
PluginDarkMode::Colors newColors;
Expand All @@ -514,6 +514,8 @@ void Plugin::RefreshDarkMode(bool ForceUseDark, bool UseDark)
// We override link colors
PluginDarkMode::setLinkTextColor(HEXRGB(0xFFC000));
}
else
CheckDarkModeLegacy();
}

// Set Dark Mode for window/application
Expand Down Expand Up @@ -550,6 +552,7 @@ void Plugin::CheckDarkModeLegacy()
colors.darkerText = stoi(GUIConfig->FindAttribute("customColorDarkText")->Value());
colors.disabledText = stoi(GUIConfig->FindAttribute("customColorDisabledText")->Value());
colors.edge = stoi(GUIConfig->FindAttribute("customColorEdge")->Value());
colors.hotEdge = stoi(GUIConfig->FindAttribute("customColorHotEdge")->Value());
colors.errorBackground = stoi(GUIConfig->FindAttribute("customColorError")->Value());
colors.hotBackground = stoi(GUIConfig->FindAttribute("customColorMenuHotTrack")->Value());
colors.linkText = stoi(GUIConfig->FindAttribute("customColorLinkText")->Value());
Expand Down
4 changes: 2 additions & 2 deletions src/ProjectVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

#define VERSION_MAJOR 1
#define VERSION_MINOR 0
#define VERSION_PATCH 2
#define VERSION_BUILD 1930
#define VERSION_PATCH 3
#define VERSION_BUILD 1950

#define VERSION_STRING stringify(VERSION_MAJOR) "." stringify(VERSION_MINOR) "." \
stringify(VERSION_PATCH) "." stringify(VERSION_BUILD)
Expand Down

0 comments on commit dc52870

Please sign in to comment.