From 614354ccb55d5aed2aa8244efdc54efb0d2b0205 Mon Sep 17 00:00:00 2001 From: Katayama Hirofumi MZ Date: Sun, 26 Dec 2021 23:05:47 +0900 Subject: [PATCH] [MSPAINT] Define GRIP_SIZE macro and use it (#4192) Reduce magic numbers. CORE-17931 --- base/applications/mspaint/common.h | 2 ++ base/applications/mspaint/imgarea.cpp | 30 ++++++++-------- base/applications/mspaint/main.cpp | 6 ++-- base/applications/mspaint/mouse.cpp | 3 +- base/applications/mspaint/scrollbox.cpp | 14 ++++---- base/applications/mspaint/selection.cpp | 47 +++++++++++-------------- base/applications/mspaint/winproc.cpp | 2 +- 7 files changed, 51 insertions(+), 53 deletions(-) diff --git a/base/applications/mspaint/common.h b/base/applications/mspaint/common.h index 5c1f01cbdd9..bfea7368523 100644 --- a/base/applications/mspaint/common.h +++ b/base/applications/mspaint/common.h @@ -23,3 +23,5 @@ static inline int UnZoomed(int xy) { return xy * 1000 / toolsModel.GetZoom(); } + +#define GRIP_SIZE 3 diff --git a/base/applications/mspaint/imgarea.cpp b/base/applications/mspaint/imgarea.cpp index f34b15ede38..99a6c72d177 100644 --- a/base/applications/mspaint/imgarea.cpp +++ b/base/applications/mspaint/imgarea.cpp @@ -23,7 +23,7 @@ updateCanvasAndScrollbars() int zoomedWidth = Zoomed(imageModel.GetWidth()); int zoomedHeight = Zoomed(imageModel.GetHeight()); - imageArea.MoveWindow(3, 3, zoomedWidth, zoomedHeight, FALSE); + imageArea.MoveWindow(GRIP_SIZE, GRIP_SIZE, zoomedWidth, zoomedHeight, FALSE); scrollboxWindow.Invalidate(TRUE); imageArea.Invalidate(FALSE); @@ -74,28 +74,30 @@ LRESULT CImgAreaWindow::OnSize(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bH int imgYRes = imageModel.GetHeight(); sizeboxLeftTop.MoveWindow( 0, - 0, 3, 3, TRUE); + 0, GRIP_SIZE, GRIP_SIZE, TRUE); sizeboxCenterTop.MoveWindow( - Zoomed(imgXRes) / 2 + 3 * 3 / 4, - 0, 3, 3, TRUE); + GRIP_SIZE + (Zoomed(imgXRes) - GRIP_SIZE) / 2, + 0, GRIP_SIZE, GRIP_SIZE, TRUE); sizeboxRightTop.MoveWindow( - Zoomed(imgXRes) + 3, - 0, 3, 3, TRUE); + GRIP_SIZE + Zoomed(imgXRes), + 0, GRIP_SIZE, GRIP_SIZE, TRUE); sizeboxLeftCenter.MoveWindow( 0, - Zoomed(imgYRes) / 2 + 3 * 3 / 4, 3, 3, TRUE); + GRIP_SIZE + (Zoomed(imgYRes) - GRIP_SIZE) / 2, + GRIP_SIZE, GRIP_SIZE, TRUE); sizeboxRightCenter.MoveWindow( - Zoomed(imgXRes) + 3, - Zoomed(imgYRes) / 2 + 3 * 3 / 4, 3, 3, TRUE); + GRIP_SIZE + Zoomed(imgXRes), + GRIP_SIZE + (Zoomed(imgYRes) - GRIP_SIZE) / 2, + GRIP_SIZE, GRIP_SIZE, TRUE); sizeboxLeftBottom.MoveWindow( 0, - Zoomed(imgYRes) + 3, 3, 3, TRUE); + GRIP_SIZE + Zoomed(imgYRes), GRIP_SIZE, GRIP_SIZE, TRUE); sizeboxCenterBottom.MoveWindow( - Zoomed(imgXRes) / 2 + 3 * 3 / 4, - Zoomed(imgYRes) + 3, 3, 3, TRUE); + GRIP_SIZE + (Zoomed(imgXRes) - GRIP_SIZE) / 2, + GRIP_SIZE + Zoomed(imgYRes), GRIP_SIZE, GRIP_SIZE, TRUE); sizeboxRightBottom.MoveWindow( - Zoomed(imgXRes) + 3, - Zoomed(imgYRes) + 3, 3, 3, TRUE); + GRIP_SIZE + Zoomed(imgXRes), + GRIP_SIZE + Zoomed(imgYRes), GRIP_SIZE, GRIP_SIZE, TRUE); UpdateScrollbox(); return 0; } diff --git a/base/applications/mspaint/main.cpp b/base/applications/mspaint/main.cpp index f1145d7f179..83e9f9d37e8 100644 --- a/base/applications/mspaint/main.cpp +++ b/base/applications/mspaint/main.cpp @@ -248,7 +248,7 @@ _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR lpszArgument selectionWindow.Create(scrlClientWindow.m_hWnd, selectionWindowPos, NULL, WS_CHILD | BS_OWNERDRAW); /* creating the window inside the scroll box, on which the image in hDrawingDC's bitmap is drawn */ - RECT imageAreaPos = {3, 3, 3 + imageModel.GetWidth(), 3 + imageModel.GetHeight()}; + RECT imageAreaPos = {GRIP_SIZE, GRIP_SIZE, GRIP_SIZE + imageModel.GetWidth(), GRIP_SIZE + imageModel.GetHeight()}; imageArea.Create(scrlClientWindow.m_hWnd, imageAreaPos, NULL, WS_CHILD | WS_VISIBLE); if (__argc >= 2) @@ -312,7 +312,7 @@ _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR lpszArgument } /* creating the size boxes */ - RECT sizeboxPos = {0, 0, 0 + 3, 0 + 3}; + RECT sizeboxPos = {0, 0, GRIP_SIZE, GRIP_SIZE}; sizeboxLeftTop.Create(scrlClientWindow.m_hWnd, sizeboxPos, NULL, WS_CHILD | WS_VISIBLE); sizeboxCenterTop.Create(scrlClientWindow.m_hWnd, sizeboxPos, NULL, WS_CHILD | WS_VISIBLE); sizeboxRightTop.Create(scrlClientWindow.m_hWnd, sizeboxPos, NULL, WS_CHILD | WS_VISIBLE); @@ -322,7 +322,7 @@ _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR lpszArgument sizeboxCenterBottom.Create(scrlClientWindow.m_hWnd, sizeboxPos, NULL, WS_CHILD | WS_VISIBLE); sizeboxRightBottom.Create(scrlClientWindow.m_hWnd, sizeboxPos, NULL, WS_CHILD | WS_VISIBLE); /* placing the size boxes around the image */ - imageArea.SendMessage(WM_SIZE, 0, 0); + imageArea.PostMessage(WM_SIZE, 0, 0); /* by moving the window, the things in WM_SIZE are done */ mainWindow.SetWindowPlacement(&(registrySettings.WindowPlacement)); diff --git a/base/applications/mspaint/mouse.cpp b/base/applications/mspaint/mouse.cpp index 10b5202dda4..0f2f1b36312 100644 --- a/base/applications/mspaint/mouse.cpp +++ b/base/applications/mspaint/mouse.cpp @@ -16,7 +16,8 @@ void placeSelWin() { selectionWindow.MoveWindow(Zoomed(selectionModel.GetDestRectLeft()), Zoomed(selectionModel.GetDestRectTop()), - Zoomed(selectionModel.GetDestRectWidth()) + 6, Zoomed(selectionModel.GetDestRectHeight()) + 6, TRUE); + Zoomed(selectionModel.GetDestRectWidth()) + 2 * GRIP_SIZE, + Zoomed(selectionModel.GetDestRectHeight()) + 2 * GRIP_SIZE, TRUE); selectionWindow.BringWindowToTop(); imageArea.InvalidateRect(NULL, FALSE); } diff --git a/base/applications/mspaint/scrollbox.cpp b/base/applications/mspaint/scrollbox.cpp index 6466b8b7f85..c2354c0cc10 100644 --- a/base/applications/mspaint/scrollbox.cpp +++ b/base/applications/mspaint/scrollbox.cpp @@ -52,8 +52,6 @@ CONST INT VSCROLL_WIDTH = ::GetSystemMetrics(SM_CXVSCROLL); void UpdateScrollbox() { - CONST INT EXTRASIZE = 5; /* 3 px of selection markers + 2 px of border */ - CRect tempRect; CSize sizeImageArea; CSize sizeScrollBox; @@ -65,7 +63,7 @@ UpdateScrollbox() imageArea.GetClientRect(&tempRect); sizeImageArea = CSize(tempRect.Width(), tempRect.Height()); - sizeImageArea += CSize(EXTRASIZE * 2, EXTRASIZE * 2); + sizeImageArea += CSize(GRIP_SIZE * 2, GRIP_SIZE * 2); /* show/hide the scrollbars */ vmode = (sizeScrollBox.cy < sizeImageArea.cy ? 0 : @@ -132,8 +130,9 @@ 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), Zoomed(imageModel.GetWidth()) + 6, - Zoomed(imageModel.GetHeight()) + 6, TRUE); + -scrollboxWindow.GetScrollPos(SB_VERT), + Zoomed(imageModel.GetWidth()) + 2 * GRIP_SIZE, + Zoomed(imageModel.GetHeight()) + 2 * GRIP_SIZE, TRUE); } return 0; } @@ -167,8 +166,9 @@ 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), Zoomed(imageModel.GetWidth()) + 6, - Zoomed(imageModel.GetHeight()) + 6, TRUE); + -scrollboxWindow.GetScrollPos(SB_VERT), + Zoomed(imageModel.GetWidth()) + 2 * GRIP_SIZE, + Zoomed(imageModel.GetHeight()) + 2 * GRIP_SIZE, TRUE); } return 0; } diff --git a/base/applications/mspaint/selection.cpp b/base/applications/mspaint/selection.cpp index e058da3e67c..c9155be1cf0 100644 --- a/base/applications/mspaint/selection.cpp +++ b/base/applications/mspaint/selection.cpp @@ -65,31 +65,24 @@ ForceRefreshSelectionContents() int CSelectionWindow::IdentifyCorner(int iXPos, int iYPos, int iWidth, int iHeight) { - if (iYPos < 3) - { - if (iXPos < 3) - return ACTION_RESIZE_TOP_LEFT; - if ((iXPos < iWidth / 2 + 2) && (iXPos >= iWidth / 2 - 1)) - return ACTION_RESIZE_TOP; - if (iXPos >= iWidth - 3) - return ACTION_RESIZE_TOP_RIGHT; - } - if ((iYPos < iHeight / 2 + 2) && (iYPos >= iHeight / 2 - 1)) - { - if (iXPos < 3) - return ACTION_RESIZE_LEFT; - if (iXPos >= iWidth - 3) - return ACTION_RESIZE_RIGHT; - } - if (iYPos >= iHeight - 3) - { - if (iXPos < 3) - return ACTION_RESIZE_BOTTOM_LEFT; - if ((iXPos < iWidth / 2 + 2) && (iXPos >= iWidth / 2 - 1)) - return ACTION_RESIZE_BOTTOM; - if (iXPos >= iWidth - 3) - return ACTION_RESIZE_BOTTOM_RIGHT; - } + POINT pt = { iXPos, iYPos }; + HWND hwndChild = ChildWindowFromPointEx(pt, CWP_SKIPINVISIBLE | CWP_SKIPDISABLED); + if (hwndChild == sizeboxLeftTop) + return ACTION_RESIZE_TOP_LEFT; + if (hwndChild == sizeboxCenterTop) + return ACTION_RESIZE_TOP; + if (hwndChild == sizeboxRightTop) + return ACTION_RESIZE_TOP_RIGHT; + if (hwndChild == sizeboxRightCenter) + return ACTION_RESIZE_RIGHT; + if (hwndChild == sizeboxLeftCenter) + return ACTION_RESIZE_LEFT; + if (hwndChild == sizeboxCenterBottom) + return ACTION_RESIZE_BOTTOM; + if (hwndChild == sizeboxRightBottom) + return ACTION_RESIZE_BOTTOM_RIGHT; + if (hwndChild == sizeboxLeftBottom) + return ACTION_RESIZE_BOTTOM_LEFT; return 0; } @@ -197,8 +190,8 @@ LRESULT CSelectionWindow::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, B } else { - int w = Zoomed(selectionModel.GetDestRectWidth()) + 6; - int h = Zoomed(selectionModel.GetDestRectHeight()) + 6; + int w = Zoomed(selectionModel.GetDestRectWidth()) + 2 * GRIP_SIZE; + int h = Zoomed(selectionModel.GetDestRectHeight()) + 2 * GRIP_SIZE; 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/winproc.cpp b/base/applications/mspaint/winproc.cpp index 1303b258c92..be060047ac3 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, Zoomed(imageModel.GetWidth()), Zoomed(imageModel.GetHeight()), FALSE); + imageArea.MoveWindow(GRIP_SIZE, GRIP_SIZE, Zoomed(imageModel.GetWidth()), Zoomed(imageModel.GetHeight()), FALSE); scrollboxWindow.Invalidate(TRUE); imageArea.Invalidate(FALSE);