diff options
-rw-r--r-- | src/EditView.cxx | 16 | ||||
-rw-r--r-- | src/Editor.cxx | 13 | ||||
-rw-r--r-- | src/ViewStyle.cxx | 9 | ||||
-rw-r--r-- | src/ViewStyle.h | 1 |
4 files changed, 23 insertions, 16 deletions
diff --git a/src/EditView.cxx b/src/EditView.cxx index e0a212f48..fde8a937e 100644 --- a/src/EditView.cxx +++ b/src/EditView.cxx @@ -1228,7 +1228,7 @@ void EditView::DrawEOL(Surface *surface, const EditModel &model, const ViewStyle if (vsDraw.IsLineFrameOpaque(model.caret.active, ll->containsCaret)) { // Draw right of frame under marker surface->FillRectangleAligned(Side(rcLine, Edge::right, vsDraw.GetFrameWidth()), - vsDraw.ElementColour(Element::CaretLineBack)->Opaque()); + vsDraw.ElementColourForced(Element::CaretLineBack).Opaque()); } } @@ -1837,7 +1837,7 @@ void EditView::DrawCarets(Surface *surface, const EditModel &model, const ViewSt rcCaret.right = rcCaret.left + vsDraw.caret.width; } const Element elementCaret = mainCaret ? Element::Caret : Element::CaretAdditional; - const ColourRGBA caretColour = *vsDraw.ElementColour(elementCaret); + const ColourRGBA caretColour = vsDraw.ElementColourForced(elementCaret); //assert(caretColour.IsOpaque()); if (drawBlockCaret) { DrawBlockCaret(surface, model, vsDraw, ll, subLine, xStart, offset, posCaret.Position(), rcCaret, caretColour); @@ -1862,7 +1862,7 @@ void DrawWrapIndentAndMarker(Surface *surface, const ViewStyle &vsDraw, const Li if (vsDraw.IsLineFrameOpaque(caretActive, ll->containsCaret)) { // Draw left of frame under marker surface->FillRectangleAligned(Side(rcLine, Edge::left, vsDraw.GetFrameWidth()), - vsDraw.ElementColour(Element::CaretLineBack)->Opaque()); + vsDraw.ElementColourForced(Element::CaretLineBack).Opaque()); } if (FlagSet(vsDraw.wrap.visualFlags, WrapVisualFlag::Start)) { @@ -1947,7 +1947,7 @@ void EditView::DrawBackground(Surface *surface, const EditModel &model, const Vi if (ll->chars[i] == '\t') { // Tab display if (drawWhitespaceBackground && vsDraw.WhiteSpaceVisible(inIndentation)) { - textBack = vsDraw.ElementColour(Element::WhiteSpaceBack)->Opaque(); + textBack = vsDraw.ElementColourForced(Element::WhiteSpaceBack).Opaque(); } } else { // Blob display @@ -1967,7 +1967,7 @@ void EditView::DrawBackground(Surface *surface, const EditModel &model, const Vi ll->positions[cpos + ts.start + 1] + xStart - static_cast<XYPOSITION>(subLineStart), rcSegment.bottom); surface->FillRectangleAligned(rcSpace, - vsDraw.ElementColour(Element::WhiteSpaceBack)->Opaque()); + vsDraw.ElementColourForced(Element::WhiteSpaceBack).Opaque()); } } else { inIndentation = false; @@ -2093,7 +2093,7 @@ static void DrawTranslucentLineState(Surface *surface, const EditModel &model, c if (vsDraw.caretLine.frame) { DrawCaretLineFramed(surface, vsDraw, ll, rcLine, subLine); } else { - surface->FillRectangleAligned(rcLine, *vsDraw.ElementColour(Element::CaretLineBack)); + surface->FillRectangleAligned(rcLine, vsDraw.ElementColourForced(Element::CaretLineBack)); } } const int marksOfLine = model.GetMark(line); @@ -2199,7 +2199,7 @@ void EditView::DrawForeground(Surface *surface, const EditModel &model, const Vi // Tab display if (phasesDraw == PhasesDraw::One) { if (drawWhitespaceBackground && vsDraw.WhiteSpaceVisible(inIndentation)) - textBack = vsDraw.ElementColour(Element::WhiteSpaceBack)->Opaque(); + textBack = vsDraw.ElementColourForced(Element::WhiteSpaceBack).Opaque(); surface->FillRectangleAligned(rcSegment, Fill(textBack)); } if (inIndentation && vsDraw.viewIndentationGuides == IndentView::Real) { @@ -2278,7 +2278,7 @@ void EditView::DrawForeground(Surface *surface, const EditModel &model, const Vi if (vsDraw.WhiteSpaceVisible(inIndentation)) { const XYPOSITION xmid = (ll->positions[cpos + ts.start] + ll->positions[cpos + ts.start + 1]) / 2; if ((phasesDraw == PhasesDraw::One) && drawWhitespaceBackground) { - textBack = vsDraw.ElementColour(Element::WhiteSpaceBack)->Opaque(); + textBack = vsDraw.ElementColourForced(Element::WhiteSpaceBack).Opaque(); const PRectangle rcSpace( ll->positions[cpos + ts.start] + xStart - static_cast<XYPOSITION>(subLineStart), rcSegment.top, diff --git a/src/Editor.cxx b/src/Editor.cxx index 68fd83e7a..ca2868dc8 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -7473,10 +7473,7 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) { InvalidateStyleRedraw(); break; case Message::GetCaretLineBack: - if (vs.ElementColour(Element::CaretLineBack)) - return vs.ElementColour(Element::CaretLineBack)->OpaqueRGB(); - else - return 0; + return vs.ElementColourForced(Element::CaretLineBack).OpaqueRGB(); case Message::SetCaretLineBack: vs.SetElementRGB(Element::CaretLineBack, static_cast<int>(wParam)); @@ -7687,7 +7684,7 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) { case Message::GetSelAlpha: if (vs.selection.layer == Layer::Base) return static_cast<sptr_t>(Alpha::NoAlpha); - return vs.ElementColour(Element::SelectionBack)->GetAlpha(); + return vs.ElementColourForced(Element::SelectionBack).GetAlpha(); case Message::GetSelEOLFilled: return vs.selection.eolFilled; @@ -7726,7 +7723,7 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) { break; case Message::GetCaretFore: - return vs.ElementColour(Element::Caret)->OpaqueRGB(); + return vs.ElementColourForced(Element::Caret).OpaqueRGB(); case Message::SetCaretStyle: if (static_cast<CaretStyle>(wParam) <= (CaretStyle::Block | CaretStyle::OverstrikeBlock | CaretStyle::Curses | CaretStyle::BlockAfter)) @@ -8747,7 +8744,7 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) { case Message::GetAdditionalSelAlpha: if (vs.selection.layer == Layer::Base) return static_cast<sptr_t>(Alpha::NoAlpha); - return vs.ElementColour(Element::SelectionAdditionalBack)->GetAlpha(); + return vs.ElementColourForced(Element::SelectionAdditionalBack).GetAlpha(); case Message::SetAdditionalCaretFore: vs.elementColours[Element::CaretAdditional] = ColourRGBA::FromIpRGB(SPtrFromUPtr(wParam)); @@ -8755,7 +8752,7 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) { break; case Message::GetAdditionalCaretFore: - return vs.ElementColour(Element::CaretAdditional)->OpaqueRGB(); + return vs.ElementColourForced(Element::CaretAdditional).OpaqueRGB(); case Message::RotateSelection: sel.RotateMain(); diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx index 19a7b5275..b8fe0c0d6 100644 --- a/src/ViewStyle.cxx +++ b/src/ViewStyle.cxx @@ -617,6 +617,15 @@ ColourOptional ViewStyle::ElementColour(Element element) const { return {}; } +ColourRGBA ViewStyle::ElementColourForced(Element element) const { + // Like ElementColour but never returns empty - when not found return opaque black. + // This method avoids warnings for unwrapping potentially empty optionals from + // Visual C++ Code Analysis + const ColourOptional colour = ElementColour(element); + constexpr ColourRGBA opaqueBlack(0, 0, 0, 0xff); + return colour.value_or(opaqueBlack); +} + bool ViewStyle::ElementAllowsTranslucent(Element element) const { return elementAllowsTranslucent.count(element) > 0; } diff --git a/src/ViewStyle.h b/src/ViewStyle.h index c9b498bdb..19a853121 100644 --- a/src/ViewStyle.h +++ b/src/ViewStyle.h @@ -221,6 +221,7 @@ public: void AddMultiEdge(int column, ColourRGBA colour); ColourOptional ElementColour(Scintilla::Element element) const; + ColourRGBA ElementColourForced(Scintilla::Element element) const; bool ElementAllowsTranslucent(Scintilla::Element element) const; bool ResetElement(Scintilla::Element element); bool SetElementColour(Scintilla::Element element, ColourRGBA colour); |