diff options
author | Neil <nyamatongwe@gmail.com> | 2021-05-14 13:33:11 +1000 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2021-05-14 13:33:11 +1000 |
commit | 91a0a5c9be59308be001bbc89c0aead0f3602494 (patch) | |
tree | 43c70147bfce95a4b3fc8d5397faed70cafcffee /src | |
parent | 2feaeaf738851055a79ffcfb9027a3637610faca (diff) | |
download | scintilla-mirror-91a0a5c9be59308be001bbc89c0aead0f3602494.tar.gz |
Add SCI_MARKERSETLAYER to define layer on which to draw content area markers.
This replaces the use of SC_ALPHA_NOALPHA for markers.
Diffstat (limited to 'src')
-rw-r--r-- | src/EditView.cxx | 16 | ||||
-rw-r--r-- | src/Editor.cxx | 22 | ||||
-rw-r--r-- | src/LineMarker.cxx | 6 | ||||
-rw-r--r-- | src/LineMarker.h | 5 | ||||
-rw-r--r-- | src/ViewStyle.cxx | 10 | ||||
-rw-r--r-- | src/ViewStyle.h | 2 |
6 files changed, 42 insertions, 19 deletions
diff --git a/src/EditView.cxx b/src/EditView.cxx index 2b389ecee..4ae9aecc9 100644 --- a/src/EditView.cxx +++ b/src/EditView.cxx @@ -888,12 +888,6 @@ void EditView::DrawIndentGuide(Surface *surface, Sci::Line lineVisible, int line highlight ? *pixmapIndentGuideHighlight : *pixmapIndentGuide); } -static void SimpleAlphaRectangle(Surface *surface, PRectangle rc, ColourAlpha fill, int alpha) { - if (alpha != SC_ALPHA_NOALPHA) { - surface->FillRectangleAligned(rc, ColourAlpha(fill, alpha)); - } -} - static void DrawTextBlob(Surface *surface, const ViewStyle &vsDraw, PRectangle rcSegment, std::string_view text, ColourAlpha textBack, ColourAlpha textFore, bool fillBackground) { if (rcSegment.Empty()) @@ -1790,13 +1784,13 @@ static void DrawEdgeLine(Surface *surface, const ViewStyle &vsDraw, const LineLa } } -// Draw underline mark as part of background if not transparent +// Draw underline mark as part of background if on base layer static void DrawMarkUnderline(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, Sci::Line line, PRectangle rcLine) { int marks = model.pdoc->GetMark(line); for (int markBit = 0; (markBit < 32) && marks; markBit++) { if ((marks & 1) && (vsDraw.markers[markBit].markType == SC_MARK_UNDERLINE) && - (vsDraw.markers[markBit].alpha == SC_ALPHA_NOALPHA)) { + (vsDraw.markers[markBit].layer == Layer::base)) { PRectangle rcUnderline = rcLine; rcUnderline.top = rcUnderline.bottom - 2; surface->FillRectangleAligned(rcUnderline, Fill(vsDraw.markers[markBit].back)); @@ -1883,11 +1877,11 @@ static void DrawTranslucentLineState(Surface *surface, const EditModel &model, c for (int markBit = 0; (markBit < 32) && marksDrawnInText; markBit++) { if (marksDrawnInText & 1) { if (vsDraw.markers[markBit].markType == SC_MARK_BACKGROUND) { - SimpleAlphaRectangle(surface, rcLine, vsDraw.markers[markBit].back, vsDraw.markers[markBit].alpha); + surface->FillRectangleAligned(rcLine, vsDraw.markers[markBit].BackWithAlpha()); } else if (vsDraw.markers[markBit].markType == SC_MARK_UNDERLINE) { PRectangle rcUnderline = rcLine; rcUnderline.top = rcUnderline.bottom - 2; - SimpleAlphaRectangle(surface, rcUnderline, vsDraw.markers[markBit].back, vsDraw.markers[markBit].alpha); + surface->FillRectangleAligned(rcUnderline, vsDraw.markers[markBit].BackWithAlpha()); } } marksDrawnInText >>= 1; @@ -1895,7 +1889,7 @@ static void DrawTranslucentLineState(Surface *surface, const EditModel &model, c int marksDrawnInLine = marksOfLine & vsDraw.maskInLine; for (int markBit = 0; (markBit < 32) && marksDrawnInLine; markBit++) { if (marksDrawnInLine & 1) { - SimpleAlphaRectangle(surface, rcLine, vsDraw.markers[markBit].back, vsDraw.markers[markBit].alpha); + surface->FillRectangleAligned(rcLine, vsDraw.markers[markBit].BackWithAlpha()); } marksDrawnInLine >>= 1; } diff --git a/src/Editor.cxx b/src/Editor.cxx index 694ac2f5f..8b6147a5b 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -6997,10 +6997,26 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { RedrawSelMargin(); break; case SCI_MARKERSETALPHA: - if (wParam <= MARKER_MAX) - vs.markers[wParam].alpha = static_cast<int>(lParam); - InvalidateStyleRedraw(); + if (wParam <= MARKER_MAX) { + if (lParam == SC_ALPHA_NOALPHA) { + SetAppearance(vs.markers[wParam].alpha, 0xff); + SetAppearance(vs.markers[wParam].layer, Layer::base); + } else { + SetAppearance(vs.markers[wParam].alpha, static_cast<int>(lParam)); + SetAppearance(vs.markers[wParam].layer, Layer::over); + } + } break; + case SCI_MARKERSETLAYER: + if (wParam <= MARKER_MAX) { + SetAppearance(vs.markers[wParam].layer, static_cast<Layer>(lParam)); + } + break; + case SCI_MARKERGETLAYER: + if (wParam <= MARKER_MAX) { + return static_cast<sptr_t>(vs.markers[wParam].layer); + } + return 0; case SCI_MARKERADD: { const int markerID = pdoc->AddMark(static_cast<Sci::Line>(wParam), static_cast<int>(lParam)); return markerID; diff --git a/src/LineMarker.cxx b/src/LineMarker.cxx index ed9c1ce7a..a3ab16b1d 100644 --- a/src/LineMarker.cxx +++ b/src/LineMarker.cxx @@ -37,6 +37,7 @@ LineMarker::LineMarker(const LineMarker &other) { back = other.back; backSelected = other.backSelected; strokeWidth = other.strokeWidth; + layer = other.layer; alpha = other.alpha; if (other.pxpm) pxpm = std::make_unique<XPM>(*other.pxpm); @@ -57,6 +58,7 @@ LineMarker &LineMarker::operator=(const LineMarker &other) { back = other.back; backSelected = other.backSelected; strokeWidth = other.strokeWidth; + layer = other.layer; alpha = other.alpha; if (other.pxpm) pxpm = std::make_unique<XPM>(*other.pxpm); @@ -71,6 +73,10 @@ LineMarker &LineMarker::operator=(const LineMarker &other) { return *this; } +ColourAlpha LineMarker::BackWithAlpha() const noexcept { + return ColourAlpha(back, alpha); +} + void LineMarker::SetXPM(const char *textForm) { pxpm = std::make_unique<XPM>(textForm); markType = SC_MARK_PIXMAP; diff --git a/src/LineMarker.h b/src/LineMarker.h index c13d4f4d0..1047d34e9 100644 --- a/src/LineMarker.h +++ b/src/LineMarker.h @@ -15,6 +15,8 @@ class RGBAImage; typedef void (*DrawLineMarkerFn)(Surface *surface, const PRectangle &rcWhole, const Font *fontForCharacter, int tFold, int marginStyle, const void *lineMarker); +enum class Layer { base = 0, over = 10 }; + /** */ class LineMarker { @@ -25,6 +27,7 @@ public: ColourAlpha fore = ColourAlpha(0, 0, 0); ColourAlpha back = ColourAlpha(0xff, 0xff, 0xff); ColourAlpha backSelected = ColourAlpha(0xff, 0x00, 0x00); + Layer layer = Layer::base; int alpha = SC_ALPHA_NOALPHA; XYPOSITION strokeWidth = 1.0f; std::unique_ptr<XPM> pxpm; @@ -42,6 +45,8 @@ public: LineMarker &operator=(LineMarker&&) noexcept = default; virtual ~LineMarker() = default; + ColourAlpha BackWithAlpha() const noexcept; + void SetXPM(const char *textForm); void SetXPM(const char *const *linesForm); void SetRGBAImage(Point sizeRGBAImage, float scale, const unsigned char *pixelsRGBAImage); diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx index 60334c2ea..455a44c1e 100644 --- a/src/ViewStyle.cxx +++ b/src/ViewStyle.cxx @@ -483,7 +483,7 @@ std::optional<ColourAlpha> ViewStyle::Background(int marksOfLine, bool caretActi int marks = marksOfLine; for (int markBit = 0; (markBit < 32) && marks; markBit++) { if ((marks & 1) && (markers[markBit].markType == SC_MARK_BACKGROUND) && - (markers[markBit].alpha == SC_ALPHA_NOALPHA)) { + (markers[markBit].layer == Layer::base)) { background = markers[markBit].back; } marks >>= 1; @@ -494,14 +494,18 @@ std::optional<ColourAlpha> ViewStyle::Background(int marksOfLine, bool caretActi if (marksMasked) { for (int markBit = 0; (markBit < 32) && marksMasked; markBit++) { if ((marksMasked & 1) && - (markers[markBit].alpha == SC_ALPHA_NOALPHA)) { + (markers[markBit].layer == Layer::base)) { background = markers[markBit].back; } marksMasked >>= 1; } } } - return background; + if (background) { + return background->Opaque(); + } else { + return {}; + } } bool ViewStyle::SelectionBackgroundDrawn() const noexcept { diff --git a/src/ViewStyle.h b/src/ViewStyle.h index 9f3cae123..20325a962 100644 --- a/src/ViewStyle.h +++ b/src/ViewStyle.h @@ -63,8 +63,6 @@ struct ForeBackColours { std::optional<ColourAlpha> back; }; -enum class Layer { base=0, over=10 }; - struct SelectionAppearance { // Whether to draw on base layer or over text Layer layer; |