diff options
author | A-R-C-A <unknown> | 2017-04-06 20:19:23 +1000 |
---|---|---|
committer | A-R-C-A <unknown> | 2017-04-06 20:19:23 +1000 |
commit | dba2fe55b8a4ab4ac34795fe4a4b30a729c77016 (patch) | |
tree | 83e69d400b6bde138c940f995e7167d0dc3af765 /src | |
parent | 84d949ba2662648114028dc3f7470e58064bf25c (diff) | |
download | scintilla-mirror-dba2fe55b8a4ab4ac34795fe4a4b30a729c77016.tar.gz |
Added a caret line frame as an alternative visual for highlighting the caret line.
Diffstat (limited to 'src')
-rw-r--r-- | src/EditView.cxx | 70 | ||||
-rw-r--r-- | src/Editor.cxx | 6 | ||||
-rw-r--r-- | src/ViewStyle.cxx | 14 | ||||
-rw-r--r-- | src/ViewStyle.h | 3 |
4 files changed, 84 insertions, 9 deletions
diff --git a/src/EditView.cxx b/src/EditView.cxx index fcd5c7ff2..4301836db 100644 --- a/src/EditView.cxx +++ b/src/EditView.cxx @@ -836,6 +836,37 @@ static void DrawTextBlob(Surface *surface, const ViewStyle &vsDraw, PRectangle r textBack, textFore); } +static void DrawFrame(Surface *surface, ColourDesired colour, int alpha, PRectangle rcFrame) { + if (alpha != SC_ALPHA_NOALPHA) + surface->AlphaRectangle(rcFrame, 0, colour, alpha, colour, alpha, 0); + else + surface->FillRectangle(rcFrame, colour); +} + +static void DrawCaretLineFramed(Surface *surface, const ViewStyle &vsDraw, const LineLayout *ll, PRectangle rcLine, int subLine) { + const int width = vsDraw.GetFrameWidth(); + if (subLine == 0 || ll->wrapIndent == 0 || vsDraw.caretLineAlpha != SC_ALPHA_NOALPHA) { + // Left + DrawFrame(surface, vsDraw.caretLineBackground, vsDraw.caretLineAlpha, + PRectangle(rcLine.left, rcLine.top, rcLine.left + width, rcLine.bottom)); + } + if (subLine == 0) { + // Top + DrawFrame(surface, vsDraw.caretLineBackground, vsDraw.caretLineAlpha, + PRectangle(rcLine.left + width, rcLine.top, rcLine.right - width, rcLine.top + width)); + } + if (subLine == ll->lines - 1 || vsDraw.caretLineAlpha != SC_ALPHA_NOALPHA) { + // Right + DrawFrame(surface, vsDraw.caretLineBackground, vsDraw.caretLineAlpha, + PRectangle(rcLine.right - width, rcLine.top, rcLine.right, rcLine.bottom)); + } + if (subLine == ll->lines - 1) { + // Bottom + DrawFrame(surface, vsDraw.caretLineBackground, vsDraw.caretLineAlpha, + PRectangle(rcLine.left + width, rcLine.bottom - width, rcLine.right - width, rcLine.bottom)); + } +} + void EditView::DrawEOL(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, PRectangle rcLine, Sci::Line line, Sci::Position lineEnd, int xStart, int subLine, XYACCUMULATOR subLineStart, ColourOptional background) { @@ -963,10 +994,16 @@ void EditView::DrawEOL(Surface *surface, const EditModel &model, const ViewStyle bool drawWrapMarkEnd = false; - if (vsDraw.wrapVisualFlags & SC_WRAPVISUALFLAG_END) { - if (subLine + 1 < ll->lines) { + if (subLine + 1 < ll->lines) { + if (vsDraw.wrapVisualFlags & SC_WRAPVISUALFLAG_END) { drawWrapMarkEnd = ll->LineStart(subLine + 1) != 0; } + if (vsDraw.IsLineFrameOpaque(model.caret.active, ll->containsCaret)) { + const int width = vsDraw.GetFrameWidth(); + // Draw right of frame under marker + DrawFrame(surface, vsDraw.caretLineBackground, vsDraw.caretLineAlpha, + PRectangle(rcLine.right - width, rcLine.top, rcLine.right, rcLine.bottom)); + } } if (drawWrapMarkEnd) { @@ -1373,11 +1410,19 @@ void EditView::DrawCarets(Surface *surface, const EditModel &model, const ViewSt } static void DrawWrapIndentAndMarker(Surface *surface, const ViewStyle &vsDraw, const LineLayout *ll, - int xStart, PRectangle rcLine, ColourOptional background, DrawWrapMarkerFn customDrawWrapMarker) { + int xStart, PRectangle rcLine, ColourOptional background, DrawWrapMarkerFn customDrawWrapMarker, + bool caretActive) { // default bgnd here.. surface->FillRectangle(rcLine, background.isSet ? background : vsDraw.styles[STYLE_DEFAULT].back); + if (vsDraw.IsLineFrameOpaque(caretActive, ll->containsCaret)) { + const int width = vsDraw.GetFrameWidth(); + // Draw left of frame under marker + DrawFrame(surface, vsDraw.caretLineBackground, vsDraw.caretLineAlpha, + PRectangle(rcLine.left, rcLine.top, rcLine.left + width, rcLine.bottom)); + } + if (vsDraw.wrapVisualFlags & SC_WRAPVISUALFLAG_START) { // draw continuation rect @@ -1551,9 +1596,14 @@ static void DrawTranslucentSelection(Surface *surface, const EditModel &model, c // Draw any translucent whole line states static void DrawTranslucentLineState(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, - Sci::Line line, PRectangle rcLine) { - if ((model.caret.active || vsDraw.alwaysShowCaretLineBackground) && vsDraw.showCaretLineBackground && ll->containsCaret) { - SimpleAlphaRectangle(surface, rcLine, vsDraw.caretLineBackground, vsDraw.caretLineAlpha); + Sci::Line line, PRectangle rcLine, int subLine) { + if ((model.caret.active || vsDraw.alwaysShowCaretLineBackground) && vsDraw.showCaretLineBackground && ll->containsCaret && + vsDraw.caretLineAlpha != SC_ALPHA_NOALPHA) { + if (vsDraw.caretLineFrame) { + DrawCaretLineFramed(surface, vsDraw, ll, rcLine, subLine); + } else { + SimpleAlphaRectangle(surface, rcLine, vsDraw.caretLineBackground, vsDraw.caretLineAlpha); + } } const int marksOfLine = model.pdoc->GetMark(line); int marksDrawnInText = marksOfLine & vsDraw.maskDrawInText; @@ -1842,7 +1892,7 @@ void EditView::DrawLine(Surface *surface, const EditModel &model, const ViewStyl if ((ll->wrapIndent != 0) && (subLine > 0)) { if (phase & drawBack) { - DrawWrapIndentAndMarker(surface, vsDraw, ll, xStart, rcLine, background, customDrawWrapMarker); + DrawWrapIndentAndMarker(surface, vsDraw, ll, xStart, rcLine, background, customDrawWrapMarker, model.caret.active); } xStart += static_cast<int>(ll->wrapIndent); } @@ -1855,6 +1905,8 @@ void EditView::DrawLine(Surface *surface, const EditModel &model, const ViewStyl phase = static_cast<DrawPhase>(phase & ~drawBack); // Remove drawBack to not draw again in DrawFoldDisplayText DrawEOL(surface, model, vsDraw, ll, rcLine, line, lineRange.end, xStart, subLine, subLineStart, background); + if (vsDraw.IsLineFrameOpaque(model.caret.active, ll->containsCaret)) + DrawCaretLineFramed(surface, vsDraw, ll, rcLine, subLine); } if (phase & drawIndicatorsBack) { @@ -1882,6 +1934,8 @@ void EditView::DrawLine(Surface *surface, const EditModel &model, const ViewStyl if (phasesDraw == phasesOne) { DrawEOL(surface, model, vsDraw, ll, rcLine, line, lineRange.end, xStart, subLine, subLineStart, background); + if (vsDraw.IsLineFrameOpaque(model.caret.active, ll->containsCaret)) + DrawCaretLineFramed(surface, vsDraw, ll, rcLine, subLine); DrawEdgeLine(surface, vsDraw, ll, rcLine, lineRange, xStart); DrawMarkUnderline(surface, model, vsDraw, line, rcLine); } @@ -1891,7 +1945,7 @@ void EditView::DrawLine(Surface *surface, const EditModel &model, const ViewStyl } if (phase & drawLineTranslucent) { - DrawTranslucentLineState(surface, model, vsDraw, ll, line, rcLine); + DrawTranslucentLineState(surface, model, vsDraw, ll, line, rcLine, subLine); } } diff --git a/src/Editor.cxx b/src/Editor.cxx index 61511cd2a..3a4b3c744 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -7067,6 +7067,12 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { InvalidateStyleRedraw(); break; + case SCI_GETCARETLINEFRAME: + return vs.caretLineFrame; + case SCI_SETCARETLINEFRAME: + vs.caretLineFrame = static_cast<int>(wParam); + InvalidateStyleRedraw(); + break; case SCI_GETCARETLINEBACK: return vs.caretLineBackground.AsLong(); case SCI_SETCARETLINEBACK: diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx index db3ad607b..64f9eee7b 100644 --- a/src/ViewStyle.cxx +++ b/src/ViewStyle.cxx @@ -136,6 +136,7 @@ ViewStyle::ViewStyle(const ViewStyle &source) { selbarlight = source.selbarlight; caretcolour = source.caretcolour; additionalCaretColour = source.additionalCaretColour; + caretLineFrame = source.caretLineFrame; showCaretLineBackground = source.showCaretLineBackground; alwaysShowCaretLineBackground = source.alwaysShowCaretLineBackground; caretLineBackground = source.caretLineBackground; @@ -264,6 +265,7 @@ void ViewStyle::Init(size_t stylesSize_) { styles[STYLE_LINENUMBER].back = Platform::Chrome(); caretcolour = ColourDesired(0, 0, 0); additionalCaretColour = ColourDesired(0x7f, 0x7f, 0x7f); + caretLineFrame = 0; showCaretLineBackground = false; alwaysShowCaretLineBackground = false; caretLineBackground = ColourDesired(0xff, 0xff, 0); @@ -479,6 +481,15 @@ void ViewStyle::CalcLargestMarkerHeight() { } } +int ViewStyle::GetFrameWidth() const { + return Platform::Clamp(caretLineFrame, 1, lineHeight / 3); +} + +bool ViewStyle::IsLineFrameOpaque(bool caretActive, bool lineContainsCaret) const { + return caretLineFrame && (caretActive || alwaysShowCaretLineBackground) && showCaretLineBackground && + (caretLineAlpha == SC_ALPHA_NOALPHA) && lineContainsCaret; +} + // See if something overrides the line background color: Either if caret is on the line // and background color is set for that, or if a marker is defined that forces its background // color onto the line, or if a marker is defined but has no selection margin in which to @@ -487,7 +498,8 @@ void ViewStyle::CalcLargestMarkerHeight() { // the color for the highest numbered one is used. ColourOptional ViewStyle::Background(int marksOfLine, bool caretActive, bool lineContainsCaret) const { ColourOptional background; - if ((caretActive || alwaysShowCaretLineBackground) && showCaretLineBackground && (caretLineAlpha == SC_ALPHA_NOALPHA) && lineContainsCaret) { + if (!caretLineFrame && (caretActive || alwaysShowCaretLineBackground) && showCaretLineBackground && + (caretLineAlpha == SC_ALPHA_NOALPHA) && lineContainsCaret) { background = ColourOptional(caretLineBackground, true); } if (!background.isSet && marksOfLine) { diff --git a/src/ViewStyle.h b/src/ViewStyle.h index 1a876f85e..db415344b 100644 --- a/src/ViewStyle.h +++ b/src/ViewStyle.h @@ -141,6 +141,7 @@ public: bool viewEOL; ColourDesired caretcolour; ColourDesired additionalCaretColour; + int caretLineFrame; bool showCaretLineBackground; bool alwaysShowCaretLineBackground; ColourDesired caretLineBackground; @@ -190,6 +191,8 @@ public: int MarginFromLocation(Point pt) const; bool ValidStyle(size_t styleIndex) const; void CalcLargestMarkerHeight(); + int GetFrameWidth() const; + bool IsLineFrameOpaque(bool caretActive, bool lineContainsCaret) const; ColourOptional Background(int marksOfLine, bool caretActive, bool lineContainsCaret) const; bool SelectionBackgroundDrawn() const; bool WhitespaceBackgroundDrawn() const; |