diff options
author | Neil <nyamatongwe@gmail.com> | 2021-04-25 09:52:20 +1000 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2021-04-25 09:52:20 +1000 |
commit | 81f7847af4cc9f51f02ab191c73f394c457518bd (patch) | |
tree | ef214ea786c00e9618756c26b99299ac1fa58bf6 /src | |
parent | 241f33a38ca0887d1a47399de1bcf7ba0d544c41 (diff) | |
download | scintilla-mirror-81f7847af4cc9f51f02ab191c73f394c457518bd.tar.gz |
Feature [feature-requests:#1402]. Unify colour type with ColourAlpha.
Change ColourDesired to ColourAlpha in styles.
Remove ColourDesired.
Diffstat (limited to 'src')
-rw-r--r-- | src/CallTip.cxx | 18 | ||||
-rw-r--r-- | src/CallTip.h | 12 | ||||
-rw-r--r-- | src/EditView.cxx | 167 | ||||
-rw-r--r-- | src/EditView.h | 6 | ||||
-rw-r--r-- | src/Editor.cxx | 74 | ||||
-rw-r--r-- | src/Geometry.h | 70 | ||||
-rw-r--r-- | src/Indicator.cxx | 2 | ||||
-rw-r--r-- | src/Indicator.h | 6 | ||||
-rw-r--r-- | src/MarginView.cxx | 18 | ||||
-rw-r--r-- | src/MarginView.h | 4 | ||||
-rw-r--r-- | src/Platform.h | 4 | ||||
-rw-r--r-- | src/ScintillaBase.cxx | 6 | ||||
-rw-r--r-- | src/Style.cxx | 8 | ||||
-rw-r--r-- | src/Style.h | 6 | ||||
-rw-r--r-- | src/ViewStyle.cxx | 71 | ||||
-rw-r--r-- | src/ViewStyle.h | 51 |
16 files changed, 251 insertions, 272 deletions
diff --git a/src/CallTip.cxx b/src/CallTip.cxx index f9f3ce7f7..56cf3c2fd 100644 --- a/src/CallTip.cxx +++ b/src/CallTip.cxx @@ -54,15 +54,15 @@ CallTip::CallTip() noexcept { #ifdef __APPLE__ // proper apple colours for the default - colourBG = ColourDesired(0xff, 0xff, 0xc6); - colourUnSel = ColourDesired(0, 0, 0); + colourBG = ColourAlpha(0xff, 0xff, 0xc6); + colourUnSel = ColourAlpha(0, 0, 0); #else - colourBG = ColourDesired(0xff, 0xff, 0xff); - colourUnSel = ColourDesired(0x80, 0x80, 0x80); + colourBG = ColourAlpha(0xff, 0xff, 0xff); + colourUnSel = ColourAlpha(0x80, 0x80, 0x80); #endif - colourSel = ColourDesired(0, 0, 0x80); - colourShade = ColourDesired(0, 0, 0); - colourLight = ColourDesired(0xc0, 0xc0, 0xc0); + colourSel = ColourAlpha(0, 0, 0x80); + colourShade = ColourAlpha(0, 0, 0); + colourLight = ColourAlpha(0xc0, 0xc0, 0xc0); codePage = 0; clickPlace = 0; } @@ -93,7 +93,7 @@ constexpr bool IsArrowCharacter(char ch) noexcept { return (ch == 0) || (ch == '\001') || (ch == '\002'); } -void DrawArrow(Scintilla::Surface *surface, const PRectangle &rc, bool upArrow, ColourDesired colourBG, ColourDesired colourUnSel) { +void DrawArrow(Scintilla::Surface *surface, const PRectangle &rc, bool upArrow, ColourAlpha colourBG, ColourAlpha colourUnSel) { surface->FillRectangle(rc, colourBG); const PRectangle rcClientInner = Clamp(rc.Inset(1), Edge::right, rc.right - 2); surface->FillRectangle(rcClientInner, colourUnSel); @@ -348,7 +348,7 @@ bool CallTip::UseStyleCallTip() const noexcept { // It might be better to have two access functions for this and to use // them for all settings of colours. -void CallTip::SetForeBack(const ColourDesired &fore, const ColourDesired &back) noexcept { +void CallTip::SetForeBack(const ColourAlpha &fore, const ColourAlpha &back) noexcept { colourBG = back; colourUnSel = fore; } diff --git a/src/CallTip.h b/src/CallTip.h index f1358a94a..78518a995 100644 --- a/src/CallTip.h +++ b/src/CallTip.h @@ -44,11 +44,11 @@ public: Window wDraw; bool inCallTipMode; Sci::Position posStartCallTip; - ColourDesired colourBG; - ColourDesired colourUnSel; - ColourDesired colourSel; - ColourDesired colourShade; - ColourDesired colourLight; + ColourAlpha colourBG; + ColourAlpha colourUnSel; + ColourAlpha colourSel; + ColourAlpha colourShade; + ColourAlpha colourLight; int codePage; int clickPlace; @@ -91,7 +91,7 @@ public: bool UseStyleCallTip() const noexcept; // Modify foreground and background colours - void SetForeBack(const ColourDesired &fore, const ColourDesired &back) noexcept; + void SetForeBack(const ColourAlpha &fore, const ColourAlpha &back) noexcept; }; } diff --git a/src/EditView.cxx b/src/EditView.cxx index c5e3a3726..fbb6f8b5c 100644 --- a/src/EditView.cxx +++ b/src/EditView.cxx @@ -820,20 +820,20 @@ Sci::Position EditView::StartEndDisplayLine(Surface *surface, const EditModel &m return posRet; } -static ColourDesired SelectionBackground(const ViewStyle &vsDraw, bool main, bool primarySelection) noexcept { +static ColourAlpha SelectionBackground(const ViewStyle &vsDraw, bool main, bool primarySelection) noexcept { return main ? - (primarySelection ? vsDraw.selColours.back : vsDraw.selBackground2) : + (primarySelection ? vsDraw.selColours.back.value() : vsDraw.selBackground2) : vsDraw.selAdditionalBackground; } -static ColourDesired TextBackground(const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, - ColourOptional background, int inSelection, bool inHotspot, int styleMain, Sci::Position i) noexcept { +static ColourAlpha TextBackground(const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, + std::optional<ColourAlpha> background, int inSelection, bool inHotspot, int styleMain, Sci::Position i) noexcept { if (inSelection == 1) { - if (vsDraw.selColours.back.isSet && (vsDraw.selAlpha == SC_ALPHA_NOALPHA)) { + if (vsDraw.selColours.back && (vsDraw.selAlpha == SC_ALPHA_NOALPHA)) { return SelectionBackground(vsDraw, true, model.primarySelection); } } else if (inSelection == 2) { - if (vsDraw.selColours.back.isSet && (vsDraw.selAdditionalAlpha == SC_ALPHA_NOALPHA)) { + if (vsDraw.selColours.back && (vsDraw.selAdditionalAlpha == SC_ALPHA_NOALPHA)) { return SelectionBackground(vsDraw, false, model.primarySelection); } } else { @@ -841,11 +841,11 @@ static ColourDesired TextBackground(const EditModel &model, const ViewStyle &vsD (i >= ll->edgeColumn) && (i < ll->numCharsBeforeEOL)) return vsDraw.theEdge.colour; - if (inHotspot && vsDraw.hotspotColours.back.isSet) - return vsDraw.hotspotColours.back; + if (inHotspot && vsDraw.hotspotColours.back) + return vsDraw.hotspotColours.back.value(); } - if (background.isSet && (styleMain != STYLE_BRACELIGHT) && (styleMain != STYLE_BRACEBAD)) { - return background; + if (background && (styleMain != STYLE_BRACELIGHT) && (styleMain != STYLE_BRACEBAD)) { + return background.value(); } else { return vsDraw.styles[styleMain].back; } @@ -859,14 +859,14 @@ void EditView::DrawIndentGuide(Surface *surface, Sci::Line lineVisible, int line highlight ? *pixmapIndentGuideHighlight : *pixmapIndentGuide); } -static void SimpleAlphaRectangle(Surface *surface, PRectangle rc, ColourDesired fill, int alpha) { +static void SimpleAlphaRectangle(Surface *surface, PRectangle rc, ColourAlpha fill, int alpha) { if (alpha != SC_ALPHA_NOALPHA) { surface->FillRectangleAligned(rc, ColourAlpha(fill, alpha)); } } static void DrawTextBlob(Surface *surface, const ViewStyle &vsDraw, PRectangle rcSegment, - std::string_view text, ColourDesired textBack, ColourDesired textFore, bool fillBackground) { + std::string_view text, ColourAlpha textBack, ColourAlpha textFore, bool fillBackground) { if (rcSegment.Empty()) return; if (fillBackground) { @@ -890,7 +890,7 @@ static void DrawTextBlob(Surface *surface, const ViewStyle &vsDraw, PRectangle r textBack, textFore); } -static void DrawFrame(Surface *surface, ColourDesired colour, int alpha, PRectangle rcFrame) { +static void DrawFrame(Surface *surface, ColourAlpha colour, int alpha, PRectangle rcFrame) { if (alpha != SC_ALPHA_NOALPHA) { surface->AlphaRectangle(rcFrame, 0, FillStroke(ColourAlpha(colour, alpha))); } else { @@ -924,7 +924,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, - ColourOptional background) { + std::optional<ColourAlpha> background) { const Sci::Position posLineStart = model.pdoc->LineStart(line); PRectangle rcSegment = rcLine; @@ -941,7 +941,7 @@ void EditView::DrawEOL(Surface *surface, const EditModel &model, const ViewStyle if (virtualSpace > 0.0f) { rcSegment.left = xEol + xStart; rcSegment.right = xEol + xStart + virtualSpace; - surface->FillRectangleAligned(rcSegment, Fill(background.isSet ? background : vsDraw.styles[ll->styles[ll->numCharsInLine]].back)); + surface->FillRectangleAligned(rcSegment, Fill(background ? background.value() : vsDraw.styles[ll->styles[ll->numCharsInLine]].back)); if (!hideSelection && ((vsDraw.selAlpha == SC_ALPHA_NOALPHA) || (vsDraw.selAdditionalAlpha == SC_ALPHA_NOALPHA))) { const SelectionSegment virtualSpaceRange(SelectionPosition(model.pdoc->LineEnd(line)), SelectionPosition(model.pdoc->LineEnd(line), @@ -984,7 +984,7 @@ void EditView::DrawEOL(Surface *surface, const EditModel &model, const ViewStyle const char *ctrlChar; const unsigned char chEOL = ll->chars[eolPos]; const int styleMain = ll->styles[eolPos]; - const ColourDesired textBack = TextBackground(model, vsDraw, ll, background, eolInSelection, false, styleMain, eolPos); + const ColourAlpha textBack = TextBackground(model, vsDraw, ll, background, eolInSelection, false, styleMain, eolPos); if (UTF8IsAscii(chEOL)) { ctrlChar = ControlCharacterString(chEOL); } else { @@ -997,11 +997,11 @@ void EditView::DrawEOL(Surface *surface, const EditModel &model, const ViewStyle ctrlChar = hexits; } } - ColourDesired textFore = vsDraw.styles[styleMain].fore; - if (eolInSelection && vsDraw.selColours.fore.isSet) { - textFore = (eolInSelection == 1) ? vsDraw.selColours.fore : vsDraw.selAdditionalForeground; + ColourAlpha textFore = vsDraw.styles[styleMain].fore; + if (eolInSelection && vsDraw.selColours.fore) { + textFore = (eolInSelection == 1) ? vsDraw.selColours.fore.value() : vsDraw.selAdditionalForeground; } - if (eolInSelection && vsDraw.selColours.back.isSet && (line < model.pdoc->LinesTotal() - 1)) { + if (eolInSelection && vsDraw.selColours.back && (line < model.pdoc->LinesTotal() - 1)) { if (alpha == SC_ALPHA_NOALPHA) { surface->FillRectangleAligned(rcSegment, Fill(SelectionBackground(vsDraw, eolInSelection == 1, model.primarySelection))); } else { @@ -1011,7 +1011,7 @@ void EditView::DrawEOL(Surface *surface, const EditModel &model, const ViewStyle surface->FillRectangleAligned(rcSegment, Fill(textBack)); } DrawTextBlob(surface, vsDraw, rcSegment, ctrlChar, textBack, textFore, phasesDraw == PhasesDraw::one); - if (eolInSelection && vsDraw.selColours.back.isSet && (line < model.pdoc->LinesTotal() - 1) && (alpha != SC_ALPHA_NOALPHA)) { + if (eolInSelection && vsDraw.selColours.back && (line < model.pdoc->LinesTotal() - 1) && (alpha != SC_ALPHA_NOALPHA)) { SimpleAlphaRectangle(surface, rcSegment, SelectionBackground(vsDraw, eolInSelection == 1, model.primarySelection), alpha); } } @@ -1021,11 +1021,11 @@ void EditView::DrawEOL(Surface *surface, const EditModel &model, const ViewStyle rcSegment.left = xEol + xStart + virtualSpace + blobsWidth; rcSegment.right = rcSegment.left + vsDraw.aveCharWidth; - if (eolInSelection && vsDraw.selColours.back.isSet && (line < model.pdoc->LinesTotal() - 1) && (alpha == SC_ALPHA_NOALPHA)) { + if (eolInSelection && vsDraw.selColours.back && (line < model.pdoc->LinesTotal() - 1) && (alpha == SC_ALPHA_NOALPHA)) { surface->FillRectangleAligned(rcSegment, Fill(SelectionBackground(vsDraw, eolInSelection == 1, model.primarySelection))); } else { - if (background.isSet) { - surface->FillRectangleAligned(rcSegment, Fill(background)); + if (background) { + surface->FillRectangleAligned(rcSegment, Fill(background.value())); } else if (line < model.pdoc->LinesTotal() - 1) { surface->FillRectangleAligned(rcSegment, Fill(vsDraw.styles[ll->styles[ll->numCharsInLine]].back)); } else if (vsDraw.styles[ll->styles[ll->numCharsInLine]].eolFilled) { @@ -1033,7 +1033,7 @@ void EditView::DrawEOL(Surface *surface, const EditModel &model, const ViewStyle } else { surface->FillRectangleAligned(rcSegment, Fill(vsDraw.styles[STYLE_DEFAULT].back)); } - if (eolInSelection && vsDraw.selColours.back.isSet && (line < model.pdoc->LinesTotal() - 1) && (alpha != SC_ALPHA_NOALPHA)) { + if (eolInSelection && vsDraw.selColours.back && (line < model.pdoc->LinesTotal() - 1) && (alpha != SC_ALPHA_NOALPHA)) { SimpleAlphaRectangle(surface, rcSegment, SelectionBackground(vsDraw, eolInSelection == 1, model.primarySelection), alpha); } } @@ -1215,12 +1215,12 @@ 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 ColourOptional background = vsDraw.Background(model.pdoc->GetMark(line), model.caret.active, ll->containsCaret); - ColourDesired textFore = vsDraw.styles[STYLE_FOLDDISPLAYTEXT].fore; - if (eolInSelection && (vsDraw.selColours.fore.isSet)) { - textFore = (eolInSelection == 1) ? vsDraw.selColours.fore : vsDraw.selAdditionalForeground; + 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.selColours.fore)) { + textFore = (eolInSelection == 1) ? vsDraw.selColours.fore.value() : vsDraw.selAdditionalForeground; } - const ColourDesired textBack = TextBackground(model, vsDraw, ll, background, eolInSelection, + const ColourAlpha textBack = TextBackground(model, vsDraw, ll, background, eolInSelection, false, STYLE_FOLDDISPLAYTEXT, -1); if (model.trackLineWidth) { @@ -1264,7 +1264,7 @@ void EditView::DrawFoldDisplayText(Surface *surface, const EditModel &model, con } if (FlagSet(phase, DrawPhase::selectionTranslucent)) { - if (eolInSelection && vsDraw.selColours.back.isSet && (line < model.pdoc->LinesTotal() - 1) && alpha != SC_ALPHA_NOALPHA) { + if (eolInSelection && vsDraw.selColours.back && (line < model.pdoc->LinesTotal() - 1) && alpha != SC_ALPHA_NOALPHA) { SimpleAlphaRectangle(surface, rcSegment, SelectionBackground(vsDraw, eolInSelection == 1, model.primarySelection), alpha); } } @@ -1342,9 +1342,9 @@ void EditView::DrawEOLAnnotationText(Surface *surface, const EditModel &model, c } rcSegment.right = rcSegment.left + static_cast<XYPOSITION>(widthEOLAnnotationText); - const ColourOptional background = vsDraw.Background(model.pdoc->GetMark(line), model.caret.active, ll->containsCaret); - const ColourDesired textFore = vsDraw.styles[style].fore; - const ColourDesired textBack = TextBackground(model, vsDraw, ll, background, false, + const std::optional<ColourAlpha> background = vsDraw.Background(model.pdoc->GetMark(line), model.caret.active, ll->containsCaret); + const ColourAlpha textFore = vsDraw.styles[style].fore; + const ColourAlpha textBack = TextBackground(model, vsDraw, ll, background, false, false, static_cast<int>(style), -1); if (model.trackLineWidth) { @@ -1388,10 +1388,10 @@ void EditView::DrawEOLAnnotationText(Surface *surface, const EditModel &model, c } else { if (phasesDraw == PhasesDraw::one) { // Draw an outline around the text - surface->Stadium(rcBox, FillStroke(ColourAlpha(textBack, 0), ColourAlpha(textFore), 1.0), ends); + surface->Stadium(rcBox, FillStroke(ColourAlpha(textBack, 0), textFore, 1.0), ends); } else { // Draw with a fill to fill the edges of the shape. - surface->Stadium(rcBox, FillStroke(ColourAlpha(textBack), ColourAlpha(textFore), 1.0), ends); + surface->Stadium(rcBox, FillStroke(textBack, textFore, 1.0), ends); } } } @@ -1451,7 +1451,7 @@ void EditView::DrawAnnotation(Surface *surface, const EditModel &model, const Vi DrawStyledText(surface, vsDraw, vsDraw.annotationStyleOffset, rcText, stAnnotation, start, lengthAnnotation, phase); if ((FlagSet(phase, DrawPhase::back)) && (vsDraw.annotationVisible == ANNOTATION_BOXED)) { - const ColourDesired colourBorder = vsDraw.styles[vsDraw.annotationStyleOffset].fore; + const ColourAlpha colourBorder = vsDraw.styles[vsDraw.annotationStyleOffset].fore; const PRectangle rcBorder = PixelAlignOutside(rcSegment, surface->PixelDivisions()); surface->FillRectangle(Side(rcBorder, Edge::left, 1), colourBorder); surface->FillRectangle(Side(rcBorder, Edge::right, 1), colourBorder); @@ -1466,7 +1466,7 @@ void EditView::DrawAnnotation(Surface *surface, const EditModel &model, const Vi } static void DrawBlockCaret(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, - int subLine, int xStart, Sci::Position offset, Sci::Position posCaret, PRectangle rcCaret, ColourDesired caretColour) { + int subLine, int xStart, Sci::Position offset, Sci::Position posCaret, PRectangle rcCaret, ColourAlpha caretColour) { const Sci::Position lineStart = ll->LineStart(subLine); Sci::Position posBefore = posCaret; @@ -1622,7 +1622,8 @@ void EditView::DrawCarets(Surface *surface, const EditModel &model, const ViewSt rcCaret.left = std::round(xposCaret - caretWidthOffset); rcCaret.right = rcCaret.left + vsDraw.caretWidth; } - const ColourDesired caretColour = mainCaret ? vsDraw.caretcolour : vsDraw.additionalCaretColour; + const ColourAlpha caretColour = mainCaret ? vsDraw.caretcolour : vsDraw.additionalCaretColour; + assert(caretColour.IsOpaque()); if (drawBlockCaret) { DrawBlockCaret(surface, model, vsDraw, ll, subLine, xStart, offset, posCaret.Position(), rcCaret, caretColour); } else { @@ -1636,10 +1637,10 @@ void EditView::DrawCarets(Surface *surface, const EditModel &model, const ViewSt } static void DrawWrapIndentAndMarker(Surface *surface, const ViewStyle &vsDraw, const LineLayout *ll, - int xStart, PRectangle rcLine, ColourOptional background, DrawWrapMarkerFn customDrawWrapMarker, + int xStart, PRectangle rcLine, std::optional<ColourAlpha> background, DrawWrapMarkerFn customDrawWrapMarker, bool caretActive) { // default bgnd here.. - surface->FillRectangleAligned(rcLine, Fill(background.isSet ? background : + surface->FillRectangleAligned(rcLine, Fill(background ? background.value() : vsDraw.styles[STYLE_DEFAULT].back)); if (vsDraw.IsLineFrameOpaque(caretActive, ll->containsCaret)) { @@ -1672,7 +1673,7 @@ static void DrawWrapIndentAndMarker(Surface *surface, const ViewStyle &vsDraw, c 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, ColourOptional background) const { + int subLine, std::optional<ColourAlpha> background) const { const bool selBackDrawn = vsDraw.SelectionBackgroundDrawn(); bool inIndentation = subLine == 0; // Do not handle indentation except on first subline. @@ -1682,7 +1683,7 @@ void EditView::DrawBackground(Surface *surface, const EditModel &model, const Vi BreakFinder bfBack(ll, &model.sel, lineRange, posLineStart, xStartVisible, selBackDrawn, model.pdoc, &model.reprs, nullptr); - const bool drawWhitespaceBackground = vsDraw.WhitespaceBackgroundDrawn() && !background.isSet; + const bool drawWhitespaceBackground = vsDraw.WhitespaceBackgroundDrawn() && !background; // Background drawing loop while (bfBack.More()) { @@ -1705,13 +1706,13 @@ void EditView::DrawBackground(Surface *surface, const EditModel &model, const Vi const int inSelection = hideSelection ? 0 : model.sel.CharacterInSelection(iDoc); const bool inHotspot = (ll->hotspot.Valid()) && ll->hotspot.ContainsCharacter(iDoc); - ColourDesired textBack = TextBackground(model, vsDraw, ll, background, inSelection, + ColourAlpha textBack = TextBackground(model, vsDraw, ll, background, inSelection, inHotspot, ll->styles[i], i); if (ts.representation) { if (ll->chars[i] == '\t') { // Tab display if (drawWhitespaceBackground && vsDraw.WhiteSpaceVisible(inIndentation)) - textBack = vsDraw.whitespaceColours.back; + textBack = vsDraw.whitespaceColours.back.value(); } else { // Blob display inIndentation = false; @@ -1729,7 +1730,7 @@ void EditView::DrawBackground(Surface *surface, const EditModel &model, const Vi rcSegment.top, ll->positions[cpos + ts.start + 1] + xStart - static_cast<XYPOSITION>(subLineStart), rcSegment.bottom); - surface->FillRectangleAligned(rcSpace, Fill(vsDraw.whitespaceColours.back)); + surface->FillRectangleAligned(rcSpace, Fill(vsDraw.whitespaceColours.back.value())); } } else { inIndentation = false; @@ -1806,7 +1807,7 @@ static void DrawTranslucentSelection(Surface *surface, const EditModel &model, c const int selectionStart = static_cast<int>(portion.start.Position() - posLineStart - lineRange.start); const int selectionEnd = static_cast<int>(portion.end.Position() - posLineStart - lineRange.start); - const ColourDesired background = SelectionBackground(vsDraw, r == model.sel.Main(), model.primarySelection); + const ColourAlpha background = SelectionBackground(vsDraw, r == model.sel.Main(), model.primarySelection); const ScreenLine screenLine(ll, subLine, vsDraw, rcLine.right, tabWidthMinimumPixels); std::unique_ptr<IScreenLineLayout> slLayout = surface->Layout(&screenLine); @@ -1884,10 +1885,10 @@ 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, ColourOptional background) { + int subLine, std::optional<ColourAlpha> background) { const bool selBackDrawn = vsDraw.SelectionBackgroundDrawn(); - const bool drawWhitespaceBackground = vsDraw.WhitespaceBackgroundDrawn() && !background.isSet; + const bool drawWhitespaceBackground = vsDraw.WhitespaceBackgroundDrawn() && !background; bool inIndentation = subLine == 0; // Do not handle indentation except on first subline. const XYACCUMULATOR subLineStart = ll->positions[lineRange.start]; @@ -1898,7 +1899,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.selColours.fore.isSet), model.pdoc, &model.reprs, &vsDraw); + (((phasesDraw == PhasesDraw::one) && selBackDrawn) || vsDraw.selColours.fore), model.pdoc, &model.reprs, &vsDraw); while (bfFore.More()) { @@ -1913,13 +1914,13 @@ void EditView::DrawForeground(Surface *surface, const EditModel &model, const Vi // draw strings that are completely past the right side of the window. if (rcSegment.Intersects(rcLine)) { const int styleMain = ll->styles[i]; - ColourDesired textFore = vsDraw.styles[styleMain].fore; + ColourAlpha textFore = vsDraw.styles[styleMain].fore; const Font *textFont = vsDraw.styles[styleMain].font.get(); //hotspot foreground const bool inHotspot = (ll->hotspot.Valid()) && ll->hotspot.ContainsCharacter(iDoc); if (inHotspot) { - if (vsDraw.hotspotColours.fore.isSet) - textFore = vsDraw.hotspotColours.fore; + if (vsDraw.hotspotColours.fore) + textFore = vsDraw.hotspotColours.fore.value(); } if (vsDraw.indicatorsSetFore) { // At least one indicator sets the text colour so see if it applies to this segment @@ -1940,7 +1941,7 @@ void EditView::DrawForeground(Surface *surface, const EditModel &model, const Vi } else { if (indicator.sacNormal.style == INDIC_TEXTFORE) { if (indicator.Flags() & SC_INDICFLAG_VALUEFORE) - textFore = ColourDesired(indicatorValue & SC_INDICVALUEMASK); + textFore = ColourAlpha::FromRGB(indicatorValue & SC_INDICVALUEMASK); else textFore = indicator.sacNormal.fore; } @@ -1949,16 +1950,16 @@ void EditView::DrawForeground(Surface *surface, const EditModel &model, const Vi } } const int inSelection = hideSelection ? 0 : model.sel.CharacterInSelection(iDoc); - if (inSelection && (vsDraw.selColours.fore.isSet)) { - textFore = (inSelection == 1) ? vsDraw.selColours.fore : vsDraw.selAdditionalForeground; + if (inSelection && (vsDraw.selColours.fore)) { + textFore = (inSelection == 1) ? vsDraw.selColours.fore.value() : vsDraw.selAdditionalForeground; } - ColourDesired textBack = TextBackground(model, vsDraw, ll, background, inSelection, inHotspot, styleMain, i); + ColourAlpha textBack = TextBackground(model, vsDraw, ll, background, inSelection, inHotspot, styleMain, i); if (ts.representation) { if (ll->chars[i] == '\t') { // Tab display if (phasesDraw == PhasesDraw::one) { if (drawWhitespaceBackground && vsDraw.WhiteSpaceVisible(inIndentation)) - textBack = vsDraw.whitespaceColours.back; + textBack = vsDraw.whitespaceColours.back.value(); surface->FillRectangleAligned(rcSegment, Fill(textBack)); } if (inIndentation && vsDraw.viewIndentationGuides == IndentView::real) { @@ -1974,8 +1975,8 @@ void EditView::DrawForeground(Surface *surface, const EditModel &model, const Vi } if (vsDraw.viewWhitespace != WhiteSpace::invisible) { if (vsDraw.WhiteSpaceVisible(inIndentation)) { - if (vsDraw.whitespaceColours.fore.isSet) - textFore = vsDraw.whitespaceColours.fore; + if (vsDraw.whitespaceColours.fore) + textFore = vsDraw.whitespaceColours.fore.value(); const PRectangle rcTab(rcSegment.left + 1, rcSegment.top + tabArrowHeight, rcSegment.right - 1, rcSegment.bottom - vsDraw.maxDescent); const int segmentTop = static_cast<int>(rcSegment.top + vsDraw.lineHeight / 2); @@ -2018,12 +2019,12 @@ void EditView::DrawForeground(Surface *surface, const EditModel &model, const Vi for (int cpos = 0; cpos <= i - ts.start; cpos++) { if (ll->chars[cpos + ts.start] == ' ') { if (vsDraw.viewWhitespace != WhiteSpace::invisible) { - if (vsDraw.whitespaceColours.fore.isSet) - textFore = vsDraw.whitespaceColours.fore; + if (vsDraw.whitespaceColours.fore) + textFore = vsDraw.whitespaceColours.fore.value(); 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.whitespaceColours.back; + textBack = vsDraw.whitespaceColours.back.value(); const PRectangle rcSpace( ll->positions[cpos + ts.start] + xStart - static_cast<XYPOSITION>(subLineStart), rcSegment.top, @@ -2060,8 +2061,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.isSet) - surface->FillRectangleAligned(rcUL, Fill(vsDraw.hotspotColours.fore)); + if (vsDraw.hotspotColours.fore) + surface->FillRectangleAligned(rcUL, Fill(vsDraw.hotspotColours.fore.value())); else surface->FillRectangleAligned(rcUL, Fill(textFore)); } else if (vsDraw.styles[styleMain].underline) { @@ -2139,7 +2140,7 @@ void EditView::DrawLine(Surface *surface, const EditModel &model, const ViewStyl } // See if something overrides the line background colour. - const ColourOptional background = vsDraw.Background(model.pdoc->GetMark(line), model.caret.active, ll->containsCaret); + const std::optional<ColourAlpha> background = vsDraw.Background(model.pdoc->GetMark(line), model.caret.active, ll->containsCaret); const Sci::Position posLineStart = model.pdoc->LineStart(line); @@ -2445,19 +2446,19 @@ void EditView::FillLineRemainder(Surface *surface, const EditModel &model, const alpha = (eolInSelection == 1) ? vsDraw.selAlpha : vsDraw.selAdditionalAlpha; } - const ColourOptional background = vsDraw.Background(model.pdoc->GetMark(line), model.caret.active, ll->containsCaret); + const std::optional<ColourAlpha> background = vsDraw.Background(model.pdoc->GetMark(line), model.caret.active, ll->containsCaret); - if (eolInSelection && vsDraw.selEOLFilled && vsDraw.selColours.back.isSet && (line < model.pdoc->LinesTotal() - 1) && (alpha == SC_ALPHA_NOALPHA)) { + if (eolInSelection && vsDraw.selEOLFilled && vsDraw.selColours.back && (line < model.pdoc->LinesTotal() - 1) && (alpha == SC_ALPHA_NOALPHA)) { surface->FillRectangleAligned(rcArea, Fill(SelectionBackground(vsDraw, eolInSelection == 1, model.primarySelection))); } else { - if (background.isSet) { - surface->FillRectangleAligned(rcArea, Fill(background)); + if (background) { + surface->FillRectangleAligned(rcArea, Fill(background.value())); } else if (vsDraw.styles[ll->styles[ll->numCharsInLine]].eolFilled) { surface->FillRectangleAligned(rcArea, Fill(vsDraw.styles[ll->styles[ll->numCharsInLine]].back)); } else { surface->FillRectangleAligned(rcArea, Fill(vsDraw.styles[STYLE_DEFAULT].back)); } - if (eolInSelection && vsDraw.selEOLFilled && vsDraw.selColours.back.isSet && (line < model.pdoc->LinesTotal() - 1) && (alpha != SC_ALPHA_NOALPHA)) { + if (eolInSelection && vsDraw.selEOLFilled && vsDraw.selColours.back && (line < model.pdoc->LinesTotal() - 1) && (alpha != SC_ALPHA_NOALPHA)) { SimpleAlphaRectangle(surface, rcArea, SelectionBackground(vsDraw, eolInSelection == 1, model.primarySelection), alpha); } } @@ -2466,18 +2467,18 @@ void EditView::FillLineRemainder(Surface *surface, const EditModel &model, const // Space (3 space characters) between line numbers and text when printing. #define lineNumberPrintSpace " " -static ColourDesired InvertedLight(ColourDesired orig) noexcept { +static ColourAlpha InvertedLight(ColourAlpha orig) noexcept { unsigned int r = orig.GetRed(); unsigned int g = orig.GetGreen(); unsigned int b = orig.GetBlue(); const unsigned int l = (r + g + b) / 3; // There is a better calculation for this that matches human eye const unsigned int il = 0xff - l; if (l == 0) - return ColourDesired(0xff, 0xff, 0xff); + return ColourAlpha(0xff, 0xff, 0xff); r = r * il / l; g = g * il / l; b = b * il / l; - return ColourDesired(std::min(r, 0xffu), std::min(g, 0xffu), std::min(b, 0xffu)); + return ColourAlpha(std::min(r, 0xffu), std::min(g, 0xffu), std::min(b, 0xffu)); } Sci::Position EditView::FormatRange(bool draw, const Sci_RangeToFormat *pfr, Surface *surface, Surface *surfaceMeasure, @@ -2504,12 +2505,12 @@ Sci::Position EditView::FormatRange(bool draw, const Sci_RangeToFormat *pfr, Sur // If this ever gets changed, cached pixmap would need to be recreated if technology != SC_TECHNOLOGY_DEFAULT vsPrint.viewIndentationGuides = IndentView::none; // Don't show the selection when printing - vsPrint.selColours.back.isSet = false; - vsPrint.selColours.fore.isSet = false; + vsPrint.selColours.back.reset(); + vsPrint.selColours.fore.reset(); vsPrint.selAlpha = SC_ALPHA_NOALPHA; vsPrint.selAdditionalAlpha = SC_ALPHA_NOALPHA; - vsPrint.whitespaceColours.back.isSet = false; - vsPrint.whitespaceColours.fore.isSet = false; + vsPrint.whitespaceColours.back.reset(); + vsPrint.whitespaceColours.fore.reset(); vsPrint.showCaretLineBackground = false; vsPrint.alwaysShowCaretLineBackground = false; // Don't highlight matching braces using indicators @@ -2522,19 +2523,19 @@ Sci::Position EditView::FormatRange(bool draw, const Sci_RangeToFormat *pfr, Sur vsPrint.styles[sty].fore = InvertedLight(vsPrint.styles[sty].fore); vsPrint.styles[sty].back = InvertedLight(vsPrint.styles[sty].back); } else if (printParameters.colourMode == SC_PRINT_BLACKONWHITE) { - vsPrint.styles[sty].fore = ColourDesired(0, 0, 0); - vsPrint.styles[sty].back = ColourDesired(0xff, 0xff, 0xff); + vsPrint.styles[sty].fore = ColourAlpha(0, 0, 0); + vsPrint.styles[sty].back = ColourAlpha(0xff, 0xff, 0xff); } else if (printParameters.colourMode == SC_PRINT_COLOURONWHITE) { - vsPrint.styles[sty].back = ColourDesired(0xff, 0xff, 0xff); + vsPrint.styles[sty].back = ColourAlpha(0xff, 0xff, 0xff); } else if (printParameters.colourMode == SC_PRINT_COLOURONWHITEDEFAULTBG) { if (sty <= STYLE_DEFAULT) { - vsPrint.styles[sty].back = ColourDesired(0xff, 0xff, 0xff); + vsPrint.styles[sty].back = ColourAlpha(0xff, 0xff, 0xff); } } } // White background for the line numbers if SC_PRINT_SCREENCOLOURS isn't used if (printParameters.colourMode != SC_PRINT_SCREENCOLOURS) - vsPrint.styles[STYLE_LINENUMBER].back = ColourDesired(0xff, 0xff, 0xff); + vsPrint.styles[STYLE_LINENUMBER].back = ColourAlpha(0xff, 0xff, 0xff); // Printing uses different margins, so reset screen margins vsPrint.leftMarginWidth = 0; diff --git a/src/EditView.h b/src/EditView.h index 91a925f4a..add58065b 100644 --- a/src/EditView.h +++ b/src/EditView.h @@ -131,7 +131,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, - ColourOptional background); + std::optional<ColourAlpha> 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, @@ -142,10 +142,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, ColourOptional background) const; + int subLine, std::optional<ColourAlpha> 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, ColourOptional background); + int subLine, std::optional<ColourAlpha> 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/Editor.cxx b/src/Editor.cxx index 208a075aa..f241bf346 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -5692,10 +5692,10 @@ void Editor::StyleSetMessage(unsigned int iMessage, uptr_t wParam, sptr_t lParam vs.EnsureStyle(wParam); switch (iMessage) { case SCI_STYLESETFORE: - vs.styles[wParam].fore = ColourDesired(static_cast<int>(lParam)); + vs.styles[wParam].fore = ColourAlpha::FromRGB(static_cast<int>(lParam)); break; case SCI_STYLESETBACK: - vs.styles[wParam].back = ColourDesired(static_cast<int>(lParam)); + vs.styles[wParam].back = ColourAlpha::FromRGB(static_cast<int>(lParam)); break; case SCI_STYLESETBOLD: vs.styles[wParam].weight = lParam != 0 ? SC_WEIGHT_BOLD : SC_WEIGHT_NORMAL; @@ -5747,9 +5747,9 @@ sptr_t Editor::StyleGetMessage(unsigned int iMessage, uptr_t wParam, sptr_t lPar vs.EnsureStyle(wParam); switch (iMessage) { case SCI_STYLEGETFORE: - return vs.styles[wParam].fore.AsInteger(); + return vs.styles[wParam].fore.OpaqueRGB(); case SCI_STYLEGETBACK: - return vs.styles[wParam].back.AsInteger(); + return vs.styles[wParam].back.OpaqueRGB(); case SCI_STYLEGETBOLD: return vs.styles[wParam].weight > SC_WEIGHT_NORMAL; case SCI_STYLEGETWEIGHT: @@ -6939,19 +6939,19 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { case SCI_MARKERSETFORE: if (wParam <= MARKER_MAX) - vs.markers[wParam].fore = ColourDesired(static_cast<int>(lParam)); + vs.markers[wParam].fore = ColourAlpha::FromRGB(static_cast<int>(lParam)); InvalidateStyleData(); RedrawSelMargin(); break; case SCI_MARKERSETBACK: if (wParam <= MARKER_MAX) - vs.markers[wParam].back = ColourDesired(static_cast<int>(lParam)); + vs.markers[wParam].back = ColourAlpha::FromRGB(static_cast<int>(lParam)); InvalidateStyleData(); RedrawSelMargin(); break; case SCI_MARKERSETBACKSELECTED: if (wParam <= MARKER_MAX) - vs.markers[wParam].backSelected = ColourDesired(static_cast<int>(lParam)); + vs.markers[wParam].backSelected = ColourAlpha::FromRGB(static_cast<int>(lParam)); InvalidateStyleData(); RedrawSelMargin(); break; @@ -7118,14 +7118,14 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { case SCI_SETMARGINBACKN: if (ValidMargin(wParam)) { - vs.ms[wParam].back = ColourDesired(static_cast<int>(lParam)); + vs.ms[wParam].back = ColourAlpha::FromRGB(static_cast<int>(lParam)); InvalidateStyleRedraw(); } break; case SCI_GETMARGINBACKN: if (ValidMargin(wParam)) - return vs.ms[wParam].back.AsInteger(); + return vs.ms[wParam].back.OpaqueRGB(); else return 0; @@ -7187,7 +7187,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { break; case SCI_GETELEMENTCOLOUR: - return vs.ElementColour(static_cast<int>(wParam)).value_or(ColourAlpha()).AsInteger(); + return vs.ElementColour(static_cast<int>(wParam)).value_or(ColourAlpha()).OpaqueRGB(); case SCI_RESETELEMENTCOLOUR: vs.elementColours[static_cast<int>(wParam)].reset(); @@ -7247,9 +7247,9 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { InvalidateStyleRedraw(); break; case SCI_GETCARETLINEBACK: - return vs.caretLineBackground.AsInteger(); + return vs.caretLineBackground.OpaqueRGB(); case SCI_SETCARETLINEBACK: - vs.caretLineBackground = ColourDesired(static_cast<int>(wParam)); + vs.caretLineBackground = ColourAlpha::FromRGB(static_cast<int>(wParam)); InvalidateStyleRedraw(); break; case SCI_GETCARETLINEBACKALPHA: @@ -7404,14 +7404,14 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { return LinesOnScreen(); case SCI_SETSELFORE: - vs.selColours.fore = ColourOptional(wParam, lParam); - vs.selAdditionalForeground = ColourDesired(static_cast<int>(lParam)); + vs.selColours.fore = OptionalColour(wParam, lParam); + vs.selAdditionalForeground = ColourAlpha::FromRGB(static_cast<int>(lParam)); InvalidateStyleRedraw(); break; case SCI_SETSELBACK: - vs.selColours.back = ColourOptional(wParam, lParam); - vs.selAdditionalBackground = ColourDesired(static_cast<int>(lParam)); + vs.selColours.back = OptionalColour(wParam, lParam); + vs.selAdditionalBackground = ColourAlpha::FromRGB(static_cast<int>(lParam)); InvalidateStyleRedraw(); break; @@ -7433,22 +7433,22 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { break; case SCI_SETWHITESPACEFORE: - vs.whitespaceColours.fore = ColourOptional(wParam, lParam); + vs.whitespaceColours.fore = OptionalColour(wParam, lParam); InvalidateStyleRedraw(); break; case SCI_SETWHITESPACEBACK: - vs.whitespaceColours.back = ColourOptional(wParam, lParam); + vs.whitespaceColours.back = OptionalColour(wParam, lParam); InvalidateStyleRedraw(); break; case SCI_SETCARETFORE: - vs.caretcolour = ColourDesired(static_cast<int>(wParam)); + vs.caretcolour = ColourAlpha::FromRGB(static_cast<int>(wParam)); InvalidateStyleRedraw(); break; case SCI_GETCARETFORE: - return vs.caretcolour.AsInteger(); + return vs.caretcolour.OpaqueRGB(); case SCI_SETCARETSTYLE: if (wParam <= (CARETSTYLE_BLOCK | CARETSTYLE_OVERSTRIKE_BLOCK | CARETSTYLE_BLOCK_AFTER)) @@ -7497,14 +7497,14 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { case SCI_INDICSETFORE: if (wParam <= INDICATOR_MAX) { - vs.indicators[wParam].sacNormal.fore = ColourDesired(static_cast<int>(lParam)); - vs.indicators[wParam].sacHover.fore = ColourDesired(static_cast<int>(lParam)); + vs.indicators[wParam].sacNormal.fore = ColourAlpha::FromRGB(static_cast<int>(lParam)); + vs.indicators[wParam].sacHover.fore = ColourAlpha::FromRGB(static_cast<int>(lParam)); InvalidateStyleRedraw(); } break; case SCI_INDICGETFORE: - return (wParam <= INDICATOR_MAX) ? vs.indicators[wParam].sacNormal.fore.AsInteger() : 0; + return (wParam <= INDICATOR_MAX) ? vs.indicators[wParam].sacNormal.fore.OpaqueRGB() : 0; case SCI_INDICSETHOVERSTYLE: if (wParam <= INDICATOR_MAX) { @@ -7518,13 +7518,13 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { case SCI_INDICSETHOVERFORE: if (wParam <= INDICATOR_MAX) { - vs.indicators[wParam].sacHover.fore = ColourDesired(static_cast<int>(lParam)); + vs.indicators[wParam].sacHover.fore = ColourAlpha::FromRGB(static_cast<int>(lParam)); InvalidateStyleRedraw(); } break; case SCI_INDICGETHOVERFORE: - return (wParam <= INDICATOR_MAX) ? vs.indicators[wParam].sacHover.fore.AsInteger() : 0; + return (wParam <= INDICATOR_MAX) ? vs.indicators[wParam].sacHover.fore.OpaqueRGB() : 0; case SCI_INDICSETFLAGS: if (wParam <= INDICATOR_MAX) { @@ -7775,10 +7775,10 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { break; case SCI_GETEDGECOLOUR: - return vs.theEdge.colour.AsInteger(); + return vs.theEdge.colour.OpaqueRGB(); case SCI_SETEDGECOLOUR: - vs.theEdge.colour = ColourDesired(static_cast<int>(wParam)); + vs.theEdge.colour = ColourAlpha::FromRGB(static_cast<int>(wParam)); InvalidateStyleRedraw(); break; @@ -8012,30 +8012,30 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { break; case SCI_SETFOLDMARGINCOLOUR: - vs.foldmarginColour = ColourOptional(wParam, lParam); + vs.foldmarginColour = OptionalColour(wParam, lParam); InvalidateStyleRedraw(); break; case SCI_SETFOLDMARGINHICOLOUR: - vs.foldmarginHighlightColour = ColourOptional(wParam, lParam); + vs.foldmarginHighlightColour = OptionalColour(wParam, lParam); InvalidateStyleRedraw(); break; case SCI_SETHOTSPOTACTIVEFORE: - vs.hotspotColours.fore = ColourOptional(wParam, lParam); + vs.hotspotColours.fore = OptionalColour(wParam, lParam); InvalidateStyleRedraw(); break; case SCI_GETHOTSPOTACTIVEFORE: - return vs.hotspotColours.fore.AsInteger(); + return vs.hotspotColours.fore.value_or(ColourAlpha()).OpaqueRGB(); case SCI_SETHOTSPOTACTIVEBACK: - vs.hotspotColours.back = ColourOptional(wParam, lParam); + vs.hotspotColours.back = OptionalColour(wParam, lParam); InvalidateStyleRedraw(); break; case SCI_GETHOTSPOTACTIVEBACK: - return vs.hotspotColours.back.AsInteger(); + return vs.hotspotColours.back.value_or(ColourAlpha()).OpaqueRGB(); case SCI_SETHOTSPOTACTIVEUNDERLINE: vs.hotspotUnderline = wParam != 0; @@ -8405,12 +8405,12 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { return virtualSpaceOptions; case SCI_SETADDITIONALSELFORE: - vs.selAdditionalForeground = ColourDesired(static_cast<int>(wParam)); + vs.selAdditionalForeground = ColourAlpha::FromRGB(static_cast<int>(wParam)); InvalidateStyleRedraw(); break; case SCI_SETADDITIONALSELBACK: - vs.selAdditionalBackground = ColourDesired(static_cast<int>(wParam)); + vs.selAdditionalBackground = ColourAlpha::FromRGB(static_cast<int>(wParam)); InvalidateStyleRedraw(); break; @@ -8423,12 +8423,12 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { return vs.selAdditionalAlpha; case SCI_SETADDITIONALCARETFORE: - vs.additionalCaretColour = ColourDesired(static_cast<int>(wParam)); + vs.additionalCaretColour = ColourAlpha::FromRGB(static_cast<int>(wParam)); InvalidateStyleRedraw(); break; case SCI_GETADDITIONALCARETFORE: - return vs.additionalCaretColour.AsInteger(); + return vs.additionalCaretColour.OpaqueRGB(); case SCI_ROTATESELECTION: sel.RotateMain(); diff --git a/src/Geometry.h b/src/Geometry.h index ed158c081..b4d10f496 100644 --- a/src/Geometry.h +++ b/src/Geometry.h @@ -158,25 +158,33 @@ PRectangle PixelAlign(const PRectangle &rc, int pixelDivisions) noexcept; PRectangle PixelAlignOutside(const PRectangle &rc, int pixelDivisions) noexcept; /** - * Holds an RGB colour with 8 bits for each component. - */ +* Holds an RGBA colour with 8 bits for each component. +*/ constexpr const float componentMaximum = 255.0f; -class ColourDesired { +class ColourAlpha { int co; public: - constexpr explicit ColourDesired(int co_=0) noexcept : co(co_) { + constexpr explicit ColourAlpha(int co_ = 0) noexcept : co(co_) { } - constexpr ColourDesired(unsigned int red, unsigned int green, unsigned int blue) noexcept : - co(red | (green << 8) | (blue << 16)) { + constexpr ColourAlpha(unsigned int red, unsigned int green, unsigned int blue, unsigned int alpha=0xff) noexcept : + ColourAlpha(red | (green << 8) | (blue << 16) | (alpha << 24)) { } - constexpr bool operator==(const ColourDesired &other) const noexcept { - return co == other.co; + constexpr ColourAlpha(ColourAlpha cd, unsigned int alpha) noexcept : + ColourAlpha(cd.OpaqueRGB() | (alpha << 24)) { } - constexpr int AsInteger() const noexcept { - return co; + static constexpr ColourAlpha FromRGB(int co_) noexcept { + return ColourAlpha(co_ | (0xffu << 24)); + } + + constexpr ColourAlpha Opaque() const noexcept { + return ColourAlpha(co & 0xffffff); + } + + constexpr int OpaqueRGB() const noexcept { + return co & 0xffffff; } // Red, green and blue values as bytes 0..255 @@ -189,8 +197,11 @@ public: constexpr unsigned char GetBlue() const noexcept { return (co >> 16) & 0xff; } + constexpr unsigned char GetAlpha() const noexcept { + return (co >> 24) & 0xff; + } - // Red, green and blue values as float 0..1.0 + // Red, green, blue, and alpha values as float 0..1.0 constexpr float GetRedComponent() const noexcept { return GetRed() / componentMaximum; } @@ -200,40 +211,14 @@ public: constexpr float GetBlueComponent() const noexcept { return GetBlue() / componentMaximum; } -}; - -/** -* Holds an RGBA colour. -*/ -class ColourAlpha : public ColourDesired { -public: - constexpr explicit ColourAlpha(int co_ = 0) noexcept : ColourDesired(co_) { - } - - constexpr ColourAlpha(unsigned int red, unsigned int green, unsigned int blue, unsigned int alpha=0xff) noexcept : - ColourDesired(red | (green << 8) | (blue << 16) | (alpha << 24)) { - } - - constexpr ColourAlpha(ColourDesired cd, unsigned int alpha) noexcept : - ColourDesired(cd.AsInteger() | (alpha << 24)) { - } - - constexpr ColourAlpha(ColourDesired cd) noexcept : - ColourDesired(cd.AsInteger() | (0xffu << 24)) { - } - - constexpr ColourDesired GetColour() const noexcept { - return ColourDesired(AsInteger() & 0xffffff); - } - - constexpr unsigned char GetAlpha() const noexcept { - return (AsInteger() >> 24) & 0xff; - } - constexpr float GetAlphaComponent() const noexcept { return GetAlpha() / componentMaximum; } + constexpr bool operator==(const ColourAlpha &other) const noexcept { + return co == other.co; + } + constexpr bool IsOpaque() const noexcept { return GetAlpha() == 0xff; } @@ -271,9 +256,6 @@ public: constexpr Fill(ColourAlpha colour_) noexcept : colour(colour_) { } - constexpr Fill(ColourDesired colour_) noexcept : - colour(colour_) { - } }; /** diff --git a/src/Indicator.cxx b/src/Indicator.cxx index f65b461ef..e43027837 100644 --- a/src/Indicator.cxx +++ b/src/Indicator.cxx @@ -28,7 +28,7 @@ using namespace Scintilla; void Indicator::Draw(Surface *surface, const PRectangle &rc, const PRectangle &rcLine, const PRectangle &rcCharacter, State state, int value) const { StyleAndColour sacDraw = sacNormal; if (Flags() & SC_INDICFLAG_VALUEFORE) { - sacDraw.fore = ColourDesired(value & SC_INDICVALUEMASK); + sacDraw.fore = ColourAlpha::FromRGB(value & SC_INDICVALUEMASK); } if (state == State::hover) { sacDraw = sacHover; diff --git a/src/Indicator.h b/src/Indicator.h index 89cf1cdc5..abceec061 100644 --- a/src/Indicator.h +++ b/src/Indicator.h @@ -12,10 +12,10 @@ namespace Scintilla { struct StyleAndColour { int style; - ColourDesired fore; + ColourAlpha fore; StyleAndColour() noexcept : style(INDIC_PLAIN), fore(0, 0, 0) { } - StyleAndColour(int style_, ColourDesired fore_ = ColourDesired(0, 0, 0)) noexcept : style(style_), fore(fore_) { + StyleAndColour(int style_, ColourAlpha fore_ = ColourAlpha(0, 0, 0)) noexcept : style(style_), fore(fore_) { } bool operator==(const StyleAndColour &other) const noexcept { return (style == other.style) && (fore == other.fore); @@ -36,7 +36,7 @@ public: XYPOSITION strokeWidth = 1.0f; Indicator() noexcept : under(false), fillAlpha(30), outlineAlpha(50), attributes(0) { } - Indicator(int style_, ColourDesired fore_=ColourDesired(0,0,0), bool under_=false, int fillAlpha_=30, int outlineAlpha_=50) noexcept : + Indicator(int style_, ColourAlpha fore_= ColourAlpha(0,0,0), bool under_=false, int fillAlpha_=30, int outlineAlpha_=50) noexcept : sacNormal(style_, fore_), sacHover(style_, fore_), under(under_), fillAlpha(fillAlpha_), outlineAlpha(outlineAlpha_), attributes(0) { } void Draw(Surface *surface, const PRectangle &rc, const PRectangle &rcLine, const PRectangle &rcCharacter, State drawState, int value) const; diff --git a/src/MarginView.cxx b/src/MarginView.cxx index 8b6f80695..2382ce1a8 100644 --- a/src/MarginView.cxx +++ b/src/MarginView.cxx @@ -59,7 +59,7 @@ using namespace Scintilla; namespace Scintilla { void DrawWrapMarker(Surface *surface, PRectangle rcPlace, - bool isEndMarker, ColourDesired wrapColour) { + bool isEndMarker, ColourAlpha wrapColour) { const XYPOSITION extraFinalPixel = surface->Supports(SC_SUPPORTS_LINE_DRAWS_FINAL) ? 0.0f : 1.0f; @@ -132,22 +132,22 @@ void MarginView::RefreshPixMaps(Surface *surfaceWindow, const ViewStyle &vsDraw) const PRectangle rcPattern = PRectangle::FromInts(0, 0, patternSize, patternSize); // Initialize default colours based on the chrome colour scheme. Typically the highlight is white. - ColourDesired colourFMFill = vsDraw.selbar; - ColourDesired colourFMStripes = vsDraw.selbarlight; + ColourAlpha colourFMFill = vsDraw.selbar; + ColourAlpha colourFMStripes = vsDraw.selbarlight; - if (!(vsDraw.selbarlight == ColourDesired(0xff, 0xff, 0xff))) { + if (!(vsDraw.selbarlight == ColourAlpha(0xff, 0xff, 0xff))) { // User has chosen an unusual chrome colour scheme so just use the highlight edge colour. // (Typically, the highlight colour is white.) colourFMFill = vsDraw.selbarlight; } - if (vsDraw.foldmarginColour.isSet) { + if (vsDraw.foldmarginColour) { // override default fold margin colour - colourFMFill = vsDraw.foldmarginColour; + colourFMFill = vsDraw.foldmarginColour.value(); } - if (vsDraw.foldmarginHighlightColour.isSet) { + if (vsDraw.foldmarginHighlightColour) { // override default fold margin highlight colour - colourFMStripes = vsDraw.foldmarginHighlightColour; + colourFMStripes = vsDraw.foldmarginHighlightColour.value(); } pixmapSelPattern->FillRectangle(rcPattern, colourFMFill); @@ -195,7 +195,7 @@ void MarginView::PaintMargin(Surface *surface, Sci::Line topLine, PRectangle rc, surface->FillRectangle(rcSelMargin, invertPhase ? *pixmapSelPattern : *pixmapSelPatternOffset1); } else { - ColourDesired colour; + ColourAlpha colour; switch (vs.ms[margin].style) { case SC_MARGIN_BACK: colour = vs.styles[STYLE_DEFAULT].back; diff --git a/src/MarginView.h b/src/MarginView.h index 9d74ddb5e..9e52e533b 100644 --- a/src/MarginView.h +++ b/src/MarginView.h @@ -10,9 +10,9 @@ namespace Scintilla { -void DrawWrapMarker(Surface *surface, PRectangle rcPlace, bool isEndMarker, ColourDesired wrapColour); +void DrawWrapMarker(Surface *surface, PRectangle rcPlace, bool isEndMarker, ColourAlpha wrapColour); -typedef void (*DrawWrapMarkerFn)(Surface *surface, PRectangle rcPlace, bool isEndMarker, ColourDesired wrapColour); +typedef void (*DrawWrapMarkerFn)(Surface *surface, PRectangle rcPlace, bool isEndMarker, ColourAlpha wrapColour); /** * MarginView draws the margins. diff --git a/src/Platform.h b/src/Platform.h index b77fe3243..2d14da96e 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -357,8 +357,8 @@ public: */ namespace Platform { -ColourDesired Chrome(); -ColourDesired ChromeHighlight(); +ColourAlpha Chrome(); +ColourAlpha ChromeHighlight(); const char *DefaultFont(); int DefaultFontSize(); unsigned int DoubleClickTime(); diff --git a/src/ScintillaBase.cxx b/src/ScintillaBase.cxx index 72bb5f6e0..0b9e8e41c 100644 --- a/src/ScintillaBase.cxx +++ b/src/ScintillaBase.cxx @@ -1008,19 +1008,19 @@ sptr_t ScintillaBase::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lPara break; case SCI_CALLTIPSETBACK: - ct.colourBG = ColourDesired(static_cast<int>(wParam)); + ct.colourBG = ColourAlpha::FromRGB(static_cast<int>(wParam)); vs.styles[STYLE_CALLTIP].back = ct.colourBG; InvalidateStyleRedraw(); break; case SCI_CALLTIPSETFORE: - ct.colourUnSel = ColourDesired(static_cast<int>(wParam)); + ct.colourUnSel = ColourAlpha::FromRGB(static_cast<int>(wParam)); vs.styles[STYLE_CALLTIP].fore = ct.colourUnSel; InvalidateStyleRedraw(); break; case SCI_CALLTIPSETFOREHLT: - ct.colourSel = ColourDesired(static_cast<int>(wParam)); + ct.colourSel = ColourAlpha::FromRGB(static_cast<int>(wParam)); InvalidateStyleRedraw(); break; diff --git a/src/Style.cxx b/src/Style.cxx index 83224c736..ae5fa6aa3 100644 --- a/src/Style.cxx +++ b/src/Style.cxx @@ -59,13 +59,13 @@ void FontMeasurements::ClearMeasurements() noexcept { } Style::Style() : FontSpecification() { - Clear(ColourDesired(0, 0, 0), ColourDesired(0xff, 0xff, 0xff), + Clear(ColourAlpha(0, 0, 0), ColourAlpha(0xff, 0xff, 0xff), Platform::DefaultFontSize() * SC_FONT_SIZE_MULTIPLIER, nullptr, SC_CHARSET_DEFAULT, SC_WEIGHT_NORMAL, false, false, false, CaseForce::mixed, true, true, false); } Style::Style(const Style &source) noexcept : FontSpecification(), FontMeasurements() { - Clear(ColourDesired(0, 0, 0), ColourDesired(0xff, 0xff, 0xff), + Clear(ColourAlpha(0, 0, 0), ColourAlpha(0xff, 0xff, 0xff), 0, nullptr, 0, SC_WEIGHT_NORMAL, false, false, false, CaseForce::mixed, true, true, false); fore = source.fore; @@ -89,7 +89,7 @@ Style::~Style() { Style &Style::operator=(const Style &source) noexcept { if (this == &source) return * this; - Clear(ColourDesired(0, 0, 0), ColourDesired(0xff, 0xff, 0xff), + Clear(ColourAlpha(0, 0, 0), ColourAlpha(0xff, 0xff, 0xff), 0, nullptr, SC_CHARSET_DEFAULT, SC_WEIGHT_NORMAL, false, false, false, CaseForce::mixed, true, true, false); fore = source.fore; @@ -107,7 +107,7 @@ Style &Style::operator=(const Style &source) noexcept { return *this; } -void Style::Clear(ColourDesired fore_, ColourDesired back_, int size_, +void Style::Clear(ColourAlpha fore_, ColourAlpha back_, int size_, const char *fontName_, int characterSet_, int weight_, bool italic_, bool eolFilled_, bool underline_, CaseForce caseForce_, diff --git a/src/Style.h b/src/Style.h index d9bf96d88..8f9b1d334 100644 --- a/src/Style.h +++ b/src/Style.h @@ -44,8 +44,8 @@ struct FontMeasurements { */ class Style : public FontSpecification, public FontMeasurements { public: - ColourDesired fore; - ColourDesired back; + ColourAlpha fore; + ColourAlpha back; bool eolFilled; bool underline; enum class CaseForce {mixed, upper, lower, camel}; @@ -62,7 +62,7 @@ public: ~Style(); Style &operator=(const Style &source) noexcept; Style &operator=(Style &&) = delete; - void Clear(ColourDesired fore_, ColourDesired back_, + void Clear(ColourAlpha fore_, ColourAlpha back_, int size_, const char *fontName_, int characterSet_, int weight_, bool italic_, bool eolFilled_, diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx index 5645e47fc..d4de3a6f5 100644 --- a/src/ViewStyle.cxx +++ b/src/ViewStyle.cxx @@ -198,9 +198,9 @@ void ViewStyle::Init(size_t stylesSize_) { // There are no image markers by default, so no need for calling CalcLargestMarkerHeight() largestMarkerHeight = 0; - indicators[0] = Indicator(INDIC_SQUIGGLE, ColourDesired(0, 0x7f, 0)); - indicators[1] = Indicator(INDIC_TT, ColourDesired(0, 0, 0xff)); - indicators[2] = Indicator(INDIC_PLAIN, ColourDesired(0xff, 0, 0)); + indicators[0] = Indicator(INDIC_SQUIGGLE, ColourAlpha(0, 0x7f, 0)); + indicators[1] = Indicator(INDIC_TT, ColourAlpha(0, 0, 0xff)); + indicators[2] = Indicator(INDIC_PLAIN, ColourAlpha(0xff, 0, 0)); technology = SC_TECHNOLOGY_DEFAULT; indicatorsDynamic = false; @@ -213,40 +213,40 @@ void ViewStyle::Init(size_t stylesSize_) { spaceWidth = 8; tabWidth = spaceWidth * 8; - selColours.fore = ColourOptional(ColourDesired(0xff, 0, 0)); - selColours.back = ColourOptional(ColourDesired(0xc0, 0xc0, 0xc0), true); - selAdditionalForeground = ColourDesired(0xff, 0, 0); - selAdditionalBackground = ColourDesired(0xd7, 0xd7, 0xd7); - selBackground2 = ColourDesired(0xb0, 0xb0, 0xb0); + selColours.fore.reset(); + selColours.back = ColourAlpha(0xc0, 0xc0, 0xc0); + selAdditionalForeground = ColourAlpha(0xff, 0, 0); + selAdditionalBackground = ColourAlpha(0xd7, 0xd7, 0xd7); + selBackground2 = ColourAlpha(0xb0, 0xb0, 0xb0); selAlpha = SC_ALPHA_NOALPHA; selAdditionalAlpha = SC_ALPHA_NOALPHA; selEOLFilled = false; - foldmarginColour = ColourOptional(ColourDesired(0xff, 0, 0)); - foldmarginHighlightColour = ColourOptional(ColourDesired(0xc0, 0xc0, 0xc0)); + foldmarginColour.reset(); + foldmarginHighlightColour.reset(); - whitespaceColours.fore = ColourOptional(); - whitespaceColours.back = ColourOptional(ColourDesired(0xff, 0xff, 0xff)); + whitespaceColours.fore.reset(); + whitespaceColours.back.reset(); controlCharSymbol = 0; /* Draw the control characters */ controlCharWidth = 0; selbar = Platform::Chrome(); selbarlight = Platform::ChromeHighlight(); - styles[STYLE_LINENUMBER].fore = ColourDesired(0, 0, 0); + styles[STYLE_LINENUMBER].fore = ColourAlpha(0, 0, 0); styles[STYLE_LINENUMBER].back = Platform::Chrome(); - caretcolour = ColourDesired(0, 0, 0); - additionalCaretColour = ColourDesired(0x7f, 0x7f, 0x7f); + caretcolour = ColourAlpha(0, 0, 0); + additionalCaretColour = ColourAlpha(0x7f, 0x7f, 0x7f); caretLineFrame = 0; showCaretLineBackground = false; alwaysShowCaretLineBackground = false; - caretLineBackground = ColourDesired(0xff, 0xff, 0); + caretLineBackground = ColourAlpha(0xff, 0xff, 0); caretLineAlpha = SC_ALPHA_NOALPHA; caretStyle = CARETSTYLE_LINE; caretWidth = 1; someStylesProtected = false; someStylesForceCase = false; - hotspotColours.fore = ColourOptional(ColourDesired(0, 0, 0xff)); - hotspotColours.back = ColourOptional(ColourDesired(0xff, 0xff, 0xff)); + hotspotColours.fore.reset(); + hotspotColours.back.reset(); hotspotUnderline = true; hotspotSingleLine = true; @@ -279,7 +279,7 @@ void ViewStyle::Init(size_t stylesSize_) { braceBadLightIndicator = 0; edgeState = EDGE_NONE; - theEdge = EdgeProperties(0, ColourDesired(0xc0, 0xc0, 0xc0)); + theEdge = EdgeProperties(0, ColourAlpha(0xc0, 0xc0, 0xc0)); marginNumberPadding = 3; ctrlCharPadding = 3; // +3 For a blank on front and rounded edge each side @@ -381,8 +381,8 @@ void ViewStyle::EnsureStyle(size_t index) { } void ViewStyle::ResetDefaultStyle() { - styles[STYLE_DEFAULT].Clear(ColourDesired(0,0,0), - ColourDesired(0xff,0xff,0xff), + styles[STYLE_DEFAULT].Clear(ColourAlpha(0,0,0), + ColourAlpha(0xff,0xff,0xff), Platform::DefaultFontSize() * SC_FONT_SIZE_MULTIPLIER, fontNames.Save(Platform::DefaultFont()), SC_CHARSET_DEFAULT, SC_WEIGHT_NORMAL, false, false, false, Style::CaseForce::mixed, true, true, false); @@ -398,8 +398,8 @@ void ViewStyle::ClearStyles() { styles[STYLE_LINENUMBER].back = Platform::Chrome(); // Set call tip fore/back to match the values previously set for call tips - styles[STYLE_CALLTIP].back = ColourDesired(0xff, 0xff, 0xff); - styles[STYLE_CALLTIP].fore = ColourDesired(0x80, 0x80, 0x80); + styles[STYLE_CALLTIP].back = ColourAlpha(0xff, 0xff, 0xff); + styles[STYLE_CALLTIP].fore = ColourAlpha(0x80, 0x80, 0x80); } void ViewStyle::SetStyleFontName(int styleIndex, const char *name) { @@ -464,29 +464,29 @@ bool ViewStyle::IsLineFrameOpaque(bool caretActive, bool lineContainsCaret) cons // display itself (as long as it's not an SC_MARK_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. -ColourOptional ViewStyle::Background(int marksOfLine, bool caretActive, bool lineContainsCaret) const noexcept { - ColourOptional background; +std::optional<ColourAlpha> ViewStyle::Background(int marksOfLine, bool caretActive, bool lineContainsCaret) const { + std::optional<ColourAlpha> background; if (!caretLineFrame && (caretActive || alwaysShowCaretLineBackground) && showCaretLineBackground && (caretLineAlpha == SC_ALPHA_NOALPHA) && lineContainsCaret) { - background = ColourOptional(caretLineBackground, true); + background = caretLineBackground; } - if (!background.isSet && marksOfLine) { + if (!background && marksOfLine) { int marks = marksOfLine; for (int markBit = 0; (markBit < 32) && marks; markBit++) { if ((marks & 1) && (markers[markBit].markType == SC_MARK_BACKGROUND) && (markers[markBit].alpha == SC_ALPHA_NOALPHA)) { - background = ColourOptional(markers[markBit].back, true); + background = markers[markBit].back; } marks >>= 1; } } - if (!background.isSet && maskInLine) { + if (!background && maskInLine) { int marksMasked = marksOfLine & maskInLine; if (marksMasked) { for (int markBit = 0; (markBit < 32) && marksMasked; markBit++) { if ((marksMasked & 1) && (markers[markBit].alpha == SC_ALPHA_NOALPHA)) { - background = ColourOptional(markers[markBit].back, true); + background = markers[markBit].back; } marksMasked >>= 1; } @@ -496,12 +496,12 @@ ColourOptional ViewStyle::Background(int marksOfLine, bool caretActive, bool lin } bool ViewStyle::SelectionBackgroundDrawn() const noexcept { - return selColours.back.isSet && + return selColours.back && ((selAlpha == SC_ALPHA_NOALPHA) || (selAdditionalAlpha == SC_ALPHA_NOALPHA)); } bool ViewStyle::WhitespaceBackgroundDrawn() const noexcept { - return (viewWhitespace != WhiteSpace::invisible) && (whitespaceColours.back.isSet); + return (viewWhitespace != WhiteSpace::invisible) && (whitespaceColours.back); } bool ViewStyle::WhiteSpaceVisible(bool inIndent) const noexcept { @@ -510,11 +510,8 @@ bool ViewStyle::WhiteSpaceVisible(bool inIndent) const noexcept { viewWhitespace == WhiteSpace::visibleAlways; } -ColourDesired ViewStyle::WrapColour() const noexcept { - if (whitespaceColours.fore.isSet) - return whitespaceColours.fore; - else - return styles[STYLE_DEFAULT].fore; +ColourAlpha ViewStyle::WrapColour() const noexcept { + return whitespaceColours.fore.value_or(styles[STYLE_DEFAULT].fore); } // Insert new edge in sorted order. diff --git a/src/ViewStyle.h b/src/ViewStyle.h index 946bd6c60..c9fe6bc98 100644 --- a/src/ViewStyle.h +++ b/src/ViewStyle.h @@ -15,7 +15,7 @@ namespace Scintilla { class MarginStyle { public: int style; - ColourDesired back; + ColourAlpha back; int width; int mask; bool sensitive; @@ -50,28 +50,27 @@ typedef std::map<FontSpecification, std::unique_ptr<FontRealised>> FontMap; enum class WrapMode { none, word, character, whitespace }; -class ColourOptional : public ColourDesired { -public: - bool isSet; - ColourOptional(ColourDesired colour_=ColourDesired(0,0,0), bool isSet_=false) noexcept : ColourDesired(colour_), isSet(isSet_) { - } - ColourOptional(uptr_t wParam, sptr_t lParam) noexcept : ColourDesired(static_cast<int>(lParam)), isSet(wParam != 0) { +inline std::optional<ColourAlpha> OptionalColour(uptr_t wParam, sptr_t lParam) { + if (wParam) { + return ColourAlpha::FromRGB(static_cast<int>(lParam)); + } else { + return {}; } -}; +} struct ForeBackColours { - ColourOptional fore; - ColourOptional back; + std::optional<ColourAlpha> fore; + std::optional<ColourAlpha> back; }; struct EdgeProperties { - int column; - ColourDesired colour; - EdgeProperties(int column_ = 0, ColourDesired colour_ = ColourDesired(0)) noexcept : + int column = 0; + ColourAlpha colour; + EdgeProperties(int column_ = 0, ColourAlpha colour_ = ColourAlpha::FromRGB(0)) noexcept : column(column_), colour(colour_) { } EdgeProperties(uptr_t wParam, sptr_t lParam) noexcept : - column(static_cast<int>(wParam)), colour(static_cast<int>(lParam)) { + column(static_cast<int>(wParam)), colour(ColourAlpha::FromRGB(static_cast<int>(lParam))) { } }; @@ -97,19 +96,19 @@ public: XYPOSITION spaceWidth; XYPOSITION tabWidth; ForeBackColours selColours; - ColourDesired selAdditionalForeground; - ColourDesired selAdditionalBackground; - ColourDesired selBackground2; + ColourAlpha selAdditionalForeground; + ColourAlpha selAdditionalBackground; + ColourAlpha selBackground2; int selAlpha; int selAdditionalAlpha; bool selEOLFilled; ForeBackColours whitespaceColours; int controlCharSymbol; XYPOSITION controlCharWidth; - ColourDesired selbar; - ColourDesired selbarlight; - ColourOptional foldmarginColour; - ColourOptional foldmarginHighlightColour; + ColourAlpha selbar; + ColourAlpha selbarlight; + std::optional<ColourAlpha> foldmarginColour; + std::optional<ColourAlpha> foldmarginHighlightColour; ForeBackColours hotspotColours; bool hotspotUnderline; bool hotspotSingleLine; @@ -128,12 +127,12 @@ public: int whitespaceSize; IndentView viewIndentationGuides; bool viewEOL; - ColourDesired caretcolour; - ColourDesired additionalCaretColour; + ColourAlpha caretcolour; + ColourAlpha additionalCaretColour; int caretLineFrame; bool showCaretLineBackground; bool alwaysShowCaretLineBackground; - ColourDesired caretLineBackground; + ColourAlpha caretLineBackground; int caretLineAlpha; int caretStyle; int caretWidth; @@ -194,10 +193,10 @@ public: void CalcLargestMarkerHeight() noexcept; int GetFrameWidth() const noexcept; bool IsLineFrameOpaque(bool caretActive, bool lineContainsCaret) const noexcept; - ColourOptional Background(int marksOfLine, bool caretActive, bool lineContainsCaret) const noexcept; + std::optional<ColourAlpha> Background(int marksOfLine, bool caretActive, bool lineContainsCaret) const; bool SelectionBackgroundDrawn() const noexcept; bool WhitespaceBackgroundDrawn() const noexcept; - ColourDesired WrapColour() const noexcept; + ColourAlpha WrapColour() const noexcept; void AddMultiEdge(uptr_t wParam, sptr_t lParam); |