From d6136af6d39ae06b4b0b51bd4576338015722591 Mon Sep 17 00:00:00 2001 From: Neil Date: Fri, 14 May 2021 14:02:39 +1000 Subject: Add elements for hot spots SC_ELEMENT_HOT_SPOT_ACTIVE and SC_ELEMENT_HOT_SPOT_ACTIVE_BACK. --- doc/ScintillaDoc.html | 31 ++++++++++++++++++++++++++----- doc/ScintillaHistory.html | 4 ++++ include/Scintilla.h | 2 ++ include/Scintilla.iface | 2 ++ src/EditView.cxx | 14 +++++++------- src/Editor.cxx | 14 ++++++++------ src/ViewStyle.cxx | 5 ++--- src/ViewStyle.h | 6 ------ test/simpleTests.py | 32 ++++++++++++++++++++++++++++++++ 9 files changed, 83 insertions(+), 27 deletions(-) diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index 380a8e81d..789e06c84 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -3457,6 +3457,22 @@ struct Sci_TextToFind { Colour of visible white space background + + SC_ELEMENT_HOT_SPOT_ACTIVE + 70 + Translucent + All + + Text colour of active hot spot + + + SC_ELEMENT_HOT_SPOT_ACTIVE_BACK + 71 + Opaque + All + + Background colour of active hot spot + @@ -3527,10 +3543,12 @@ struct Sci_TextToFind { SCI_GETCARETSTICKY → int
SCI_TOGGLECARETSTICKY

- SCI_SETHOTSPOTACTIVEFORE(bool useSetting, colour fore)
- SCI_GETHOTSPOTACTIVEFORE → colour
- SCI_SETHOTSPOTACTIVEBACK(bool useSetting, colour back)
- SCI_GETHOTSPOTACTIVEBACK → colour
+ SC_ELEMENT_HOT_SPOT_ACTIVE : colouralpha
+ SCI_SETHOTSPOTACTIVEFORE(bool useSetting, colour fore)
+ SCI_GETHOTSPOTACTIVEFORE → colour
+ SC_ELEMENT_HOT_SPOT_ACTIVE_BACK : colouralpha
+ SCI_SETHOTSPOTACTIVEBACK(bool useSetting, colour back)
+ SCI_GETHOTSPOTACTIVEBACK → colour
SCI_SETHOTSPOTACTIVEUNDERLINE(bool underline)
SCI_GETHOTSPOTACTIVEUNDERLINE → bool
SCI_SETHOTSPOTSINGLELINE(bool singleLine)
@@ -3767,8 +3785,11 @@ struct Sci_TextToFind {

SCI_TOGGLECARETSTICKY switches from SC_CARETSTICKY_ON and SC_CARETSTICKY_WHITESPACE to SC_CARETSTICKY_OFF and from SC_CARETSTICKY_OFF to SC_CARETSTICKY_ON.

-

SCI_SETHOTSPOTACTIVEFORE(bool useSetting, colour fore)
+

+ SC_ELEMENT_HOT_SPOT_ACTIVE : colouralpha
+ SCI_SETHOTSPOTACTIVEFORE(bool useSetting, colour fore)
SCI_GETHOTSPOTACTIVEFORE → colour
+ SC_ELEMENT_HOT_SPOT_ACTIVE_BACK : colouralpha
SCI_SETHOTSPOTACTIVEBACK(bool useSetting, colour back)
SCI_GETHOTSPOTACTIVEBACK → colour
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index c0123dd4a..6d64439c7 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -603,6 +603,10 @@ Add SC_ELEMENT_WHITE_SPACE to set the colour of visible whitespace including translucency.

  • + Add elements for hot spots SC_ELEMENT_HOT_SPOT_ACTIVE and + SC_ELEMENT_HOT_SPOT_ACTIVE_BACK. +
  • +
  • Make idle actions wrapping and background styling smoother by measuring per-byte instead of per-line and allowing just one line to be processed in a time slice. diff --git a/include/Scintilla.h b/include/Scintilla.h index 2c91400af..3a5738bde 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -289,6 +289,8 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SC_ELEMENT_CARET_LINE_BACK 50 #define SC_ELEMENT_WHITE_SPACE 60 #define SC_ELEMENT_WHITE_SPACE_BACK 61 +#define SC_ELEMENT_HOT_SPOT_ACTIVE 70 +#define SC_ELEMENT_HOT_SPOT_ACTIVE_BACK 71 #define SCI_SETELEMENTCOLOUR 2753 #define SCI_GETELEMENTCOLOUR 2754 #define SCI_RESETELEMENTCOLOUR 2755 diff --git a/include/Scintilla.iface b/include/Scintilla.iface index 730c7bb12..dfe555168 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -696,6 +696,8 @@ val SC_ELEMENT_CARET_SECONDARY=42 val SC_ELEMENT_CARET_LINE_BACK=50 val SC_ELEMENT_WHITE_SPACE=60 val SC_ELEMENT_WHITE_SPACE_BACK=61 +val SC_ELEMENT_HOT_SPOT_ACTIVE=70 +val SC_ELEMENT_HOT_SPOT_ACTIVE_BACK=71 # Set the colour of an element. Translucency (alpha) may or may not be significant # and this may depend on the platform. The alpha byte should commonly be 0xff for opaque. diff --git a/src/EditView.cxx b/src/EditView.cxx index 7797236c8..e76921139 100644 --- a/src/EditView.cxx +++ b/src/EditView.cxx @@ -871,8 +871,8 @@ static ColourAlpha TextBackground(const EditModel &model, const ViewStyle &vsDra (i >= ll->edgeColumn) && (i < ll->numCharsBeforeEOL)) return vsDraw.theEdge.colour; - if (inHotspot && vsDraw.hotspotColours.back) - return *vsDraw.hotspotColours.back; + if (inHotspot && vsDraw.ElementColour(SC_ELEMENT_HOT_SPOT_ACTIVE_BACK)) + return vsDraw.ElementColour(SC_ELEMENT_HOT_SPOT_ACTIVE_BACK)->Opaque(); if (background && (styleMain != STYLE_BRACELIGHT) && (styleMain != STYLE_BRACEBAD)) { return *background; } else { @@ -1930,11 +1930,11 @@ void EditView::DrawForeground(Surface *surface, const EditModel &model, const Vi const int styleMain = ll->styles[i]; ColourAlpha textFore = vsDraw.styles[styleMain].fore; const Font *textFont = vsDraw.styles[styleMain].font.get(); - //hotspot foreground + // Hot-spot foreground const bool inHotspot = (ll->hotspot.Valid()) && ll->hotspot.ContainsCharacter(iDoc); if (inHotspot) { - if (vsDraw.hotspotColours.fore) - textFore = *vsDraw.hotspotColours.fore; + if (vsDraw.ElementColour(SC_ELEMENT_HOT_SPOT_ACTIVE)) + textFore = *vsDraw.ElementColour(SC_ELEMENT_HOT_SPOT_ACTIVE); } if (vsDraw.indicatorsSetFore) { // At least one indicator sets the text colour so see if it applies to this segment @@ -2074,8 +2074,8 @@ void EditView::DrawForeground(Surface *surface, const EditModel &model, const Vi PRectangle rcUL = rcSegment; rcUL.top = rcUL.top + vsDraw.maxAscent + 1; rcUL.bottom = rcUL.top + 1; - if (vsDraw.hotspotColours.fore) - surface->FillRectangleAligned(rcUL, Fill(*vsDraw.hotspotColours.fore)); + if (vsDraw.ElementColour(SC_ELEMENT_HOT_SPOT_ACTIVE)) + surface->FillRectangleAligned(rcUL, Fill(*vsDraw.ElementColour(SC_ELEMENT_HOT_SPOT_ACTIVE))); else surface->FillRectangleAligned(rcUL, Fill(textFore)); } else if (vsDraw.styles[styleMain].underline) { diff --git a/src/Editor.cxx b/src/Editor.cxx index 9b5bfd6ee..1a0248522 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -8114,20 +8114,22 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { break; case SCI_SETHOTSPOTACTIVEFORE: - vs.hotspotColours.fore = OptionalColour(wParam, lParam); - InvalidateStyleRedraw(); + if (vs.SetElementColourOptional(SC_ELEMENT_HOT_SPOT_ACTIVE, wParam, lParam)) { + InvalidateStyleRedraw(); + } break; case SCI_GETHOTSPOTACTIVEFORE: - return vs.hotspotColours.fore.value_or(ColourAlpha()).OpaqueRGB(); + return vs.ElementColour(SC_ELEMENT_HOT_SPOT_ACTIVE).value_or(ColourAlpha()).OpaqueRGB(); case SCI_SETHOTSPOTACTIVEBACK: - vs.hotspotColours.back = OptionalColour(wParam, lParam); - InvalidateStyleRedraw(); + if (vs.SetElementColourOptional(SC_ELEMENT_HOT_SPOT_ACTIVE_BACK, wParam, lParam)) { + InvalidateStyleRedraw(); + } break; case SCI_GETHOTSPOTACTIVEBACK: - return vs.hotspotColours.back.value_or(ColourAlpha()).OpaqueRGB(); + return vs.ElementColour(SC_ELEMENT_HOT_SPOT_ACTIVE_BACK).value_or(ColourAlpha()).OpaqueRGB(); case SCI_SETHOTSPOTACTIVEUNDERLINE: vs.hotspotUnderline = wParam != 0; diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx index 489758c71..ca59fef2c 100644 --- a/src/ViewStyle.cxx +++ b/src/ViewStyle.cxx @@ -87,7 +87,6 @@ ViewStyle::ViewStyle(const ViewStyle &source) : markers(MARKER_MAX + 1), indicat foldmarginColour = source.foldmarginColour; foldmarginHighlightColour = source.foldmarginHighlightColour; - hotspotColours = source.hotspotColours; hotspotUnderline = source.hotspotUnderline; controlCharSymbol = source.controlCharSymbol; @@ -249,9 +248,9 @@ void ViewStyle::Init(size_t stylesSize_) { someStylesProtected = false; someStylesForceCase = false; - hotspotColours.fore.reset(); - hotspotColours.back.reset(); hotspotUnderline = true; + elementColours.erase(SC_ELEMENT_HOT_SPOT_ACTIVE); + elementAllowsTranslucent.insert(SC_ELEMENT_HOT_SPOT_ACTIVE); leftMarginWidth = 1; rightMarginWidth = 1; diff --git a/src/ViewStyle.h b/src/ViewStyle.h index cf8da4fe6..524699590 100644 --- a/src/ViewStyle.h +++ b/src/ViewStyle.h @@ -58,11 +58,6 @@ inline std::optional OptionalColour(uptr_t wParam, sptr_t lParam) { } } -struct ForeBackColours { - std::optional fore; - std::optional back; -}; - struct SelectionAppearance { // Whether to draw on base layer or over text Layer layer; @@ -140,7 +135,6 @@ public: ColourAlpha selbarlight; std::optional foldmarginColour; std::optional foldmarginHighlightColour; - ForeBackColours hotspotColours; bool hotspotUnderline; /// Margins are ordered: Line Numbers, Selection Margin, Spacing Margin int leftMarginWidth; ///< Spacing margin on left of text diff --git a/test/simpleTests.py b/test/simpleTests.py index 470b56509..c28c31593 100644 --- a/test/simpleTests.py +++ b/test/simpleTests.py @@ -2054,6 +2054,38 @@ class TestElements(unittest.TestCase): self.ed.MarkerSetAlpha(1, 0x100) self.assertEquals(self.ed.MarkerGetLayer(1), 0) + def testHotSpot(self): + self.assertFalse(self.ed.GetElementIsSet(self.ed.SC_ELEMENT_HOT_SPOT_ACTIVE)) + self.assertFalse(self.ed.GetElementIsSet(self.ed.SC_ELEMENT_HOT_SPOT_ACTIVE_BACK)) + self.assertEquals(self.ed.HotspotActiveFore, 0) + self.assertEquals(self.ed.HotspotActiveBack, 0) + + testColour = 0x804020 + resetColour = 0x112233 # Doesn't get set + self.ed.SetHotspotActiveFore(1, testColour) + self.assertEquals(self.ed.HotspotActiveFore, testColour) + self.assertTrue(self.ed.GetElementIsSet(self.ed.SC_ELEMENT_HOT_SPOT_ACTIVE)) + self.assertEquals(self.ElementColour(self.ed.SC_ELEMENT_HOT_SPOT_ACTIVE), testColour | self.opaque) + self.ed.SetHotspotActiveFore(0, resetColour) + self.assertEquals(self.ed.HotspotActiveFore, 0) + self.assertFalse(self.ed.GetElementIsSet(self.ed.SC_ELEMENT_HOT_SPOT_ACTIVE)) + self.assertEquals(self.ElementColour(self.ed.SC_ELEMENT_HOT_SPOT_ACTIVE), 0) + + translucentColour = 0x50403020 + self.ed.SetElementColour(self.ed.SC_ELEMENT_HOT_SPOT_ACTIVE, translucentColour) + self.assertEquals(self.ElementColour(self.ed.SC_ELEMENT_HOT_SPOT_ACTIVE), translucentColour) + self.assertEquals(self.ed.HotspotActiveFore, translucentColour & self.dropAlpha) + + backColour = 0x204080 + self.ed.SetHotspotActiveBack(1, backColour) + self.assertEquals(self.ed.HotspotActiveBack, backColour) + self.assertTrue(self.ed.GetElementIsSet(self.ed.SC_ELEMENT_HOT_SPOT_ACTIVE_BACK)) + self.assertEquals(self.ElementColour(self.ed.SC_ELEMENT_HOT_SPOT_ACTIVE_BACK), backColour | self.opaque) + + # Restore + self.ed.ResetElementColour(self.ed.SC_ELEMENT_HOT_SPOT_ACTIVE) + self.ed.ResetElementColour(self.ed.SC_ELEMENT_HOT_SPOT_ACTIVE_BACK) + class TestIndices(unittest.TestCase): def setUp(self): self.xite = Xite.xiteFrame -- cgit v1.2.3