aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2014-06-26 13:06:24 +1000
committerNeil <nyamatongwe@gmail.com>2014-06-26 13:06:24 +1000
commitc2111963a126dd0e66bdceb33dcfe39a3f90478f (patch)
treef601fc5c1dce17a19c429a45d3a27db9df7d6710 /src
parentbef1bd1c8a4c409ccb5e831d62ef42d24489050e (diff)
downloadscintilla-mirror-c2111963a126dd0e66bdceb33dcfe39a3f90478f.tar.gz
Move calculation of line background colour to ViewStyle and represent as a
ColourOptional to tightly bind the value with whether it is set.
Diffstat (limited to 'src')
-rw-r--r--src/Editor.cxx69
-rw-r--r--src/Editor.h4
-rw-r--r--src/ViewStyle.cxx37
-rw-r--r--src/ViewStyle.h1
4 files changed, 56 insertions, 55 deletions
diff --git a/src/Editor.cxx b/src/Editor.cxx
index 98440fe0f..ce298a66d 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -2395,8 +2395,8 @@ ColourDesired Editor::SelectionBackground(const ViewStyle &vsDraw, bool main) co
vsDraw.selAdditionalBackground;
}
-ColourDesired Editor::TextBackground(const ViewStyle &vsDraw, bool overrideBackground,
- ColourDesired background, int inSelection, bool inHotspot, int styleMain, int i, LineLayout *ll) const {
+ColourDesired Editor::TextBackground(const ViewStyle &vsDraw,
+ ColourOptional background, int inSelection, bool inHotspot, int styleMain, int i, LineLayout *ll) const {
if (inSelection == 1) {
if (vsDraw.selColours.back.isSet && (vsDraw.selAlpha == SC_ALPHA_NOALPHA)) {
return SelectionBackground(vsDraw, true);
@@ -2413,7 +2413,7 @@ ColourDesired Editor::TextBackground(const ViewStyle &vsDraw, bool overrideBackg
if (inHotspot && vsDraw.hotspotColours.back.isSet)
return vsDraw.hotspotColours.back;
}
- if (overrideBackground && (styleMain != STYLE_BRACELIGHT) && (styleMain != STYLE_BRACEBAD)) {
+ if (background.isSet && (styleMain != STYLE_BRACELIGHT) && (styleMain != STYLE_BRACEBAD)) {
return background;
} else {
return vsDraw.styles[styleMain].back;
@@ -2503,8 +2503,7 @@ void DrawTextBlob(Surface *surface, const ViewStyle &vsDraw, PRectangle rcSegmen
void Editor::DrawEOL(Surface *surface, const ViewStyle &vsDraw, PRectangle rcLine, LineLayout *ll,
int line, int lineEnd, int xStart, int subLine, XYACCUMULATOR subLineStart,
- bool overrideBackground, ColourDesired background,
- bool drawWrapMarkEnd, ColourDesired wrapColour) {
+ ColourOptional background, bool drawWrapMarkEnd, ColourDesired wrapColour) {
const int posLineStart = pdoc->LineStart(line);
PRectangle rcSegment = rcLine;
@@ -2521,7 +2520,7 @@ void Editor::DrawEOL(Surface *surface, const ViewStyle &vsDraw, PRectangle rcLin
if (virtualSpace) {
rcSegment.left = xEol + xStart;
rcSegment.right = xEol + xStart + virtualSpace;
- surface->FillRectangle(rcSegment, overrideBackground ? background : vsDraw.styles[ll->styles[ll->numCharsInLine]].back);
+ surface->FillRectangle(rcSegment, background.isSet ? background : vsDraw.styles[ll->styles[ll->numCharsInLine]].back);
if (!hideSelection && ((vsDraw.selAlpha == SC_ALPHA_NOALPHA) || (vsDraw.selAdditionalAlpha == SC_ALPHA_NOALPHA))) {
SelectionSegment virtualSpaceRange(SelectionPosition(pdoc->LineEnd(line)), SelectionPosition(pdoc->LineEnd(line), sel.VirtualSpaceFor(pdoc->LineEnd(line))));
for (size_t r=0; r<sel.Count(); r++) {
@@ -2562,7 +2561,7 @@ void Editor::DrawEOL(Surface *surface, const ViewStyle &vsDraw, PRectangle rcLin
const char *ctrlChar;
unsigned char chEOL = ll->chars[eolPos];
int styleMain = ll->styles[eolPos];
- ColourDesired textBack = TextBackground(vsDraw, overrideBackground, background, eolInSelection, false, styleMain, eolPos, ll);
+ ColourDesired textBack = TextBackground(vsDraw, background, eolInSelection, false, styleMain, eolPos, ll);
if (UTF8IsAscii(chEOL)) {
ctrlChar = ControlCharacterString(chEOL);
} else {
@@ -2602,7 +2601,7 @@ void Editor::DrawEOL(Surface *surface, const ViewStyle &vsDraw, PRectangle rcLin
if (eolInSelection && vsDraw.selColours.back.isSet && (line < pdoc->LinesTotal() - 1) && (alpha == SC_ALPHA_NOALPHA)) {
surface->FillRectangle(rcSegment, SelectionBackground(vsDraw, eolInSelection == 1));
} else {
- if (overrideBackground) {
+ if (background.isSet) {
surface->FillRectangle(rcSegment, background);
} else if (line < pdoc->LinesTotal() - 1) {
surface->FillRectangle(rcSegment, vsDraw.styles[ll->styles[ll->numCharsInLine]].back);
@@ -2625,7 +2624,7 @@ void Editor::DrawEOL(Surface *surface, const ViewStyle &vsDraw, PRectangle rcLin
if (eolInSelection && vsDraw.selEOLFilled && vsDraw.selColours.back.isSet && (line < pdoc->LinesTotal() - 1) && (alpha == SC_ALPHA_NOALPHA)) {
surface->FillRectangle(rcSegment, SelectionBackground(vsDraw, eolInSelection == 1));
} else {
- if (overrideBackground) {
+ if (background.isSet) {
surface->FillRectangle(rcSegment, background);
} else if (vsDraw.styles[ll->styles[ll->numCharsInLine]].eolFilled) {
surface->FillRectangle(rcSegment, vsDraw.styles[ll->styles[ll->numCharsInLine]].back);
@@ -2784,47 +2783,11 @@ void Editor::DrawLine(Surface *surface, const ViewStyle &vsDraw, int line, int l
// is taken by an individual character - internal leading gives varying results.
FontAlias ctrlCharsFont = vsDraw.styles[STYLE_CONTROLCHAR].font;
- // 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
- // display itself (as long as it's not an SC_MARK_EMPTY marker). These are checked in order
- // with the earlier taking precedence. When multiple markers cause background override,
- // the color for the highest numbered one is used.
- bool overrideBackground = false;
- ColourDesired background;
- if ((caret.active || vsDraw.alwaysShowCaretLineBackground) && vsDraw.showCaretLineBackground && (vsDraw.caretLineAlpha == SC_ALPHA_NOALPHA) && ll->containsCaret) {
- overrideBackground = true;
- background = vsDraw.caretLineBackground;
- }
- if (!overrideBackground) {
- int marks = pdoc->GetMark(line);
- for (int markBit = 0; (markBit < 32) && marks; markBit++) {
- if ((marks & 1) && (vsDraw.markers[markBit].markType == SC_MARK_BACKGROUND) &&
- (vsDraw.markers[markBit].alpha == SC_ALPHA_NOALPHA)) {
- background = vsDraw.markers[markBit].back;
- overrideBackground = true;
- }
- marks >>= 1;
- }
- }
- if (!overrideBackground) {
- if (vsDraw.maskInLine) {
- int marksMasked = pdoc->GetMark(line) & vsDraw.maskInLine;
- if (marksMasked) {
- for (int markBit = 0; (markBit < 32) && marksMasked; markBit++) {
- if ((marksMasked & 1) && (vsDraw.markers[markBit].markType != SC_MARK_EMPTY) &&
- (vsDraw.markers[markBit].alpha == SC_ALPHA_NOALPHA)) {
- overrideBackground = true;
- background = vsDraw.markers[markBit].back;
- }
- marksMasked >>= 1;
- }
- }
- }
- }
+ // See if something overrides the line background color.
+ const ColourOptional background = vsDraw.Background(pdoc->GetMark(line), caret.active, ll->containsCaret);
const bool drawWhitespaceBackground = (vsDraw.viewWhitespace != wsInvisible) &&
- (!overrideBackground) && (vsDraw.whitespaceColours.back.isSet);
+ (!background.isSet) && (vsDraw.whitespaceColours.back.isSet);
bool inIndentation = subLine == 0; // Do not handle indentation except on first subline.
const XYPOSITION indentWidth = pdoc->IndentSize() * vsDraw.spaceWidth;
@@ -2869,7 +2832,7 @@ void Editor::DrawLine(Surface *surface, const ViewStyle &vsDraw, int line, int l
rcPlace.right = rcPlace.left + ll->wrapIndent;
// default bgnd here..
- surface->FillRectangle(rcSegment, overrideBackground ? background :
+ surface->FillRectangle(rcSegment, background.isSet ? background :
vsDraw.styles[STYLE_DEFAULT].back);
// main line style would be below but this would be inconsistent with end markers
@@ -2920,7 +2883,7 @@ void Editor::DrawLine(Surface *surface, const ViewStyle &vsDraw, int line, int l
const int inSelection = hideSelection ? 0 : sel.CharacterInSelection(iDoc);
const bool inHotspot = (ll->hotspot.Valid()) && ll->hotspot.ContainsCharacter(iDoc);
- ColourDesired textBack = TextBackground(vsDraw, overrideBackground, background, inSelection,
+ ColourDesired textBack = TextBackground(vsDraw, background, inSelection,
inHotspot, ll->styles[i], i, ll);
if (ts.representation) {
if (ll->chars[i] == '\t') {
@@ -2961,7 +2924,7 @@ void Editor::DrawLine(Surface *surface, const ViewStyle &vsDraw, int line, int l
}
DrawEOL(surface, vsDraw, rcLine, ll, line, lineEnd,
- xStart, subLine, subLineStart, overrideBackground, background,
+ xStart, subLine, subLineStart, background,
drawWrapMarkEnd, wrapColour);
}
@@ -3018,7 +2981,7 @@ void Editor::DrawLine(Surface *surface, const ViewStyle &vsDraw, int line, int l
if (inSelection && (vsDraw.selColours.fore.isSet)) {
textFore = (inSelection == 1) ? vsDraw.selColours.fore : vsDraw.selAdditionalForeground;
}
- ColourDesired textBack = TextBackground(vsDraw, overrideBackground, background, inSelection, inHotspot, styleMain, i, ll);
+ ColourDesired textBack = TextBackground(vsDraw, background, inSelection, inHotspot, styleMain, i, ll);
if (ts.representation) {
if (ll->chars[i] == '\t') {
// Tab display
@@ -3189,7 +3152,7 @@ void Editor::DrawLine(Surface *surface, const ViewStyle &vsDraw, int line, int l
// End of the drawing of the current line
if (!twoPhaseDraw) {
DrawEOL(surface, vsDraw, rcLine, ll, line, lineEnd,
- xStart, subLine, subLineStart, overrideBackground, background,
+ xStart, subLine, subLineStart, background,
drawWrapMarkEnd, wrapColour);
}
if (!hideSelection && ((vsDraw.selAlpha != SC_ALPHA_NOALPHA) || (vsDraw.selAdditionalAlpha != SC_ALPHA_NOALPHA))) {
diff --git a/src/Editor.h b/src/Editor.h
index f26f1c447..7a84690af 100644
--- a/src/Editor.h
+++ b/src/Editor.h
@@ -437,12 +437,12 @@ protected: // ScintillaBase subclass needs access to much of Editor
void LayoutLine(int line, Surface *surface, const ViewStyle &vstyle, LineLayout *ll,
int width=LineLayout::wrapWidthInfinite);
ColourDesired SelectionBackground(const ViewStyle &vsDraw, bool main) const;
- ColourDesired TextBackground(const ViewStyle &vsDraw, bool overrideBackground, ColourDesired background, int inSelection, bool inHotspot, int styleMain, int i, LineLayout *ll) const;
+ ColourDesired TextBackground(const ViewStyle &vsDraw, ColourOptional background, int inSelection, bool inHotspot, int styleMain, int i, LineLayout *ll) const;
void DrawIndentGuide(Surface *surface, int lineVisible, int lineHeight, int start, PRectangle rcSegment, bool highlight);
static void DrawWrapMarker(Surface *surface, PRectangle rcPlace, bool isEndMarker, ColourDesired wrapColour);
void DrawEOL(Surface *surface, const ViewStyle &vsDraw, PRectangle rcLine, LineLayout *ll,
int line, int lineEnd, int xStart, int subLine, XYACCUMULATOR subLineStart,
- bool overrideBackground, ColourDesired background,
+ ColourOptional background,
bool drawWrapMark, ColourDesired wrapColour);
static void DrawIndicator(int indicNum, int startPos, int endPos, Surface *surface, const ViewStyle &vsDraw,
int xStart, PRectangle rcLine, LineLayout *ll, int subLine);
diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx
index af808f3c1..2983bb0c0 100644
--- a/src/ViewStyle.cxx
+++ b/src/ViewStyle.cxx
@@ -434,6 +434,43 @@ void ViewStyle::CalcLargestMarkerHeight() {
}
}
+// 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
+// display itself (as long as it's not an SC_MARK_EMPTY marker). These are checked in order
+// with the earlier taking precedence. When multiple markers cause background override,
+// 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) {
+ background = ColourOptional(caretLineBackground, true);
+ }
+ if (!background.isSet && marksOfLine) {
+ 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)) {
+ background = ColourOptional(markers[markBit].back, true);
+ }
+ marks >>= 1;
+ }
+ }
+ if (!background.isSet && maskInLine) {
+ int marksMasked = marksOfLine & maskInLine;
+ if (marksMasked) {
+ for (int markBit = 0; (markBit < 32) && marksMasked; markBit++) {
+ if ((marksMasked & 1) && (markers[markBit].markType != SC_MARK_EMPTY) &&
+ (markers[markBit].alpha == SC_ALPHA_NOALPHA)) {
+ background = ColourOptional(markers[markBit].back, true);
+ }
+ marksMasked >>= 1;
+ }
+ }
+ }
+ return background;
+}
+
+
ColourDesired ViewStyle::WrapColour() const {
if (whitespaceColours.fore.isSet)
return whitespaceColours.fore;
diff --git a/src/ViewStyle.h b/src/ViewStyle.h
index 4dfb14a33..60bd9688e 100644
--- a/src/ViewStyle.h
+++ b/src/ViewStyle.h
@@ -169,6 +169,7 @@ public:
int ExternalMarginWidth() const;
bool ValidStyle(size_t styleIndex) const;
void CalcLargestMarkerHeight();
+ ColourOptional Background(int marksOfLine, bool caretActive, bool lineContainsCaret) const;
ColourDesired WrapColour() const;
bool SetWrapState(int wrapState_);
bool SetWrapVisualFlags(int wrapVisualFlags_);