diff options
author | Neil <nyamatongwe@gmail.com> | 2015-02-15 23:51:05 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2015-02-15 23:51:05 +1100 |
commit | 4e705edb0910461ebe675eb57d8fd08cc94495ec (patch) | |
tree | 1752b16a47f18b341d6cc96a4bf09dd4a730c78d /src | |
parent | 982ee92ffbbd5c2f223a06ec5bf42910cefc4894 (diff) | |
download | scintilla-mirror-4e705edb0910461ebe675eb57d8fd08cc94495ec.tar.gz |
Add SC_INDICFLAG_VALUEFORE and INDIC_TEXTFORE to allow a wide range of indicator
colours and to change the colour of text.
Diffstat (limited to 'src')
-rw-r--r-- | src/EditView.cxx | 41 | ||||
-rw-r--r-- | src/Editor.cxx | 10 | ||||
-rw-r--r-- | src/Indicator.cxx | 10 | ||||
-rw-r--r-- | src/Indicator.h | 14 | ||||
-rw-r--r-- | src/PositionCache.cxx | 14 | ||||
-rw-r--r-- | src/PositionCache.h | 2 | ||||
-rw-r--r-- | src/ViewStyle.cxx | 7 | ||||
-rw-r--r-- | src/ViewStyle.h | 1 |
8 files changed, 83 insertions, 16 deletions
diff --git a/src/EditView.cxx b/src/EditView.cxx index 2c8979f8c..9d940f701 100644 --- a/src/EditView.cxx +++ b/src/EditView.cxx @@ -445,7 +445,7 @@ void EditView::LayoutLine(const EditModel &model, int line, Surface *surface, co ll->positions[0] = 0; bool lastSegItalics = false; - BreakFinder bfLayout(ll, NULL, Range(0, numCharsInLine), posLineStart, 0, false, model.pdoc, &model.reprs); + BreakFinder bfLayout(ll, NULL, Range(0, numCharsInLine), posLineStart, 0, false, model.pdoc, &model.reprs, NULL); while (bfLayout.More()) { const TextSegment ts = bfLayout.Next(); @@ -940,14 +940,14 @@ void EditView::DrawEOL(Surface *surface, const EditModel &model, const ViewStyle } static void DrawIndicator(int indicNum, int startPos, int endPos, Surface *surface, const ViewStyle &vsDraw, - const LineLayout *ll, int xStart, PRectangle rcLine, int subLine, Indicator::DrawState drawState) { + const LineLayout *ll, int xStart, PRectangle rcLine, int subLine, Indicator::DrawState drawState, int value) { const XYPOSITION subLineStart = ll->positions[ll->LineStart(subLine)]; PRectangle rcIndic( ll->positions[startPos] + xStart - subLineStart, rcLine.top + vsDraw.maxAscent, ll->positions[endPos] + xStart - subLineStart, rcLine.top + vsDraw.maxAscent + 3); - vsDraw.indicators[indicNum].Draw(surface, rcIndic, rcLine, drawState); + vsDraw.indicators[indicNum].Draw(surface, rcIndic, rcLine, drawState, value); } static void DrawIndicators(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, @@ -969,9 +969,10 @@ static void DrawIndicators(Surface *surface, const EditModel &model, const ViewS endPos = posLineEnd; const bool hover = vsDraw.indicators[deco->indicator].IsDynamic() && ((hoverIndicatorPos >= startPos) && (hoverIndicatorPos <= endPos)); + const int value = deco->rs.ValueAt(startPos); Indicator::DrawState drawState = hover ? Indicator::drawHover : Indicator::drawNormal; DrawIndicator(deco->indicator, startPos - posLineStart, endPos - posLineStart, - surface, vsDraw, ll, xStart, rcLine, subLine, drawState); + surface, vsDraw, ll, xStart, rcLine, subLine, drawState, value); startPos = endPos; if (!deco->rs.ValueAt(startPos)) { startPos = deco->rs.EndRun(startPos); @@ -989,13 +990,13 @@ static void DrawIndicators(Surface *surface, const EditModel &model, const ViewS if (rangeLine.ContainsCharacter(model.braces[0])) { int braceOffset = model.braces[0] - posLineStart; if (braceOffset < ll->numCharsInLine) { - DrawIndicator(braceIndicator, braceOffset, braceOffset + 1, surface, vsDraw, ll, xStart, rcLine, subLine, Indicator::drawNormal); + DrawIndicator(braceIndicator, braceOffset, braceOffset + 1, surface, vsDraw, ll, xStart, rcLine, subLine, Indicator::drawNormal, 1); } } if (rangeLine.ContainsCharacter(model.braces[1])) { int braceOffset = model.braces[1] - posLineStart; if (braceOffset < ll->numCharsInLine) { - DrawIndicator(braceIndicator, braceOffset, braceOffset + 1, surface, vsDraw, ll, xStart, rcLine, subLine, Indicator::drawNormal); + DrawIndicator(braceIndicator, braceOffset, braceOffset + 1, surface, vsDraw, ll, xStart, rcLine, subLine, Indicator::drawNormal, 1); } } } @@ -1250,7 +1251,7 @@ void EditView::DrawBackground(Surface *surface, const EditModel &model, const Vi // Does not take margin into account but not significant const int xStartVisible = static_cast<int>(subLineStart)-xStart; - BreakFinder bfBack(ll, &model.sel, lineRange, posLineStart, xStartVisible, selBackDrawn, model.pdoc, &model.reprs); + BreakFinder bfBack(ll, &model.sel, lineRange, posLineStart, xStartVisible, selBackDrawn, model.pdoc, &model.reprs, NULL); const bool drawWhitespaceBackground = vsDraw.WhitespaceBackgroundDrawn() && !background.isSet; @@ -1427,7 +1428,7 @@ void EditView::DrawForeground(Surface *surface, const EditModel &model, const Vi // Foreground drawing loop BreakFinder bfFore(ll, &model.sel, lineRange, posLineStart, xStartVisible, - (((phasesDraw == phasesOne) && selBackDrawn) || vsDraw.selColours.fore.isSet), model.pdoc, &model.reprs); + (((phasesDraw == phasesOne) && selBackDrawn) || vsDraw.selColours.fore.isSet), model.pdoc, &model.reprs, &vsDraw); while (bfFore.More()) { @@ -1450,6 +1451,30 @@ void EditView::DrawForeground(Surface *surface, const EditModel &model, const Vi if (vsDraw.hotspotColours.fore.isSet) textFore = vsDraw.hotspotColours.fore; } + if (vsDraw.indicatorsSetFore > 0) { + // At least one indicator sets the text colour so see if it applies to this segment + for (Decoration *deco = model.pdoc->decorations.root; deco; deco = deco->next) { + const int indicatorValue = deco->rs.ValueAt(ts.start + posLineStart); + if (indicatorValue) { + const Indicator &indicator = vsDraw.indicators[deco->indicator]; + const bool hover = indicator.IsDynamic() && + ((model.hoverIndicatorPos >= ts.start + posLineStart) && + (model.hoverIndicatorPos <= ts.end() + posLineStart)); + if (hover) { + if (indicator.sacHover.style == INDIC_TEXTFORE) { + textFore = indicator.sacHover.fore; + } + } else { + if (indicator.sacNormal.style == INDIC_TEXTFORE) { + if (indicator.Flags() & SC_INDICFLAG_VALUEFORE) + textFore = indicatorValue & SC_INDICVALUEMASK; + else + textFore = indicator.sacNormal.fore; + } + } + } + } + } const int inSelection = hideSelection ? 0 : model.sel.CharacterInSelection(iDoc); if (inSelection && (vsDraw.selColours.fore.isSet)) { textFore = (inSelection == 1) ? vsDraw.selColours.fore : vsDraw.selAdditionalForeground; diff --git a/src/Editor.cxx b/src/Editor.cxx index 85fab6e70..382e173c3 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -6855,6 +6855,16 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { case SCI_INDICGETHOVERFORE: return (wParam <= INDIC_MAX) ? vs.indicators[wParam].sacHover.fore.AsLong() : 0; + case SCI_INDICSETFLAGS: + if (wParam <= INDIC_MAX) { + vs.indicators[wParam].SetFlags(static_cast<int>(lParam)); + InvalidateStyleRedraw(); + } + break; + + case SCI_INDICGETFLAGS: + return (wParam <= INDIC_MAX) ? vs.indicators[wParam].Flags() : 0; + case SCI_INDICSETUNDER: if (wParam <= INDIC_MAX) { vs.indicators[wParam].under = lParam != 0; diff --git a/src/Indicator.cxx b/src/Indicator.cxx index eea5877bb..62df0b716 100644 --- a/src/Indicator.cxx +++ b/src/Indicator.cxx @@ -23,8 +23,11 @@ static PRectangle PixelGridAlign(const PRectangle &rc) { return PRectangle::FromInts(int(rc.left + 0.5), int(rc.top), int(rc.right + 0.5), int(rc.bottom)); } -void Indicator::Draw(Surface *surface, const PRectangle &rc, const PRectangle &rcLine, DrawState drawState) const { +void Indicator::Draw(Surface *surface, const PRectangle &rc, const PRectangle &rcLine, DrawState drawState, int value) const { StyleAndColour sacDraw = sacNormal; + if (Flags() & SC_INDICFLAG_VALUEFORE) { + sacDraw.fore = value & SC_INDICVALUEMASK; + } if (drawState == drawHover) { sacDraw = sacHover; } @@ -108,7 +111,7 @@ void Indicator::Draw(Surface *surface, const PRectangle &rc, const PRectangle &r } else if (sacDraw.style == INDIC_STRIKE) { surface->MoveTo(static_cast<int>(rc.left), static_cast<int>(rc.top) - 4); surface->LineTo(static_cast<int>(rc.right), static_cast<int>(rc.top) - 4); - } else if (sacDraw.style == INDIC_HIDDEN) { + } else if ((sacDraw.style == INDIC_HIDDEN) || (sacDraw.style == INDIC_TEXTFORE)) { // Draw nothing } else if (sacDraw.style == INDIC_BOX) { surface->MoveTo(static_cast<int>(rc.left), ymid + 1); @@ -172,3 +175,6 @@ void Indicator::Draw(Surface *surface, const PRectangle &rc, const PRectangle &r } } +void Indicator::SetFlags(int attributes_) { + attributes = attributes_; +} diff --git a/src/Indicator.h b/src/Indicator.h index 56777e93e..c22ec71c6 100644 --- a/src/Indicator.h +++ b/src/Indicator.h @@ -34,15 +34,23 @@ public: bool under; int fillAlpha; int outlineAlpha; - Indicator() : under(false), fillAlpha(30), outlineAlpha(50) { + int attributes; + Indicator() : under(false), fillAlpha(30), outlineAlpha(50), attributes(0) { } Indicator(int style_, ColourDesired fore_=ColourDesired(0,0,0), bool under_=false, int fillAlpha_=30, int outlineAlpha_=50) : - sacNormal(style_, fore_), sacHover(style_, fore_), under(under_), fillAlpha(fillAlpha_), outlineAlpha(outlineAlpha_) { + sacNormal(style_, fore_), sacHover(style_, fore_), under(under_), fillAlpha(fillAlpha_), outlineAlpha(outlineAlpha_), attributes(0) { } - void Draw(Surface *surface, const PRectangle &rc, const PRectangle &rcLine, DrawState drawState) const; + void Draw(Surface *surface, const PRectangle &rc, const PRectangle &rcLine, DrawState drawState, int value) const; bool IsDynamic() const { return !(sacNormal == sacHover); } + bool OverridesTextFore() const { + return sacNormal.style == INDIC_TEXTFORE || sacHover.style == INDIC_TEXTFORE; + } + int Flags() const { + return attributes; + } + void SetFlags(int attributes_); }; #ifdef SCI_NAMESPACE diff --git a/src/PositionCache.cxx b/src/PositionCache.cxx index 666399503..860a780d9 100644 --- a/src/PositionCache.cxx +++ b/src/PositionCache.cxx @@ -440,7 +440,7 @@ void BreakFinder::Insert(int val) { } BreakFinder::BreakFinder(const LineLayout *ll_, const Selection *psel, Range lineRange_, int posLineStart_, - int xStart, bool breakForSelection, const Document *pdoc_, const SpecialRepresentations *preprs_) : + int xStart, bool breakForSelection, const Document *pdoc_, const SpecialRepresentations *preprs_, const ViewStyle *pvsDraw) : ll(ll_), lineRange(lineRange_), posLineStart(posLineStart_), @@ -475,7 +475,17 @@ BreakFinder::BreakFinder(const LineLayout *ll_, const Selection *psel, Range lin } } } - + if (pvsDraw && pvsDraw->indicatorsSetFore > 0) { + for (Decoration *deco = pdoc->decorations.root; deco; deco = deco->next) { + if (pvsDraw->indicators[deco->indicator].OverridesTextFore()) { + int startPos = deco->rs.EndRun(posLineStart); + while (startPos < (posLineStart + lineRange.end)) { + Insert(startPos - posLineStart); + startPos = deco->rs.EndRun(startPos); + } + } + } + } Insert(ll->edgeColumn); Insert(lineRange.end); saeNext = (!selAndEdge.empty()) ? selAndEdge[0] : -1; diff --git a/src/PositionCache.h b/src/PositionCache.h index 9d9821f8f..edc0a5ddb 100644 --- a/src/PositionCache.h +++ b/src/PositionCache.h @@ -168,7 +168,7 @@ public: // Try to make each subdivided run lengthEachSubdivision or shorter. enum { lengthEachSubdivision = 100 }; BreakFinder(const LineLayout *ll_, const Selection *psel, Range rangeLine_, int posLineStart_, - int xStart, bool breakForSelection, const Document *pdoc_, const SpecialRepresentations *preprs_); + int xStart, bool breakForSelection, const Document *pdoc_, const SpecialRepresentations *preprs_, const ViewStyle *pvsDraw); ~BreakFinder(); TextSegment Next(); bool More() const; diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx index 864356bc1..e56c8f375 100644 --- a/src/ViewStyle.cxx +++ b/src/ViewStyle.cxx @@ -102,10 +102,13 @@ ViewStyle::ViewStyle(const ViewStyle &source) { } CalcLargestMarkerHeight(); indicatorsDynamic = 0; + indicatorsSetFore = 0; for (int ind=0; ind<=INDIC_MAX; ind++) { indicators[ind] = source.indicators[ind]; if (indicators[ind].IsDynamic()) indicatorsDynamic++; + if (indicators[ind].OverridesTextFore()) + indicatorsSetFore++; } selColours = source.selColours; @@ -201,6 +204,7 @@ void ViewStyle::Init(size_t stylesSize_) { technology = SC_TECHNOLOGY_DEFAULT; indicatorsDynamic = 0; + indicatorsSetFore = 0; lineHeight = 1; lineOverlap = 0; maxAscent = 1; @@ -323,9 +327,12 @@ void ViewStyle::Refresh(Surface &surface, int tabInChars) { styles[k].Copy(fr->font, *fr); } indicatorsDynamic = 0; + indicatorsSetFore = 0; for (int ind = 0; ind <= INDIC_MAX; ind++) { if (indicators[ind].IsDynamic()) indicatorsDynamic++; + if (indicators[ind].OverridesTextFore()) + indicatorsSetFore++; } maxAscent = 1; maxDescent = 1; diff --git a/src/ViewStyle.h b/src/ViewStyle.h index 08afebaa5..930ad104c 100644 --- a/src/ViewStyle.h +++ b/src/ViewStyle.h @@ -84,6 +84,7 @@ public: int largestMarkerHeight; Indicator indicators[INDIC_MAX + 1]; unsigned int indicatorsDynamic; + unsigned int indicatorsSetFore; int technology; int lineHeight; int lineOverlap; |