https://git.reactos.org/?p=reactos.git;a=commitdiff;h=3799d37a48340c83206e90c2789b19c6da662bfa

commit 3799d37a48340c83206e90c2789b19c6da662bfa
Author:     Katayama Hirofumi MZ <[email protected]>
AuthorDate: Sat Nov 25 14:14:14 2023 +0900
Commit:     Katayama Hirofumi MZ <[email protected]>
CommitDate: Sat Nov 25 14:14:14 2023 +0900

    [MSPAINT] mouse.cpp: Renaming some items for human readability
    
    CORE-19094
---
 base/applications/mspaint/mouse.cpp    | 150 ++++++++++++++++-----------------
 base/applications/mspaint/toolsmodel.h |   1 -
 2 files changed, 75 insertions(+), 76 deletions(-)

diff --git a/base/applications/mspaint/mouse.cpp 
b/base/applications/mspaint/mouse.cpp
index af8fb48ab25..083467b0eb1 100644
--- a/base/applications/mspaint/mouse.cpp
+++ b/base/applications/mspaint/mouse.cpp
@@ -9,11 +9,11 @@
 #include "precomp.h"
 #include <atlalloc.h>
 
-static SIZE_T s_pointSP = 0;
-static CHeapPtr<POINT, CLocalAllocator> s_pointsAllocated;
-static POINT s_staticPointStack[512]; // 512 is enough
-static SIZE_T s_maxPointSP = _countof(s_staticPointStack);
-static LPPOINT s_pointStack = s_staticPointStack;
+static SIZE_T s_cPoints = 0;
+static CHeapPtr<POINT, CLocalAllocator> s_dynamicPoints;
+static POINT s_staticPoints[512]; // 512 is enough
+static SIZE_T s_maxPoints = _countof(s_staticPoints);
+static LPPOINT s_pPoints = s_staticPoints;
 static POINT g_ptStart, g_ptEnd;
 
 /* FUNCTIONS ********************************************************/
@@ -53,7 +53,7 @@ BOOL nearlyEqualPoints(INT x0, INT y0, INT x1, INT y1)
     return (abs(x1 - x0) <= cxThreshold) && (abs(y1 - y0) <= cyThreshold);
 }
 
-void getBoundaryOfPtStack(RECT& rcBoundary, SIZE_T cPoints, const POINT 
*pPoints)
+void getBoundaryOfPoints(RECT& rcBoundary, SIZE_T cPoints, const POINT 
*pPoints)
 {
     POINT ptMin = { MAXLONG, MAXLONG }, ptMax = { (LONG)MINLONG, (LONG)MINLONG 
};
     while (cPoints-- > 0)
@@ -71,22 +71,22 @@ void getBoundaryOfPtStack(RECT& rcBoundary, SIZE_T cPoints, 
const POINT *pPoints
     rcBoundary = rc;
 }
 
-void ShiftPtStack(INT dx, INT dy)
+void ShiftPoints(INT dx, INT dy)
 {
-    for (SIZE_T i = 0; i < s_pointSP; ++i)
+    for (SIZE_T i = 0; i < s_cPoints; ++i)
     {
-        POINT& pt = s_pointStack[i];
+        POINT& pt = s_pPoints[i];
         pt.x += dx;
         pt.y += dy;
     }
 }
 
-void BuildMaskFromPtStack()
+void BuildMaskFromPoints()
 {
     CRect rc;
-    getBoundaryOfPtStack(rc, s_pointSP, s_pointStack);
+    getBoundaryOfPoints(rc, s_cPoints, s_pPoints);
 
-    ShiftPtStack(-rc.left, -rc.top);
+    ShiftPoints(-rc.left, -rc.top);
 
     HDC hdcMem = ::CreateCompatibleDC(NULL);
     HBITMAP hbmMask = ::CreateBitmap(rc.Width(), rc.Height(), 1, 1, NULL);
@@ -94,7 +94,7 @@ void BuildMaskFromPtStack()
     ::FillRect(hdcMem, &rc, (HBRUSH)::GetStockObject(BLACK_BRUSH));
     HGDIOBJ hPenOld = ::SelectObject(hdcMem, GetStockObject(NULL_PEN));
     HGDIOBJ hbrOld = ::SelectObject(hdcMem, GetStockObject(WHITE_BRUSH));
-    ::Polygon(hdcMem, s_pointStack, (INT)s_pointSP);
+    ::Polygon(hdcMem, s_pPoints, (INT)s_cPoints);
     ::SelectObject(hdcMem, hbrOld);
     ::SelectObject(hdcMem, hPenOld);
     ::SelectObject(hdcMem, hbmOld);
@@ -105,14 +105,14 @@ void BuildMaskFromPtStack()
 
 void ToolBase::reset()
 {
-    if (s_pointStack != s_staticPointStack)
+    if (s_pPoints != s_staticPoints)
     {
-        s_pointsAllocated.Free();
-        s_pointStack = s_staticPointStack;
-        s_maxPointSP = _countof(s_staticPointStack);
+        s_dynamicPoints.Free();
+        s_pPoints = s_staticPoints;
+        s_maxPoints = _countof(s_staticPoints);
     }
 
-    s_pointSP = 0;
+    s_cPoints = 0;
     g_ptEnd = g_ptStart = { -1, -1 };
 
     if (selectionModel.m_bShow)
@@ -140,26 +140,26 @@ void ToolBase::endEvent()
     m_hdc = NULL;
 }
 
-void ToolBase::pushToPtStack(LONG x, LONG y)
+static void pushToPoints(LONG x, LONG y)
 {
-    if (s_pointSP + 1 >= s_maxPointSP)
+    if (s_cPoints + 1 >= s_maxPoints)
     {
-        SIZE_T newMax = s_maxPointSP + 512;
+        SIZE_T newMax = s_maxPoints + 512;
         SIZE_T cbNew = newMax * sizeof(POINT);
-        if (!s_pointsAllocated.ReallocateBytes(cbNew))
+        if (!s_dynamicPoints.ReallocateBytes(cbNew))
         {
-            ATLTRACE("%d, %d, %d\n", (INT)s_pointSP, (INT)s_maxPointSP, 
(INT)cbNew);
+            ATLTRACE("%d, %d, %d\n", (INT)s_cPoints, (INT)s_maxPoints, 
(INT)cbNew);
             return;
         }
 
-        if (s_pointStack == s_staticPointStack)
-            CopyMemory(s_pointsAllocated, s_staticPointStack, s_pointSP * 
sizeof(POINT));
+        if (s_pPoints == s_staticPoints)
+            CopyMemory(s_dynamicPoints, s_staticPoints, s_cPoints * 
sizeof(POINT));
 
-        s_pointStack = s_pointsAllocated;
-        s_maxPointSP = newMax;
+        s_pPoints = s_dynamicPoints;
+        s_maxPoints = newMax;
     }
 
-    s_pointStack[s_pointSP++] = { x, y };
+    s_pPoints[s_cPoints++] = { x, y };
 }
 
 /* TOOLS ********************************************************/
@@ -312,9 +312,9 @@ struct SmoothDrawTool : ToolBase
         m_direction = NO_DIRECTION;
         m_bShiftDown = (::GetKeyState(VK_SHIFT) & 0x8000); // Is Shift key 
pressed?
         m_bLeftButton = bLeftButton;
-        s_pointSP = 0;
-        pushToPtStack(x, y);
-        pushToPtStack(x, y); // We have to draw the first point
+        s_cPoints = 0;
+        pushToPoints(x, y);
+        pushToPoints(x, y); // We have to draw the first point
         imageModel.NotifyImageChanged();
     }
 
@@ -322,7 +322,7 @@ struct SmoothDrawTool : ToolBase
     {
         if (!m_bShiftDown)
         {
-            pushToPtStack(x, y);
+            pushToPoints(x, y);
             imageModel.NotifyImageChanged();
             return TRUE;
         }
@@ -335,7 +335,7 @@ struct SmoothDrawTool : ToolBase
         }
 
         RestrictDrawDirection(m_direction, g_ptStart.x, g_ptStart.y, x, y);
-        pushToPtStack(x, y);
+        pushToPoints(x, y);
         imageModel.NotifyImageChanged();
         return TRUE;
     }
@@ -345,10 +345,10 @@ struct SmoothDrawTool : ToolBase
         if (m_bShiftDown && m_direction != NO_DIRECTION)
             RestrictDrawDirection(m_direction, g_ptStart.x, g_ptStart.y, x, y);
 
-        pushToPtStack(x, y);
+        pushToPoints(x, y);
 
         CRect rcPartial;
-        getBoundaryOfPtStack(rcPartial, s_pointSP, s_pointStack);
+        getBoundaryOfPoints(rcPartial, s_cPoints, s_pPoints);
 
         SIZE size = toolsModel.GetToolSize();
         rcPartial.InflateRect((size.cx + 1) / 2, (size.cy + 1) / 2);
@@ -363,9 +363,9 @@ struct SmoothDrawTool : ToolBase
 
     void OnDrawOverlayOnImage(HDC hdc) override
     {
-        for (SIZE_T i = 1; i < s_pointSP; ++i)
+        for (SIZE_T i = 1; i < s_cPoints; ++i)
         {
-            OnDraw(hdc, m_bLeftButton, s_pointStack[i - 1], s_pointStack[i]);
+            OnDraw(hdc, m_bLeftButton, s_pPoints[i - 1], s_pPoints[i]);
         }
     }
 };
@@ -446,8 +446,8 @@ struct SelectionBaseTool : ToolBase
         }
         else
         {
-            s_pointSP = 0;
-            pushToPtStack(pt.x, pt.y);
+            s_cPoints = 0;
+            pushToPoints(pt.x, pt.y);
         }
 
         imageModel.NotifyImageChanged();
@@ -478,7 +478,7 @@ struct SelectionBaseTool : ToolBase
         if (isRectSelect())
             selectionModel.SetRectFromPoints(g_ptStart, pt);
         else
-            pushToPtStack(pt.x, pt.y);
+            pushToPoints(pt.x, pt.y);
 
         imageModel.NotifyImageChanged();
         return TRUE;
@@ -515,14 +515,14 @@ struct SelectionBaseTool : ToolBase
         }
         else
         {
-            if (s_pointSP > 2)
+            if (s_cPoints > 2)
             {
-                BuildMaskFromPtStack();
+                BuildMaskFromPoints();
                 selectionModel.m_bShow = TRUE;
             }
             else
             {
-                s_pointSP = 0;
+                s_cPoints = 0;
                 selectionModel.m_bShow = FALSE;
             }
         }
@@ -560,7 +560,7 @@ struct FreeSelTool : SelectionBaseTool
         if (!selectionModel.m_bShow && m_bDrawing)
         {
             /* Draw the freehand selection inverted/xored */
-            Poly(hdc, s_pointStack, (INT)s_pointSP, 0, 0, 2, 0, FALSE, TRUE);
+            Poly(hdc, s_pPoints, (INT)s_cPoints, 0, 0, 2, 0, FALSE, TRUE);
         }
     }
 };
@@ -911,17 +911,17 @@ struct BezierTool : ToolBase
     void OnDrawOverlayOnImage(HDC hdc)
     {
         COLORREF rgb = (m_bLeftButton ? m_fg : m_bg);
-        switch (s_pointSP)
+        switch (s_cPoints)
         {
             case 2:
-                Line(hdc, s_pointStack[0].x, s_pointStack[0].y, 
s_pointStack[1].x, s_pointStack[1].y, rgb,
+                Line(hdc, s_pPoints[0].x, s_pPoints[0].y, s_pPoints[1].x, 
s_pPoints[1].y, rgb,
                      toolsModel.GetLineWidth());
                 break;
             case 3:
-                Bezier(hdc, s_pointStack[0], s_pointStack[2], s_pointStack[2], 
s_pointStack[1], rgb, toolsModel.GetLineWidth());
+                Bezier(hdc, s_pPoints[0], s_pPoints[2], s_pPoints[2], 
s_pPoints[1], rgb, toolsModel.GetLineWidth());
                 break;
             case 4:
-                Bezier(hdc, s_pointStack[0], s_pointStack[2], s_pointStack[3], 
s_pointStack[1], rgb, toolsModel.GetLineWidth());
+                Bezier(hdc, s_pPoints[0], s_pPoints[2], s_pPoints[3], 
s_pPoints[1], rgb, toolsModel.GetLineWidth());
                 break;
         }
     }
@@ -930,14 +930,14 @@ struct BezierTool : ToolBase
     {
         m_bLeftButton = bLeftButton;
 
-        if (s_pointSP == 0)
+        if (s_cPoints == 0)
         {
-            pushToPtStack(x, y);
-            pushToPtStack(x, y);
+            pushToPoints(x, y);
+            pushToPoints(x, y);
         }
         else
         {
-            s_pointStack[s_pointSP - 1] = { x, y };
+            s_pPoints[s_cPoints - 1] = { x, y };
         }
 
         imageModel.NotifyImageChanged();
@@ -945,27 +945,27 @@ struct BezierTool : ToolBase
 
     BOOL OnMouseMove(BOOL bLeftButton, LONG& x, LONG& y) override
     {
-        if (s_pointSP > 0)
-            s_pointStack[s_pointSP - 1] = { x, y };
+        if (s_cPoints > 0)
+            s_pPoints[s_cPoints - 1] = { x, y };
         imageModel.NotifyImageChanged();
         return TRUE;
     }
 
     BOOL OnButtonUp(BOOL bLeftButton, LONG& x, LONG& y) override
     {
-        if (s_pointSP >= 4)
+        if (s_cPoints >= 4)
         {
             OnEndDraw(FALSE);
             return TRUE;
         }
-        pushToPtStack(x, y);
+        pushToPoints(x, y);
         imageModel.NotifyImageChanged();
         return TRUE;
     }
 
     void OnEndDraw(BOOL bCancel) override
     {
-        if (!bCancel && s_pointSP > 1)
+        if (!bCancel && s_cPoints > 1)
         {
             // FIXME: I couldn't calculate boundary rectangle from Bezier curve
             imageModel.PushImageForUndo();
@@ -1004,13 +1004,13 @@ struct ShapeTool : ToolBase
 
     void OnDrawOverlayOnImage(HDC hdc)
     {
-        if (s_pointSP <= 0)
+        if (s_cPoints <= 0)
             return;
 
         if (m_bLeftButton)
-            Poly(hdc, s_pointStack, (INT)s_pointSP, m_fg, m_bg, 
toolsModel.GetLineWidth(), toolsModel.GetShapeStyle(), m_bClosed, FALSE);
+            Poly(hdc, s_pPoints, (INT)s_cPoints, m_fg, m_bg, 
toolsModel.GetLineWidth(), toolsModel.GetShapeStyle(), m_bClosed, FALSE);
         else
-            Poly(hdc, s_pointStack, (INT)s_pointSP, m_bg, m_fg, 
toolsModel.GetLineWidth(), toolsModel.GetShapeStyle(), m_bClosed, FALSE);
+            Poly(hdc, s_pPoints, (INT)s_cPoints, m_bg, m_fg, 
toolsModel.GetLineWidth(), toolsModel.GetShapeStyle(), m_bClosed, FALSE);
     }
 
     void OnButtonDown(BOOL bLeftButton, LONG x, LONG y, BOOL bDoubleClick) 
override
@@ -1018,31 +1018,31 @@ struct ShapeTool : ToolBase
         m_bLeftButton = bLeftButton;
         m_bClosed = FALSE;
 
-        if ((s_pointSP > 0) && (GetAsyncKeyState(VK_SHIFT) < 0))
-            roundTo8Directions(s_pointStack[s_pointSP - 1].x, 
s_pointStack[s_pointSP - 1].y, x, y);
+        if ((s_cPoints > 0) && (GetAsyncKeyState(VK_SHIFT) < 0))
+            roundTo8Directions(s_pPoints[s_cPoints - 1].x, s_pPoints[s_cPoints 
- 1].y, x, y);
 
-        pushToPtStack(x, y);
+        pushToPoints(x, y);
 
-        if (s_pointSP > 1 && bDoubleClick)
+        if (s_cPoints > 1 && bDoubleClick)
         {
             OnEndDraw(FALSE);
             return;
         }
 
-        if (s_pointSP == 1)
-            pushToPtStack(x, y); // We have to draw the first point
+        if (s_cPoints == 1)
+            pushToPoints(x, y); // We have to draw the first point
 
         imageModel.NotifyImageChanged();
     }
 
     BOOL OnMouseMove(BOOL bLeftButton, LONG& x, LONG& y) override
     {
-        if (s_pointSP > 1)
+        if (s_cPoints > 1)
         {
             if (GetAsyncKeyState(VK_SHIFT) < 0)
-                roundTo8Directions(s_pointStack[s_pointSP - 2].x, 
s_pointStack[s_pointSP - 2].y, x, y);
+                roundTo8Directions(s_pPoints[s_cPoints - 2].x, 
s_pPoints[s_cPoints - 2].y, x, y);
 
-            s_pointStack[s_pointSP - 1] = { x, y };
+            s_pPoints[s_cPoints - 1] = { x, y };
         }
 
         imageModel.NotifyImageChanged();
@@ -1051,27 +1051,27 @@ struct ShapeTool : ToolBase
 
     BOOL OnButtonUp(BOOL bLeftButton, LONG& x, LONG& y) override
     {
-        if ((s_pointSP > 1) && (GetAsyncKeyState(VK_SHIFT) < 0))
-            roundTo8Directions(s_pointStack[s_pointSP - 2].x, 
s_pointStack[s_pointSP - 2].y, x, y);
+        if ((s_cPoints > 1) && (GetAsyncKeyState(VK_SHIFT) < 0))
+            roundTo8Directions(s_pPoints[s_cPoints - 2].x, s_pPoints[s_cPoints 
- 2].y, x, y);
 
         m_bClosed = FALSE;
-        if (nearlyEqualPoints(x, y, s_pointStack[0].x, s_pointStack[0].y))
+        if (nearlyEqualPoints(x, y, s_pPoints[0].x, s_pPoints[0].y))
         {
             OnEndDraw(FALSE);
             return TRUE;
         }
 
-        pushToPtStack(x, y);
+        pushToPoints(x, y);
         imageModel.NotifyImageChanged();
         return TRUE;
     }
 
     void OnEndDraw(BOOL bCancel) override
     {
-        if (!bCancel && s_pointSP > 1)
+        if (!bCancel && s_cPoints > 1)
         {
             CRect rcPartial;
-            getBoundaryOfPtStack(rcPartial, s_pointSP, s_pointStack);
+            getBoundaryOfPoints(rcPartial, s_cPoints, s_pPoints);
 
             SIZE size = toolsModel.GetToolSize();
             rcPartial.InflateRect((size.cx + 1) / 2, (size.cy + 1) / 2);
diff --git a/base/applications/mspaint/toolsmodel.h 
b/base/applications/mspaint/toolsmodel.h
index 2cd2e68d235..43d4c6ecf28 100644
--- a/base/applications/mspaint/toolsmodel.h
+++ b/base/applications/mspaint/toolsmodel.h
@@ -60,7 +60,6 @@ struct ToolBase
     void beginEvent();
     void endEvent();
     void reset();
-    void pushToPtStack(LONG x, LONG y);
 
     static ToolBase* createToolObject(TOOLTYPE type);
 };

Reply via email to