https://git.reactos.org/?p=reactos.git;a=commitdiff;h=ce54a8a5f287d0fc45630…
commit ce54a8a5f287d0fc4563052d9eba1f6a677b1220
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Mon Dec 27 20:06:21 2021 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Mon Dec 27 20:06:21 2021 +0900
[MSPAINT] Add nearlyEqualPoints and use it (#4194)
CORE-17931
---
base/applications/mspaint/common.h | 1 +
base/applications/mspaint/mouse.cpp | 14 ++++++++++----
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/base/applications/mspaint/common.h b/base/applications/mspaint/common.h
index bfea7368523..e6864cc21a8 100644
--- a/base/applications/mspaint/common.h
+++ b/base/applications/mspaint/common.h
@@ -13,6 +13,7 @@
/* FUNCTIONS ********************************************************/
BOOL zoomTo(int newZoom, int mouseX, int mouseY);
+BOOL nearlyEqualPoints(INT x0, INT y0, INT x1, INT y1);
static inline int Zoomed(int xy)
{
diff --git a/base/applications/mspaint/mouse.cpp b/base/applications/mspaint/mouse.cpp
index 0f2f1b36312..8c81c88562c 100644
--- a/base/applications/mspaint/mouse.cpp
+++ b/base/applications/mspaint/mouse.cpp
@@ -4,6 +4,7 @@
* FILE: base/applications/mspaint/mouse.cpp
* PURPOSE: Things which should not be in the mouse event handler itself
* PROGRAMMERS: Benedikt Freisen
+ * Katayama Hirofumi MZ
*/
/* INCLUDES *********************************************************/
@@ -50,6 +51,13 @@ roundTo8Directions(LONG x0, LONG y0, LONG& x1, LONG& y1)
}
}
+BOOL nearlyEqualPoints(INT x0, INT y0, INT x1, INT y1)
+{
+ INT cxThreshold = toolsModel.GetLineWidth() + UnZoomed(GetSystemMetrics(SM_CXDRAG));
+ INT cyThreshold = toolsModel.GetLineWidth() + UnZoomed(GetSystemMetrics(SM_CYDRAG));
+ return (abs(x1 - x0) <= cxThreshold) && (abs(y1 - y0) <= cyThreshold);
+}
+
POINT pointStack[256];
short pointSP;
@@ -297,8 +305,7 @@ endPaintingL(HDC hdc, LONG x, LONG y, COLORREF fg, COLORREF bg)
pointSP++;
if (pointSP >= 2)
{
- if ((pointStack[0].x - x) * (pointStack[0].x - x) +
- (pointStack[0].y - y) * (pointStack[0].y - y) <=
toolsModel.GetLineWidth() * toolsModel.GetLineWidth() + 1)
+ if (nearlyEqualPoints(x, y, pointStack[0].x, pointStack[0].y))
{
Poly(hdc, pointStack, pointSP, fg, bg, toolsModel.GetLineWidth(),
toolsModel.GetShapeStyle(), TRUE, FALSE);
pointSP = 0;
@@ -500,8 +507,7 @@ endPaintingR(HDC hdc, LONG x, LONG y, COLORREF fg, COLORREF bg)
pointSP++;
if (pointSP >= 2)
{
- if ((pointStack[0].x - x) * (pointStack[0].x - x) +
- (pointStack[0].y - y) * (pointStack[0].y - y) <=
toolsModel.GetLineWidth() * toolsModel.GetLineWidth() + 1)
+ if (nearlyEqualPoints(x, y, pointStack[0].x, pointStack[0].y))
{
Poly(hdc, pointStack, pointSP, bg, fg, toolsModel.GetLineWidth(),
toolsModel.GetShapeStyle(), TRUE, FALSE);
pointSP = 0;