Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
donho committed Sep 2, 2024
1 parent 52eb243 commit 2f99023
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 31 deletions.
24 changes: 12 additions & 12 deletions PowerEditor/src/Parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8836,62 +8836,62 @@ void NppParameters::initTabCustomColors()
const Style* pStyle = stylers.findByName(TABBAR_INDIVIDUALCOLOR_1);
if (pStyle)
{
individualTabHues[0].changeHLSFrom(pStyle->_bgColor);
individualTabHues[0].loadFromRGB(pStyle->_bgColor);
}

pStyle = stylers.findByName(TABBAR_INDIVIDUALCOLOR_2);
if (pStyle)
{
individualTabHues[1].changeHLSFrom(pStyle->_bgColor);
individualTabHues[1].loadFromRGB(pStyle->_bgColor);
}

pStyle = stylers.findByName(TABBAR_INDIVIDUALCOLOR_3);
if (pStyle)
{
individualTabHues[2].changeHLSFrom(pStyle->_bgColor);
individualTabHues[2].loadFromRGB(pStyle->_bgColor);
}

pStyle = stylers.findByName(TABBAR_INDIVIDUALCOLOR_4);
if (pStyle)
{
individualTabHues[3].changeHLSFrom(pStyle->_bgColor);
individualTabHues[3].loadFromRGB(pStyle->_bgColor);
}

pStyle = stylers.findByName(TABBAR_INDIVIDUALCOLOR_5);
if (pStyle)
{
individualTabHues[4].changeHLSFrom(pStyle->_bgColor);
individualTabHues[4].loadFromRGB(pStyle->_bgColor);
}


pStyle = stylers.findByName(TABBAR_INDIVIDUALCOLOR_DM_1);
if (pStyle)
{
individualTabHuesFor_Dark[0].changeHLSFrom(pStyle->_bgColor);
individualTabHuesFor_Dark[0].loadFromRGB(pStyle->_bgColor);
}

pStyle = stylers.findByName(TABBAR_INDIVIDUALCOLOR_DM_2);
if (pStyle)
{
individualTabHuesFor_Dark[1].changeHLSFrom(pStyle->_bgColor);
individualTabHuesFor_Dark[1].loadFromRGB(pStyle->_bgColor);
}

pStyle = stylers.findByName(TABBAR_INDIVIDUALCOLOR_DM_3);
if (pStyle)
{
individualTabHuesFor_Dark[2].changeHLSFrom(pStyle->_bgColor);
individualTabHuesFor_Dark[2].loadFromRGB(pStyle->_bgColor);
}

pStyle = stylers.findByName(TABBAR_INDIVIDUALCOLOR_DM_4);
if (pStyle)
{
individualTabHuesFor_Dark[3].changeHLSFrom(pStyle->_bgColor);
individualTabHuesFor_Dark[3].loadFromRGB(pStyle->_bgColor);
}

pStyle = stylers.findByName(TABBAR_INDIVIDUALCOLOR_DM_5);
if (pStyle)
{
individualTabHuesFor_Dark[4].changeHLSFrom(pStyle->_bgColor);
individualTabHuesFor_Dark[4].loadFromRGB(pStyle->_bgColor);
}
}

Expand All @@ -8901,9 +8901,9 @@ void NppParameters::setIndividualTabColor(COLORREF colour2Set, int colourIndex,
if (colourIndex < 0 || colourIndex > 4) return;

if (isDarkMode)
individualTabHuesFor_Dark[colourIndex].changeHLSFrom(colour2Set);
individualTabHuesFor_Dark[colourIndex].loadFromRGB(colour2Set);
else
individualTabHues[colourIndex].changeHLSFrom(colour2Set);
individualTabHues[colourIndex].loadFromRGB(colour2Set);

return;
}
Expand Down
15 changes: 11 additions & 4 deletions PowerEditor/src/Parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -1390,12 +1390,19 @@ friend class NppParameters;

struct HLSColour
{
WORD _hue;
WORD _lightness;
WORD _saturation;
WORD _hue = 0;
WORD _lightness = 0;
WORD _saturation = 0;

void changeHLSFrom(COLORREF rgb) { ColorRGBToHLS(rgb, &_hue, &_lightness, &_saturation); }
HLSColour() = default;
HLSColour(WORD hue, WORD lightness, WORD saturation): _hue(hue), _lightness(lightness), _saturation(saturation) {}
HLSColour(COLORREF rgb) { ColorRGBToHLS(rgb, &_hue, &_lightness, &_saturation); }

void loadFromRGB(COLORREF rgb) { ColorRGBToHLS(rgb, &_hue, &_lightness, &_saturation); }
COLORREF toRGB() const { return ColorHLSToRGB(_hue, _lightness, _saturation); }

COLORREF toRGB4DarkModWithTuning(int lightnessMore, int saturationLess) const { return ColorHLSToRGB(_hue, _lightness + lightnessMore, _saturation - saturationLess); }
COLORREF toRGB4DarkMod() const { return toRGB4DarkModWithTuning(50, 20); }
};

struct UdlXmlFileState final {
Expand Down
21 changes: 6 additions & 15 deletions PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4980,27 +4980,18 @@ void FindReplaceDlg::drawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)

if (_statusbarFindStatus == FSNotFound)
{
HLSColour hls;
hls.changeHLSFrom(nppParamInst.getFindDlgStatusMsgColor(0));
hls._lightness += 50;
hls._saturation -= 20;
fgColor = hls.toRGB();
HLSColour hls(nppParamInst.getFindDlgStatusMsgColor(0));
fgColor = hls.toRGB4DarkMod();
}
else if (_statusbarFindStatus == FSMessage)
{
HLSColour hls;
hls.changeHLSFrom(nppParamInst.getFindDlgStatusMsgColor(1));
hls._lightness += 50;
hls._saturation -= 20;
fgColor = hls.toRGB();
HLSColour hls(nppParamInst.getFindDlgStatusMsgColor(1));
fgColor = hls.toRGB4DarkMod();
}
else if (_statusbarFindStatus == FSTopReached || _statusbarFindStatus == FSEndReached)
{
HLSColour hls;
hls.changeHLSFrom(nppParamInst.getFindDlgStatusMsgColor(2));
hls._lightness += 50;
hls._saturation -= 20;
fgColor = hls.toRGB();
HLSColour hls(nppParamInst.getFindDlgStatusMsgColor(2));
fgColor = hls.toRGB4DarkMod();
}
}

Expand Down

0 comments on commit 2f99023

Please sign in to comment.