aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2022-12-09 13:54:57 +1100
committerNeil <nyamatongwe@gmail.com>2022-12-09 13:54:57 +1100
commit4bae79983a02af9c822a714f3dba48c52f347629 (patch)
tree62b06832e2549cdfcaa1808cf21e22397cc64985
parent8895da569aa861143b5fd1dbf3bfc7de52594158 (diff)
downloadscintilla-mirror-4bae79983a02af9c822a714f3dba48c52f347629.tar.gz
Shorten code with ColourOptional alias for std::optional<ColourRGBA>.
-rw-r--r--src/EditView.cxx30
-rw-r--r--src/EditView.h6
-rw-r--r--src/ViewStyle.cxx6
-rw-r--r--src/ViewStyle.h14
4 files changed, 29 insertions, 27 deletions
diff --git a/src/EditView.cxx b/src/EditView.cxx
index 29569a00b..650734ad1 100644
--- a/src/EditView.cxx
+++ b/src/EditView.cxx
@@ -965,7 +965,7 @@ ColourRGBA SelectionBackground(const EditModel &model, const ViewStyle &vsDraw,
return vsDraw.ElementColour(element).value_or(bugColour);
}
-std::optional<ColourRGBA> SelectionForeground(const EditModel &model, const ViewStyle &vsDraw, InSelection inSelection) {
+ColourOptional SelectionForeground(const EditModel &model, const ViewStyle &vsDraw, InSelection inSelection) {
if (inSelection == InSelection::inNone)
return {};
Element element = Element::SelectionText;
@@ -986,7 +986,7 @@ std::optional<ColourRGBA> SelectionForeground(const EditModel &model, const View
}
static ColourRGBA TextBackground(const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll,
- std::optional<ColourRGBA> background, InSelection inSelection, bool inHotspot, int styleMain, Sci::Position i) {
+ ColourOptional background, InSelection inSelection, bool inHotspot, int styleMain, Sci::Position i) {
if (inSelection && (vsDraw.selection.layer == Layer::Base)) {
return SelectionBackground(model, vsDraw, inSelection).Opaque();
}
@@ -1037,7 +1037,7 @@ static void DrawTextBlob(Surface *surface, const ViewStyle &vsDraw, PRectangle r
}
static void DrawCaretLineFramed(Surface *surface, const ViewStyle &vsDraw, const LineLayout *ll, PRectangle rcLine, int subLine) {
- const std::optional<ColourRGBA> caretlineBack = vsDraw.ElementColour(Element::CaretLineBack);
+ const ColourOptional caretlineBack = vsDraw.ElementColour(Element::CaretLineBack);
if (!caretlineBack) {
return;
}
@@ -1070,7 +1070,7 @@ static void DrawCaretLineFramed(Surface *surface, const ViewStyle &vsDraw, const
void EditView::DrawEOL(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll,
PRectangle rcLine, Sci::Line line, Sci::Position lineEnd, int xStart, int subLine, XYACCUMULATOR subLineStart,
- std::optional<ColourRGBA> background) {
+ ColourOptional background) {
const Sci::Position posLineStart = model.pdoc->LineStart(line);
PRectangle rcSegment = rcLine;
@@ -1122,7 +1122,7 @@ void EditView::DrawEOL(Surface *surface, const EditModel &model, const ViewStyle
if (lastSubLine) {
for (Sci::Position eolPos = ll->numCharsBeforeEOL; eolPos<ll->numCharsInLine;) {
const int styleMain = ll->styles[eolPos];
- const std::optional<ColourRGBA> selectionFore = SelectionForeground(model, vsDraw, eolInSelection);
+ const ColourOptional selectionFore = SelectionForeground(model, vsDraw, eolInSelection);
ColourRGBA textFore = selectionFore.value_or(vsDraw.styles[styleMain].fore);
char hexits[4] = "";
std::string_view ctrlChar;
@@ -1407,8 +1407,8 @@ void EditView::DrawFoldDisplayText(Surface *surface, const EditModel &model, con
rcSegment.left = xStart + static_cast<XYPOSITION>(ll->positions[ll->numCharsInLine] - subLineStart) + virtualSpace + vsDraw.aveCharWidth;
rcSegment.right = rcSegment.left + static_cast<XYPOSITION>(widthFoldDisplayText);
- const std::optional<ColourRGBA> background = vsDraw.Background(model.GetMark(line), model.caret.active, ll->containsCaret);
- const std::optional<ColourRGBA> selectionFore = SelectionForeground(model, vsDraw, eolInSelection);
+ const ColourOptional background = vsDraw.Background(model.GetMark(line), model.caret.active, ll->containsCaret);
+ const ColourOptional selectionFore = SelectionForeground(model, vsDraw, eolInSelection);
const ColourRGBA textFore = selectionFore.value_or(vsDraw.styles[StyleFoldDisplayText].fore);
const ColourRGBA textBack = TextBackground(model, vsDraw, ll, background, eolInSelection,
false, StyleFoldDisplayText, -1);
@@ -1534,7 +1534,7 @@ void EditView::DrawEOLAnnotationText(Surface *surface, const EditModel &model, c
}
rcSegment.right = rcSegment.left + static_cast<XYPOSITION>(widthEOLAnnotationText);
- const std::optional<ColourRGBA> background = vsDraw.Background(model.GetMark(line), model.caret.active, ll->containsCaret);
+ const ColourOptional background = vsDraw.Background(model.GetMark(line), model.caret.active, ll->containsCaret);
const ColourRGBA textFore = vsDraw.styles[style].fore;
const ColourRGBA textBack = TextBackground(model, vsDraw, ll, background, InSelection::inNone,
false, static_cast<int>(style), -1);
@@ -1851,7 +1851,7 @@ void EditView::DrawCarets(Surface *surface, const EditModel &model, const ViewSt
namespace {
void DrawWrapIndentAndMarker(Surface *surface, const ViewStyle &vsDraw, const LineLayout *ll,
- int xStart, PRectangle rcLine, std::optional<ColourRGBA> background, DrawWrapMarkerFn customDrawWrapMarker,
+ int xStart, PRectangle rcLine, ColourOptional background, DrawWrapMarkerFn customDrawWrapMarker,
bool caretActive) {
// default bgnd here..
surface->FillRectangleAligned(rcLine, Fill(background ? *background :
@@ -1903,7 +1903,7 @@ InSelection CharacterInCursesSelection(Sci::Position iDoc, const EditModel &mode
void EditView::DrawBackground(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll,
PRectangle rcLine, Range lineRange, Sci::Position posLineStart, int xStart,
- int subLine, std::optional<ColourRGBA> background) const {
+ int subLine, ColourOptional background) const {
const bool selBackDrawn = vsDraw.SelectionBackgroundDrawn();
bool inIndentation = subLine == 0; // Do not handle indentation except on first subline.
@@ -2119,7 +2119,7 @@ static void DrawTranslucentLineState(Surface *surface, const EditModel &model, c
void EditView::DrawForeground(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll,
Sci::Line lineVisible, PRectangle rcLine, Range lineRange, Sci::Position posLineStart, int xStart,
- int subLine, std::optional<ColourRGBA> background) {
+ int subLine, ColourOptional background) {
const bool selBackDrawn = vsDraw.SelectionBackgroundDrawn();
const bool drawWhitespaceBackground = vsDraw.WhitespaceBackgroundDrawn() && !background;
@@ -2187,7 +2187,7 @@ void EditView::DrawForeground(Surface *surface, const EditModel &model, const Vi
InSelection inSelection = vsDraw.selection.visible ? model.sel.CharacterInSelection(iDoc) : InSelection::inNone;
if (FlagSet(vsDraw.caret.style, CaretStyle::Curses) && (inSelection == InSelection::inMain))
inSelection = CharacterInCursesSelection(iDoc, model, vsDraw);
- const std::optional<ColourRGBA> selectionFore = SelectionForeground(model, vsDraw, inSelection);
+ const ColourOptional selectionFore = SelectionForeground(model, vsDraw, inSelection);
if (selectionFore) {
textFore = *selectionFore;
}
@@ -2398,7 +2398,7 @@ void EditView::DrawLine(Surface *surface, const EditModel &model, const ViewStyl
}
// See if something overrides the line background colour.
- const std::optional<ColourRGBA> background = vsDraw.Background(model.GetMark(line), model.caret.active, ll->containsCaret);
+ const ColourOptional background = vsDraw.Background(model.GetMark(line), model.caret.active, ll->containsCaret);
const Sci::Position posLineStart = model.pdoc->LineStart(line);
@@ -2509,7 +2509,7 @@ static void DrawFoldLines(Surface *surface, const EditModel &model, const ViewSt
}
}
if (lastSubLine && model.pcs->GetVisible(line) && !model.pcs->GetVisible(line + 1)) {
- std::optional<ColourRGBA> hiddenLineColour = vsDraw.ElementColour(Element::HiddenLine);
+ ColourOptional hiddenLineColour = vsDraw.ElementColour(Element::HiddenLine);
if (hiddenLineColour) {
surface->FillRectangleAligned(Side(rcLine, Edge::bottom, 1.0), *hiddenLineColour);
}
@@ -2720,7 +2720,7 @@ void EditView::FillLineRemainder(Surface *surface, const EditModel &model, const
eolInSelection = model.LineEndInSelection(line);
}
- const std::optional<ColourRGBA> background = vsDraw.Background(model.GetMark(line), model.caret.active, ll->containsCaret);
+ const ColourOptional background = vsDraw.Background(model.GetMark(line), model.caret.active, ll->containsCaret);
if (eolInSelection && vsDraw.selection.eolFilled && (line < model.pdoc->LinesTotal() - 1) && (vsDraw.selection.layer == Layer::Base)) {
surface->FillRectangleAligned(rcArea, Fill(SelectionBackground(model, vsDraw, eolInSelection).Opaque()));
diff --git a/src/EditView.h b/src/EditView.h
index 832da9f15..33da5f294 100644
--- a/src/EditView.h
+++ b/src/EditView.h
@@ -136,7 +136,7 @@ public:
void DrawIndentGuide(Surface *surface, Sci::Line lineVisible, int lineHeight, XYPOSITION start, PRectangle rcSegment, bool highlight);
void DrawEOL(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, PRectangle rcLine,
Sci::Line line, Sci::Position lineEnd, int xStart, int subLine, XYACCUMULATOR subLineStart,
- std::optional<ColourRGBA> background);
+ ColourOptional background);
void DrawFoldDisplayText(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll,
Sci::Line line, int xStart, PRectangle rcLine, int subLine, XYACCUMULATOR subLineStart, DrawPhase phase);
void DrawEOLAnnotationText(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll,
@@ -147,10 +147,10 @@ public:
int xStart, PRectangle rcLine, int subLine) const;
void DrawBackground(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, PRectangle rcLine,
Range lineRange, Sci::Position posLineStart, int xStart,
- int subLine, std::optional<ColourRGBA> background) const;
+ int subLine, ColourOptional background) const;
void DrawForeground(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, Sci::Line lineVisible,
PRectangle rcLine, Range lineRange, Sci::Position posLineStart, int xStart,
- int subLine, std::optional<ColourRGBA> background);
+ int subLine, ColourOptional background);
void DrawIndentGuidesOverEmpty(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll,
Sci::Line line, Sci::Line lineVisible, PRectangle rcLine, int xStart, int subLine);
void DrawLine(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, Sci::Line line,
diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx
index a79e60102..19a7b5275 100644
--- a/src/ViewStyle.cxx
+++ b/src/ViewStyle.cxx
@@ -530,8 +530,8 @@ bool ViewStyle::IsLineFrameOpaque(bool caretActive, bool lineContainsCaret) cons
// display itself (as long as it's not an MarkerSymbol::Empty marker). These are checked in order
// with the earlier taking precedence. When multiple markers cause background override,
// the colour for the highest numbered one is used.
-std::optional<ColourRGBA> ViewStyle::Background(int marksOfLine, bool caretActive, bool lineContainsCaret) const {
- std::optional<ColourRGBA> background;
+ColourOptional ViewStyle::Background(int marksOfLine, bool caretActive, bool lineContainsCaret) const {
+ ColourOptional background;
if (!caretLine.frame && (caretActive || caretLine.alwaysShow) &&
(caretLine.layer == Layer::Base) && lineContainsCaret) {
background = ElementColour(Element::CaretLineBack);
@@ -601,7 +601,7 @@ void ViewStyle::AddMultiEdge(int column, ColourRGBA colour) {
EdgeProperties(column, colour));
}
-std::optional<ColourRGBA> ViewStyle::ElementColour(Element element) const {
+ColourOptional ViewStyle::ElementColour(Element element) const {
ElementMap::const_iterator search = elementColours.find(element);
if (search != elementColours.end()) {
if (search->second.has_value()) {
diff --git a/src/ViewStyle.h b/src/ViewStyle.h
index a91aea501..4fa95d0f2 100644
--- a/src/ViewStyle.h
+++ b/src/ViewStyle.h
@@ -37,7 +37,9 @@ public:
typedef std::map<FontSpecification, std::unique_ptr<FontRealised>> FontMap;
-inline std::optional<ColourRGBA> OptionalColour(Scintilla::uptr_t wParam, Scintilla::sptr_t lParam) {
+using ColourOptional = std::optional<ColourRGBA>;
+
+inline ColourOptional OptionalColour(Scintilla::uptr_t wParam, Scintilla::sptr_t lParam) {
if (wParam) {
return ColourRGBA::FromIpRGB(lParam);
} else {
@@ -133,8 +135,8 @@ public:
XYPOSITION controlCharWidth;
ColourRGBA selbar;
ColourRGBA selbarlight;
- std::optional<ColourRGBA> foldmarginColour;
- std::optional<ColourRGBA> foldmarginHighlightColour;
+ ColourOptional foldmarginColour;
+ ColourOptional foldmarginHighlightColour;
bool hotspotUnderline;
/// Margins are ordered: Line Numbers, Selection Margin, Spacing Margin
int leftMarginWidth; ///< Spacing margin on left of text
@@ -178,7 +180,7 @@ public:
int ctrlCharPadding; // the padding around control character text blobs
int lastSegItalicsOffset; // the offset so as not to clip italic characters at EOLs
- using ElementMap = std::map<Scintilla::Element, std::optional<ColourRGBA>>;
+ using ElementMap = std::map<Scintilla::Element, ColourOptional>;
ElementMap elementColours;
ElementMap elementBaseColours;
std::set<Scintilla::Element> elementAllowsTranslucent;
@@ -210,7 +212,7 @@ public:
void CalcLargestMarkerHeight() noexcept;
int GetFrameWidth() const noexcept;
bool IsLineFrameOpaque(bool caretActive, bool lineContainsCaret) const;
- std::optional<ColourRGBA> Background(int marksOfLine, bool caretActive, bool lineContainsCaret) const;
+ ColourOptional Background(int marksOfLine, bool caretActive, bool lineContainsCaret) const;
bool SelectionBackgroundDrawn() const noexcept;
bool SelectionTextDrawn() const;
bool WhitespaceBackgroundDrawn() const;
@@ -218,7 +220,7 @@ public:
void AddMultiEdge(int column, ColourRGBA colour);
- std::optional<ColourRGBA> ElementColour(Scintilla::Element element) const;
+ ColourOptional ElementColour(Scintilla::Element element) const;
bool ElementAllowsTranslucent(Scintilla::Element element) const;
bool ResetElement(Scintilla::Element element);
bool SetElementColour(Scintilla::Element element, ColourRGBA colour);