diff options
author | Zufu Liu <unknown> | 2020-06-10 10:31:02 +1000 |
---|---|---|
committer | Zufu Liu <unknown> | 2020-06-10 10:31:02 +1000 |
commit | 1cdba1d42d7cdec5bad6071f297ca1ce60fb6119 (patch) | |
tree | 2043dba1fa076b14b4004e413bff6b463b088fc4 | |
parent | dccca71620f0ef2bef0b93da33ff758b2c23fcfd (diff) | |
download | scintilla-mirror-1cdba1d42d7cdec5bad6071f297ca1ce60fb6119.tar.gz |
Feature [feature-requests:1357]. Convert to switch.
-rw-r--r-- | src/Indicator.cxx | 339 |
1 files changed, 195 insertions, 144 deletions
diff --git a/src/Indicator.cxx b/src/Indicator.cxx index baa7c3bd0..4ebf57b38 100644 --- a/src/Indicator.cxx +++ b/src/Indicator.cxx @@ -40,166 +40,214 @@ void Indicator::Draw(Surface *surface, const PRectangle &rc, const PRectangle &r const IntegerRectangle irc(rc); surface->PenColour(sacDraw.fore); const int ymid = (irc.bottom + irc.top) / 2; - if (sacDraw.style == INDIC_SQUIGGLE) { - const IntegerRectangle ircSquiggle(PixelGridAlign(rc)); - int x = ircSquiggle.left; - const int xLast = ircSquiggle.right; - int y = 0; - surface->MoveTo(x, irc.top + y); - while (x < xLast) { - if ((x + 2) > xLast) { - y = 1; - x = xLast; - } else { - x += 2; - y = 2 - y; + + switch (sacDraw.style) { + case INDIC_SQUIGGLE: { + const IntegerRectangle ircSquiggle(PixelGridAlign(rc)); + int x = ircSquiggle.left; + const int xLast = ircSquiggle.right; + int y = 0; + surface->MoveTo(x, irc.top + y); + while (x < xLast) { + if ((x + 2) > xLast) { + y = 1; + x = xLast; + } else { + x += 2; + y = 2 - y; + } + surface->LineTo(x, irc.top + y); } - surface->LineTo(x, irc.top + y); } - } else if (sacDraw.style == INDIC_SQUIGGLEPIXMAP) { - const PRectangle rcSquiggle = PixelGridAlign(rc); - - const int width = std::min(4000, static_cast<int>(rcSquiggle.Width())); - RGBAImage image(width, 3, 1.0, nullptr); - enum { alphaFull = 0xff, alphaSide = 0x2f, alphaSide2=0x5f }; - for (int x = 0; x < width; x++) { - if (x%2) { - // Two halfway columns have a full pixel in middle flanked by light pixels - image.SetPixel(x, 0, sacDraw.fore, alphaSide); - image.SetPixel(x, 1, sacDraw.fore, alphaFull); - image.SetPixel(x, 2, sacDraw.fore, alphaSide); - } else { - // Extreme columns have a full pixel at bottom or top and a mid-tone pixel in centre - image.SetPixel(x, (x % 4) ? 0 : 2, sacDraw.fore, alphaFull); - image.SetPixel(x, 1, sacDraw.fore, alphaSide2); + break; + + case INDIC_SQUIGGLEPIXMAP: { + const PRectangle rcSquiggle = PixelGridAlign(rc); + + const int width = std::min(4000, static_cast<int>(rcSquiggle.Width())); + RGBAImage image(width, 3, 1.0, nullptr); + enum { alphaFull = 0xff, alphaSide = 0x2f, alphaSide2=0x5f }; + for (int x = 0; x < width; x++) { + if (x%2) { + // Two halfway columns have a full pixel in middle flanked by light pixels + image.SetPixel(x, 0, sacDraw.fore, alphaSide); + image.SetPixel(x, 1, sacDraw.fore, alphaFull); + image.SetPixel(x, 2, sacDraw.fore, alphaSide); + } else { + // Extreme columns have a full pixel at bottom or top and a mid-tone pixel in centre + image.SetPixel(x, (x % 4) ? 0 : 2, sacDraw.fore, alphaFull); + image.SetPixel(x, 1, sacDraw.fore, alphaSide2); + } } + surface->DrawRGBAImage(rcSquiggle, image.GetWidth(), image.GetHeight(), image.Pixels()); } - surface->DrawRGBAImage(rcSquiggle, image.GetWidth(), image.GetHeight(), image.Pixels()); - } else if (sacDraw.style == INDIC_SQUIGGLELOW) { - surface->MoveTo(irc.left, irc.top); - int x = irc.left + 3; - int y = 0; - while (x < rc.right) { - surface->LineTo(x - 1, irc.top + y); - y = 1 - y; - surface->LineTo(x, irc.top + y); - x += 3; - } - surface->LineTo(irc.right, irc.top + y); // Finish the line - } else if (sacDraw.style == INDIC_TT) { - surface->MoveTo(irc.left, ymid); - int x = irc.left + 5; - while (x < rc.right) { - surface->LineTo(x, ymid); - surface->MoveTo(x-3, ymid); - surface->LineTo(x-3, ymid+2); - x++; - surface->MoveTo(x, ymid); - x += 5; + break; + + case INDIC_SQUIGGLELOW: { + surface->MoveTo(irc.left, irc.top); + int x = irc.left + 3; + int y = 0; + while (x < rc.right) { + surface->LineTo(x - 1, irc.top + y); + y = 1 - y; + surface->LineTo(x, irc.top + y); + x += 3; + } + surface->LineTo(irc.right, irc.top + y); // Finish the line } - surface->LineTo(irc.right, ymid); // Finish the line - if (x - 3 <= rc.right) { - surface->MoveTo(x-3, ymid); - surface->LineTo(x-3, ymid+2); + break; + + case INDIC_TT: { + surface->MoveTo(irc.left, ymid); + int x = irc.left + 5; + while (x < rc.right) { + surface->LineTo(x, ymid); + surface->MoveTo(x-3, ymid); + surface->LineTo(x-3, ymid+2); + x++; + surface->MoveTo(x, ymid); + x += 5; + } + surface->LineTo(irc.right, ymid); // Finish the line + if (x - 3 <= rc.right) { + surface->MoveTo(x-3, ymid); + surface->LineTo(x-3, ymid+2); + } } - } else if (sacDraw.style == INDIC_DIAGONAL) { - int x = irc.left; - while (x < rc.right) { - surface->MoveTo(x, irc.top + 2); - int endX = x+3; - int endY = irc.top - 1; - if (endX > rc.right) { - endY += endX - irc.right; - endX = irc.right; + break; + + case INDIC_DIAGONAL: { + int x = irc.left; + while (x < rc.right) { + surface->MoveTo(x, irc.top + 2); + int endX = x+3; + int endY = irc.top - 1; + if (endX > rc.right) { + endY += endX - irc.right; + endX = irc.right; + } + surface->LineTo(endX, endY); + x += 4; } - surface->LineTo(endX, endY); - x += 4; } - } else if (sacDraw.style == INDIC_STRIKE) { - surface->MoveTo(irc.left, irc.top - 4); - surface->LineTo(irc.right, irc.top - 4); - } else if ((sacDraw.style == INDIC_HIDDEN) || (sacDraw.style == INDIC_TEXTFORE)) { + break; + + case INDIC_STRIKE: { + surface->MoveTo(irc.left, irc.top - 4); + surface->LineTo(irc.right, irc.top - 4); + } + break; + + case INDIC_HIDDEN: + case INDIC_TEXTFORE: // Draw nothing - } else if (sacDraw.style == INDIC_BOX) { - surface->MoveTo(irc.left, ymid + 1); - surface->LineTo(irc.right, ymid + 1); - const int lineTop = static_cast<int>(rcLine.top) + 1; - surface->LineTo(irc.right, lineTop); - surface->LineTo(irc.left, lineTop); - surface->LineTo(irc.left, ymid + 1); - } else if (sacDraw.style == INDIC_ROUNDBOX || - sacDraw.style == INDIC_STRAIGHTBOX || - sacDraw.style == INDIC_FULLBOX) { - PRectangle rcBox = rcLine; - if (sacDraw.style != INDIC_FULLBOX) + break; + + case INDIC_BOX: { + surface->MoveTo(irc.left, ymid + 1); + surface->LineTo(irc.right, ymid + 1); + const int lineTop = static_cast<int>(rcLine.top) + 1; + surface->LineTo(irc.right, lineTop); + surface->LineTo(irc.left, lineTop); + surface->LineTo(irc.left, ymid + 1); + } + break; + + case INDIC_ROUNDBOX: + case INDIC_STRAIGHTBOX: + case INDIC_FULLBOX: { + PRectangle rcBox = rcLine; + if (sacDraw.style != INDIC_FULLBOX) + rcBox.top = rcLine.top + 1; + rcBox.left = rc.left; + rcBox.right = rc.right; + surface->AlphaRectangle(rcBox, (sacDraw.style == INDIC_ROUNDBOX) ? 1 : 0, + sacDraw.fore, fillAlpha, sacDraw.fore, outlineAlpha, 0); + } + break; + + case INDIC_GRADIENT: + case INDIC_GRADIENTCENTRE: { + PRectangle rcBox = rc; + rcBox.top = rcLine.top + 1; + rcBox.bottom = rcLine.bottom; + const Surface::GradientOptions options = Surface::GradientOptions::topToBottom; + const ColourAlpha start(sacNormal.fore, fillAlpha); + const ColourAlpha end(sacNormal.fore, 0); + std::vector<ColourStop> stops; + switch (sacDraw.style) { + case INDIC_GRADIENT: + stops.push_back(ColourStop(0.0, start)); + stops.push_back(ColourStop(1.0, end)); + break; + case INDIC_GRADIENTCENTRE: + stops.push_back(ColourStop(0.0, end)); + stops.push_back(ColourStop(0.5, start)); + stops.push_back(ColourStop(1.0, end)); + break; + } + surface->GradientRectangle(rcBox, stops, options); + } + break; + + case INDIC_DOTBOX: { + PRectangle rcBox = PixelGridAlign(rc); rcBox.top = rcLine.top + 1; - rcBox.left = rc.left; - rcBox.right = rc.right; - surface->AlphaRectangle(rcBox, (sacDraw.style == INDIC_ROUNDBOX) ? 1 : 0, - sacDraw.fore, fillAlpha, sacDraw.fore, outlineAlpha, 0); - } else if (sacDraw.style == INDIC_GRADIENT || - sacDraw.style == INDIC_GRADIENTCENTRE) { - PRectangle rcBox = rc; - rcBox.top = rcLine.top + 1; - rcBox.bottom = rcLine.bottom; - const Surface::GradientOptions options = Surface::GradientOptions::topToBottom; - const ColourAlpha start(sacNormal.fore, fillAlpha); - const ColourAlpha end(sacNormal.fore, 0); - std::vector<ColourStop> stops; - switch (sacDraw.style) { - case INDIC_GRADIENT: - stops.push_back(ColourStop(0.0, start)); - stops.push_back(ColourStop(1.0, end)); - break; - case INDIC_GRADIENTCENTRE: - stops.push_back(ColourStop(0.0, end)); - stops.push_back(ColourStop(0.5, start)); - stops.push_back(ColourStop(1.0, end)); - break; + rcBox.bottom = rcLine.bottom; + IntegerRectangle ircBox(rcBox); + // Cap width at 4000 to avoid large allocations when mistakes made + const int width = std::min(ircBox.Width(), 4000); + RGBAImage image(width, ircBox.Height(), 1.0, nullptr); + // Draw horizontal lines top and bottom + for (int x=0; x<width; x++) { + for (int y = 0; y<ircBox.Height(); y += ircBox.Height() - 1) { + image.SetPixel(x, y, sacDraw.fore, ((x + y) % 2) ? outlineAlpha : fillAlpha); + } + } + // Draw vertical lines left and right + for (int y = 1; y<ircBox.Height(); y++) { + for (int x=0; x<width; x += width-1) { + image.SetPixel(x, y, sacDraw.fore, ((x + y) % 2) ? outlineAlpha : fillAlpha); + } + } + surface->DrawRGBAImage(rcBox, image.GetWidth(), image.GetHeight(), image.Pixels()); } - surface->GradientRectangle(rcBox, stops, options); - } else if (sacDraw.style == INDIC_DOTBOX) { - PRectangle rcBox = PixelGridAlign(rc); - rcBox.top = rcLine.top + 1; - rcBox.bottom = rcLine.bottom; - IntegerRectangle ircBox(rcBox); - // Cap width at 4000 to avoid large allocations when mistakes made - const int width = std::min(ircBox.Width(), 4000); - RGBAImage image(width, ircBox.Height(), 1.0, nullptr); - // Draw horizontal lines top and bottom - for (int x=0; x<width; x++) { - for (int y = 0; y<ircBox.Height(); y += ircBox.Height() - 1) { - image.SetPixel(x, y, sacDraw.fore, ((x + y) % 2) ? outlineAlpha : fillAlpha); + break; + + case INDIC_DASH: { + int x = irc.left; + while (x < rc.right) { + surface->MoveTo(x, ymid); + surface->LineTo(std::min(x + 4, irc.right), ymid); + x += 7; } } - // Draw vertical lines left and right - for (int y = 1; y<ircBox.Height(); y++) { - for (int x=0; x<width; x += width-1) { - image.SetPixel(x, y, sacDraw.fore, ((x + y) % 2) ? outlineAlpha : fillAlpha); + break; + + case INDIC_DOTS: { + int x = irc.left; + while (x < irc.right) { + const PRectangle rcDot = PRectangle::FromInts(x, ymid, x + 1, ymid + 1); + surface->FillRectangle(rcDot, sacDraw.fore); + x += 2; } } - surface->DrawRGBAImage(rcBox, image.GetWidth(), image.GetHeight(), image.Pixels()); - } else if (sacDraw.style == INDIC_DASH) { - int x = irc.left; - while (x < rc.right) { - surface->MoveTo(x, ymid); - surface->LineTo(std::min(x + 4, irc.right), ymid); - x += 7; + break; + + case INDIC_COMPOSITIONTHICK: { + const PRectangle rcComposition(rc.left+1, rcLine.bottom-2, rc.right-1, rcLine.bottom); + surface->FillRectangle(rcComposition, sacDraw.fore); } - } else if (sacDraw.style == INDIC_DOTS) { - int x = irc.left; - while (x < irc.right) { - const PRectangle rcDot = PRectangle::FromInts(x, ymid, x + 1, ymid + 1); - surface->FillRectangle(rcDot, sacDraw.fore); - x += 2; + break; + + case INDIC_COMPOSITIONTHIN: { + const PRectangle rcComposition(rc.left+1, rcLine.bottom-2, rc.right-1, rcLine.bottom-1); + surface->FillRectangle(rcComposition, sacDraw.fore); } - } else if (sacDraw.style == INDIC_COMPOSITIONTHICK) { - const PRectangle rcComposition(rc.left+1, rcLine.bottom-2, rc.right-1, rcLine.bottom); - surface->FillRectangle(rcComposition, sacDraw.fore); - } else if (sacDraw.style == INDIC_COMPOSITIONTHIN) { - const PRectangle rcComposition(rc.left+1, rcLine.bottom-2, rc.right-1, rcLine.bottom-1); - surface->FillRectangle(rcComposition, sacDraw.fore); - } else if (sacDraw.style == INDIC_POINT || sacDraw.style == INDIC_POINTCHARACTER) { + break; + + case INDIC_POINT: + case INDIC_POINTCHARACTER: if (rcCharacter.Width() >= 0.1) { const XYPOSITION pixelHeight = std::floor(rc.Height() - 1.0f); // 1 pixel onto next line if multiphase const XYPOSITION x = (sacDraw.style == INDIC_POINT) ? (rcCharacter.left) : ((rcCharacter.right + rcCharacter.left) / 2); @@ -212,7 +260,10 @@ void Indicator::Draw(Surface *surface, const PRectangle &rc, const PRectangle &r }; surface->Polygon(pts, std::size(pts), sacDraw.fore, sacDraw.fore); } - } else { // Either INDIC_PLAIN or unknown + break; + + default: + // Either INDIC_PLAIN or unknown surface->MoveTo(irc.left, ymid); surface->LineTo(irc.right, ymid); } |