From e056a167c96e226dc7487f5df2263d17a4dec399 Mon Sep 17 00:00:00 2001 From: Neil Date: Sat, 27 Mar 2021 09:40:14 +1100 Subject: Add APIs for setting translucency and stroke width of markers. --- doc/ScintillaDoc.html | 45 +++++++++++++++++++++++++++++++++++---------- doc/ScintillaHistory.html | 5 +++++ include/Scintilla.h | 4 ++++ include/Scintilla.iface | 12 ++++++++++++ scripts/CheckMentioned.py | 6 ++++++ src/Editor.cxx | 32 ++++++++++++++++++++++++++++---- src/LineMarker.cxx | 26 +++++++++++++------------- src/LineMarker.h | 7 ++++--- 8 files changed, 107 insertions(+), 30 deletions(-) diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index ea1484501..ccbdf6550 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -251,6 +251,17 @@ system and the current screen mode. + + colouralpha + + Colours are set using the RGBA format (Red, Green, Blue, Alpha). + This is similar to colour but with a byte + of alpha added. They are combined as: + red | (green << 8) | (blue << 16) | (alpha << 24). + Fully opaque uses an alpha of 255. SC_ALPHA_NOALPHA is not possible for + colouralpha values. + + alpha @@ -4051,7 +4062,7 @@ struct Sci_TextToFind { For example, on Win32, Direct2D supports drawing translucent lines but GDI does not so SCI_SUPPORTSFEATURE(SC_SUPPORTS_TRANSLUCENT_STROKE) will return 1 for Direct2D and 0 for GDI. Its possible that translucent line drawing will be implemented in a future - revision to the GDI platform layer or will be implmented on particular Windows versions. + revision to the GDI platform layer or will be implemented on particular Windows versions. This call allows applications to tailor their settings: perhaps displaying a box with translucent coloured fill on Direct2D but a hollow box on GDI.

The features that can be queried are:

@@ -4321,12 +4332,15 @@ struct Sci_TextToFind { SCI_MARKERDEFINERGBAIMAGE(int markerNumber, const char *pixels)
SCI_MARKERSYMBOLDEFINED(int markerNumber) → int
- SCI_MARKERSETFORE(int markerNumber, colour - fore)
- SCI_MARKERSETBACK(int markerNumber, colour - back)
+ SCI_MARKERSETFORE(int markerNumber, colour fore)
+ SCI_MARKERSETFORETRANSLUCENT(int markerNumber, colouralpha fore)
+ SCI_MARKERSETBACK(int markerNumber, colour back)
+ SCI_MARKERSETBACKTRANSLUCENT(int markerNumber, colouralpha back)
SCI_MARKERSETBACKSELECTED(int markerNumber, colour back)
+ SCI_MARKERSETBACKSELECTEDTRANSLUCENT(int markerNumber, colouralpha + back)
+ SCI_MARKERSETSTROKEWIDTH(int markerNumber, int hundredths)
SCI_MARKERENABLEHIGHLIGHT(bool enabled)
SCI_MARKERSETALPHA(int markerNumber, alpha alpha)
SCI_MARKERADD(line line, int markerNumber) → int
@@ -4540,18 +4554,30 @@ struct Sci_TextToFind { or SC_MARK_PIXMAP if defined with SCI_MARKERDEFINEPIXMAP or SC_MARK_RGBAIMAGE if defined with SCI_MARKERDEFINERGBAIMAGE.

-

SCI_MARKERSETFORE(int markerNumber, colour fore)
+

+ SCI_MARKERSETFORE(int markerNumber, colour fore)
+ SCI_MARKERSETFORETRANSLUCENT(int markerNumber, colouralpha fore)
SCI_MARKERSETBACK(int markerNumber, colour back)
- These two messages set the foreground and background colour of a marker number.
+ SCI_MARKERSETBACKTRANSLUCENT(int markerNumber, colouralpha back)
+ These messages set the foreground and background colour of a marker number. + The TRANSLUCENT variants can define different degrees of opacity.
SCI_MARKERSETBACKSELECTED(int markerNumber, colour back)
+ SCI_MARKERSETBACKSELECTEDTRANSLUCENT(int markerNumber, colouralpha back)
This message sets the highlight background colour of a marker number when its folding block is selected. The default colour is #FF0000.

+ +

SCI_MARKERSETSTROKEWIDTH(int markerNumber, int hundredths)
+ This message sets the stroke width used to draw the marker in hundredths of a pixel. + The default value is 100 indicating a single pixel wide line.

+

SCI_MARKERENABLEHIGHLIGHT(bool enabled)
This message allows to enable/disable the highlight folding block when it is selected. (i.e. block that contains the caret)

+

SCI_MARKERSETALPHA(int markerNumber, alpha alpha)
When markers are drawn in the content area, either because there is no margin for them or they are of SC_MARK_BACKGROUND or SC_MARK_UNDERLINE types, they may be drawn translucently by - setting an alpha value.

+ setting an alpha value. This is only for the content area - in margins, translucency is achieved through the SCI_MARKERSET…TRANSLUCENT + methods.

SCI_MARKERADD(line line, int markerNumber) → int
This message adds marker number markerNumber to a line. The message returns -1 if @@ -5009,8 +5035,7 @@ struct Sci_TextToFind { SCI_INDICATORFILLRANGE(position start, position lengthFill)
SCI_INDICATORCLEARRANGE(position start, position lengthClear)
These two messages fill or clear a range for the current indicator. - SCI_INDICATORFILLRANGE fills with the - the current value. + SCI_INDICATORFILLRANGE fills with the current value.

diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index 47f16e0ce..614866e30 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -600,6 +600,11 @@ Add SCI_INDICSETSTROKEWIDTH to set stroke width of indicators.

  • + Add methods to set translucency and stroke width of markers. + SCI_MARKERSETFORETRANSLUCENT, SCI_MARKERSETBACKTRANSLUCENT, + SCI_MARKERSETBACKSELECTEDTRANSLUCENT, SCI_MARKERSETSTROKEWIDTH. +
  • +
  • Change graphics coordinates from float (32-bit) to double (64-bit). Fixes uneven line heights in large documents on Cocoa. Increases memory use. diff --git a/include/Scintilla.h b/include/Scintilla.h index 69dc2d057..752c105a8 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -161,6 +161,10 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_MARKERSETFORE 2041 #define SCI_MARKERSETBACK 2042 #define SCI_MARKERSETBACKSELECTED 2292 +#define SCI_MARKERSETFORETRANSLUCENT 2294 +#define SCI_MARKERSETBACKTRANSLUCENT 2295 +#define SCI_MARKERSETBACKSELECTEDTRANSLUCENT 2296 +#define SCI_MARKERSETSTROKEWIDTH 2297 #define SCI_MARKERENABLEHIGHLIGHT 2293 #define SCI_MARKERADD 2043 #define SCI_MARKERDELETE 2044 diff --git a/include/Scintilla.iface b/include/Scintilla.iface index 23938bfd9..333362cc0 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -404,6 +404,18 @@ set void MarkerSetBack=2042(int markerNumber, colour back) # Set the background colour used for a particular marker number when its folding block is selected. set void MarkerSetBackSelected=2292(int markerNumber, colour back) +# Set the foreground colour used for a particular marker number. +set void MarkerSetForeTranslucent=2294(int markerNumber, colouralpha fore) + +# Set the background colour used for a particular marker number. +set void MarkerSetBackTranslucent=2295(int markerNumber, colouralpha back) + +# Set the background colour used for a particular marker number when its folding block is selected. +set void MarkerSetBackSelectedTranslucent=2296(int markerNumber, colouralpha back) + +# Set the width of strokes used in .01 pixels so 50 = 1/2 pixel width. +set void MarkerSetStrokeWidth=2297(int markerNumber, int hundredths) + # Enable/disable highlight for current folding block (smallest one that contains the caret) fun void MarkerEnableHighlight=2293(bool enabled,) diff --git a/scripts/CheckMentioned.py b/scripts/CheckMentioned.py index bcbbaa6c9..cd518ce28 100644 --- a/scripts/CheckMentioned.py +++ b/scripts/CheckMentioned.py @@ -144,7 +144,10 @@ def checkDocumentation(): for api, sig in re.findall(dirPattern, docs): sigApi = re.split('\W+', sig)[0] sigFlat = flattenSpaces(sig) + sigFlat = sigFlat.replace('colouralpha ', 'xxxx ') # Temporary to avoid next line sigFlat = sigFlat.replace('alpha ', 'int ') + sigFlat = sigFlat.replace('xxxx ', 'colouralpha ') + sigFlat = sigFlat.replace("document *", "int ") sigFlat = sigFlat.rstrip() if '(' in sigFlat or api.startswith("SCI_"): @@ -170,8 +173,11 @@ def checkDocumentation(): sigFlat = flattenSpaces(sig) if '(.+)', '\\1', sigFlat) + sigFlat = sigFlat.replace('colouralpha ', 'xxxx ') # Temporary to avoid next line sigFlat = sigFlat.replace('alpha ', 'int ') + sigFlat = sigFlat.replace('xxxx ', 'colouralpha ') sigFlat = sigFlat.replace("document *", "int ") + sigFlat = sigFlat.replace(' NUL-terminated', '') sigFlat = sigFlat.rstrip() #~ sigFlat = sigFlat.replace(' NUL-terminated', '') diff --git a/src/Editor.cxx b/src/Editor.cxx index 7ad889c23..ad56a8eb8 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -6946,22 +6946,46 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { InvalidateStyleData(); RedrawSelMargin(); break; + case SCI_MARKERSETBACK: + if (wParam <= MARKER_MAX) + vs.markers[wParam].back = ColourDesired(static_cast(lParam)); + InvalidateStyleData(); + RedrawSelMargin(); + break; case SCI_MARKERSETBACKSELECTED: if (wParam <= MARKER_MAX) vs.markers[wParam].backSelected = ColourDesired(static_cast(lParam)); InvalidateStyleData(); RedrawSelMargin(); break; - case SCI_MARKERENABLEHIGHLIGHT: - marginView.highlightDelimiter.isEnabled = wParam == 1; + case SCI_MARKERSETFORETRANSLUCENT: + if (wParam <= MARKER_MAX) + vs.markers[wParam].fore = ColourAlpha(static_cast(lParam)); + InvalidateStyleData(); RedrawSelMargin(); break; - case SCI_MARKERSETBACK: + case SCI_MARKERSETBACKTRANSLUCENT: if (wParam <= MARKER_MAX) - vs.markers[wParam].back = ColourDesired(static_cast(lParam)); + vs.markers[wParam].back = ColourAlpha(static_cast(lParam)); InvalidateStyleData(); RedrawSelMargin(); break; + case SCI_MARKERSETBACKSELECTEDTRANSLUCENT: + if (wParam <= MARKER_MAX) + vs.markers[wParam].backSelected = ColourAlpha(static_cast(lParam)); + InvalidateStyleData(); + RedrawSelMargin(); + break; + case SCI_MARKERSETSTROKEWIDTH: + if (wParam <= MARKER_MAX) + vs.markers[wParam].strokeWidth = lParam / 100.0f; + InvalidateStyleData(); + RedrawSelMargin(); + break; + case SCI_MARKERENABLEHIGHLIGHT: + marginView.highlightDelimiter.isEnabled = wParam == 1; + RedrawSelMargin(); + break; case SCI_MARKERSETALPHA: if (wParam <= MARKER_MAX) vs.markers[wParam].alpha = static_cast(lParam); diff --git a/src/LineMarker.cxx b/src/LineMarker.cxx index 5acfb7cb3..35cf0ab4c 100644 --- a/src/LineMarker.cxx +++ b/src/LineMarker.cxx @@ -34,6 +34,7 @@ LineMarker::LineMarker(const LineMarker &other) { fore = other.fore; back = other.back; backSelected = other.backSelected; + strokeWidth = other.strokeWidth; alpha = other.alpha; if (other.pxpm) pxpm = std::make_unique(*other.pxpm); @@ -53,6 +54,7 @@ LineMarker &LineMarker::operator=(const LineMarker &other) { fore = other.fore; back = other.back; backSelected = other.backSelected; + strokeWidth = other.strokeWidth; alpha = other.alpha; if (other.pxpm) pxpm = std::make_unique(*other.pxpm); @@ -88,7 +90,7 @@ enum class Expansion { Minus, Plus }; enum class Shape { Square, Circle }; void DrawSymbol(Surface *surface, Shape shape, Expansion expansion, PRectangle rcSymbol, XYPOSITION widthStroke, - ColourDesired colourFill, ColourDesired colourFrame, ColourDesired colourFrameRight, ColourDesired colourExpansion) { + ColourAlpha colourFill, ColourAlpha colourFrame, ColourAlpha colourFrameRight, ColourAlpha colourExpansion) { const FillStroke fillStroke(colourFill, colourFrame, widthStroke); const PRectangle rcSymbolLeft = Side(rcSymbol, Edge::left, (rcSymbol.Width() + widthStroke) / 2.0f); @@ -127,7 +129,7 @@ void DrawSymbol(Surface *surface, Shape shape, Expansion expansion, PRectangle r } } -void DrawTail(Surface *surface, XYPOSITION leftLine, XYPOSITION rightTail, XYPOSITION centreY, XYPOSITION widthSymbolStroke, ColourDesired fill) { +void DrawTail(Surface *surface, XYPOSITION leftLine, XYPOSITION rightTail, XYPOSITION centreY, XYPOSITION widthSymbolStroke, ColourAlpha fill) { const XYPOSITION slopeLength = 2.0f + widthSymbolStroke; const XYPOSITION strokeTop = centreY + slopeLength; const XYPOSITION halfWidth = widthSymbolStroke / 2.0f; @@ -147,11 +149,10 @@ void DrawTail(Surface *surface, XYPOSITION leftLine, XYPOSITION rightTail, XYPOS void LineMarker::DrawFoldingMark(Surface *surface, const PRectangle &rcWhole, FoldPart part) const { // Assume: edges of rcWhole are integers. // Code can only really handle integer strokeWidth. - constexpr XYPOSITION strokeWidth = 1.0f; - ColourDesired colourHead = back; - ColourDesired colourBody = back; - ColourDesired colourTail = back; + ColourAlpha colourHead = back; + ColourAlpha colourBody = back; + ColourAlpha colourTail = back; switch (part) { case FoldPart::head: @@ -249,11 +250,11 @@ void LineMarker::DrawFoldingMark(Surface *surface, const PRectangle &rcWhole, Fo break; case SC_MARK_BOXPLUSCONNECTED: { - const ColourDesired colourBelow = (part == FoldPart::headWithTail) ? colourTail : colourBody; + const ColourAlpha colourBelow = (part == FoldPart::headWithTail) ? colourTail : colourBody; surface->FillRectangle(rcBelowSymbol, colourBelow); surface->FillRectangle(rcAboveSymbol, colourBody); - const ColourDesired colourRight = (part == FoldPart::body) ? colourTail : colourHead; + const ColourAlpha colourRight = (part == FoldPart::body) ? colourTail : colourHead; DrawSymbol(surface, Shape::Square, Expansion::Plus, rcSymbol, widthStroke, fore, colourHead, colourRight, colourTail); } @@ -269,7 +270,7 @@ void LineMarker::DrawFoldingMark(Surface *surface, const PRectangle &rcWhole, Fo surface->FillRectangle(rcBelowSymbol, colourHead); surface->FillRectangle(rcAboveSymbol, colourBody); - const ColourDesired colourRight = (part == FoldPart::body) ? colourTail : colourHead; + const ColourAlpha colourRight = (part == FoldPart::body) ? colourTail : colourHead; DrawSymbol(surface, Shape::Square, Expansion::Minus, rcSymbol, widthStroke, fore, colourHead, colourRight, colourTail); } @@ -281,11 +282,11 @@ void LineMarker::DrawFoldingMark(Surface *surface, const PRectangle &rcWhole, Fo break; case SC_MARK_CIRCLEPLUSCONNECTED: { - const ColourDesired colourBelow = (part == FoldPart::headWithTail) ? colourTail : colourBody; + const ColourAlpha colourBelow = (part == FoldPart::headWithTail) ? colourTail : colourBody; surface->FillRectangle(rcBelowSymbol, colourBelow); surface->FillRectangle(rcAboveSymbol, colourBody); - const ColourDesired colourRight = (part == FoldPart::body) ? colourTail : colourHead; + const ColourAlpha colourRight = (part == FoldPart::body) ? colourTail : colourHead; DrawSymbol(surface, Shape::Circle, Expansion::Plus, rcSymbol, widthStroke, fore, colourHead, colourRight, colourTail); } @@ -300,7 +301,7 @@ void LineMarker::DrawFoldingMark(Surface *surface, const PRectangle &rcWhole, Fo case SC_MARK_CIRCLEMINUSCONNECTED: { surface->FillRectangle(rcBelowSymbol, colourHead); surface->FillRectangle(rcAboveSymbol, colourBody); - const ColourDesired colourRight = (part == FoldPart::body) ? colourTail : colourHead; + const ColourAlpha colourRight = (part == FoldPart::body) ? colourTail : colourHead; DrawSymbol(surface, Shape::Circle, Expansion::Minus, rcSymbol, widthStroke, fore, colourHead, colourRight, colourTail); } @@ -311,7 +312,6 @@ void LineMarker::DrawFoldingMark(Surface *surface, const PRectangle &rcWhole, Fo void LineMarker::Draw(Surface *surface, const PRectangle &rcWhole, const Font *fontForCharacter, FoldPart part, int marginStyle) const { // This is to satisfy the changed API - eventually the stroke width will be exposed to clients - constexpr float strokeWidth = 1.0f; if (customDraw) { customDraw(surface, rcWhole, fontForCharacter, static_cast(part), marginStyle, this); diff --git a/src/LineMarker.h b/src/LineMarker.h index 232a29dbb..b417ec34d 100644 --- a/src/LineMarker.h +++ b/src/LineMarker.h @@ -22,10 +22,11 @@ public: enum class FoldPart { undefined, head, body, tail, headWithTail }; int markType = SC_MARK_CIRCLE; - ColourDesired fore = ColourDesired(0, 0, 0); - ColourDesired back = ColourDesired(0xff, 0xff, 0xff); - ColourDesired backSelected = ColourDesired(0xff, 0x00, 0x00); + ColourAlpha fore = ColourAlpha(0, 0, 0); + ColourAlpha back = ColourAlpha(0xff, 0xff, 0xff); + ColourAlpha backSelected = ColourAlpha(0xff, 0x00, 0x00); int alpha = SC_ALPHA_NOALPHA; + XYPOSITION strokeWidth = 1.0f; std::unique_ptr pxpm; std::unique_ptr image; /** Some platforms, notably PLAT_CURSES, do not support Scintilla's native -- cgit v1.2.3