https://git.reactos.org/?p=reactos.git;a=commitdiff;h=a114169c4de46e464ca7c…
commit a114169c4de46e464ca7c7d37566b8883da8ec63
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Fri Nov 3 22:41:06 2023 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Fri Nov 3 22:41:06 2023 +0900
[MSPAINT] Refactor mouse moving code on canvas (#5878)
Move some mouse moving code to toolsModel.
CORE-19094
---
base/applications/mspaint/canvas.cpp | 73 +-------------------------------
base/applications/mspaint/toolsmodel.cpp | 72 +++++++++++++++++++++++++++++++
base/applications/mspaint/toolsmodel.h | 2 +
3 files changed, 75 insertions(+), 72 deletions(-)
diff --git a/base/applications/mspaint/canvas.cpp b/base/applications/mspaint/canvas.cpp
index 4b19a34e10d..b1b76ce9901 100644
--- a/base/applications/mspaint/canvas.cpp
+++ b/base/applications/mspaint/canvas.cpp
@@ -459,78 +459,7 @@ LRESULT CCanvasWindow::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM
lParam, BOOL
if (m_drawing)
{
- // values displayed in statusbar
- LONG xRel = pt.x - g_ptStart.x;
- LONG yRel = pt.y - g_ptStart.y;
-
- switch (toolsModel.GetActiveTool())
- {
- // freesel, rectsel and text tools always show numbers limited to fit into
image area
- case TOOL_FREESEL:
- case TOOL_RECTSEL:
- case TOOL_TEXT:
- if (xRel < 0)
- xRel = (pt.x < 0) ? -g_ptStart.x : xRel;
- else if (pt.x > imageModel.GetWidth())
- xRel = imageModel.GetWidth() - g_ptStart.x;
- if (yRel < 0)
- yRel = (pt.y < 0) ? -g_ptStart.y : yRel;
- else if (pt.y > imageModel.GetHeight())
- yRel = imageModel.GetHeight() - g_ptStart.y;
- break;
-
- // while drawing, update cursor coordinates only for tools 3, 7, 8, 9, 14
- case TOOL_RUBBER:
- case TOOL_PEN:
- case TOOL_BRUSH:
- case TOOL_AIRBRUSH:
- case TOOL_SHAPE:
- {
- CString strCoord;
- strCoord.Format(_T("%ld, %ld"), pt.x, pt.y);
- ::SendMessage(g_hStatusBar, SB_SETTEXT, 1, (LPARAM) (LPCTSTR) strCoord);
- break;
- }
- default:
- break;
- }
-
- // rectsel and shape tools always show non-negative numbers when drawing
- if (toolsModel.GetActiveTool() == TOOL_RECTSEL || toolsModel.GetActiveTool() ==
TOOL_SHAPE)
- {
- if (xRel < 0)
- xRel = -xRel;
- if (yRel < 0)
- yRel = -yRel;
- }
-
- if (wParam & MK_LBUTTON)
- {
- toolsModel.OnMouseMove(TRUE, pt.x, pt.y);
- Invalidate(FALSE);
- if ((toolsModel.GetActiveTool() >= TOOL_TEXT) ||
toolsModel.IsSelection())
- {
- CString strSize;
- if ((toolsModel.GetActiveTool() >= TOOL_LINE) &&
(GetAsyncKeyState(VK_SHIFT) < 0))
- yRel = xRel;
- strSize.Format(_T("%ld x %ld"), xRel, yRel);
- ::SendMessage(g_hStatusBar, SB_SETTEXT, 2, (LPARAM) (LPCTSTR) strSize);
- }
- }
-
- if (wParam & MK_RBUTTON)
- {
- toolsModel.OnMouseMove(FALSE, pt.x, pt.y);
- Invalidate(FALSE);
- if (toolsModel.GetActiveTool() >= TOOL_TEXT)
- {
- CString strSize;
- if ((toolsModel.GetActiveTool() >= TOOL_LINE) &&
(GetAsyncKeyState(VK_SHIFT) < 0))
- yRel = xRel;
- strSize.Format(_T("%ld x %ld"), xRel, yRel);
- ::SendMessage(g_hStatusBar, SB_SETTEXT, 2, (LPARAM) (LPCTSTR) strSize);
- }
- }
+ toolsModel.DrawWithMouseTool(pt, wParam);
return 0;
}
diff --git a/base/applications/mspaint/toolsmodel.cpp
b/base/applications/mspaint/toolsmodel.cpp
index 6efb859066b..0700617403e 100644
--- a/base/applications/mspaint/toolsmodel.cpp
+++ b/base/applications/mspaint/toolsmodel.cpp
@@ -321,3 +321,75 @@ void ToolsModel::SpecialTweak(BOOL bMinus)
{
m_pToolObject->OnSpecialTweak(bMinus);
}
+
+void ToolsModel::DrawWithMouseTool(POINT pt, WPARAM wParam)
+{
+ LONG xRel = pt.x - g_ptStart.x, yRel = pt.y - g_ptStart.y;
+
+ switch (m_activeTool)
+ {
+ // freesel, rectsel and text tools always show numbers limited to fit into image
area
+ case TOOL_FREESEL:
+ case TOOL_RECTSEL:
+ case TOOL_TEXT:
+ if (xRel < 0)
+ xRel = (pt.x < 0) ? -g_ptStart.x : xRel;
+ else if (pt.x > imageModel.GetWidth())
+ xRel = imageModel.GetWidth() - g_ptStart.x;
+ if (yRel < 0)
+ yRel = (pt.y < 0) ? -g_ptStart.y : yRel;
+ else if (pt.y > imageModel.GetHeight())
+ yRel = imageModel.GetHeight() - g_ptStart.y;
+ break;
+
+ // while drawing, update cursor coordinates only for tools 3, 7, 8, 9, 14
+ case TOOL_RUBBER:
+ case TOOL_PEN:
+ case TOOL_BRUSH:
+ case TOOL_AIRBRUSH:
+ case TOOL_SHAPE:
+ {
+ CStringW strCoord;
+ strCoord.Format(L"%ld, %ld", pt.x, pt.y);
+ ::SendMessageW(g_hStatusBar, SB_SETTEXT, 1, (LPARAM)(LPCWSTR)strCoord);
+ break;
+ }
+ default:
+ break;
+ }
+
+ // rectsel and shape tools always show non-negative numbers when drawing
+ if (m_activeTool == TOOL_RECTSEL || m_activeTool == TOOL_SHAPE)
+ {
+ xRel = labs(xRel);
+ yRel = labs(yRel);
+ }
+
+ if (wParam & MK_LBUTTON)
+ {
+ OnMouseMove(TRUE, pt.x, pt.y);
+ canvasWindow.Invalidate(FALSE);
+ if ((m_activeTool >= TOOL_TEXT) || IsSelection())
+ {
+ CStringW strSize;
+ if ((m_activeTool >= TOOL_LINE) && (GetAsyncKeyState(VK_SHIFT)
< 0))
+ yRel = xRel;
+ strSize.Format(L"%ld x %ld", xRel, yRel);
+ ::SendMessageW(g_hStatusBar, SB_SETTEXT, 2, (LPARAM)(LPCWSTR)strSize);
+ }
+ }
+
+ if (wParam & MK_RBUTTON)
+ {
+ OnMouseMove(FALSE, pt.x, pt.y);
+ canvasWindow.Invalidate(FALSE);
+ if (m_activeTool >= TOOL_TEXT)
+ {
+ CStringW strSize;
+ if ((m_activeTool >= TOOL_LINE) && (GetAsyncKeyState(VK_SHIFT)
< 0))
+ yRel = xRel;
+ strSize.Format(L"%ld x %ld", xRel, yRel);
+ ::SendMessageW(g_hStatusBar, SB_SETTEXT, 2, (LPARAM)(LPCWSTR)strSize);
+ }
+ }
+}
diff --git a/base/applications/mspaint/toolsmodel.h
b/base/applications/mspaint/toolsmodel.h
index 3cd14e8e6d3..9af67a501c7 100644
--- a/base/applications/mspaint/toolsmodel.h
+++ b/base/applications/mspaint/toolsmodel.h
@@ -145,6 +145,8 @@ public:
void NotifyZoomChanged();
void SpecialTweak(BOOL bMinus);
+
+ void DrawWithMouseTool(POINT pt, WPARAM wParam);
};
extern ToolsModel toolsModel;