aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2019-03-18 19:22:38 +1100
committerNeil <nyamatongwe@gmail.com>2019-03-18 19:22:38 +1100
commit983d5165878df0190964a8f903c24055f9144612 (patch)
tree8f88b9eecbb4ee07725af5bafed081c68a453016 /src
parentb52af20e7318e19b2becf5b191d22d6ccb7139b2 (diff)
downloadscintilla-mirror-983d5165878df0190964a8f903c24055f9144612.tar.gz
Add some operators to Point to simplify client code.
Diffstat (limited to 'src')
-rw-r--r--src/Editor.cxx20
-rw-r--r--src/ScintillaBase.cxx8
2 files changed, 10 insertions, 18 deletions
diff --git a/src/Editor.cxx b/src/Editor.cxx
index 953cae81a..639f3a242 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -1150,13 +1150,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);
@@ -4174,9 +4170,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;
}
@@ -4266,9 +4263,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;
}
@@ -4748,7 +4744,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 68cdd7f2b..3fab6b767 100644
--- a/src/ScintillaBase.cxx
+++ b/src/ScintillaBase.cxx
@@ -276,9 +276,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();
@@ -463,9 +461,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,