[MSPAINT] Add nearlyEqualPoints and use it (#4194)

CORE-17931
This commit is contained in:
Katayama Hirofumi MZ 2021-12-27 20:06:21 +09:00 committed by GitHub
parent 30e47fdb77
commit ce54a8a5f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 4 deletions

View file

@ -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)
{

View file

@ -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;