[MSPAINT] Move selection by arrow keys (#5334)

Improve keyboard usability.
- Add CCanvasWindow::MoveSelection.
- Modify CMainWindow::OnKeyDown.
- If Esc key is pressed, then the selection will land to canvas.
- If any arrow key is pressed, then the selection will move a bit.
CORE-18867
This commit is contained in:
Katayama Hirofumi MZ 2023-06-13 16:31:18 +09:00 committed by GitHub
parent 0087ea6597
commit 1a88607387
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 8 deletions

View file

@ -777,6 +777,16 @@ VOID CCanvasWindow::EndSelectionDrag(POINT ptImage)
Invalidate(FALSE);
}
VOID CCanvasWindow::MoveSelection(INT xDelta, INT yDelta)
{
if (!selectionModel.m_bShow)
return;
selectionModel.TakeOff();
::OffsetRect(&selectionModel.m_rc, xDelta, yDelta);
Invalidate(FALSE);
}
LRESULT CCanvasWindow::OnCtlColorEdit(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
SetTextColor((HDC)wParam, paletteModel.GetFgColor());

View file

@ -48,6 +48,7 @@ public:
VOID CanvasToImage(POINT& pt, BOOL bZoomed = FALSE);
VOID CanvasToImage(RECT& rc, BOOL bZoomed = FALSE);
VOID GetImageRect(RECT& rc);
VOID MoveSelection(INT xDelta, INT yDelta);
protected:
CANVAS_HITTEST m_hitSelection;

View file

@ -493,17 +493,39 @@ LRESULT CMainWindow::OnGetMinMaxInfo(UINT nMsg, WPARAM wParam, LPARAM lParam, BO
LRESULT CMainWindow::OnKeyDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
if (wParam == VK_ESCAPE)
HWND hwndCapture;
switch (wParam)
{
HWND hwndCapture = GetCapture();
if (hwndCapture)
{
if (canvasWindow.m_hWnd == hwndCapture ||
fullscreenWindow.m_hWnd == hwndCapture)
case VK_ESCAPE:
hwndCapture = GetCapture();
if (hwndCapture)
{
SendMessage(hwndCapture, nMsg, wParam, lParam);
if (canvasWindow.m_hWnd == hwndCapture ||
fullscreenWindow.m_hWnd == hwndCapture)
{
SendMessage(hwndCapture, nMsg, wParam, lParam);
}
}
}
else if (selectionModel.m_bShow)
{
selectionModel.Landing();
selectionModel.m_bShow = FALSE;
canvasWindow.Invalidate(FALSE);
}
break;
case VK_LEFT:
canvasWindow.MoveSelection(-1, 0);
break;
case VK_RIGHT:
canvasWindow.MoveSelection(+1, 0);
break;
case VK_UP:
canvasWindow.MoveSelection(0, -1);
break;
case VK_DOWN:
canvasWindow.MoveSelection(0, +1);
break;
}
return 0;
}