https://git.reactos.org/?p=reactos.git;a=commitdiff;h=9e1386db43f64ac405b4ebf04f025227221e9c2f

commit 9e1386db43f64ac405b4ebf04f025227221e9c2f
Author:     Katayama Hirofumi MZ <[email protected]>
AuthorDate: Sun Dec 26 19:49:56 2021 +0900
Commit:     GitHub <[email protected]>
CommitDate: Sun Dec 26 19:49:56 2021 +0900

    [MSPAINT] Add Zoomed and UnZoomed and use them (#4188)
    
    - Define Zoomed and UnZoomed helper functions.
    - Use them.
    CORE-17931
---
 base/applications/mspaint/common.h       | 13 +++++++-
 base/applications/mspaint/imgarea.cpp    | 54 ++++++++++++++++----------------
 base/applications/mspaint/mouse.cpp      |  4 +--
 base/applications/mspaint/precomp.h      |  2 +-
 base/applications/mspaint/scrollbox.cpp  |  8 ++---
 base/applications/mspaint/selection.cpp  | 16 +++++-----
 base/applications/mspaint/sizebox.cpp    |  4 +--
 base/applications/mspaint/toolsmodel.cpp |  2 +-
 base/applications/mspaint/toolsmodel.h   |  2 +-
 base/applications/mspaint/winproc.cpp    |  2 +-
 10 files changed, 59 insertions(+), 48 deletions(-)

diff --git a/base/applications/mspaint/common.h 
b/base/applications/mspaint/common.h
index 45cde747b86..5c1f01cbdd9 100644
--- a/base/applications/mspaint/common.h
+++ b/base/applications/mspaint/common.h
@@ -5,10 +5,21 @@
  * PURPOSE:     Commonly used functions
  * PROGRAMMERS: Benedikt Freisen
  *              Stanislav Motylkov
+ *              Katayama Hirofumi MZ
  */
 
 #pragma once
 
 /* FUNCTIONS ********************************************************/
 
-extern BOOL zoomTo(int, int, int);
+BOOL zoomTo(int newZoom, int mouseX, int mouseY);
+
+static inline int Zoomed(int xy)
+{
+    return xy * toolsModel.GetZoom() / 1000;
+}
+
+static inline int UnZoomed(int xy)
+{
+    return xy * 1000 / toolsModel.GetZoom();
+}
diff --git a/base/applications/mspaint/imgarea.cpp 
b/base/applications/mspaint/imgarea.cpp
index b31f7642c74..f34b15ede38 100644
--- a/base/applications/mspaint/imgarea.cpp
+++ b/base/applications/mspaint/imgarea.cpp
@@ -21,8 +21,8 @@ updateCanvasAndScrollbars()
 {
     selectionWindow.ShowWindow(SW_HIDE);
 
-    int zoomedWidth = imageModel.GetWidth() * toolsModel.GetZoom() / 1000;
-    int zoomedHeight = imageModel.GetHeight() * toolsModel.GetZoom() / 1000;
+    int zoomedWidth = Zoomed(imageModel.GetWidth());
+    int zoomedHeight = Zoomed(imageModel.GetHeight());
     imageArea.MoveWindow(3, 3, zoomedWidth, zoomedHeight, FALSE);
 
     scrollboxWindow.Invalidate(TRUE);
@@ -76,26 +76,26 @@ LRESULT CImgAreaWindow::OnSize(UINT nMsg, WPARAM wParam, 
LPARAM lParam, BOOL& bH
                0,
                0, 3, 3, TRUE);
     sizeboxCenterTop.MoveWindow(
-               imgXRes * toolsModel.GetZoom() / 2000 + 3 * 3 / 4,
+               Zoomed(imgXRes) / 2 + 3 * 3 / 4,
                0, 3, 3, TRUE);
     sizeboxRightTop.MoveWindow(
-               imgXRes * toolsModel.GetZoom() / 1000 + 3,
+               Zoomed(imgXRes) + 3,
                0, 3, 3, TRUE);
     sizeboxLeftCenter.MoveWindow(
                0,
-               imgYRes * toolsModel.GetZoom() / 2000 + 3 * 3 / 4, 3, 3, TRUE);
+               Zoomed(imgYRes) / 2 + 3 * 3 / 4, 3, 3, TRUE);
     sizeboxRightCenter.MoveWindow(
-               imgXRes * toolsModel.GetZoom() / 1000 + 3,
-               imgYRes * toolsModel.GetZoom() / 2000 + 3 * 3 / 4, 3, 3, TRUE);
+               Zoomed(imgXRes) + 3,
+               Zoomed(imgYRes) / 2 + 3 * 3 / 4, 3, 3, TRUE);
     sizeboxLeftBottom.MoveWindow(
                0,
-               imgYRes * toolsModel.GetZoom() / 1000 + 3, 3, 3, TRUE);
+               Zoomed(imgYRes) + 3, 3, 3, TRUE);
     sizeboxCenterBottom.MoveWindow(
-               imgXRes * toolsModel.GetZoom() / 2000 + 3 * 3 / 4,
-               imgYRes * toolsModel.GetZoom() / 1000 + 3, 3, 3, TRUE);
+               Zoomed(imgXRes) / 2 + 3 * 3 / 4,
+               Zoomed(imgYRes) + 3, 3, 3, TRUE);
     sizeboxRightBottom.MoveWindow(
-               imgXRes * toolsModel.GetZoom() / 1000 + 3,
-               imgYRes * toolsModel.GetZoom() / 1000 + 3, 3, 3, TRUE);
+               Zoomed(imgXRes) + 3,
+               Zoomed(imgYRes) + 3, 3, 3, TRUE);
     UpdateScrollbox();
     return 0;
 }
@@ -106,7 +106,7 @@ LRESULT CImgAreaWindow::OnPaint(UINT nMsg, WPARAM wParam, 
LPARAM lParam, BOOL& b
     HDC hdc = GetDC();
     int imgXRes = imageModel.GetWidth();
     int imgYRes = imageModel.GetHeight();
-    StretchBlt(hdc, 0, 0, imgXRes * toolsModel.GetZoom() / 1000, imgYRes * 
toolsModel.GetZoom() / 1000, imageModel.GetDC(), 0, 0, imgXRes,
+    StretchBlt(hdc, 0, 0, Zoomed(imgXRes), Zoomed(imgYRes), 
imageModel.GetDC(), 0, 0, imgXRes,
                imgYRes, SRCCOPY);
     if (showGrid && (toolsModel.GetZoom() >= 4000))
     {
@@ -114,13 +114,13 @@ LRESULT CImgAreaWindow::OnPaint(UINT nMsg, WPARAM wParam, 
LPARAM lParam, BOOL& b
         int counter;
         for(counter = 0; counter <= imgYRes; counter++)
         {
-            MoveToEx(hdc, 0, counter * toolsModel.GetZoom() / 1000, NULL);
-            LineTo(hdc, imgXRes * toolsModel.GetZoom() / 1000, counter * 
toolsModel.GetZoom() / 1000);
+            MoveToEx(hdc, 0, Zoomed(counter), NULL);
+            LineTo(hdc, Zoomed(imgXRes), Zoomed(counter));
         }
         for(counter = 0; counter <= imgXRes; counter++)
         {
-            MoveToEx(hdc, counter * toolsModel.GetZoom() / 1000, 0, NULL);
-            LineTo(hdc, counter * toolsModel.GetZoom() / 1000, imgYRes * 
toolsModel.GetZoom() / 1000);
+            MoveToEx(hdc, Zoomed(counter), 0, NULL);
+            LineTo(hdc, Zoomed(counter), Zoomed(imgYRes));
         }
         DeleteObject(SelectObject(hdc, oldPen));
     }
@@ -161,7 +161,7 @@ LRESULT CImgAreaWindow::OnLButtonDown(UINT nMsg, WPARAM 
wParam, LPARAM lParam, B
     {
         SetCapture();
         drawing = TRUE;
-        startPaintingL(imageModel.GetDC(), GET_X_LPARAM(lParam) * 1000 / 
toolsModel.GetZoom(), GET_Y_LPARAM(lParam) * 1000 / toolsModel.GetZoom(),
+        startPaintingL(imageModel.GetDC(), UnZoomed(GET_X_LPARAM(lParam)), 
UnZoomed(GET_Y_LPARAM(lParam)),
                        paletteModel.GetFgColor(), paletteModel.GetBgColor());
     }
     else
@@ -181,7 +181,7 @@ LRESULT CImgAreaWindow::OnRButtonDown(UINT nMsg, WPARAM 
wParam, LPARAM lParam, B
     {
         SetCapture();
         drawing = TRUE;
-        startPaintingR(imageModel.GetDC(), GET_X_LPARAM(lParam) * 1000 / 
toolsModel.GetZoom(), GET_Y_LPARAM(lParam) * 1000 / toolsModel.GetZoom(),
+        startPaintingR(imageModel.GetDC(), UnZoomed(GET_X_LPARAM(lParam)), 
UnZoomed(GET_Y_LPARAM(lParam)),
                        paletteModel.GetFgColor(), paletteModel.GetBgColor());
     }
     else
@@ -199,13 +199,13 @@ LRESULT CImgAreaWindow::OnLButtonUp(UINT nMsg, WPARAM 
wParam, LPARAM lParam, BOO
 {
     if (drawing)
     {
-        endPaintingL(imageModel.GetDC(), GET_X_LPARAM(lParam) * 1000 / 
toolsModel.GetZoom(), GET_Y_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), 
paletteModel.GetFgColor(),
+        endPaintingL(imageModel.GetDC(), UnZoomed(GET_X_LPARAM(lParam)), 
UnZoomed(GET_Y_LPARAM(lParam)), paletteModel.GetFgColor(),
                      paletteModel.GetBgColor());
         Invalidate(FALSE);
         if (toolsModel.GetActiveTool() == TOOL_COLOR)
         {
             COLORREF tempColor =
-                GetPixel(imageModel.GetDC(), GET_X_LPARAM(lParam) * 1000 / 
toolsModel.GetZoom(), GET_Y_LPARAM(lParam) * 1000 / toolsModel.GetZoom());
+                GetPixel(imageModel.GetDC(), UnZoomed(GET_X_LPARAM(lParam)), 
UnZoomed(GET_Y_LPARAM(lParam)));
             if (tempColor != CLR_INVALID)
                 paletteModel.SetFgColor(tempColor);
         }
@@ -234,12 +234,12 @@ void CImgAreaWindow::cancelDrawing()
             // FIXME: dirty hack
             if (GetKeyState(VK_LBUTTON) < 0)
             {
-                endPaintingL(imageModel.GetDC(), pt.x * 1000 / 
toolsModel.GetZoom(), pt.y * 1000 / toolsModel.GetZoom(), 
paletteModel.GetFgColor(),
+                endPaintingL(imageModel.GetDC(), UnZoomed(pt.x), 
UnZoomed(pt.y), paletteModel.GetFgColor(),
                              paletteModel.GetBgColor());
             }
             else if (GetKeyState(VK_RBUTTON) < 0)
             {
-                endPaintingR(imageModel.GetDC(), pt.x * 1000 / 
toolsModel.GetZoom(), pt.y * 1000 / toolsModel.GetZoom(), 
paletteModel.GetFgColor(),
+                endPaintingR(imageModel.GetDC(), UnZoomed(pt.x), 
UnZoomed(pt.y), paletteModel.GetFgColor(),
                              paletteModel.GetBgColor());
             }
             imageModel.Undo();
@@ -283,13 +283,13 @@ LRESULT CImgAreaWindow::OnRButtonUp(UINT nMsg, WPARAM 
wParam, LPARAM lParam, BOO
 {
     if (drawing)
     {
-        endPaintingR(imageModel.GetDC(), GET_X_LPARAM(lParam) * 1000 / 
toolsModel.GetZoom(), GET_Y_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), 
paletteModel.GetFgColor(),
+        endPaintingR(imageModel.GetDC(), UnZoomed(GET_X_LPARAM(lParam)), 
UnZoomed(GET_Y_LPARAM(lParam)), paletteModel.GetFgColor(),
                      paletteModel.GetBgColor());
         Invalidate(FALSE);
         if (toolsModel.GetActiveTool() == TOOL_COLOR)
         {
             COLORREF tempColor =
-                GetPixel(imageModel.GetDC(), GET_X_LPARAM(lParam) * 1000 / 
toolsModel.GetZoom(), GET_Y_LPARAM(lParam) * 1000 / toolsModel.GetZoom());
+                GetPixel(imageModel.GetDC(), UnZoomed(GET_X_LPARAM(lParam)), 
UnZoomed(GET_Y_LPARAM(lParam)));
             if (tempColor != CLR_INVALID)
                 paletteModel.SetBgColor(tempColor);
         }
@@ -302,8 +302,8 @@ LRESULT CImgAreaWindow::OnRButtonUp(UINT nMsg, WPARAM 
wParam, LPARAM lParam, BOO
 
 LRESULT CImgAreaWindow::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, 
BOOL& bHandled)
 {
-    LONG xNow = GET_X_LPARAM(lParam) * 1000 / toolsModel.GetZoom();
-    LONG yNow = GET_Y_LPARAM(lParam) * 1000 / toolsModel.GetZoom();
+    LONG xNow = UnZoomed(GET_X_LPARAM(lParam));
+    LONG yNow = UnZoomed(GET_Y_LPARAM(lParam));
     if ((!drawing) || (toolsModel.GetActiveTool() <= TOOL_AIRBRUSH))
     {
         TRACKMOUSEEVENT tme;
diff --git a/base/applications/mspaint/mouse.cpp 
b/base/applications/mspaint/mouse.cpp
index b5c09b092af..10b5202dda4 100644
--- a/base/applications/mspaint/mouse.cpp
+++ b/base/applications/mspaint/mouse.cpp
@@ -15,8 +15,8 @@
 void
 placeSelWin()
 {
-    selectionWindow.MoveWindow(selectionModel.GetDestRectLeft() * 
toolsModel.GetZoom() / 1000, selectionModel.GetDestRectTop() * 
toolsModel.GetZoom() / 1000,
-        selectionModel.GetDestRectWidth() * toolsModel.GetZoom() / 1000 + 6, 
selectionModel.GetDestRectHeight() * toolsModel.GetZoom() / 1000 + 6, TRUE);
+    selectionWindow.MoveWindow(Zoomed(selectionModel.GetDestRectLeft()), 
Zoomed(selectionModel.GetDestRectTop()),
+        Zoomed(selectionModel.GetDestRectWidth()) + 6, 
Zoomed(selectionModel.GetDestRectHeight()) + 6, TRUE);
     selectionWindow.BringWindowToTop();
     imageArea.InvalidateRect(NULL, FALSE);
 }
diff --git a/base/applications/mspaint/precomp.h 
b/base/applications/mspaint/precomp.h
index f4720837fff..6bdbafceb30 100644
--- a/base/applications/mspaint/precomp.h
+++ b/base/applications/mspaint/precomp.h
@@ -21,7 +21,6 @@
 #include <shellapi.h>
 #include <htmlhelp.h>
 
-#include "common.h"
 #include "definitions.h"
 #include "drawing.h"
 #include "dib.h"
@@ -43,5 +42,6 @@
 #include "toolsettings.h"
 #include "toolsmodel.h"
 #include "winproc.h"
+#include "common.h"
 
 #endif /* _MSPAINT_H */
diff --git a/base/applications/mspaint/scrollbox.cpp 
b/base/applications/mspaint/scrollbox.cpp
index 351c59c717d..6466b8b7f85 100644
--- a/base/applications/mspaint/scrollbox.cpp
+++ b/base/applications/mspaint/scrollbox.cpp
@@ -132,8 +132,8 @@ LRESULT CScrollboxWindow::OnHScroll(UINT nMsg, WPARAM 
wParam, LPARAM lParam, BOO
         }
         scrollboxWindow.SetScrollInfo(SB_HORZ, &si);
         scrlClientWindow.MoveWindow(-scrollboxWindow.GetScrollPos(SB_HORZ),
-                   -scrollboxWindow.GetScrollPos(SB_VERT), 
imageModel.GetWidth() * toolsModel.GetZoom() / 1000 + 6,
-                   imageModel.GetHeight() * toolsModel.GetZoom() / 1000 + 6, 
TRUE);
+                   -scrollboxWindow.GetScrollPos(SB_VERT), 
Zoomed(imageModel.GetWidth()) + 6,
+                   Zoomed(imageModel.GetHeight()) + 6, TRUE);
     }
     return 0;
 }
@@ -167,8 +167,8 @@ LRESULT CScrollboxWindow::OnVScroll(UINT nMsg, WPARAM 
wParam, LPARAM lParam, BOO
         }
         scrollboxWindow.SetScrollInfo(SB_VERT, &si);
         scrlClientWindow.MoveWindow(-scrollboxWindow.GetScrollPos(SB_HORZ),
-                   -scrollboxWindow.GetScrollPos(SB_VERT), 
imageModel.GetWidth() * toolsModel.GetZoom() / 1000 + 6,
-                   imageModel.GetHeight() * toolsModel.GetZoom() / 1000 + 6, 
TRUE);
+                   -scrollboxWindow.GetScrollPos(SB_VERT), 
Zoomed(imageModel.GetWidth()) + 6,
+                   Zoomed(imageModel.GetHeight()) + 6, TRUE);
     }
     return 0;
 }
diff --git a/base/applications/mspaint/selection.cpp 
b/base/applications/mspaint/selection.cpp
index 45d72e8fb21..e058da3e67c 100644
--- a/base/applications/mspaint/selection.cpp
+++ b/base/applications/mspaint/selection.cpp
@@ -99,8 +99,8 @@ LRESULT CSelectionWindow::OnPaint(UINT nMsg, WPARAM wParam, 
LPARAM lParam, BOOL&
     {
         HDC hDC = GetDC();
         DefWindowProc(WM_PAINT, wParam, lParam);
-        SelectionFrame(hDC, 1, 1, selectionModel.GetDestRectWidth() * 
toolsModel.GetZoom() / 1000 + 5,
-                       selectionModel.GetDestRectHeight() * 
toolsModel.GetZoom() / 1000 + 5,
+        SelectionFrame(hDC, 1, 1, Zoomed(selectionModel.GetDestRectWidth()) + 
5,
+                       Zoomed(selectionModel.GetDestRectHeight()) + 5,
                        m_dwSystemSelectionColor);
         ReleaseDC(hDC);
     }
@@ -161,8 +161,8 @@ LRESULT CSelectionWindow::OnMouseMove(UINT nMsg, WPARAM 
wParam, LPARAM lParam, B
         imageModel.ResetToPrevious();
         m_ptFrac.x += GET_X_LPARAM(lParam) - m_ptPos.x;
         m_ptFrac.y += GET_Y_LPARAM(lParam) - m_ptPos.y;
-        m_ptDelta.x += m_ptFrac.x * 1000 / toolsModel.GetZoom();
-        m_ptDelta.y += m_ptFrac.y * 1000 / toolsModel.GetZoom();
+        m_ptDelta.x += UnZoomed(m_ptFrac.x);
+        m_ptDelta.y += UnZoomed(m_ptFrac.y);
         if (toolsModel.GetZoom() < 1000)
         {
             m_ptFrac.x = 0;
@@ -170,8 +170,8 @@ LRESULT CSelectionWindow::OnMouseMove(UINT nMsg, WPARAM 
wParam, LPARAM lParam, B
         }
         else
         {
-            m_ptFrac.x -= (m_ptFrac.x * 1000 / toolsModel.GetZoom()) * 
toolsModel.GetZoom() / 1000;
-            m_ptFrac.y -= (m_ptFrac.y * 1000 / toolsModel.GetZoom()) * 
toolsModel.GetZoom() / 1000;
+            m_ptFrac.x -= Zoomed(UnZoomed(m_ptFrac.x));
+            m_ptFrac.y -= Zoomed(UnZoomed(m_ptFrac.y));
         }
         selectionModel.ModifyDestRect(m_ptDelta, m_iAction);
 
@@ -197,8 +197,8 @@ LRESULT CSelectionWindow::OnMouseMove(UINT nMsg, WPARAM 
wParam, LPARAM lParam, B
     }
     else
     {
-        int w = selectionModel.GetDestRectWidth() * toolsModel.GetZoom() / 
1000 + 6;
-        int h = selectionModel.GetDestRectHeight() * toolsModel.GetZoom() / 
1000 + 6;
+        int w = Zoomed(selectionModel.GetDestRectWidth()) + 6;
+        int h = Zoomed(selectionModel.GetDestRectHeight()) + 6;
         m_ptPos.x = GET_X_LPARAM(lParam);
         m_ptPos.y = GET_Y_LPARAM(lParam);
         SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) NULL);
diff --git a/base/applications/mspaint/sizebox.cpp 
b/base/applications/mspaint/sizebox.cpp
index 71fcb6aca2d..2ebbbcc70a3 100644
--- a/base/applications/mspaint/sizebox.cpp
+++ b/base/applications/mspaint/sizebox.cpp
@@ -48,8 +48,8 @@ LRESULT CSizeboxWindow::OnMouseMove(UINT nMsg, WPARAM wParam, 
LPARAM lParam, BOO
         short yRel;
         int imgXRes = imageModel.GetWidth();
         int imgYRes = imageModel.GetHeight();
-        xRel = (GET_X_LPARAM(lParam) - xOrig) * 1000 / toolsModel.GetZoom();
-        yRel = (GET_Y_LPARAM(lParam) - yOrig) * 1000 / toolsModel.GetZoom();
+        xRel = UnZoomed(GET_X_LPARAM(lParam) - xOrig);
+        yRel = UnZoomed(GET_Y_LPARAM(lParam) - yOrig);
         if (m_hWnd == sizeboxLeftTop.m_hWnd)
             strSize.Format(_T("%d x %d"), imgXRes - xRel, imgYRes - yRel);
         if (m_hWnd == sizeboxCenterTop.m_hWnd)
diff --git a/base/applications/mspaint/toolsmodel.cpp 
b/base/applications/mspaint/toolsmodel.cpp
index ebd7fee883b..26621e75ee8 100644
--- a/base/applications/mspaint/toolsmodel.cpp
+++ b/base/applications/mspaint/toolsmodel.cpp
@@ -101,7 +101,7 @@ void ToolsModel::SetBackgroundTransparent(BOOL bTransparent)
     NotifyToolSettingsChanged();
 }
 
-int ToolsModel::GetZoom()
+int ToolsModel::GetZoom() const
 {
     return m_zoom;
 }
diff --git a/base/applications/mspaint/toolsmodel.h 
b/base/applications/mspaint/toolsmodel.h
index 49ab71bcc38..3b7205634f6 100644
--- a/base/applications/mspaint/toolsmodel.h
+++ b/base/applications/mspaint/toolsmodel.h
@@ -42,6 +42,6 @@ public:
     void SetRubberRadius(int nRubberRadius);
     BOOL IsBackgroundTransparent();
     void SetBackgroundTransparent(BOOL bTransparent);
-    int GetZoom();
+    int GetZoom() const;
     void SetZoom(int nZoom);
 };
diff --git a/base/applications/mspaint/winproc.cpp 
b/base/applications/mspaint/winproc.cpp
index 686f2eec5d0..1303b258c92 100644
--- a/base/applications/mspaint/winproc.cpp
+++ b/base/applications/mspaint/winproc.cpp
@@ -39,7 +39,7 @@ zoomTo(int newZoom, int mouseX, int mouseY)
     toolsModel.SetZoom(newZoom);
 
     selectionWindow.ShowWindow(SW_HIDE);
-    imageArea.MoveWindow(3, 3, imageModel.GetWidth() * toolsModel.GetZoom() / 
1000, imageModel.GetHeight() * toolsModel.GetZoom() / 1000, FALSE);
+    imageArea.MoveWindow(3, 3, Zoomed(imageModel.GetWidth()), 
Zoomed(imageModel.GetHeight()), FALSE);
     scrollboxWindow.Invalidate(TRUE);
     imageArea.Invalidate(FALSE);
 

Reply via email to