From 1cfccee93cc5fd4d0fb56937b0402611b354e8c2 Mon Sep 17 00:00:00 2001 From: Neil Date: Tue, 11 May 2021 22:43:15 +1000 Subject: When setting or resetting elements, redraw if caused change. --- src/Editor.cxx | 8 ++++++-- src/ViewStyle.cxx | 27 +++++++++++++++++---------- src/ViewStyle.h | 3 ++- 3 files changed, 25 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/Editor.cxx b/src/Editor.cxx index 458d34ccf..35ca7bb77 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -7196,14 +7196,18 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { break; case SCI_SETELEMENTCOLOUR: - vs.elementColours[static_cast(wParam)] = ColourAlpha(static_cast(lParam)); + if (vs.SetElementColour(static_cast(wParam), ColourAlpha(static_cast(lParam)))) { + InvalidateStyleRedraw(); + } break; case SCI_GETELEMENTCOLOUR: return vs.ElementColour(static_cast(wParam)).value_or(ColourAlpha()).AsInteger(); case SCI_RESETELEMENTCOLOUR: - vs.ResetElement(static_cast(wParam)); + if (vs.ResetElement(static_cast(wParam))) { + InvalidateStyleRedraw(); + } break; case SCI_GETELEMENTISSET: diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx index 4d555b1c2..a8fcd2d8c 100644 --- a/src/ViewStyle.cxx +++ b/src/ViewStyle.cxx @@ -560,8 +560,20 @@ bool ViewStyle::ElementAllowsTranslucent(int element) const { return elementAllowsTranslucent.count(element) > 0; } -void ViewStyle::ResetElement(int element) { +bool ViewStyle::ResetElement(int element) { + ElementMap::const_iterator search = elementColours.find(element); + const bool changed = (search != elementColours.end()) && (search->second.has_value()); elementColours.erase(element); + return changed; +} + +bool ViewStyle::SetElementColour(int element, ColourAlpha colour) { + ElementMap::const_iterator search = elementColours.find(element); + const bool changed = + (search == elementColours.end()) || + (search->second.has_value() && !(*search->second == colour)); + elementColours[element] = colour; + return changed; } void ViewStyle::SetElementRGB(int element, int rgb) { @@ -583,17 +595,12 @@ bool ViewStyle::ElementIsSet(int element) const { } bool ViewStyle::SetElementBase(int element, ColourAlpha colour) { - bool different = false; ElementMap::const_iterator search = elementBaseColours.find(element); - if (search == elementBaseColours.end()) { - different = true; - } else { - if (search->second.has_value() && !(*search->second == colour)) { - different = true; - } - } + const bool changed = + (search == elementBaseColours.end()) || + (search->second.has_value() && !(*search->second == colour)); elementBaseColours[element] = colour; - return different; + return changed; } bool ViewStyle::SetWrapState(int wrapState_) noexcept { diff --git a/src/ViewStyle.h b/src/ViewStyle.h index 6aab53f64..13c489aa2 100644 --- a/src/ViewStyle.h +++ b/src/ViewStyle.h @@ -233,7 +233,8 @@ public: std::optional ElementColour(int element) const; bool ElementAllowsTranslucent(int element) const; - void ResetElement(int element); + bool ResetElement(int element); + bool SetElementColour(int element, ColourAlpha colour); void SetElementRGB(int element, int rgb); void SetElementAlpha(int element, int alpha); bool ElementIsSet(int element) const; -- cgit v1.2.3