diff options
| author | Neil <nyamatongwe@gmail.com> | 2019-03-18 19:22:38 +1100 |
|---|---|---|
| committer | Neil <nyamatongwe@gmail.com> | 2019-03-18 19:22:38 +1100 |
| commit | 7e4bd49b1315de495ad37ed7d19897abdcf44b94 (patch) | |
| tree | 8737893d8ce56a276bd673d4d236ed2ab66f3b9a | |
| parent | 0bc5b663b3166f562053413ce9381ad481e68a99 (diff) | |
| download | scintilla-mirror-7e4bd49b1315de495ad37ed7d19897abdcf44b94.tar.gz | |
Backport: Add some operators to Point to simplify client code.
Backport of changeset 7321:d488340e94c0.
| -rw-r--r-- | include/Platform.h | 12 | ||||
| -rw-r--r-- | src/Editor.cxx | 20 | ||||
| -rw-r--r-- | src/ScintillaBase.cxx | 8 | ||||
| -rw-r--r-- | win32/PlatWin.cxx | 4 | ||||
| -rw-r--r-- | win32/ScintillaWin.cxx | 7 |
5 files changed, 27 insertions, 24 deletions
diff --git a/include/Platform.h b/include/Platform.h index 654460901..8f5417fe0 100644 --- a/include/Platform.h +++ b/include/Platform.h @@ -108,6 +108,18 @@ public: return Point(static_cast<XYPOSITION>(x_), static_cast<XYPOSITION>(y_)); } + bool operator!=(Point other) const noexcept { + return (x != other.x) || (y != other.y); + } + + Point operator+(Point other) const noexcept { + return Point(x + other.x, y + other.y); + } + + Point operator-(Point other) const noexcept { + return Point(x - other.x, y - other.y); + } + // Other automatically defined methods (assignment, copy constructor, destructor) are fine }; diff --git a/src/Editor.cxx b/src/Editor.cxx index 94e1f6164..1c67bfd0b 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -1147,13 +1147,9 @@ slop | strict | jumps | even | Caret can go to the margin | When Editor::XYScrollPosition Editor::XYScrollToMakeVisible(const SelectionRange &range, const XYScrollOptions options) { const PRectangle rcClient = GetTextRectangle(); - Point pt = LocationFromPosition(range.caret); - Point ptAnchor = LocationFromPosition(range.anchor); const Point ptOrigin = GetVisibleOriginInMain(); - pt.x += ptOrigin.x; - pt.y += ptOrigin.y; - ptAnchor.x += ptOrigin.x; - ptAnchor.y += ptOrigin.y; + const Point pt = LocationFromPosition(range.caret) + ptOrigin; + const Point ptAnchor = LocationFromPosition(range.anchor) + ptOrigin; const Point ptBottomCaret(pt.x, pt.y + vs.lineHeight - 1); XYScrollPosition newXY(xOffset, topLine); @@ -4171,9 +4167,10 @@ void Editor::GoToLine(Sci::Line lineNo) { } static bool Close(Point pt1, Point pt2, Point threshold) noexcept { - if (std::abs(pt1.x - pt2.x) > threshold.x) + const Point ptDifference = pt2 - pt1; + if (std::abs(ptDifference.x) > threshold.x) return false; - if (std::abs(pt1.y - pt2.y) > threshold.y) + if (std::abs(ptDifference.y) > threshold.y) return false; return true; } @@ -4263,9 +4260,8 @@ void Editor::DisplayCursor(Window::Cursor c) { } bool Editor::DragThreshold(Point ptStart, Point ptNow) { - const XYPOSITION xMove = ptStart.x - ptNow.x; - const XYPOSITION yMove = ptStart.y - ptNow.y; - const XYPOSITION distanceSquared = xMove * xMove + yMove * yMove; + const Point ptDiff = ptStart - ptNow; + const XYPOSITION distanceSquared = ptDiff.x * ptDiff.x + ptDiff.y * ptDiff.y; return distanceSquared > 16.0f; } @@ -4745,7 +4741,7 @@ Range Editor::GetHotSpotRange() const noexcept { } void Editor::ButtonMoveWithModifiers(Point pt, unsigned int, int modifiers) { - if ((ptMouseLast.x != pt.x) || (ptMouseLast.y != pt.y)) { + if (ptMouseLast != pt) { DwellEnd(true); } diff --git a/src/ScintillaBase.cxx b/src/ScintillaBase.cxx index c327206d8..9e4c3d4a8 100644 --- a/src/ScintillaBase.cxx +++ b/src/ScintillaBase.cxx @@ -275,9 +275,7 @@ void ScintillaBase::AutoCompleteStart(Sci::Position lenEntered, const char *list pt = PointMainCaret(); } if (wMargin.Created()) { - const Point ptOrigin = GetVisibleOriginInMain(); - pt.x += ptOrigin.x; - pt.y += ptOrigin.y; + pt = pt + GetVisibleOriginInMain(); } PRectangle rcac; rcac.left = pt.x - ac.lb->CaretFromEdge(); @@ -462,9 +460,7 @@ void ScintillaBase::CallTipShow(Point pt, const char *defn) { ct.SetForeBack(vs.styles[STYLE_CALLTIP].fore, vs.styles[STYLE_CALLTIP].back); } if (wMargin.Created()) { - const Point ptOrigin = GetVisibleOriginInMain(); - pt.x += ptOrigin.x; - pt.y += ptOrigin.y; + pt = pt + GetVisibleOriginInMain(); } PRectangle rc = ct.CallTipStart(sel.MainCaret(), pt, vs.lineHeight, diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx index 1c937a194..20fcdbfd4 100644 --- a/win32/PlatWin.cxx +++ b/win32/PlatWin.cxx @@ -2385,9 +2385,7 @@ void ListBoxX::ResizeToCursor() { PRectangle rc = GetPosition(); POINT ptw; ::GetCursorPos(&ptw); - Point pt = Point::FromInts(ptw.x, ptw.y); - pt.x += dragOffset.x; - pt.y += dragOffset.y; + const Point pt = Point::FromInts(ptw.x, ptw.y) + dragOffset; switch (resizeHit) { case HTLEFT: diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx index d4f9a7a14..b1f0412bd 100644 --- a/win32/ScintillaWin.cxx +++ b/win32/ScintillaWin.cxx @@ -627,8 +627,9 @@ HWND ScintillaWin::MainHWND() const noexcept { } bool ScintillaWin::DragThreshold(Point ptStart, Point ptNow) { - const int xMove = static_cast<int>(std::abs(ptStart.x - ptNow.x)); - const int yMove = static_cast<int>(std::abs(ptStart.y - ptNow.y)); + const Point ptDifference = ptStart - ptNow; + const XYPOSITION xMove = std::trunc(std::abs(ptDifference.x)); + const XYPOSITION yMove = std::trunc(std::abs(ptDifference.y)); return (xMove > ::GetSystemMetrics(SM_CXDRAG)) || (yMove > ::GetSystemMetrics(SM_CYDRAG)); } @@ -1418,7 +1419,7 @@ sptr_t ScintillaWin::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam // Windows might send WM_MOUSEMOVE even though the mouse has not been moved: // http://blogs.msdn.com/b/oldnewthing/archive/2003/10/01/55108.aspx - if (ptMouseLast.x != pt.x || ptMouseLast.y != pt.y) { + if (ptMouseLast != pt) { SetTrackMouseLeaveEvent(true); ButtonMoveWithModifiers(pt, ::GetMessageTime(), MouseModifiers(wParam)); } |
