From 17d2d5c793eaa95b170684213b18ff2e3f5ce291 Mon Sep 17 00:00:00 2001 From: Neil Date: Fri, 14 May 2021 13:54:44 +1000 Subject: Add SC_ELEMENT_WHITE_SPACE_BACK to set the background colour of visible whitespace. --- doc/ScintillaDoc.html | 55 ++++++++++++++++++++++++++++++++++++++----------- include/Scintilla.h | 1 + include/Scintilla.iface | 1 + src/EditView.cxx | 13 ++++++------ src/Editor.cxx | 5 +++-- src/ViewStyle.cxx | 8 +++---- src/ViewStyle.h | 5 ++--- 7 files changed, 60 insertions(+), 28 deletions(-) diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index e91c80783..380a8e81d 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -128,7 +128,7 @@

Scintilla Documentation

-

Last edited 11 May 2021 NH

+

Last edited 13 May 2021 NH

Scintilla 5 has moved the lexers from Scintilla into a new Lexilla project.
@@ -2302,9 +2302,10 @@ struct Sci_TextToFind { SCI_SETVIEWWS(int viewWS)
SCI_GETVIEWWS → int
SC_ELEMENT_WHITE_SPACE : colouralpha
- SCI_SETWHITESPACEFORE(bool + SCI_SETWHITESPACEFORE(bool useSetting, colour fore)
- SCI_SETWHITESPACEBACK(bool + SC_ELEMENT_WHITE_SPACE_BACK : colouralpha
+ SCI_SETWHITESPACEBACK(bool useSetting, colour back)
SCI_SETWHITESPACESIZE(int size)
@@ -2368,13 +2369,16 @@ struct Sci_TextToFind {

SC_ELEMENT_WHITE_SPACE : colouralpha
SCI_SETWHITESPACEFORE(bool useSetting, colour fore)
+ SC_ELEMENT_WHITE_SPACE_BACK : colouralpha
SCI_SETWHITESPACEBACK(bool useSetting, colour back)
By default, the colour of visible white space is determined by the lexer in use. The foreground and/or background colour of all visible white space can be set globally, overriding - the lexer's colours with SC_ELEMENT_WHITE_SPACE and - SCI_SETWHITESPACEBACK.
- SCI_SETWHITESPACEFORE also changes the white space colour but SC_ELEMENT_WHITE_SPACE - is preferred and allows setting translucency.

+ the lexer's colours with SC_ELEMENT_WHITE_SPACE + and SC_ELEMENT_WHITE_SPACE_BACK. + .
+ SCI_SETWHITESPACEFORE and SCI_SETWHITESPACEBACK also + change the white space colours but the element APIs are preferred with SC_ELEMENT_WHITE_SPACE + allowing translucency.

SCI_SETWHITESPACESIZE(int size)
SCI_GETWHITESPACESIZE → int
@@ -3288,8 +3292,8 @@ struct Sci_TextToFind { When undefined the return value is 0 which is equivalent to completely transparent black. These colours may be useful when defining styles with similarities such as synthesizing dark mode styles that use the same colours as the system

-

On Win32, autocompletion list colours like SC_ELEMENT_LIST are currently available. - On Cocoa, selection background colours like SC_ELEMENT_SELECTION_BACK are currently available. +

On Win32, autocompletion list colours like SC_ELEMENT_LIST are currently provided by the platform layer and + on Cocoa, selection background colours like SC_ELEMENT_SELECTION_BACK are provided.

@@ -3301,7 +3305,9 @@ struct Sci_TextToFind { - + + + @@ -3312,6 +3318,7 @@ struct Sci_TextToFind { + @@ -3319,6 +3326,7 @@ struct Sci_TextToFind { + @@ -3326,6 +3334,7 @@ struct Sci_TextToFind { + @@ -3333,6 +3342,7 @@ struct Sci_TextToFind { + @@ -3340,6 +3350,7 @@ struct Sci_TextToFind { + @@ -3347,6 +3358,7 @@ struct Sci_TextToFind { + @@ -3354,6 +3366,7 @@ struct Sci_TextToFind { + @@ -3361,6 +3374,7 @@ struct Sci_TextToFind { + @@ -3368,6 +3382,7 @@ struct Sci_TextToFind { + @@ -3375,6 +3390,7 @@ struct Sci_TextToFind { + @@ -3382,6 +3398,7 @@ struct Sci_TextToFind { + @@ -3389,6 +3406,7 @@ struct Sci_TextToFind { + @@ -3396,6 +3414,7 @@ struct Sci_TextToFind { + @@ -3403,6 +3422,7 @@ struct Sci_TextToFind { + @@ -3410,22 +3430,33 @@ struct Sci_TextToFind { + - + + - + + + + + + + + + +
Translucent?PlatformsActiveBase Description
0 Opaque Win32Win32 Text colour in autocompletion lists
1 Opaque Win32Win32 Background colour of autocompletion lists
2 Opaque Win32Win32 Text colour of selected item in autocompletion lists
3 Opaque Win32Win32 Background colour of selected item in autocompletion lists
10 Translucent All Text colour of main selection
11 Translucent AllCocoa Background colour of main selection
12 Translucent All Text colour of additional selections
13 Translucent AllCocoa Background colour of additional selections
14 Translucent All Text colour of selections when another window contains the primary selection
15 Translucent All Background colour of selections when another window contains the primary selection
16 Translucent All Text colour of selections when another window has focus
17 Translucent AllCocoa Background colour of selections when another window has focus
40 Translucent All Colour of caret for main selection
41 Translucent All Colour of caret for additional selections
42 Translucent All Colour of carets when another window has focus
SC_ELEMENT_CARET_LINE_BACK 50 Translucent All Colour of caret line background
SC_ELEMENT_WHITE_SPACE 60 Translucent All Colour of visible white space
SC_ELEMENT_WHITE_SPACE_BACK61OpaqueAllColour of visible white space background
diff --git a/include/Scintilla.h b/include/Scintilla.h index b4ec3b462..2c91400af 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -288,6 +288,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SC_ELEMENT_CARET_SECONDARY 42 #define SC_ELEMENT_CARET_LINE_BACK 50 #define SC_ELEMENT_WHITE_SPACE 60 +#define SC_ELEMENT_WHITE_SPACE_BACK 61 #define SCI_SETELEMENTCOLOUR 2753 #define SCI_GETELEMENTCOLOUR 2754 #define SCI_RESETELEMENTCOLOUR 2755 diff --git a/include/Scintilla.iface b/include/Scintilla.iface index 38b548d0d..730c7bb12 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -695,6 +695,7 @@ val SC_ELEMENT_CARET_ADDITIONAL=41 val SC_ELEMENT_CARET_SECONDARY=42 val SC_ELEMENT_CARET_LINE_BACK=50 val SC_ELEMENT_WHITE_SPACE=60 +val SC_ELEMENT_WHITE_SPACE_BACK=61 # Set the colour of an element. Translucency (alpha) may or may not be significant # and this may depend on the platform. The alpha byte should commonly be 0xff for opaque. diff --git a/src/EditView.cxx b/src/EditView.cxx index 4a10f6584..7797236c8 100644 --- a/src/EditView.cxx +++ b/src/EditView.cxx @@ -1726,8 +1726,9 @@ void EditView::DrawBackground(Surface *surface, const EditModel &model, const Vi if (ts.representation) { if (ll->chars[i] == '\t') { // Tab display - if (drawWhitespaceBackground && vsDraw.WhiteSpaceVisible(inIndentation)) - textBack = *vsDraw.whitespaceBack; + if (drawWhitespaceBackground && vsDraw.WhiteSpaceVisible(inIndentation)) { + textBack = vsDraw.ElementColour(SC_ELEMENT_WHITE_SPACE_BACK)->Opaque(); + } } else { // Blob display inIndentation = false; @@ -1745,7 +1746,8 @@ void EditView::DrawBackground(Surface *surface, const EditModel &model, const Vi rcSegment.top, ll->positions[cpos + ts.start + 1] + xStart - static_cast(subLineStart), rcSegment.bottom); - surface->FillRectangleAligned(rcSpace, Fill(*vsDraw.whitespaceBack)); + surface->FillRectangleAligned(rcSpace, + vsDraw.ElementColour(SC_ELEMENT_WHITE_SPACE_BACK)->Opaque()); } } else { inIndentation = false; @@ -1972,7 +1974,7 @@ void EditView::DrawForeground(Surface *surface, const EditModel &model, const Vi // Tab display if (phasesDraw == PhasesDraw::one) { if (drawWhitespaceBackground && vsDraw.WhiteSpaceVisible(inIndentation)) - textBack = *vsDraw.whitespaceBack; + textBack = vsDraw.ElementColour(SC_ELEMENT_WHITE_SPACE_BACK)->Opaque(); surface->FillRectangleAligned(rcSegment, Fill(textBack)); } if (inIndentation && vsDraw.viewIndentationGuides == IndentView::real) { @@ -2034,7 +2036,7 @@ void EditView::DrawForeground(Surface *surface, const EditModel &model, const Vi if (vsDraw.WhiteSpaceVisible(inIndentation)) { const XYPOSITION xmid = (ll->positions[cpos + ts.start] + ll->positions[cpos + ts.start + 1]) / 2; if ((phasesDraw == PhasesDraw::one) && drawWhitespaceBackground) { - textBack = *vsDraw.whitespaceBack; + textBack = vsDraw.ElementColour(SC_ELEMENT_WHITE_SPACE_BACK)->Opaque(); const PRectangle rcSpace( ll->positions[cpos + ts.start] + xStart - static_cast(subLineStart), rcSegment.top, @@ -2514,7 +2516,6 @@ Sci::Position EditView::FormatRange(bool draw, const Sci_RangeToFormat *pfr, Sur // Don't show the selection when printing vsPrint.elementColours.clear(); vsPrint.elementBaseColours.clear(); - vsPrint.whitespaceBack.reset(); vsPrint.caretLine.alwaysShow = false; // Don't highlight matching braces using indicators vsPrint.braceHighlightIndicatorSet = false; diff --git a/src/Editor.cxx b/src/Editor.cxx index 62cb170d3..9b5bfd6ee 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -7518,8 +7518,9 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { break; case SCI_SETWHITESPACEBACK: - vs.whitespaceBack = OptionalColour(wParam, lParam); - InvalidateStyleRedraw(); + if (vs.SetElementColourOptional(SC_ELEMENT_WHITE_SPACE_BACK, wParam, lParam)) { + InvalidateStyleRedraw(); + } break; case SCI_SETSELECTIONLAYER: diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx index 3785dec37..489758c71 100644 --- a/src/ViewStyle.cxx +++ b/src/ViewStyle.cxx @@ -108,7 +108,6 @@ ViewStyle::ViewStyle(const ViewStyle &source) : markers(MARKER_MAX + 1), indicat textStart = source.textStart; zoomLevel = source.zoomLevel; viewWhitespace = source.viewWhitespace; - whitespaceBack = source.whitespaceBack; tabDrawMode = source.tabDrawMode; whitespaceSize = source.whitespaceSize; viewIndentationGuides = source.viewIndentationGuides; @@ -265,7 +264,6 @@ void ViewStyle::Init(size_t stylesSize_) { textStart = marginInside ? fixedColumnWidth : leftMarginWidth; zoomLevel = 0; viewWhitespace = WhiteSpace::invisible; - whitespaceBack.reset(); tabDrawMode = TabDrawMode::longArrow; whitespaceSize = 1; elementColours.erase(SC_ELEMENT_WHITE_SPACE); @@ -522,8 +520,8 @@ bool ViewStyle::SelectionTextDrawn() const { ElementIsSet(SC_ELEMENT_SELECTION_NO_FOCUS_TEXT); } -bool ViewStyle::WhitespaceBackgroundDrawn() const noexcept { - return (viewWhitespace != WhiteSpace::invisible) && (whitespaceBack); +bool ViewStyle::WhitespaceBackgroundDrawn() const { + return (viewWhitespace != WhiteSpace::invisible) && (ElementIsSet(SC_ELEMENT_WHITE_SPACE_BACK)); } bool ViewStyle::WhiteSpaceVisible(bool inIndent) const noexcept { @@ -532,7 +530,7 @@ bool ViewStyle::WhiteSpaceVisible(bool inIndent) const noexcept { viewWhitespace == WhiteSpace::visibleAlways; } -ColourAlpha ViewStyle::WrapColour() const noexcept { +ColourAlpha ViewStyle::WrapColour() const { return ElementColour(SC_ELEMENT_WHITE_SPACE).value_or(styles[STYLE_DEFAULT].fore); } diff --git a/src/ViewStyle.h b/src/ViewStyle.h index b726cc559..cf8da4fe6 100644 --- a/src/ViewStyle.h +++ b/src/ViewStyle.h @@ -153,7 +153,6 @@ public: int textStart; ///< Starting x position of text within the view int zoomLevel; WhiteSpace viewWhitespace; - std::optional whitespaceBack; TabDrawMode tabDrawMode; int whitespaceSize; IndentView viewIndentationGuides; @@ -220,8 +219,8 @@ public: std::optional Background(int marksOfLine, bool caretActive, bool lineContainsCaret) const; bool SelectionBackgroundDrawn() const noexcept; bool SelectionTextDrawn() const; - bool WhitespaceBackgroundDrawn() const noexcept; - ColourAlpha WrapColour() const noexcept; + bool WhitespaceBackgroundDrawn() const; + ColourAlpha WrapColour() const; void AddMultiEdge(uptr_t wParam, sptr_t lParam); -- cgit v1.2.3