diff options
author | Neil <nyamatongwe@gmail.com> | 2015-02-04 08:04:06 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2015-02-04 08:04:06 +1100 |
commit | ca6e6726ea248cc86dad9a3eddf649abe98add60 (patch) | |
tree | 39dd457627c279bf35444c81c2ab69068dde1577 | |
parent | 2a01e4a708c371b061a9669ea3204a295e835ada (diff) | |
download | scintilla-mirror-ca6e6726ea248cc86dad9a3eddf649abe98add60.tar.gz |
Implement hover style and colour for indicators.
-rw-r--r-- | doc/ScintillaDoc.html | 34 | ||||
-rw-r--r-- | doc/ScintillaHistory.html | 3 | ||||
-rw-r--r-- | include/Scintilla.h | 4 | ||||
-rw-r--r-- | include/Scintilla.iface | 12 | ||||
-rw-r--r-- | src/EditModel.cxx | 1 | ||||
-rw-r--r-- | src/EditModel.h | 1 | ||||
-rw-r--r-- | src/EditView.cxx | 19 | ||||
-rw-r--r-- | src/Editor.cxx | 86 | ||||
-rw-r--r-- | src/Editor.h | 2 | ||||
-rw-r--r-- | src/Indicator.cxx | 59 | ||||
-rw-r--r-- | src/Indicator.h | 26 | ||||
-rw-r--r-- | src/ViewStyle.cxx | 9 | ||||
-rw-r--r-- | src/ViewStyle.h | 1 |
13 files changed, 203 insertions, 54 deletions
diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index dc9c006cf..ed3f23966 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -3900,8 +3900,12 @@ struct Sci_TextToFind { They can be used to show, for example, syntax errors, deprecated names and bad indentation by drawing underlines under text or boxes around text.</p> + <p>Indicators may have a different "hover" colour and style when the mouse is over them or the caret is moved into them. + This may be used, for example, to indicate that a URL can be clicked.</p + <p>Indicators may be displayed as simple underlines, squiggly underlines, a - line of small 'T' shapes, a line of diagonal hatching, a strike-out or a rectangle around the text.</p> + line of small 'T' shapes, a line of diagonal hatching, a strike-out or a rectangle around the text. + They may also be invisible when used to track pieces of content for the application as <code>INDIC_HIDDEN</code>.</p> <p>The <code>SCI_INDIC*</code> messages allow you to get and set the visual appearance of the indicators. They all use an <code>indicatorNumber</code> argument in the range 0 to INDIC_MAX(35) @@ -3910,6 +3914,11 @@ struct Sci_TextToFind { (8=<code>INDIC_CONTAINER</code> .. 31=<code>INDIC_IME-1</code>) and a range for IME indicators (32=<code>INDIC_IME</code> .. 35=<code>INDIC_IME_MAX</code>).</p> + <p>Indicators are stored in a format similar to run length encoding which is efficient in both + speed and storage for sparse information.</p> + <p>An indicator may store different values for each range but currently all values are drawn the same. + In the future, it may be possible to draw different values in different styles.</p> + <p>Originally, Scintilla used a different technique for indicators but this has been <a href="#RemovedFeatures">removed</a> and the APIs perform <a href="#StyleByteIndicators">no action</a>. @@ -3928,6 +3937,13 @@ struct Sci_TextToFind { <a class="message" href="#SCI_INDICGETOUTLINEALPHA">SCI_INDICGETOUTLINEALPHA(int indicatorNumber)</a><br /> <a class="message" href="#SCI_INDICSETUNDER">SCI_INDICSETUNDER(int indicatorNumber, bool under)</a><br /> <a class="message" href="#SCI_INDICGETUNDER">SCI_INDICGETUNDER(int indicatorNumber)</a><br /> + <a class="message" href="#SCI_INDICSETHOVERSTYLE">SCI_INDICSETHOVERSTYLE(int indicatorNumber, int + indicatorStyle)</a><br /> + <a class="message" href="#SCI_INDICGETHOVERSTYLE">SCI_INDICGETHOVERSTYLE(int indicatorNumber)</a><br /> + <a class="message" href="#SCI_INDICSETHOVERFORE">SCI_INDICSETHOVERFORE(int indicatorNumber, int + colour)</a><br /> + <a class="message" href="#SCI_INDICGETHOVERFORE">SCI_INDICGETHOVERFORE(int indicatorNumber)</a><br /> + <br /> <a class="message" href="#SCI_SETINDICATORCURRENT">SCI_SETINDICATORCURRENT(int indicator)</a><br /> <a class="message" href="#SCI_GETINDICATORCURRENT">SCI_GETINDICATORCURRENT</a><br /> @@ -4150,10 +4166,18 @@ struct Sci_TextToFind { Drawing under text works only for indicators when <a class="message" href="#SCI_SETTWOPHASEDRAW">two phase drawing</a> is enabled.</p> - <p>Indicators are stored in a format similar to run length encoding which is efficient in both - speed and storage for sparse information.</p> - <p>An indicator may store different values for each range but currently all values are drawn the same. - In the future, it may be possible to draw different values in different styles.</p> + <p><b id="SCI_INDICSETHOVERSTYLE">SCI_INDICSETHOVERSTYLE(int indicatorNumber, int + indicatorStyle)</b><br /> + <b id="SCI_INDICGETHOVERSTYLE">SCI_INDICGETHOVERSTYLE(int indicatorNumber)</b><br /> + <b id="SCI_INDICSETHOVERFORE">SCI_INDICSETHOVERFORE(int indicatorNumber, int <a class="jump" href="#colour">colour</a>)</b><br /> + <b id="SCI_INDICGETHOVERFORE">SCI_INDICGETHOVERFORE(int indicatorNumber)</b><br /> + These messages set and get the colour and style used to draw indicators when the mouse is over them or the caret moved into them. + The mouse cursor also changes when an indicator is drawn in hover style. + The default is for the hover appearance to be the same as the normal appearance and calling + <a class="message" href="#SCI_INDICSETFORE">SCI_INDICSETFORE</a> or + <a class="message" href="#SCI_INDICSETSTYLE">SCI_INDICSETSTYLE</a> will + also reset the hover attribute.</p> + <p> <b id="SCI_SETINDICATORCURRENT">SCI_SETINDICATORCURRENT(int indicator)</b><br /> <b id="SCI_GETINDICATORCURRENT">SCI_GETINDICATORCURRENT</b><br /> diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index 529e22eb0..e629bb2b4 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -486,6 +486,9 @@ Released 20 January 2015. </li> <li> + Indicators may have a different colour and style when the mouse is over them or the caret is moved into them. + </li> + <li> Minimum version of Qt supported is now 4.8 due to the use of QElapsedTimer::nsecsElapsed. </li> <li> diff --git a/include/Scintilla.h b/include/Scintilla.h index e4625356b..e8c5a7414 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -289,6 +289,10 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_INDICGETFORE 2083 #define SCI_INDICSETUNDER 2510 #define SCI_INDICGETUNDER 2511 +#define SCI_INDICSETHOVERSTYLE 2680 +#define SCI_INDICGETHOVERSTYLE 2681 +#define SCI_INDICSETHOVERFORE 2682 +#define SCI_INDICGETHOVERFORE 2683 #define SCI_SETWHITESPACEFORE 2084 #define SCI_SETWHITESPACEBACK 2085 #define SCI_SETWHITESPACESIZE 2086 diff --git a/include/Scintilla.iface b/include/Scintilla.iface index fe0b66454..b609c056f 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -633,6 +633,18 @@ set void IndicSetUnder=2510(int indic, bool under) # Retrieve whether indicator drawn under or over text. get bool IndicGetUnder=2511(int indic,) +# Set a hover indicator to plain, squiggle or TT. +set void IndicSetHoverStyle=2680(int indic, int style) + +# Retrieve the hover style of an indicator. +get int IndicGetHoverStyle=2681(int indic,) + +# Set the foreground hover colour of an indicator. +set void IndicSetHoverFore=2682(int indic, colour fore) + +# Retrieve the foreground hover colour of an indicator. +get colour IndicGetHoverFore=2683(int indic,) + # Set the foreground colour of all whitespace and whether to use this setting. fun void SetWhitespaceFore=2084(bool useSetting, colour fore) diff --git a/src/EditModel.cxx b/src/EditModel.cxx index fe65a8bf8..b50ade258 100644 --- a/src/EditModel.cxx +++ b/src/EditModel.cxx @@ -65,6 +65,7 @@ EditModel::EditModel() { imeInteraction = imeWindowed; foldFlags = 0; hotspot = Range(invalidPosition); + hoverIndicatorPos = invalidPosition; wrapWidth = LineLayout::wrapWidthInfinite; pdoc = new Document(); pdoc->AddRef(); diff --git a/src/EditModel.h b/src/EditModel.h index d8def3294..fce26bd22 100644 --- a/src/EditModel.h +++ b/src/EditModel.h @@ -48,6 +48,7 @@ public: ContractionState cs; // Hotspot support Range hotspot; + int hoverIndicatorPos; // Wrapping support int wrapWidth; diff --git a/src/EditView.cxx b/src/EditView.cxx index 4976d3614..c33f62d7b 100644 --- a/src/EditView.cxx +++ b/src/EditView.cxx @@ -940,18 +940,18 @@ 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) { + const LineLayout *ll, int xStart, PRectangle rcLine, int subLine, Indicator::DrawState drawState) { 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); + vsDraw.indicators[indicNum].Draw(surface, rcIndic, rcLine, drawState); } static void DrawIndicators(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, - int line, int xStart, PRectangle rcLine, int subLine, int lineEnd, bool under) { + int line, int xStart, PRectangle rcLine, int subLine, int lineEnd, bool under, int hoverIndicatorPos) { // Draw decorators const int posLineStart = model.pdoc->LineStart(line); const int lineStart = ll->LineStart(subLine); @@ -967,8 +967,11 @@ static void DrawIndicators(Surface *surface, const EditModel &model, const ViewS int endPos = deco->rs.EndRun(startPos); if (endPos > posLineEnd) endPos = posLineEnd; + const bool hover = vsDraw.indicators[deco->indicator].IsDynamic() && + ((hoverIndicatorPos >= startPos) && (hoverIndicatorPos <= endPos)); + Indicator::DrawState drawState = hover ? Indicator::drawHover : Indicator::drawNormal; DrawIndicator(deco->indicator, startPos - posLineStart, endPos - posLineStart, - surface, vsDraw, ll, xStart, rcLine, subLine); + surface, vsDraw, ll, xStart, rcLine, subLine, drawState); startPos = endPos; if (!deco->rs.ValueAt(startPos)) { startPos = deco->rs.EndRun(startPos); @@ -986,13 +989,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); + DrawIndicator(braceIndicator, braceOffset, braceOffset + 1, surface, vsDraw, ll, xStart, rcLine, subLine, Indicator::drawNormal); } } 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); + DrawIndicator(braceIndicator, braceOffset, braceOffset + 1, surface, vsDraw, ll, xStart, rcLine, subLine, Indicator::drawNormal); } } } @@ -1662,7 +1665,7 @@ void EditView::DrawLine(Surface *surface, const EditModel &model, const ViewStyl } if (phase & drawIndicatorsBack) { - DrawIndicators(surface, model, vsDraw, ll, line, xStart, rcLine, subLine, lineRange.end, true); + DrawIndicators(surface, model, vsDraw, ll, line, xStart, rcLine, subLine, lineRange.end, true, model.hoverIndicatorPos); DrawEdgeLine(surface, vsDraw, ll, rcLine, lineRange, xStart); DrawMarkUnderline(surface, model, vsDraw, line, rcLine); } @@ -1677,7 +1680,7 @@ void EditView::DrawLine(Surface *surface, const EditModel &model, const ViewStyl } if (phase & drawIndicatorsFore) { - DrawIndicators(surface, model, vsDraw, ll, line, xStart, rcLine, subLine, lineRange.end, false); + DrawIndicators(surface, model, vsDraw, ll, line, xStart, rcLine, subLine, lineRange.end, false, model.hoverIndicatorPos); } // End of the drawing of the current line diff --git a/src/Editor.cxx b/src/Editor.cxx index 8cf77ead1..8c406242d 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -630,6 +630,7 @@ void Editor::SetSelection(SelectionPosition currentPos_, SelectionPosition ancho sel.RangeMain() = rangeNew; SetRectangularRange(); ClaimSelection(); + SetHoverIndicatorPosition(sel.MainCaret()); if (marginView.highlightDelimiter.NeedsDrawing(currentLine)) { RedrawSelMargin(); @@ -657,6 +658,7 @@ void Editor::SetSelection(SelectionPosition currentPos_) { SelectionRange(SelectionPosition(currentPos_), sel.RangeMain().anchor); } ClaimSelection(); + SetHoverIndicatorPosition(sel.MainCaret()); if (marginView.highlightDelimiter.NeedsDrawing(currentLine)) { RedrawSelMargin(); @@ -678,6 +680,7 @@ void Editor::SetEmptySelection(SelectionPosition currentPos_) { sel.RangeMain() = rangeNew; SetRectangularRange(); ClaimSelection(); + SetHoverIndicatorPosition(sel.MainCaret()); if (marginView.highlightDelimiter.NeedsDrawing(currentLine)) { RedrawSelMargin(); @@ -1988,6 +1991,7 @@ void Editor::ClearSelection(bool retainMultipleSelections) { ThinRectangularRange(); sel.RemoveDuplicates(); ClaimSelection(); + SetHoverIndicatorPosition(sel.MainCaret()); } void Editor::ClearAll() { @@ -4117,6 +4121,7 @@ static bool AllowVirtualSpace(int virtualSpaceOptions, bool rectangular) { } void Editor::ButtonDownWithModifiers(Point pt, unsigned int curTime, int modifiers) { + SetHoverIndicatorPoint(pt); //Platform::DebugPrintf("ButtonDown %d %d = %d alt=%d %d\n", curTime, lastClickTime, curTime - lastClickTime, alt, inDragDrop); ptMouseLast = pt; const bool ctrl = (modifiers & SCI_CTRL) != 0; @@ -4315,6 +4320,36 @@ bool Editor::PointIsHotspot(Point pt) { return PositionIsHotspot(pos); } +void Editor::SetHoverIndicatorPosition(int position) { + int hoverIndicatorPosPrev = hoverIndicatorPos; + hoverIndicatorPos = INVALID_POSITION; + if (vs.indicatorsDynamic == 0) + return; + if (position != INVALID_POSITION) { + for (Decoration *deco = pdoc->decorations.root; deco; deco = deco->next) { + if (vs.indicators[deco->indicator].IsDynamic()) { + if (pdoc->decorations.ValueAt(deco->indicator, position)) { + hoverIndicatorPos = position; + } + } + } + } + if (hoverIndicatorPosPrev != hoverIndicatorPos) { + if (hoverIndicatorPosPrev != INVALID_POSITION) + InvalidateRange(hoverIndicatorPosPrev, hoverIndicatorPosPrev + 1); + if (hoverIndicatorPos != INVALID_POSITION) + InvalidateRange(hoverIndicatorPos, hoverIndicatorPos + 1); + } +} + +void Editor::SetHoverIndicatorPoint(Point pt) { + if (vs.indicatorsDynamic == 0) { + SetHoverIndicatorPosition(INVALID_POSITION); + } else { + SetHoverIndicatorPosition(PositionFromLocation(pt, true, true)); + } +} + void Editor::SetHotSpotRange(Point *pt) { if (pt) { int pos = PositionFromLocation(*pt, false, true); @@ -4457,12 +4492,18 @@ void Editor::ButtonMoveWithModifiers(Point pt, int modifiers) { // Display regular (drag) cursor over selection if (PointInSelection(pt) && !SelectionEmpty()) { DisplayCursor(Window::cursorArrow); - } else if (PointIsHotspot(pt)) { - DisplayCursor(Window::cursorHand); - SetHotSpotRange(&pt); } else { - DisplayCursor(Window::cursorText); - SetHotSpotRange(NULL); + SetHoverIndicatorPoint(pt); + if (PointIsHotspot(pt)) { + DisplayCursor(Window::cursorHand); + SetHotSpotRange(&pt); + } else { + if (hoverIndicatorPos != invalidPosition) + DisplayCursor(Window::cursorHand); + else + DisplayCursor(Window::cursorText); + SetHotSpotRange(NULL); + } } } } @@ -4475,6 +4516,8 @@ void Editor::ButtonUp(Point pt, unsigned int curTime, bool ctrl) { //Platform::DebugPrintf("ButtonUp %d %d\n", HaveMouseCapture(), inDragDrop); SelectionPosition newPos = SPositionFromLocation(pt, false, false, AllowVirtualSpace(virtualSpaceOptions, sel.IsRectangular())); + if (hoverIndicatorPos != INVALID_POSITION) + InvalidateRange(newPos.Position(), newPos.Position() + 1); newPos = MovePositionOutsideChar(newPos, sel.MainCaret() - newPos.Position()); if (inDragDrop == ddInitial) { inDragDrop = ddNone; @@ -4840,6 +4883,9 @@ void Editor::SetDocPointer(Document *document) { view.llc.Deallocate(); NeedWrapping(); + hotspot = Range(invalidPosition); + hoverIndicatorPos = invalidPosition; + view.ClearAllTabstops(); pdoc->AddWatcher(this, 0); @@ -6765,23 +6811,45 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { case SCI_INDICSETSTYLE: if (wParam <= INDIC_MAX) { - vs.indicators[wParam].style = static_cast<int>(lParam); + vs.indicators[wParam].sacNormal.style = static_cast<int>(lParam); + vs.indicators[wParam].sacHover.style = static_cast<int>(lParam); InvalidateStyleRedraw(); } break; case SCI_INDICGETSTYLE: - return (wParam <= INDIC_MAX) ? vs.indicators[wParam].style : 0; + return (wParam <= INDIC_MAX) ? vs.indicators[wParam].sacNormal.style : 0; case SCI_INDICSETFORE: if (wParam <= INDIC_MAX) { - vs.indicators[wParam].fore = ColourDesired(static_cast<long>(lParam)); + vs.indicators[wParam].sacNormal.fore = ColourDesired(static_cast<long>(lParam)); + vs.indicators[wParam].sacHover.fore = ColourDesired(static_cast<long>(lParam)); InvalidateStyleRedraw(); } break; case SCI_INDICGETFORE: - return (wParam <= INDIC_MAX) ? vs.indicators[wParam].fore.AsLong() : 0; + return (wParam <= INDIC_MAX) ? vs.indicators[wParam].sacNormal.fore.AsLong() : 0; + + case SCI_INDICSETHOVERSTYLE: + if (wParam <= INDIC_MAX) { + vs.indicators[wParam].sacHover.style = static_cast<int>(lParam); + InvalidateStyleRedraw(); + } + break; + + case SCI_INDICGETHOVERSTYLE: + return (wParam <= INDIC_MAX) ? vs.indicators[wParam].sacHover.style : 0; + + case SCI_INDICSETHOVERFORE: + if (wParam <= INDIC_MAX) { + vs.indicators[wParam].sacHover.fore = ColourDesired(static_cast<long>(lParam)); + InvalidateStyleRedraw(); + } + break; + + case SCI_INDICGETHOVERFORE: + return (wParam <= INDIC_MAX) ? vs.indicators[wParam].sacHover.fore.AsLong() : 0; case SCI_INDICSETUNDER: if (wParam <= INDIC_MAX) { diff --git a/src/Editor.h b/src/Editor.h index ec24f66fd..1fc907ac7 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -545,6 +545,8 @@ protected: // ScintillaBase subclass needs access to much of Editor bool PointIsHotspot(Point pt); void SetHotSpotRange(Point *pt); Range GetHotSpotRange() const; + void SetHoverIndicatorPosition(int position); + void SetHoverIndicatorPoint(Point pt); int CodePage() const; virtual bool ValidCodePage(int /* codePage */) const { return true; } diff --git a/src/Indicator.cxx b/src/Indicator.cxx index daf62aa02..9cbf7e12d 100644 --- a/src/Indicator.cxx +++ b/src/Indicator.cxx @@ -23,10 +23,14 @@ 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) const { - surface->PenColour(fore); +void Indicator::Draw(Surface *surface, const PRectangle &rc, const PRectangle &rcLine, DrawState drawState) const { + StyleAndColour sacDraw = sacNormal; + if (drawState == drawHover) { + sacDraw = sacHover; + } + surface->PenColour(sacDraw.fore); int ymid = static_cast<int>(rc.bottom + rc.top) / 2; - if (style == INDIC_SQUIGGLE) { + if (sacDraw.style == INDIC_SQUIGGLE) { int x = int(rc.left+0.5); int xLast = int(rc.right+0.5); int y = 0; @@ -42,7 +46,7 @@ void Indicator::Draw(Surface *surface, const PRectangle &rc, const PRectangle &r } surface->LineTo(x, static_cast<int>(rc.top) + y); } - } else if (style == INDIC_SQUIGGLEPIXMAP) { + } else if (sacDraw.style == INDIC_SQUIGGLEPIXMAP) { PRectangle rcSquiggle = PixelGridAlign(rc); int width = Platform::Minimum(4000, static_cast<int>(rcSquiggle.Width())); @@ -51,17 +55,17 @@ void Indicator::Draw(Surface *surface, const PRectangle &rc, const PRectangle &r for (int x = 0; x < width; x++) { if (x%2) { // Two halfway columns have a full pixel in middle flanked by light pixels - image.SetPixel(x, 0, fore, alphaSide); - image.SetPixel(x, 1, fore, alphaFull); - image.SetPixel(x, 2, fore, alphaSide); + image.SetPixel(x, 0, sacDraw.fore, alphaSide); + image.SetPixel(x, 1, sacDraw.fore, alphaFull); + image.SetPixel(x, 2, sacDraw.fore, alphaSide); } else { // Extreme columns have a full pixel at bottom or top and a mid-tone pixel in centre - image.SetPixel(x, (x%4) ? 0 : 2, fore, alphaFull); - image.SetPixel(x, 1, fore, alphaSide2); + image.SetPixel(x, (x % 4) ? 0 : 2, sacDraw.fore, alphaFull); + image.SetPixel(x, 1, sacDraw.fore, alphaSide2); } } surface->DrawRGBAImage(rcSquiggle, image.GetWidth(), image.GetHeight(), image.Pixels()); - } else if (style == INDIC_SQUIGGLELOW) { + } else if (sacDraw.style == INDIC_SQUIGGLELOW) { surface->MoveTo(static_cast<int>(rc.left), static_cast<int>(rc.top)); int x = static_cast<int>(rc.left) + 3; int y = 0; @@ -72,7 +76,7 @@ void Indicator::Draw(Surface *surface, const PRectangle &rc, const PRectangle &r x += 3; } surface->LineTo(static_cast<int>(rc.right), static_cast<int>(rc.top) + y); // Finish the line - } else if (style == INDIC_TT) { + } else if (sacDraw.style == INDIC_TT) { surface->MoveTo(static_cast<int>(rc.left), ymid); int x = static_cast<int>(rc.left) + 5; while (x < rc.right) { @@ -88,7 +92,7 @@ void Indicator::Draw(Surface *surface, const PRectangle &rc, const PRectangle &r surface->MoveTo(x-3, ymid); surface->LineTo(x-3, ymid+2); } - } else if (style == INDIC_DIAGONAL) { + } else if (sacDraw.style == INDIC_DIAGONAL) { int x = static_cast<int>(rc.left); while (x < rc.right) { surface->MoveTo(x, static_cast<int>(rc.top) + 2); @@ -101,24 +105,25 @@ void Indicator::Draw(Surface *surface, const PRectangle &rc, const PRectangle &r surface->LineTo(endX, endY); x += 4; } - } else if (style == INDIC_STRIKE) { + } 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 (style == INDIC_HIDDEN) { + } else if (sacDraw.style == INDIC_HIDDEN) { // Draw nothing - } else if (style == INDIC_BOX) { + } else if (sacDraw.style == INDIC_BOX) { surface->MoveTo(static_cast<int>(rc.left), ymid + 1); surface->LineTo(static_cast<int>(rc.right), ymid + 1); surface->LineTo(static_cast<int>(rc.right), static_cast<int>(rcLine.top) + 1); surface->LineTo(static_cast<int>(rc.left), static_cast<int>(rcLine.top) + 1); surface->LineTo(static_cast<int>(rc.left), ymid + 1); - } else if (style == INDIC_ROUNDBOX || style == INDIC_STRAIGHTBOX) { + } else if (sacDraw.style == INDIC_ROUNDBOX || sacDraw.style == INDIC_STRAIGHTBOX) { PRectangle rcBox = rcLine; rcBox.top = rcLine.top + 1; rcBox.left = rc.left; rcBox.right = rc.right; - surface->AlphaRectangle(rcBox, (style == INDIC_ROUNDBOX) ? 1 : 0, fore, fillAlpha, fore, outlineAlpha, 0); - } else if (style == INDIC_DOTBOX) { + surface->AlphaRectangle(rcBox, (sacDraw.style == INDIC_ROUNDBOX) ? 1 : 0, + sacDraw.fore, fillAlpha, sacDraw.fore, outlineAlpha, 0); + } else if (sacDraw.style == INDIC_DOTBOX) { PRectangle rcBox = PixelGridAlign(rc); rcBox.top = rcLine.top + 1; rcBox.bottom = rcLine.bottom; @@ -128,36 +133,36 @@ void Indicator::Draw(Surface *surface, const PRectangle &rc, const PRectangle &r // Draw horizontal lines top and bottom for (int x=0; x<width; x++) { for (int y = 0; y<static_cast<int>(rcBox.Height()); y += static_cast<int>(rcBox.Height()) - 1) { - image.SetPixel(x, y, fore, ((x + y) % 2) ? outlineAlpha : fillAlpha); + image.SetPixel(x, y, sacDraw.fore, ((x + y) % 2) ? outlineAlpha : fillAlpha); } } // Draw vertical lines left and right for (int y = 1; y<static_cast<int>(rcBox.Height()); y++) { for (int x=0; x<width; x += width-1) { - image.SetPixel(x, y, fore, ((x + y) % 2) ? outlineAlpha : fillAlpha); + image.SetPixel(x, y, sacDraw.fore, ((x + y) % 2) ? outlineAlpha : fillAlpha); } } surface->DrawRGBAImage(rcBox, image.GetWidth(), image.GetHeight(), image.Pixels()); - } else if (style == INDIC_DASH) { + } else if (sacDraw.style == INDIC_DASH) { int x = static_cast<int>(rc.left); while (x < rc.right) { surface->MoveTo(x, ymid); surface->LineTo(Platform::Minimum(x + 4, static_cast<int>(rc.right)), ymid); x += 7; } - } else if (style == INDIC_DOTS) { + } else if (sacDraw.style == INDIC_DOTS) { int x = static_cast<int>(rc.left); while (x < static_cast<int>(rc.right)) { PRectangle rcDot = PRectangle::FromInts(x, ymid, x + 1, ymid + 1); - surface->FillRectangle(rcDot, fore); + surface->FillRectangle(rcDot, sacDraw.fore); x += 2; } - } else if (style == INDIC_COMPOSITIONTHICK) { + } else if (sacDraw.style == INDIC_COMPOSITIONTHICK) { PRectangle rcComposition(rc.left+1, rcLine.bottom-2, rc.right-1, rcLine.bottom); - surface->FillRectangle(rcComposition, fore); - } else if (style == INDIC_COMPOSITIONTHIN) { + surface->FillRectangle(rcComposition, sacDraw.fore); + } else if (sacDraw.style == INDIC_COMPOSITIONTHIN) { PRectangle rcComposition(rc.left+1, rcLine.bottom-2, rc.right-1, rcLine.bottom-1); - surface->FillRectangle(rcComposition, fore); + surface->FillRectangle(rcComposition, sacDraw.fore); } else { // Either INDIC_PLAIN or unknown surface->MoveTo(static_cast<int>(rc.left), ymid); surface->LineTo(static_cast<int>(rc.right), ymid); diff --git a/src/Indicator.h b/src/Indicator.h index 96cba3c05..c17ae494c 100644 --- a/src/Indicator.h +++ b/src/Indicator.h @@ -12,21 +12,37 @@ namespace Scintilla { #endif +struct StyleAndColour { + int style; + ColourDesired fore; + StyleAndColour() : style(INDIC_PLAIN), fore(0, 0, 0) { + } + StyleAndColour(int style_, ColourDesired fore_ = ColourDesired(0, 0, 0)) : style(style_), fore(fore_) { + } + bool operator==(const StyleAndColour &other) const { + return (style == other.style) && (fore == other.fore); + } +}; + /** */ class Indicator { public: - int style; - ColourDesired fore; + enum DrawState { drawNormal, drawHover, drawActive }; + StyleAndColour sacNormal; + StyleAndColour sacHover; bool under; int fillAlpha; int outlineAlpha; - Indicator() : style(INDIC_PLAIN), fore(ColourDesired(0,0,0)), under(false), fillAlpha(30), outlineAlpha(50) { + Indicator() : under(false), fillAlpha(30), outlineAlpha(50) { } Indicator(int style_, ColourDesired fore_=ColourDesired(0,0,0), bool under_=false, int fillAlpha_=30, int outlineAlpha_=50) : - style(style_), fore(fore_), under(under_), fillAlpha(fillAlpha_), outlineAlpha(outlineAlpha_) { + sacNormal(style_, fore_), sacHover(style_, fore_), under(under_), fillAlpha(fillAlpha_), outlineAlpha(outlineAlpha_) { + } + void Draw(Surface *surface, const PRectangle &rc, const PRectangle &rcLine, DrawState drawState) const; + bool IsDynamic() const { + return !(sacNormal == sacHover); } - void Draw(Surface *surface, const PRectangle &rc, const PRectangle &rcLine) const; }; #ifdef SCI_NAMESPACE diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx index b60905caf..864356bc1 100644 --- a/src/ViewStyle.cxx +++ b/src/ViewStyle.cxx @@ -101,8 +101,11 @@ ViewStyle::ViewStyle(const ViewStyle &source) { markers[mrk] = source.markers[mrk]; } CalcLargestMarkerHeight(); + indicatorsDynamic = 0; for (int ind=0; ind<=INDIC_MAX; ind++) { indicators[ind] = source.indicators[ind]; + if (indicators[ind].IsDynamic()) + indicatorsDynamic++; } selColours = source.selColours; @@ -197,6 +200,7 @@ void ViewStyle::Init(size_t stylesSize_) { indicators[2] = Indicator(INDIC_PLAIN, ColourDesired(0xff, 0, 0)); technology = SC_TECHNOLOGY_DEFAULT; + indicatorsDynamic = 0; lineHeight = 1; lineOverlap = 0; maxAscent = 1; @@ -318,6 +322,11 @@ void ViewStyle::Refresh(Surface &surface, int tabInChars) { FontRealised *fr = Find(styles[k]); styles[k].Copy(fr->font, *fr); } + indicatorsDynamic = 0; + for (int ind = 0; ind <= INDIC_MAX; ind++) { + if (indicators[ind].IsDynamic()) + indicatorsDynamic++; + } maxAscent = 1; maxDescent = 1; FindMaxAscentDescent(); diff --git a/src/ViewStyle.h b/src/ViewStyle.h index 4a4ffcdf0..08afebaa5 100644 --- a/src/ViewStyle.h +++ b/src/ViewStyle.h @@ -83,6 +83,7 @@ public: LineMarker markers[MARKER_MAX + 1]; int largestMarkerHeight; Indicator indicators[INDIC_MAX + 1]; + unsigned int indicatorsDynamic; int technology; int lineHeight; int lineOverlap; |