diff options
author | YX Hao <unknown> | 2021-05-14 13:45:47 +1000 |
---|---|---|
committer | YX Hao <unknown> | 2021-05-14 13:45:47 +1000 |
commit | c173fc47fda7bb86399bd777540bb17f8e05172d (patch) | |
tree | 7d2e3f3b7ae1bea1dffd5c859414d35eb83f3a14 | |
parent | cafd88c083472076372469759addf9f491499de3 (diff) | |
download | scintilla-mirror-c173fc47fda7bb86399bd777540bb17f8e05172d.tar.gz |
Feature [feature-requests:#1402] Add SC_ELEMENT_WHITE_SPACE to set the colour of
visible whitespace including translucency.
-rw-r--r-- | doc/ScintillaDoc.html | 18 | ||||
-rw-r--r-- | doc/ScintillaHistory.html | 4 | ||||
-rw-r--r-- | include/Scintilla.h | 1 | ||||
-rw-r--r-- | include/Scintilla.iface | 1 | ||||
-rw-r--r-- | src/EditView.cxx | 23 | ||||
-rw-r--r-- | src/Editor.cxx | 7 | ||||
-rw-r--r-- | src/ViewStyle.cxx | 20 | ||||
-rw-r--r-- | src/ViewStyle.h | 3 |
8 files changed, 52 insertions, 25 deletions
diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index 990868241..e91c80783 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -2301,6 +2301,7 @@ struct Sci_TextToFind { <h2 id="WhiteSpace">White space</h2> <code><a class="message" href="#SCI_SETVIEWWS">SCI_SETVIEWWS(int viewWS)</a><br /> <a class="message" href="#SCI_GETVIEWWS">SCI_GETVIEWWS → int</a><br /> + <a class="element" href="#SC_ELEMENT_WHITE_SPACE">SC_ELEMENT_WHITE_SPACE : colouralpha</a><br /> <a class="message" href="#SCI_SETWHITESPACEFORE">SCI_SETWHITESPACEFORE(bool useSetting, colour fore)</a><br /> <a class="message" href="#SCI_SETWHITESPACEBACK">SCI_SETWHITESPACEBACK(bool @@ -2364,12 +2365,16 @@ struct Sci_TextToFind { <p>The effect of using any other <code class="parameter">viewWS</code> value is undefined.</p> - <p><b id="SCI_SETWHITESPACEFORE">SCI_SETWHITESPACEFORE(bool useSetting, <a class="jump" href="#colour">colour</a> fore)</b><br /> + <p> + <b id="SC_ELEMENT_WHITE_SPACE">SC_ELEMENT_WHITE_SPACE : colouralpha</b><br /> + <b id="SCI_SETWHITESPACEFORE">SCI_SETWHITESPACEFORE(bool useSetting, <a class="jump" href="#colour">colour</a> fore)</b><br /> <b id="SCI_SETWHITESPACEBACK">SCI_SETWHITESPACEBACK(bool useSetting, <a class="jump" href="#colour">colour</a> back)</b><br /> 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 <code>SCI_SETWHITESPACEFORE</code> and - <code>SCI_SETWHITESPACEBACK</code>.</p> + the lexer's colours with <a href="#SCI_SETELEMENTCOLOUR"><code>SC_ELEMENT_WHITE_SPACE</code></a> and + <code>SCI_SETWHITESPACEBACK</code>.<br /> + <code>SCI_SETWHITESPACEFORE</code> also changes the white space colour but <code>SC_ELEMENT_WHITE_SPACE</code> + is preferred and allows setting translucency.</p> <p><b id="SCI_SETWHITESPACESIZE">SCI_SETWHITESPACESIZE(int size)</b><br /> <b id="SCI_GETWHITESPACESIZE">SCI_GETWHITESPACESIZE → int</b><br /> @@ -3414,6 +3419,13 @@ struct Sci_TextToFind { <td>All</td> <td>Colour of caret line background</td> </tr> + <tr> + <th align="left"><code>SC_ELEMENT_WHITE_SPACE</code></th> + <td>60</td> + <td>Translucent</td> + <td>All</td> + <td>Colour of visible white space</td> + </tr> </tbody> </table> diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index 8fdea24bc..c0123dd4a 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -559,6 +559,7 @@ </tr><tr> <td>cshnik</td> <td>Petko Georgiev</td> + <td>YX Hao</td> </tr> </table> <p> @@ -599,6 +600,9 @@ Add SCI_GETELEMENTBASECOLOUR to return the default values for element colours. </li> <li> + Add SC_ELEMENT_WHITE_SPACE to set the colour of visible whitespace including translucency. + </li> + <li> Make idle actions wrapping and background styling smoother by measuring per-byte instead of per-line and allowing just one line to be processed in a time slice. diff --git a/include/Scintilla.h b/include/Scintilla.h index de0e37ca7..b4ec3b462 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -287,6 +287,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SC_ELEMENT_CARET_ADDITIONAL 41 #define SC_ELEMENT_CARET_SECONDARY 42 #define SC_ELEMENT_CARET_LINE_BACK 50 +#define SC_ELEMENT_WHITE_SPACE 60 #define SCI_SETELEMENTCOLOUR 2753 #define SCI_GETELEMENTCOLOUR 2754 #define SCI_RESETELEMENTCOLOUR 2755 diff --git a/include/Scintilla.iface b/include/Scintilla.iface index 0f1b0fc3c..38b548d0d 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -694,6 +694,7 @@ val SC_ELEMENT_CARET=40 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 # 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 bef27fd3e..4a10f6584 100644 --- a/src/EditView.cxx +++ b/src/EditView.cxx @@ -1727,7 +1727,7 @@ void EditView::DrawBackground(Surface *surface, const EditModel &model, const Vi if (ll->chars[i] == '\t') { // Tab display if (drawWhitespaceBackground && vsDraw.WhiteSpaceVisible(inIndentation)) - textBack = *vsDraw.whitespaceColours.back; + textBack = *vsDraw.whitespaceBack; } else { // Blob display inIndentation = false; @@ -1745,7 +1745,7 @@ void EditView::DrawBackground(Surface *surface, const EditModel &model, const Vi rcSegment.top, ll->positions[cpos + ts.start + 1] + xStart - static_cast<XYPOSITION>(subLineStart), rcSegment.bottom); - surface->FillRectangleAligned(rcSpace, Fill(*vsDraw.whitespaceColours.back)); + surface->FillRectangleAligned(rcSpace, Fill(*vsDraw.whitespaceBack)); } } else { inIndentation = false; @@ -1972,7 +1972,7 @@ void EditView::DrawForeground(Surface *surface, const EditModel &model, const Vi // Tab display if (phasesDraw == PhasesDraw::one) { if (drawWhitespaceBackground && vsDraw.WhiteSpaceVisible(inIndentation)) - textBack = *vsDraw.whitespaceColours.back; + textBack = *vsDraw.whitespaceBack; surface->FillRectangleAligned(rcSegment, Fill(textBack)); } if (inIndentation && vsDraw.viewIndentationGuides == IndentView::real) { @@ -1988,15 +1988,14 @@ void EditView::DrawForeground(Surface *surface, const EditModel &model, const Vi } if (vsDraw.viewWhitespace != WhiteSpace::invisible) { if (vsDraw.WhiteSpaceVisible(inIndentation)) { - if (vsDraw.whitespaceColours.fore) - textFore = *vsDraw.whitespaceColours.fore; const PRectangle rcTab(rcSegment.left + 1, rcSegment.top + tabArrowHeight, rcSegment.right - 1, rcSegment.bottom - vsDraw.maxDescent); const int segmentTop = static_cast<int>(rcSegment.top) + vsDraw.lineHeight / 2; + const ColourAlpha whiteSpaceFore = vsDraw.ElementColour(SC_ELEMENT_WHITE_SPACE).value_or(textFore); if (!customDrawTabArrow) - DrawTabArrow(surface, rcTab, segmentTop, vsDraw, Stroke(textFore, 1.0f)); + DrawTabArrow(surface, rcTab, segmentTop, vsDraw, Stroke(whiteSpaceFore, 1.0f)); else - customDrawTabArrow(surface, rcTab, segmentTop, vsDraw, Stroke(textFore, 1.0f)); + customDrawTabArrow(surface, rcTab, segmentTop, vsDraw, Stroke(whiteSpaceFore, 1.0f)); } } } else { @@ -2032,12 +2031,10 @@ void EditView::DrawForeground(Surface *surface, const EditModel &model, const Vi for (int cpos = 0; cpos <= i - ts.start; cpos++) { if (ll->chars[cpos + ts.start] == ' ') { if (vsDraw.viewWhitespace != WhiteSpace::invisible) { - if (vsDraw.whitespaceColours.fore) - textFore = *vsDraw.whitespaceColours.fore; 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.whitespaceColours.back; + textBack = *vsDraw.whitespaceBack; const PRectangle rcSpace( ll->positions[cpos + ts.start] + xStart - static_cast<XYPOSITION>(subLineStart), rcSegment.top, @@ -2050,7 +2047,8 @@ void EditView::DrawForeground(Surface *surface, const EditModel &model, const Vi rcSegment.top + vsDraw.lineHeight / 2, 0.0f, 0.0f); rcDot.right = rcDot.left + vsDraw.whitespaceSize; rcDot.bottom = rcDot.top + vsDraw.whitespaceSize; - surface->FillRectangleAligned(rcDot, Fill(textFore)); + const ColourAlpha whiteSpaceFore = vsDraw.ElementColour(SC_ELEMENT_WHITE_SPACE).value_or(textFore); + surface->FillRectangleAligned(rcDot, Fill(whiteSpaceFore)); } } if (inIndentation && vsDraw.viewIndentationGuides == IndentView::real) { @@ -2516,8 +2514,7 @@ 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.whitespaceColours.back.reset(); - vsPrint.whitespaceColours.fore.reset(); + 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 8b6147a5b..62cb170d3 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -7512,12 +7512,13 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { break; case SCI_SETWHITESPACEFORE: - vs.whitespaceColours.fore = OptionalColour(wParam, lParam); - InvalidateStyleRedraw(); + if (vs.SetElementColourOptional(SC_ELEMENT_WHITE_SPACE, wParam, lParam)) { + InvalidateStyleRedraw(); + } break; case SCI_SETWHITESPACEBACK: - vs.whitespaceColours.back = OptionalColour(wParam, lParam); + vs.whitespaceBack = OptionalColour(wParam, lParam); InvalidateStyleRedraw(); break; diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx index 455a44c1e..3785dec37 100644 --- a/src/ViewStyle.cxx +++ b/src/ViewStyle.cxx @@ -90,7 +90,6 @@ ViewStyle::ViewStyle(const ViewStyle &source) : markers(MARKER_MAX + 1), indicat hotspotColours = source.hotspotColours; hotspotUnderline = source.hotspotUnderline; - whitespaceColours = source.whitespaceColours; controlCharSymbol = source.controlCharSymbol; controlCharWidth = source.controlCharWidth; selbar = source.selbar; @@ -109,6 +108,7 @@ 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; @@ -223,8 +223,6 @@ void ViewStyle::Init(size_t stylesSize_) { foldmarginColour.reset(); foldmarginHighlightColour.reset(); - whitespaceColours.fore.reset(); - whitespaceColours.back.reset(); controlCharSymbol = 0; /* Draw the control characters */ controlCharWidth = 0; selbar = Platform::Chrome(); @@ -267,8 +265,12 @@ 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); + elementAllowsTranslucent.insert(SC_ELEMENT_WHITE_SPACE); + viewIndentationGuides = IndentView::none; viewEOL = false; extraFontFlag = 0; @@ -521,7 +523,7 @@ bool ViewStyle::SelectionTextDrawn() const { } bool ViewStyle::WhitespaceBackgroundDrawn() const noexcept { - return (viewWhitespace != WhiteSpace::invisible) && (whitespaceColours.back); + return (viewWhitespace != WhiteSpace::invisible) && (whitespaceBack); } bool ViewStyle::WhiteSpaceVisible(bool inIndent) const noexcept { @@ -531,7 +533,7 @@ bool ViewStyle::WhiteSpaceVisible(bool inIndent) const noexcept { } ColourAlpha ViewStyle::WrapColour() const noexcept { - return whitespaceColours.fore.value_or(styles[STYLE_DEFAULT].fore); + return ElementColour(SC_ELEMENT_WHITE_SPACE).value_or(styles[STYLE_DEFAULT].fore); } // Insert new edge in sorted order. @@ -581,6 +583,14 @@ bool ViewStyle::SetElementColour(int element, ColourAlpha colour) { return changed; } +bool ViewStyle::SetElementColourOptional(int element, uptr_t wParam, sptr_t lParam) { + if (wParam) { + return SetElementColour(element, ColourAlpha::FromRGB(static_cast<int>(lParam))); + } else { + return ResetElement(element); + } +} + void ViewStyle::SetElementRGB(int element, int rgb) { const ColourAlpha current = ElementColour(element).value_or(ColourAlpha(0, 0, 0, 0)); elementColours[element] = ColourAlpha(ColourAlpha(rgb), current.GetAlpha()); diff --git a/src/ViewStyle.h b/src/ViewStyle.h index 20325a962..b726cc559 100644 --- a/src/ViewStyle.h +++ b/src/ViewStyle.h @@ -134,7 +134,6 @@ public: SelectionAppearance selection; - ForeBackColours whitespaceColours; int controlCharSymbol; XYPOSITION controlCharWidth; ColourAlpha selbar; @@ -154,6 +153,7 @@ public: int textStart; ///< Starting x position of text within the view int zoomLevel; WhiteSpace viewWhitespace; + std::optional<ColourAlpha> whitespaceBack; TabDrawMode tabDrawMode; int whitespaceSize; IndentView viewIndentationGuides; @@ -229,6 +229,7 @@ public: bool ElementAllowsTranslucent(int element) const; bool ResetElement(int element); bool SetElementColour(int element, ColourAlpha colour); + bool SetElementColourOptional(int element, uptr_t wParam, sptr_t lParam); void SetElementRGB(int element, int rgb); void SetElementAlpha(int element, int alpha); bool ElementIsSet(int element) const; |