diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/CallTip.cxx | 94 | ||||
-rw-r--r-- | src/CallTip.h | 16 |
2 files changed, 61 insertions, 49 deletions
diff --git a/src/CallTip.cxx b/src/CallTip.cxx index 0cc818d44..d12033de3 100644 --- a/src/CallTip.cxx +++ b/src/CallTip.cxx @@ -28,8 +28,8 @@ using namespace Scintilla; -CallTip::CallTip() { - wCallTip = 0; +CallTip::CallTip() noexcept { + wCallTip = {}; inCallTipMode = false; posStartCallTip = 0; rectUp = PRectangle(0,0,0,0); @@ -67,17 +67,12 @@ CallTip::~CallTip() { wCallTip.Destroy(); } -// Although this test includes 0, we should never see a \0 character. -static bool IsArrowCharacter(char ch) { - return (ch == 0) || (ch == '\001') || (ch == '\002'); -} - // We ignore tabs unless a tab width has been set. -bool CallTip::IsTabCharacter(char ch) const { +bool CallTip::IsTabCharacter(char ch) const noexcept { return (tabSize > 0) && (ch == '\t'); } -int CallTip::NextTabPos(int x) const { +int CallTip::NextTabPos(int x) const noexcept { if (tabSize > 0) { // paranoia... not called unless this is true x -= insetX; // position relative to text x = (x + tabSize) / tabSize; // tab "number" @@ -87,6 +82,42 @@ int CallTip::NextTabPos(int x) const { } } +namespace { + +// Although this test includes 0, we should never see a \0 character. +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) { + surface->FillRectangle(rc, colourBG); + const int width = static_cast<int>(rc.Width()); + const int halfWidth = width / 2 - 3; + const int quarterWidth = halfWidth / 2; + const int centreX = static_cast<int>(rc.left) + width / 2 - 1; + const int centreY = static_cast<int>(rc.top + rc.bottom) / 2; + const PRectangle rcClientInner(rc.left + 1, rc.top + 1, rc.right - 2, rc.bottom - 1); + surface->FillRectangle(rcClientInner, colourUnSel); + + if (upArrow) { // Up arrow + Point pts[] = { + Point::FromInts(centreX - halfWidth, centreY + quarterWidth), + Point::FromInts(centreX + halfWidth, centreY + quarterWidth), + Point::FromInts(centreX, centreY - halfWidth + quarterWidth), + }; + surface->Polygon(pts, std::size(pts), colourBG, colourBG); + } else { // Down arrow + Point pts[] = { + Point::FromInts(centreX - halfWidth, centreY - quarterWidth), + Point::FromInts(centreX + halfWidth, centreY - quarterWidth), + Point::FromInts(centreX, centreY + halfWidth - quarterWidth), + }; + surface->Polygon(pts, std::size(pts), colourBG, colourBG); + } +} + +} + // Draw a section of the call tip that does not include \n in one colour. // The text may include up to numEnds tabs or arrow characters. void CallTip::DrawChunk(Surface *surface, int &x, const char *s, @@ -98,8 +129,8 @@ void CallTip::DrawChunk(Surface *surface, int &x, const char *s, // Divide the text into sections that are all text, or that are // single arrows or single tab characters (if tabSize > 0). int maxEnd = 0; - const int numEnds = 10; - int ends[numEnds + 2]; + constexpr int numEnds = 10; + int ends[numEnds + 2] {}; for (int i=0; i<len; i++) { if ((maxEnd < numEnds) && (IsArrowCharacter(s[i]) || IsTabCharacter(s[i]))) { @@ -110,40 +141,17 @@ void CallTip::DrawChunk(Surface *surface, int &x, const char *s, } ends[maxEnd++] = len; int startSeg = 0; - int xEnd; for (int seg = 0; seg<maxEnd; seg++) { const int endSeg = ends[seg]; if (endSeg > startSeg) { + int xEnd; if (IsArrowCharacter(s[startSeg])) { xEnd = x + widthArrow; const bool upArrow = s[startSeg] == '\001'; rcClient.left = static_cast<XYPOSITION>(x); rcClient.right = static_cast<XYPOSITION>(xEnd); if (draw) { - const int halfWidth = widthArrow / 2 - 3; - const int quarterWidth = halfWidth / 2; - const int centreX = x + widthArrow / 2 - 1; - const int centreY = static_cast<int>(rcClient.top + rcClient.bottom) / 2; - surface->FillRectangle(rcClient, colourBG); - const PRectangle rcClientInner(rcClient.left + 1, rcClient.top + 1, - rcClient.right - 2, rcClient.bottom - 1); - surface->FillRectangle(rcClientInner, colourUnSel); - - if (upArrow) { // Up arrow - Point pts[] = { - Point::FromInts(centreX - halfWidth, centreY + quarterWidth), - Point::FromInts(centreX + halfWidth, centreY + quarterWidth), - Point::FromInts(centreX, centreY - halfWidth + quarterWidth), - }; - surface->Polygon(pts, std::size(pts), colourBG, colourBG); - } else { // Down arrow - Point pts[] = { - Point::FromInts(centreX - halfWidth, centreY - quarterWidth), - Point::FromInts(centreX + halfWidth, centreY - quarterWidth), - Point::FromInts(centreX, centreY + halfWidth - quarterWidth), - }; - surface->Polygon(pts, std::size(pts), colourBG, colourBG); - } + DrawArrow(surface, rcClient, upArrow, colourBG, colourUnSel); } offsetMain = xEnd; if (upArrow) { @@ -154,7 +162,7 @@ void CallTip::DrawChunk(Surface *surface, int &x, const char *s, } else if (IsTabCharacter(s[startSeg])) { xEnd = NextTabPos(x); } else { - std::string_view segText(s + startSeg, endSeg - startSeg); + const std::string_view segText(s + startSeg, endSeg - startSeg); xEnd = x + static_cast<int>(std::lround(surface->WidthText(font, segText))); if (draw) { rcClient.left = static_cast<XYPOSITION>(x); @@ -247,7 +255,7 @@ void CallTip::PaintCT(Surface *surfaceWindow) { #endif } -void CallTip::MouseClick(Point pt) { +void CallTip::MouseClick(Point pt) noexcept { clickPlace = 0; if (rectUp.Contains(pt)) clickPlace = 1; @@ -313,20 +321,24 @@ void CallTip::SetHighlight(int start, int end) { // Set the tab size (sizes > 0 enable the use of tabs). This also enables the // use of the STYLE_CALLTIP. -void CallTip::SetTabSize(int tabSz) { +void CallTip::SetTabSize(int tabSz) noexcept { tabSize = tabSz; useStyleCallTip = true; } // Set the calltip position, below the text by default or if above is false // else above the text. -void CallTip::SetPosition(bool aboveText) { +void CallTip::SetPosition(bool aboveText) noexcept { above = aboveText; } +bool CallTip::UseStyleCallTip() const noexcept { + return useStyleCallTip; +} + // 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) { +void CallTip::SetForeBack(const ColourDesired &fore, const ColourDesired &back) noexcept { colourBG = back; colourUnSel = fore; } diff --git a/src/CallTip.h b/src/CallTip.h index a37138d5f..a720bd3a3 100644 --- a/src/CallTip.h +++ b/src/CallTip.h @@ -29,8 +29,8 @@ class CallTip { int posStart, int posEnd, int ytext, PRectangle rcClient, bool highlight, bool draw); int PaintContents(Surface *surfaceWindow, bool draw); - bool IsTabCharacter(char ch) const; - int NextTabPos(int x) const; + bool IsTabCharacter(char ch) const noexcept; + int NextTabPos(int x) const noexcept; public: Window wCallTip; @@ -50,7 +50,7 @@ public: int borderHeight; int verticalOffset; // pixel offset up or down of the calltip with respect to the line - CallTip(); + CallTip() noexcept; // Deleted so CallTip objects can not be copied. CallTip(const CallTip &) = delete; CallTip(CallTip &&) = delete; @@ -60,7 +60,7 @@ public: void PaintCT(Surface *surfaceWindow); - void MouseClick(Point pt); + void MouseClick(Point pt) noexcept; /// Setup the calltip and return a rectangle of the area required. PRectangle CallTipStart(Sci::Position pos, Point pt, int textHeight, const char *defn, @@ -74,16 +74,16 @@ public: void SetHighlight(int start, int end); /// Set the tab size in pixels for the call tip. 0 or -ve means no tab expand. - void SetTabSize(int tabSz); + void SetTabSize(int tabSz) noexcept; /// Set calltip position. - void SetPosition(bool aboveText); + void SetPosition(bool aboveText) noexcept; /// Used to determine which STYLE_xxxx to use for call tip information - bool UseStyleCallTip() const { return useStyleCallTip;} + bool UseStyleCallTip() const noexcept; // Modify foreground and background colours - void SetForeBack(const ColourDesired &fore, const ColourDesired &back); + void SetForeBack(const ColourDesired &fore, const ColourDesired &back) noexcept; }; } |