aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2021-05-14 13:33:11 +1000
committerNeil <nyamatongwe@gmail.com>2021-05-14 13:33:11 +1000
commit91a0a5c9be59308be001bbc89c0aead0f3602494 (patch)
tree43c70147bfce95a4b3fc8d5397faed70cafcffee
parent2feaeaf738851055a79ffcfb9027a3637610faca (diff)
downloadscintilla-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.
-rw-r--r--doc/ScintillaDoc.html27
-rw-r--r--doc/ScintillaHistory.html4
-rw-r--r--include/Scintilla.h2
-rw-r--r--include/Scintilla.iface6
-rw-r--r--src/EditView.cxx16
-rw-r--r--src/Editor.cxx22
-rw-r--r--src/LineMarker.cxx6
-rw-r--r--src/LineMarker.h5
-rw-r--r--src/ViewStyle.cxx10
-rw-r--r--src/ViewStyle.h2
-rw-r--r--test/simpleTests.py7
11 files changed, 78 insertions, 29 deletions
diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html
index 2ba53c837..990868241 100644
--- a/doc/ScintillaDoc.html
+++ b/doc/ScintillaDoc.html
@@ -267,19 +267,18 @@
This is similar to <a class="seealso" href="#colour">colour</a> but with a byte
of <a class="seealso" href="#colour">alpha</a> added. They are combined as:
red | (green &lt;&lt; 8) | (blue &lt;&lt; 16) | (alpha &lt;&lt; 24).
- Fully opaque uses an alpha of 255. SC_ALPHA_NOALPHA is not possible for
- colouralpha values.</td>
+ Fully opaque uses an alpha of 255.
</tr>
<tr>
<th align="left" id="alpha"><code>alpha</code></th>
<td>Translucency is set using an alpha value.
- Alpha ranges from 0 (SC_ALPHA_TRANSPARENT) which is completely transparent to
- 255 (SC_ALPHA_OPAQUE) which is opaque. The value 256 (SC_ALPHA_NOALPHA)
- is opaque and uses code that is not alpha-aware and may be faster. Not all platforms support
- translucency and only some Scintilla features implement translucency.
- The default alpha value for most features is SC_ALPHA_NOALPHA.</td>
+ Alpha ranges from 0 (SC_ALPHA_TRANSPARENT) which is completely transparent to
+ 255 (SC_ALPHA_OPAQUE) which is opaque.
+ Previous versions used the value 256 (SC_ALPHA_NOALPHA) to indicate that drawing was to be
+ performed opaquely on the base layer. This is now discouraged and code should use the <code>&hellip;LAYER&hellip;</code>
+ methods to choose the layer.</td>
</tr>
<tr>
@@ -4744,6 +4743,8 @@ struct Sci_TextToFind {
back)</a><br />
<a class="message" href="#SCI_MARKERSETSTROKEWIDTH">SCI_MARKERSETSTROKEWIDTH(int markerNumber, int hundredths)</a><br />
<a class="message" href="#SCI_MARKERENABLEHIGHLIGHT">SCI_MARKERENABLEHIGHLIGHT(bool enabled)</a><br />
+ <a class="message" href="#SCI_MARKERSETLAYER">SCI_MARKERSETLAYER(int markerNumber, int layer)</a><br />
+ <a class="message" href="#SCI_MARKERGETLAYER">SCI_MARKERGETLAYER(int markerNumber) &rarr; int</a><br />
<a class="message" href="#SCI_MARKERSETALPHA">SCI_MARKERSETALPHA(int markerNumber, alpha alpha)</a><br />
<a class="message" href="#SCI_MARKERADD">SCI_MARKERADD(line line, int markerNumber) &rarr; int</a><br />
<a class="message" href="#SCI_MARKERADDSET">SCI_MARKERADDSET(line line, int markerSet)</a><br />
@@ -4974,11 +4975,17 @@ struct Sci_TextToFind {
<p><b id="SCI_MARKERENABLEHIGHLIGHT">SCI_MARKERENABLEHIGHLIGHT(bool enabled)</b><br />
This message allows to enable/disable the highlight folding block when it is selected. (i.e. block that contains the caret)</p>
- <p><b id="SCI_MARKERSETALPHA">SCI_MARKERSETALPHA(int markerNumber,
+ <p>
+ <b id="SCI_MARKERSETLAYER">SCI_MARKERSETLAYER(int markerNumber, int layer)</b><br />
+ <b id="SCI_MARKERGETLAYER">SCI_MARKERGETLAYER(int markerNumber) &rarr; int</b><br />
+ <b id="SCI_MARKERSETALPHA">SCI_MARKERSETALPHA(int markerNumber,
<a class="jump" href="#alpha">alpha</a> alpha)</b><br />
When markers are drawn in the content area, either because there is no margin for them or
- they are of <code>SC_MARK_BACKGROUND</code> or <code>SC_MARK_UNDERLINE</code> types, they may be drawn translucently by
- setting an alpha value. This is only for the content area - in margins, translucency is achieved through the <code>SCI_MARKERSET&hellip;TRANSLUCENT</code>
+ they are of <code>SC_MARK_BACKGROUND</code> or <code>SC_MARK_UNDERLINE</code> types, they may be drawn translucently over text
+ or opaquely on the base layer.
+ The layer to draw on is defined by <code>SCI_MARKERSETLAYER</code>.
+ The degree of translucency can be chosen by setting an alpha value.
+ This is only for the content area - in margins, translucency is achieved through the <code>SCI_MARKERSET&hellip;TRANSLUCENT</code>
methods.</p>
<p><b id="SCI_MARKERADD">SCI_MARKERADD(line line, int markerNumber) &rarr; int</b><br />
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html
index 6985807e1..8fdea24bc 100644
--- a/doc/ScintillaHistory.html
+++ b/doc/ScintillaHistory.html
@@ -592,6 +592,10 @@
SCI_SETCARETLINEBACKALPHA now discouraged.
</li>
<li>
+ Add SCI_MARKERSETLAYER to define layer on which to draw conetent area markers.
+ This replaces the use of SC_ALPHA_NOALPHA for markers.
+ </li>
+ <li>
Add SCI_GETELEMENTBASECOLOUR to return the default values for element colours.
</li>
<li>
diff --git a/include/Scintilla.h b/include/Scintilla.h
index d48ad6c5a..de0e37ca7 100644
--- a/include/Scintilla.h
+++ b/include/Scintilla.h
@@ -177,6 +177,8 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam,
#define SCI_MARKERDEFINEPIXMAP 2049
#define SCI_MARKERADDSET 2466
#define SCI_MARKERSETALPHA 2476
+#define SCI_MARKERGETLAYER 2734
+#define SCI_MARKERSETLAYER 2735
#define SC_MAX_MARGIN 4
#define SC_MARGIN_SYMBOL 0
#define SC_MARGIN_NUMBER 1
diff --git a/include/Scintilla.iface b/include/Scintilla.iface
index 8a2b0de66..0f1b0fc3c 100644
--- a/include/Scintilla.iface
+++ b/include/Scintilla.iface
@@ -453,6 +453,12 @@ fun void MarkerAddSet=2466(line line, int markerSet)
# Set the alpha used for a marker that is drawn in the text area, not the margin.
set void MarkerSetAlpha=2476(int markerNumber, Alpha alpha)
+# Get the layer used for a marker that is drawn in the text area, not the margin.
+get Layer MarkerGetLayer=2734(int markerNumber,)
+
+# Set the layer used for a marker that is drawn in the text area, not the margin.
+set void MarkerSetLayer=2735(int markerNumber, Layer layer)
+
val SC_MAX_MARGIN=4
enu MarginType=SC_MARGIN_
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;
diff --git a/test/simpleTests.py b/test/simpleTests.py
index 9ac1c43fd..470b56509 100644
--- a/test/simpleTests.py
+++ b/test/simpleTests.py
@@ -2047,6 +2047,13 @@ class TestElements(unittest.TestCase):
self.RestoreCaretLine()
+ def testMarkerLayer(self):
+ self.assertEquals(self.ed.MarkerGetLayer(1), 0)
+ self.ed.MarkerSetAlpha(1, 23)
+ self.assertEquals(self.ed.MarkerGetLayer(1), 10)
+ self.ed.MarkerSetAlpha(1, 0x100)
+ self.assertEquals(self.ed.MarkerGetLayer(1), 0)
+
class TestIndices(unittest.TestCase):
def setUp(self):
self.xite = Xite.xiteFrame