[MSPAINT] Define GRIP_SIZE macro and use it (#4192)

Reduce magic numbers. CORE-17931
This commit is contained in:
Katayama Hirofumi MZ 2021-12-26 23:05:47 +09:00 committed by GitHub
parent 9e1386db43
commit 614354ccb5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 51 additions and 53 deletions

View file

@ -23,3 +23,5 @@ static inline int UnZoomed(int xy)
{ {
return xy * 1000 / toolsModel.GetZoom(); return xy * 1000 / toolsModel.GetZoom();
} }
#define GRIP_SIZE 3

View file

@ -23,7 +23,7 @@ updateCanvasAndScrollbars()
int zoomedWidth = Zoomed(imageModel.GetWidth()); int zoomedWidth = Zoomed(imageModel.GetWidth());
int zoomedHeight = Zoomed(imageModel.GetHeight()); int zoomedHeight = Zoomed(imageModel.GetHeight());
imageArea.MoveWindow(3, 3, zoomedWidth, zoomedHeight, FALSE); imageArea.MoveWindow(GRIP_SIZE, GRIP_SIZE, zoomedWidth, zoomedHeight, FALSE);
scrollboxWindow.Invalidate(TRUE); scrollboxWindow.Invalidate(TRUE);
imageArea.Invalidate(FALSE); imageArea.Invalidate(FALSE);
@ -74,28 +74,30 @@ LRESULT CImgAreaWindow::OnSize(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bH
int imgYRes = imageModel.GetHeight(); int imgYRes = imageModel.GetHeight();
sizeboxLeftTop.MoveWindow( sizeboxLeftTop.MoveWindow(
0, 0,
0, 3, 3, TRUE); 0, GRIP_SIZE, GRIP_SIZE, TRUE);
sizeboxCenterTop.MoveWindow( sizeboxCenterTop.MoveWindow(
Zoomed(imgXRes) / 2 + 3 * 3 / 4, GRIP_SIZE + (Zoomed(imgXRes) - GRIP_SIZE) / 2,
0, 3, 3, TRUE); 0, GRIP_SIZE, GRIP_SIZE, TRUE);
sizeboxRightTop.MoveWindow( sizeboxRightTop.MoveWindow(
Zoomed(imgXRes) + 3, GRIP_SIZE + Zoomed(imgXRes),
0, 3, 3, TRUE); 0, GRIP_SIZE, GRIP_SIZE, TRUE);
sizeboxLeftCenter.MoveWindow( sizeboxLeftCenter.MoveWindow(
0, 0,
Zoomed(imgYRes) / 2 + 3 * 3 / 4, 3, 3, TRUE); GRIP_SIZE + (Zoomed(imgYRes) - GRIP_SIZE) / 2,
GRIP_SIZE, GRIP_SIZE, TRUE);
sizeboxRightCenter.MoveWindow( sizeboxRightCenter.MoveWindow(
Zoomed(imgXRes) + 3, GRIP_SIZE + Zoomed(imgXRes),
Zoomed(imgYRes) / 2 + 3 * 3 / 4, 3, 3, TRUE); GRIP_SIZE + (Zoomed(imgYRes) - GRIP_SIZE) / 2,
GRIP_SIZE, GRIP_SIZE, TRUE);
sizeboxLeftBottom.MoveWindow( sizeboxLeftBottom.MoveWindow(
0, 0,
Zoomed(imgYRes) + 3, 3, 3, TRUE); GRIP_SIZE + Zoomed(imgYRes), GRIP_SIZE, GRIP_SIZE, TRUE);
sizeboxCenterBottom.MoveWindow( sizeboxCenterBottom.MoveWindow(
Zoomed(imgXRes) / 2 + 3 * 3 / 4, GRIP_SIZE + (Zoomed(imgXRes) - GRIP_SIZE) / 2,
Zoomed(imgYRes) + 3, 3, 3, TRUE); GRIP_SIZE + Zoomed(imgYRes), GRIP_SIZE, GRIP_SIZE, TRUE);
sizeboxRightBottom.MoveWindow( sizeboxRightBottom.MoveWindow(
Zoomed(imgXRes) + 3, GRIP_SIZE + Zoomed(imgXRes),
Zoomed(imgYRes) + 3, 3, 3, TRUE); GRIP_SIZE + Zoomed(imgYRes), GRIP_SIZE, GRIP_SIZE, TRUE);
UpdateScrollbox(); UpdateScrollbox();
return 0; return 0;
} }

View file

@ -248,7 +248,7 @@ _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR lpszArgument
selectionWindow.Create(scrlClientWindow.m_hWnd, selectionWindowPos, NULL, WS_CHILD | BS_OWNERDRAW); 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 */ /* 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); imageArea.Create(scrlClientWindow.m_hWnd, imageAreaPos, NULL, WS_CHILD | WS_VISIBLE);
if (__argc >= 2) if (__argc >= 2)
@ -312,7 +312,7 @@ _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR lpszArgument
} }
/* creating the size boxes */ /* 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); sizeboxLeftTop.Create(scrlClientWindow.m_hWnd, sizeboxPos, NULL, WS_CHILD | WS_VISIBLE);
sizeboxCenterTop.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); 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); sizeboxCenterBottom.Create(scrlClientWindow.m_hWnd, sizeboxPos, NULL, WS_CHILD | WS_VISIBLE);
sizeboxRightBottom.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 */ /* 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 */ /* by moving the window, the things in WM_SIZE are done */
mainWindow.SetWindowPlacement(&(registrySettings.WindowPlacement)); mainWindow.SetWindowPlacement(&(registrySettings.WindowPlacement));

View file

@ -16,7 +16,8 @@ void
placeSelWin() placeSelWin()
{ {
selectionWindow.MoveWindow(Zoomed(selectionModel.GetDestRectLeft()), Zoomed(selectionModel.GetDestRectTop()), 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(); selectionWindow.BringWindowToTop();
imageArea.InvalidateRect(NULL, FALSE); imageArea.InvalidateRect(NULL, FALSE);
} }

View file

@ -52,8 +52,6 @@ CONST INT VSCROLL_WIDTH = ::GetSystemMetrics(SM_CXVSCROLL);
void void
UpdateScrollbox() UpdateScrollbox()
{ {
CONST INT EXTRASIZE = 5; /* 3 px of selection markers + 2 px of border */
CRect tempRect; CRect tempRect;
CSize sizeImageArea; CSize sizeImageArea;
CSize sizeScrollBox; CSize sizeScrollBox;
@ -65,7 +63,7 @@ UpdateScrollbox()
imageArea.GetClientRect(&tempRect); imageArea.GetClientRect(&tempRect);
sizeImageArea = CSize(tempRect.Width(), tempRect.Height()); sizeImageArea = CSize(tempRect.Width(), tempRect.Height());
sizeImageArea += CSize(EXTRASIZE * 2, EXTRASIZE * 2); sizeImageArea += CSize(GRIP_SIZE * 2, GRIP_SIZE * 2);
/* show/hide the scrollbars */ /* show/hide the scrollbars */
vmode = (sizeScrollBox.cy < sizeImageArea.cy ? 0 : 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); scrollboxWindow.SetScrollInfo(SB_HORZ, &si);
scrlClientWindow.MoveWindow(-scrollboxWindow.GetScrollPos(SB_HORZ), scrlClientWindow.MoveWindow(-scrollboxWindow.GetScrollPos(SB_HORZ),
-scrollboxWindow.GetScrollPos(SB_VERT), Zoomed(imageModel.GetWidth()) + 6, -scrollboxWindow.GetScrollPos(SB_VERT),
Zoomed(imageModel.GetHeight()) + 6, TRUE); Zoomed(imageModel.GetWidth()) + 2 * GRIP_SIZE,
Zoomed(imageModel.GetHeight()) + 2 * GRIP_SIZE, TRUE);
} }
return 0; return 0;
} }
@ -167,8 +166,9 @@ LRESULT CScrollboxWindow::OnVScroll(UINT nMsg, WPARAM wParam, LPARAM lParam, BOO
} }
scrollboxWindow.SetScrollInfo(SB_VERT, &si); scrollboxWindow.SetScrollInfo(SB_VERT, &si);
scrlClientWindow.MoveWindow(-scrollboxWindow.GetScrollPos(SB_HORZ), scrlClientWindow.MoveWindow(-scrollboxWindow.GetScrollPos(SB_HORZ),
-scrollboxWindow.GetScrollPos(SB_VERT), Zoomed(imageModel.GetWidth()) + 6, -scrollboxWindow.GetScrollPos(SB_VERT),
Zoomed(imageModel.GetHeight()) + 6, TRUE); Zoomed(imageModel.GetWidth()) + 2 * GRIP_SIZE,
Zoomed(imageModel.GetHeight()) + 2 * GRIP_SIZE, TRUE);
} }
return 0; return 0;
} }

View file

@ -65,31 +65,24 @@ ForceRefreshSelectionContents()
int CSelectionWindow::IdentifyCorner(int iXPos, int iYPos, int iWidth, int iHeight) int CSelectionWindow::IdentifyCorner(int iXPos, int iYPos, int iWidth, int iHeight)
{ {
if (iYPos < 3) POINT pt = { iXPos, iYPos };
{ HWND hwndChild = ChildWindowFromPointEx(pt, CWP_SKIPINVISIBLE | CWP_SKIPDISABLED);
if (iXPos < 3) if (hwndChild == sizeboxLeftTop)
return ACTION_RESIZE_TOP_LEFT; return ACTION_RESIZE_TOP_LEFT;
if ((iXPos < iWidth / 2 + 2) && (iXPos >= iWidth / 2 - 1)) if (hwndChild == sizeboxCenterTop)
return ACTION_RESIZE_TOP; return ACTION_RESIZE_TOP;
if (iXPos >= iWidth - 3) if (hwndChild == sizeboxRightTop)
return ACTION_RESIZE_TOP_RIGHT; return ACTION_RESIZE_TOP_RIGHT;
} if (hwndChild == sizeboxRightCenter)
if ((iYPos < iHeight / 2 + 2) && (iYPos >= iHeight / 2 - 1)) return ACTION_RESIZE_RIGHT;
{ if (hwndChild == sizeboxLeftCenter)
if (iXPos < 3) return ACTION_RESIZE_LEFT;
return ACTION_RESIZE_LEFT; if (hwndChild == sizeboxCenterBottom)
if (iXPos >= iWidth - 3) return ACTION_RESIZE_BOTTOM;
return ACTION_RESIZE_RIGHT; if (hwndChild == sizeboxRightBottom)
} return ACTION_RESIZE_BOTTOM_RIGHT;
if (iYPos >= iHeight - 3) if (hwndChild == sizeboxLeftBottom)
{ return ACTION_RESIZE_BOTTOM_LEFT;
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;
}
return 0; return 0;
} }
@ -197,8 +190,8 @@ LRESULT CSelectionWindow::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, B
} }
else else
{ {
int w = Zoomed(selectionModel.GetDestRectWidth()) + 6; int w = Zoomed(selectionModel.GetDestRectWidth()) + 2 * GRIP_SIZE;
int h = Zoomed(selectionModel.GetDestRectHeight()) + 6; int h = Zoomed(selectionModel.GetDestRectHeight()) + 2 * GRIP_SIZE;
m_ptPos.x = GET_X_LPARAM(lParam); m_ptPos.x = GET_X_LPARAM(lParam);
m_ptPos.y = GET_Y_LPARAM(lParam); m_ptPos.y = GET_Y_LPARAM(lParam);
SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) NULL); SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) NULL);

View file

@ -39,7 +39,7 @@ zoomTo(int newZoom, int mouseX, int mouseY)
toolsModel.SetZoom(newZoom); toolsModel.SetZoom(newZoom);
selectionWindow.ShowWindow(SW_HIDE); 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); scrollboxWindow.Invalidate(TRUE);
imageArea.Invalidate(FALSE); imageArea.Invalidate(FALSE);