aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/EditView.cxx59
-rw-r--r--src/ViewStyle.cxx12
-rw-r--r--src/ViewStyle.h8
3 files changed, 47 insertions, 32 deletions
diff --git a/src/EditView.cxx b/src/EditView.cxx
index 8b9eff781..0bde50833 100644
--- a/src/EditView.cxx
+++ b/src/EditView.cxx
@@ -823,31 +823,43 @@ Sci::Position EditView::StartEndDisplayLine(Surface *surface, const EditModel &m
namespace {
-ColourAlpha SelectionBackground(const ViewStyle &vsDraw, InSelection inSelection, bool primarySelection) noexcept {
- if (!inSelection)
- return ColourAlpha(0, 0, 0, 0); // Not selected -> transparent
+constexpr ColourAlpha bugColour = ColourAlpha(0xff, 0, 0xff, 0xf0);
+
+ColourAlpha SelectionBackground(const EditModel &model, const ViewStyle &vsDraw, InSelection inSelection) noexcept {
+ if (inSelection == InSelection::inNone)
+ return bugColour; // Not selected is a bug
if (!vsDraw.selection.colours.back)
- return ColourAlpha(0, 0, 0, 0); // Not set -> transparent
+ return bugColour; // Not set -> bug
- if (!primarySelection)
+ if (!model.primarySelection)
return vsDraw.selection.background2; // Secondary selection
- if (inSelection == 1)
+ if (inSelection == InSelection::inMain)
return *vsDraw.selection.colours.back; // Main selection
return vsDraw.selection.additionalBackground; // Additional selection
}
+std::optional<ColourAlpha> SelectionForeground(const ViewStyle &vsDraw, InSelection inSelection) noexcept {
+ if (inSelection == InSelection::inNone)
+ return {};
+ if (inSelection == InSelection::inMain)
+ return vsDraw.selection.colours.fore;
+ if (!vsDraw.selection.colours.fore) // Main not set means don't use additional either
+ return {};
+ return vsDraw.selection.additionalForeground;
+}
+
}
static ColourAlpha TextBackground(const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll,
std::optional<ColourAlpha> background, InSelection inSelection, bool inHotspot, int styleMain, Sci::Position i) noexcept {
if (inSelection && vsDraw.selection.colours.back) {
if ((inSelection == InSelection::inMain) && (vsDraw.selection.alpha == SC_ALPHA_NOALPHA)) {
- return SelectionBackground(vsDraw, inSelection, model.primarySelection);
+ return SelectionBackground(model, vsDraw, inSelection);
} else if ((inSelection == InSelection::inAdditional) && (vsDraw.selection.additionalAlpha == SC_ALPHA_NOALPHA)) {
- return SelectionBackground(vsDraw, inSelection, model.primarySelection);
+ return SelectionBackground(model, vsDraw, inSelection);
}
}
if ((vsDraw.edgeState == EDGE_BACKGROUND) &&
@@ -971,7 +983,7 @@ void EditView::DrawEOL(Surface *surface, const EditModel &model, const ViewStyle
static_cast<XYPOSITION>(subLineStart)+portion.end.VirtualSpace() * spaceWidth;
rcSegment.left = (rcSegment.left > rcLine.left) ? rcSegment.left : rcLine.left;
rcSegment.right = (rcSegment.right < rcLine.right) ? rcSegment.right : rcLine.right;
- surface->FillRectangleAligned(rcSegment, Fill(SelectionBackground(vsDraw, model.sel.RangeType(r), model.primarySelection)));
+ surface->FillRectangleAligned(rcSegment, Fill(SelectionBackground(model, vsDraw, model.sel.RangeType(r))));
}
}
}
@@ -985,7 +997,7 @@ void EditView::DrawEOL(Surface *surface, const EditModel &model, const ViewStyle
alpha = (eolInSelection == InSelection::inMain) ? vsDraw.selection.alpha : vsDraw.selection.additionalAlpha;
}
- const ColourAlpha selectionBack = SelectionBackground(vsDraw, eolInSelection, model.primarySelection);
+ const ColourAlpha selectionBack = SelectionBackground(model, vsDraw, eolInSelection);
// Draw the [CR], [LF], or [CR][LF] blobs if visible line ends are on
XYPOSITION blobsWidth = 0;
@@ -1011,10 +1023,8 @@ void EditView::DrawEOL(Surface *surface, const EditModel &model, const ViewStyle
ctrlChar = hexits;
}
}
- ColourAlpha textFore = vsDraw.styles[styleMain].fore;
- if (eolInSelection && vsDraw.selection.colours.fore) {
- textFore = (eolInSelection == InSelection::inMain) ? *vsDraw.selection.colours.fore : vsDraw.selection.additionalForeground;
- }
+ const std::optional<ColourAlpha> selectionFore = SelectionForeground(vsDraw, eolInSelection);
+ const ColourAlpha textFore = selectionFore.value_or(vsDraw.styles[styleMain].fore);
if (eolInSelection && vsDraw.selection.colours.back && (line < model.pdoc->LinesTotal() - 1)) {
if (alpha == SC_ALPHA_NOALPHA) {
surface->FillRectangleAligned(rcSegment, Fill(selectionBack));
@@ -1229,10 +1239,8 @@ void EditView::DrawFoldDisplayText(Surface *surface, const EditModel &model, con
rcSegment.right = rcSegment.left + static_cast<XYPOSITION>(widthFoldDisplayText);
const std::optional<ColourAlpha> background = vsDraw.Background(model.pdoc->GetMark(line), model.caret.active, ll->containsCaret);
- ColourAlpha textFore = vsDraw.styles[STYLE_FOLDDISPLAYTEXT].fore;
- if (eolInSelection && (vsDraw.selection.colours.fore)) {
- textFore = (eolInSelection == InSelection::inMain) ? *vsDraw.selection.colours.fore : vsDraw.selection.additionalForeground;
- }
+ const std::optional<ColourAlpha> selectionFore = SelectionForeground(vsDraw, eolInSelection);
+ const ColourAlpha textFore = selectionFore.value_or(vsDraw.styles[STYLE_FOLDDISPLAYTEXT].fore);
const ColourAlpha textBack = TextBackground(model, vsDraw, ll, background, eolInSelection,
false, STYLE_FOLDDISPLAYTEXT, -1);
@@ -1278,7 +1286,7 @@ void EditView::DrawFoldDisplayText(Surface *surface, const EditModel &model, con
if (FlagSet(phase, DrawPhase::selectionTranslucent)) {
if (eolInSelection && vsDraw.selection.colours.back && (line < model.pdoc->LinesTotal() - 1) && alpha != SC_ALPHA_NOALPHA) {
- surface->FillRectangleAligned(rcSegment, ColourAlpha(SelectionBackground(vsDraw, eolInSelection, model.primarySelection), alpha));
+ surface->FillRectangleAligned(rcSegment, ColourAlpha(SelectionBackground(model, vsDraw, eolInSelection), alpha));
}
}
}
@@ -1816,7 +1824,7 @@ static void DrawTranslucentSelection(Surface *surface, const EditModel &model, c
const SelectionSegment portion = model.sel.Range(r).Intersect(virtualSpaceRange);
if (!portion.Empty()) {
const ColourAlpha selectionBack = ColourAlpha(
- SelectionBackground(vsDraw, model.sel.RangeType(r), model.primarySelection), alpha);
+ SelectionBackground(model, vsDraw, model.sel.RangeType(r)), alpha);
const XYPOSITION spaceWidth = vsDraw.styles[ll->EndLineStyle()].spaceWidth;
if (model.BidirectionalEnabled()) {
const int selectionStart = static_cast<int>(portion.start.Position() - posLineStart - lineRange.start);
@@ -1912,7 +1920,7 @@ void EditView::DrawForeground(Surface *surface, const EditModel &model, const Vi
// Foreground drawing loop
BreakFinder bfFore(ll, &model.sel, lineRange, posLineStart, xStartVisible,
- (((phasesDraw == PhasesDraw::one) && selBackDrawn) || vsDraw.selection.colours.fore), model.pdoc, &model.reprs, &vsDraw);
+ (((phasesDraw == PhasesDraw::one) && selBackDrawn) || vsDraw.SelectionTextDrawn()), model.pdoc, &model.reprs, &vsDraw);
while (bfFore.More()) {
@@ -1963,8 +1971,9 @@ void EditView::DrawForeground(Surface *surface, const EditModel &model, const Vi
}
}
const InSelection inSelection = hideSelection ? InSelection::inNone : model.sel.CharacterInSelection(iDoc);
- if (inSelection && (vsDraw.selection.colours.fore)) {
- textFore = (inSelection == 1) ? *vsDraw.selection.colours.fore : vsDraw.selection.additionalForeground;
+ const std::optional<ColourAlpha> selectionFore = SelectionForeground(vsDraw, inSelection);
+ if (selectionFore) {
+ textFore = *selectionFore;
}
ColourAlpha textBack = TextBackground(model, vsDraw, ll, background, inSelection, inHotspot, styleMain, i);
if (ts.representation) {
@@ -2461,7 +2470,7 @@ void EditView::FillLineRemainder(Surface *surface, const EditModel &model, const
const std::optional<ColourAlpha> background = vsDraw.Background(model.pdoc->GetMark(line), model.caret.active, ll->containsCaret);
if (eolInSelection && vsDraw.selection.eolFilled && vsDraw.selection.colours.back && (line < model.pdoc->LinesTotal() - 1) && (alpha == SC_ALPHA_NOALPHA)) {
- surface->FillRectangleAligned(rcArea, Fill(SelectionBackground(vsDraw, eolInSelection, model.primarySelection)));
+ surface->FillRectangleAligned(rcArea, Fill(SelectionBackground(model, vsDraw, eolInSelection)));
} else {
if (background) {
surface->FillRectangleAligned(rcArea, Fill(*background));
@@ -2471,7 +2480,7 @@ void EditView::FillLineRemainder(Surface *surface, const EditModel &model, const
surface->FillRectangleAligned(rcArea, Fill(vsDraw.styles[STYLE_DEFAULT].back));
}
if (eolInSelection && vsDraw.selection.eolFilled && vsDraw.selection.colours.back && (line < model.pdoc->LinesTotal() - 1) && (alpha != SC_ALPHA_NOALPHA)) {
- surface->FillRectangleAligned(rcArea, ColourAlpha(SelectionBackground(vsDraw, eolInSelection, model.primarySelection), alpha));
+ surface->FillRectangleAligned(rcArea, ColourAlpha(SelectionBackground(model, vsDraw, eolInSelection), alpha));
}
}
}
diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx
index 9d9fd6712..58af810b8 100644
--- a/src/ViewStyle.cxx
+++ b/src/ViewStyle.cxx
@@ -487,6 +487,10 @@ bool ViewStyle::SelectionBackgroundDrawn() const noexcept {
((selection.alpha == SC_ALPHA_NOALPHA) || (selection.additionalAlpha == SC_ALPHA_NOALPHA));
}
+bool ViewStyle::SelectionTextDrawn() const {
+ return selection.colours.fore.has_value();
+}
+
bool ViewStyle::WhitespaceBackgroundDrawn() const noexcept {
return (viewWhitespace != WhiteSpace::invisible) && (whitespaceColours.back);
}
@@ -512,8 +516,8 @@ void ViewStyle::AddMultiEdge(uptr_t wParam, sptr_t lParam) {
EdgeProperties(column, lParam));
}
-std::optional<ColourAlpha> ViewStyle::ElementColour(int index) const {
- auto search = elementColours.find(index);
+std::optional<ColourAlpha> ViewStyle::ElementColour(int element) const {
+ ElementMap::const_iterator search = elementColours.find(element);
if (search != elementColours.end()) {
if (search->second.has_value()) {
return search->second;
@@ -522,8 +526,8 @@ std::optional<ColourAlpha> ViewStyle::ElementColour(int index) const {
return {};
}
-bool ViewStyle::ElementAllowsTranslucent(int index) const {
- return elementAllowsTranslucent.count(index) > 0;
+bool ViewStyle::ElementAllowsTranslucent(int element) const {
+ return elementAllowsTranslucent.count(element) > 0;
}
bool ViewStyle::SetWrapState(int wrapState_) noexcept {
diff --git a/src/ViewStyle.h b/src/ViewStyle.h
index 27abfdf6f..4118f0daf 100644
--- a/src/ViewStyle.h
+++ b/src/ViewStyle.h
@@ -201,7 +201,8 @@ public:
int ctrlCharPadding; // the padding around control character text blobs
int lastSegItalicsOffset; // the offset so as not to clip italic characters at EOLs
- std::map<int, std::optional<ColourAlpha>> elementColours;
+ using ElementMap = std::map<int, std::optional<ColourAlpha>>;
+ ElementMap elementColours;
std::set<int> elementAllowsTranslucent;
WrapAppearance wrap;
@@ -234,13 +235,14 @@ public:
bool IsLineFrameOpaque(bool caretActive, bool lineContainsCaret) const noexcept;
std::optional<ColourAlpha> Background(int marksOfLine, bool caretActive, bool lineContainsCaret) const;
bool SelectionBackgroundDrawn() const noexcept;
+ bool SelectionTextDrawn() const;
bool WhitespaceBackgroundDrawn() const noexcept;
ColourAlpha WrapColour() const noexcept;
void AddMultiEdge(uptr_t wParam, sptr_t lParam);
- std::optional<ColourAlpha> ElementColour(int index) const;
- bool ElementAllowsTranslucent(int index) const;
+ std::optional<ColourAlpha> ElementColour(int element) const;
+ bool ElementAllowsTranslucent(int element) const;
bool SetWrapState(int wrapState_) noexcept;
bool SetWrapVisualFlags(int wrapVisualFlags_) noexcept;