Skip to content

Commit

Permalink
Make current block highlighting color customizable.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Apr 9, 2020
1 parent f7ee5bc commit 4daf95f
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 16 deletions.
Binary file modified doc/Notepad2 DarkTheme.ini
Binary file not shown.
1 change: 1 addition & 0 deletions src/EditLexers/EditStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define NP2STYLE_IMEIndicator 63117
#define NP2STYLE_Bookmark 63118
#define NP2STYLE_CallTip 63119
#define NP2STYLE_CurrentBlock 63120

#define NP2STYLE_Default 63126
#define NP2STYLE_Comment 63127
Expand Down
1 change: 1 addition & 0 deletions src/EditLexers/EditStyleX.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#define NP2StyleX_IMEIndicator EDITSTYLE_HOLE(IMEIndicator, L"IME Indicator")
#define NP2StyleX_Bookmark EDITSTYLE_HOLE(Bookmark, L"Bookmark")
#define NP2StyleX_CallTip EDITSTYLE_HOLE(CallTip, L"CallTip")
#define NP2StyleX_CurrentBlock EDITSTYLE_HOLE(CurrentBlock, L"Current Block")

#define NP2StyleX_Default EDITSTYLE_HOLE(Default, L"Default")
#define NP2StyleX_Comment EDITSTYLE_HOLE(Comment, L"Comment")
Expand Down
2 changes: 2 additions & 0 deletions src/EditLexers/stlDefault.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ static EDITSTYLE Styles_Global[] = {
{ STYLE_INDENTGUIDE, NP2StyleX_IndentationGuide, L"fore:#FF8000" },
{ SCI_SETSELFORE + SCI_SETSELBACK, NP2StyleX_SelectedText, L"eolfilled; alpha:95; outline:50" },
{ SCI_SETWHITESPACEFORE + SCI_SETWHITESPACEBACK + SCI_SETWHITESPACESIZE, NP2StyleX_Whitespace, L"size:1; fore:#FF4000" },
{ 0, NP2StyleX_CurrentBlock, L"" },
{ SCI_SETCARETLINEBACK, NP2StyleX_CurrentLine, L"size:2; fore:#C2C0C3; back:#FFFF00; alpha:90; outline:90" },
{ SCI_SETCARETFORE + SCI_SETCARETWIDTH, NP2StyleX_Caret, L"back:#FF0000" },
{ 0, NP2StyleX_IMEIndicator, L"fore:#108010" },
Expand All @@ -39,6 +40,7 @@ static EDITSTYLE Styles_2ndGlobal[] = {
{ STYLE_INDENTGUIDE, NP2StyleX_IndentationGuide, L"fore:#605F63" },
{ SCI_SETSELFORE + SCI_SETSELBACK, NP2StyleX_SelectedText, L"eolfilled; alpha:95; outline:50" },
{ SCI_SETWHITESPACEFORE + SCI_SETWHITESPACEBACK + SCI_SETWHITESPACESIZE, NP2StyleX_Whitespace, L"size:1; fore:#FF4000" },
{ 0, NP2StyleX_CurrentBlock, L"fore:#FF8000" },
{ SCI_SETCARETLINEBACK, NP2StyleX_CurrentLine, L"size:2; fore:#C2C0C3; back:#FFFF00; alpha:25; outline:25" },
{ SCI_SETCARETFORE + SCI_SETCARETWIDTH, NP2StyleX_Caret, L"fore:#FFFFFF; back:#00FF00" },
{ 0, NP2StyleX_IMEIndicator, L"fore:#108010" },
Expand Down
4 changes: 4 additions & 0 deletions src/SciCall.h
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,10 @@ NP2_inline void SciCall_MarkerSetBack(int markerNumber, COLORREF back) {
SciCall(SCI_MARKERSETBACK, markerNumber, back);
}

NP2_inline void SciCall_MarkerSetBackSelected(int markerNumber, COLORREF back) {
SciCall(SCI_MARKERSETBACKSELECTED, markerNumber, back);
}

NP2_inline void SciCall_MarkerSetAlpha(int markerNumber, int alpha) {
SciCall(SCI_MARKERSETALPHA, markerNumber, alpha);
}
Expand Down
42 changes: 26 additions & 16 deletions src/Styles.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ enum GlobalStyleIndex {
GlobalStyleIndex_IndentationGuide, // inherited style. `fore`, `back`
GlobalStyleIndex_Selection, // standalone style. main selection (`back`, `alpha`), additional selection (`fore`, `outline`), `eolfilled`
GlobalStyleIndex_Whitespace, // standalone style. `fore`, `back`, `size`: dot size
GlobalStyleIndex_CurrentBlock, // standalone style. `fore`
GlobalStyleIndex_CurrentLine, // standalone style. frame (`fore`, `size`, `outline`), background (`back`, `alpha`)
GlobalStyleIndex_Caret, // standalone style. `fore`: main caret color, `back`: additional caret color
GlobalStyleIndex_IMEIndicator, // indicator style. `fore`: IME indicator color
Expand Down Expand Up @@ -451,6 +452,7 @@ static inline UINT GetDefaultStyleControlMask(int index) {
return StyleControl_Fore | StyleControl_Back | StyleControl_EOLFilled;
case GlobalStyleIndex_MatchBrace:
case GlobalStyleIndex_MatchBraceError:
case GlobalStyleIndex_CurrentBlock:
case GlobalStyleIndex_IMEIndicator:
case GlobalStyleIndex_MarkOccurrence:
return StyleControl_Fore;
Expand Down Expand Up @@ -1589,44 +1591,52 @@ void Style_SetLexer(PEDITLEXER pLexNew, BOOL bLexerChanged) {
SC_MARKNUM_FOLDERMIDTAIL
};

COLORREF clrFore;
COLORREF clrFill;
COLORREF foreColor;
COLORREF fillColor;
COLORREF highlightColor;

szValue = pLexGlobal->Styles[GlobalStyleIndex_FoldingMarker].szValue;
if (Style_StrGetForeColor(szValue, &rgb)) {
clrFore = rgb;
foreColor = rgb;
} else {
clrFore = (bUse2ndGlobalStyle || np2StyleTheme == StyleTheme_Dark) ? FoldingMarkerLineColorDark : FoldingMarkerLineColorDefault;
foreColor = (bUse2ndGlobalStyle || np2StyleTheme == StyleTheme_Dark) ? FoldingMarkerLineColorDark : FoldingMarkerLineColorDefault;
}
if (Style_StrGetBackColor(szValue, &rgb)) {
clrFill = rgb;
fillColor = rgb;
} else {
clrFill = (bUse2ndGlobalStyle || np2StyleTheme == StyleTheme_Dark) ? FoldingMarkerFillColorDark : FoldingMarkerFillColorDefault;
fillColor = (bUse2ndGlobalStyle || np2StyleTheme == StyleTheme_Dark) ? FoldingMarkerFillColorDark : FoldingMarkerFillColorDefault;
}

szValue = pLexGlobal->Styles[GlobalStyleIndex_CurrentBlock].szValue;
if (!Style_StrGetForeColor(szValue, &highlightColor)) {
highlightColor = RGB(0xFF, 0x00, 0x00); // Scintilla default red color
}

SciCall_SetFoldMarginColour(TRUE, backColor);
SciCall_SetFoldMarginHiColour(TRUE, backColor);
#if 0 // use gray fold color
COLORREF clrFore = SciCall_StyleGetFore(STYLE_DEFAULT);
COLORREF foreColor = SciCall_StyleGetFore(STYLE_DEFAULT);
// Marker fore/back colors
// Set marker color to the average of clrFore and backColor
clrFore = (((clrFore & 0xFF0000) + (backColor & 0xFF0000)) >> 1 & 0xFF0000) |
(((clrFore & 0x00FF00) + (backColor & 0x00FF00)) >> 1 & 0x00FF00) |
(((clrFore & 0x0000FF) + (backColor & 0x0000FF)) >> 1 & 0x0000FF);
// Set marker color to the average of foreColor and backColor
foreColor = (((foreColor & 0xFF0000) + (backColor & 0xFF0000)) >> 1 & 0xFF0000) |
(((foreColor & 0x00FF00) + (backColor & 0x00FF00)) >> 1 & 0x00FF00) |
(((foreColor & 0x0000FF) + (backColor & 0x0000FF)) >> 1 & 0x0000FF);

// Rounding hack for pure white against pure black
if (clrFore == 0x7F7F7F) {
clrFore = 0x808080;
if (foreColor == 0x7F7F7F) {
foreColor = 0x808080;
}
#endif

for (UINT i = 0; i < (UINT)COUNTOF(iMarkerIDs); ++i) {
const int marker = iMarkerIDs[i];
SciCall_MarkerSetBack(marker, clrFore);
SciCall_MarkerSetBack(marker, foreColor);
SciCall_MarkerSetFore(marker, backColor);
SciCall_MarkerSetBackSelected(marker, highlightColor);
}
SciCall_MarkerSetFore(SC_MARKNUM_FOLDER, clrFill);
SciCall_MarkerSetFore(SC_MARKNUM_FOLDEREND, clrFill);

SciCall_MarkerSetFore(SC_MARKNUM_FOLDER, fillColor);
SciCall_MarkerSetFore(SC_MARKNUM_FOLDEREND, fillColor);

Style_SetDefaultStyle(GlobalStyleIndex_FoldDispalyText);
} // end set folding style
Expand Down

0 comments on commit 4daf95f

Please sign in to comment.