diff --git a/base/applications/mspaint/globalvar.h b/base/applications/mspaint/globalvar.h index cb6eed1ebd42a..e2257fbb69321 100644 --- a/base/applications/mspaint/globalvar.h +++ b/base/applications/mspaint/globalvar.h @@ -11,8 +11,6 @@ extern BOOL g_askBeforeEnlarging; -extern POINT g_ptStart, g_ptEnd; - extern HINSTANCE g_hinstExe; extern WCHAR g_szFileName[MAX_LONG_PATH]; diff --git a/base/applications/mspaint/main.cpp b/base/applications/mspaint/main.cpp index 470c4fd4348c8..dcc3bab80f13d 100644 --- a/base/applications/mspaint/main.cpp +++ b/base/applications/mspaint/main.cpp @@ -10,7 +10,6 @@ #include #include -POINT g_ptStart, g_ptEnd; BOOL g_askBeforeEnlarging = FALSE; // TODO: initialize from registry HINSTANCE g_hinstExe = NULL; WCHAR g_szFileName[MAX_LONG_PATH] = { 0 }; diff --git a/base/applications/mspaint/mouse.cpp b/base/applications/mspaint/mouse.cpp index d4b22296a16ea..ad709d9c3dbbf 100644 --- a/base/applications/mspaint/mouse.cpp +++ b/base/applications/mspaint/mouse.cpp @@ -3,7 +3,7 @@ * LICENSE: LGPL-2.0-or-later (https://spdx.org/licenses/LGPL-2.0-or-later) * PURPOSE: Things which should not be in the mouse event handler itself * COPYRIGHT: Copyright 2015 Benedikt Freisen - * Copyright 2021 Katayama Hirofumi MZ + * Copyright 2021-2023 Katayama Hirofumi MZ */ /* INCLUDES *********************************************************/ @@ -12,6 +12,7 @@ INT ToolBase::s_pointSP = 0; POINT ToolBase::s_pointStack[256] = { { 0 } }; +static POINT g_ptStart, g_ptEnd; /* FUNCTIONS ********************************************************/ @@ -1097,3 +1098,129 @@ ToolBase::createToolObject(TOOLTYPE type) UNREACHABLE; return NULL; } + +void ToolsModel::OnButtonDown(BOOL bLeftButton, LONG x, LONG y, BOOL bDoubleClick) +{ + m_pToolObject->beginEvent(); + g_ptStart.x = g_ptEnd.x = x; + g_ptStart.y = g_ptEnd.y = y; + m_pToolObject->OnButtonDown(bLeftButton, x, y, bDoubleClick); + m_pToolObject->endEvent(); +} + +void ToolsModel::OnMouseMove(BOOL bLeftButton, LONG x, LONG y) +{ + m_pToolObject->beginEvent(); + if (m_pToolObject->OnMouseMove(bLeftButton, x, y)) + { + g_ptEnd.x = x; + g_ptEnd.y = y; + } + m_pToolObject->endEvent(); +} + +void ToolsModel::OnButtonUp(BOOL bLeftButton, LONG x, LONG y) +{ + m_pToolObject->beginEvent(); + if (m_pToolObject->OnButtonUp(bLeftButton, x, y)) + { + g_ptEnd.x = x; + g_ptEnd.y = y; + } + m_pToolObject->endEvent(); +} + +void ToolsModel::OnEndDraw(BOOL bCancel) +{ + ATLTRACE("ToolsModel::OnEndDraw(%d)\n", bCancel); + m_pToolObject->beginEvent(); + m_pToolObject->OnEndDraw(bCancel); + m_pToolObject->endEvent(); +} + +void ToolsModel::OnDrawOverlayOnImage(HDC hdc) +{ + m_pToolObject->OnDrawOverlayOnImage(hdc); +} + +void ToolsModel::OnDrawOverlayOnCanvas(HDC hdc) +{ + m_pToolObject->OnDrawOverlayOnCanvas(hdc); +} + +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.cpp b/base/applications/mspaint/toolsmodel.cpp index 0700617403e67..884b92d7d6c4e 100644 --- a/base/applications/mspaint/toolsmodel.cpp +++ b/base/applications/mspaint/toolsmodel.cpp @@ -255,55 +255,6 @@ void ToolsModel::NotifyZoomChanged() canvasWindow.SendMessage(WM_TOOLSMODELZOOMCHANGED); } -void ToolsModel::OnButtonDown(BOOL bLeftButton, LONG x, LONG y, BOOL bDoubleClick) -{ - m_pToolObject->beginEvent(); - g_ptStart.x = g_ptEnd.x = x; - g_ptStart.y = g_ptEnd.y = y; - m_pToolObject->OnButtonDown(bLeftButton, x, y, bDoubleClick); - m_pToolObject->endEvent(); -} - -void ToolsModel::OnMouseMove(BOOL bLeftButton, LONG x, LONG y) -{ - m_pToolObject->beginEvent(); - if (m_pToolObject->OnMouseMove(bLeftButton, x, y)) - { - g_ptEnd.x = x; - g_ptEnd.y = y; - } - m_pToolObject->endEvent(); -} - -void ToolsModel::OnButtonUp(BOOL bLeftButton, LONG x, LONG y) -{ - m_pToolObject->beginEvent(); - if (m_pToolObject->OnButtonUp(bLeftButton, x, y)) - { - g_ptEnd.x = x; - g_ptEnd.y = y; - } - m_pToolObject->endEvent(); -} - -void ToolsModel::OnEndDraw(BOOL bCancel) -{ - ATLTRACE("ToolsModel::OnEndDraw(%d)\n", bCancel); - m_pToolObject->beginEvent(); - m_pToolObject->OnEndDraw(bCancel); - m_pToolObject->endEvent(); -} - -void ToolsModel::OnDrawOverlayOnImage(HDC hdc) -{ - m_pToolObject->OnDrawOverlayOnImage(hdc); -} - -void ToolsModel::OnDrawOverlayOnCanvas(HDC hdc) -{ - m_pToolObject->OnDrawOverlayOnCanvas(hdc); -} - void ToolsModel::resetTool() { m_pToolObject->reset(); @@ -316,80 +267,3 @@ void ToolsModel::selectAll() OnMouseMove(TRUE, imageModel.GetWidth(), imageModel.GetHeight()); OnButtonUp(TRUE, imageModel.GetWidth(), imageModel.GetHeight()); } - -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); - } - } -}