https://git.reactos.org/?p=reactos.git;a=commitdiff;h=37f56d2448059c78f8cde…
commit 37f56d2448059c78f8cde65915b7a2103c06c3c4
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Fri Nov 3 16:20:03 2023 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Fri Nov 3 16:20:03 2023 +0900
[MSPAINT] Commonize OnFinishDraw and OnCancelDraw (#5875)
Reduce code and binary size a bit. This will reduce 1024 bytes in binary.
Unify ToolBase::OnFinishDraw and ToolBase::OnCancelDraw to ToolBase::OnEndDraw.
CORE-19094
---
base/applications/mspaint/canvas.cpp | 8 +-
base/applications/mspaint/mouse.cpp | 140 ++++++++++++-------------------
base/applications/mspaint/textedit.cpp | 2 +-
base/applications/mspaint/toolsmodel.cpp | 16 +---
base/applications/mspaint/toolsmodel.h | 8 +-
5 files changed, 67 insertions(+), 107 deletions(-)
diff --git a/base/applications/mspaint/canvas.cpp b/base/applications/mspaint/canvas.cpp
index b423662d882..4b19a34e10d 100644
--- a/base/applications/mspaint/canvas.cpp
+++ b/base/applications/mspaint/canvas.cpp
@@ -357,13 +357,13 @@ LRESULT CCanvasWindow::OnButtonDown(UINT nMsg, WPARAM wParam, LPARAM
lParam, BOO
{
case TOOL_BEZIER:
case TOOL_SHAPE:
- toolsModel.OnCancelDraw();
+ toolsModel.OnEndDraw(TRUE);
Invalidate();
break;
case TOOL_FREESEL:
case TOOL_RECTSEL:
- toolsModel.OnFinishDraw();
+ toolsModel.OnEndDraw(FALSE);
Invalidate();
break;
@@ -814,13 +814,13 @@ VOID CCanvasWindow::cancelDrawing()
selectionModel.ClearMaskImage();
m_hitSelection = HIT_NONE;
m_drawing = FALSE;
- toolsModel.OnCancelDraw();
+ toolsModel.OnEndDraw(TRUE);
Invalidate(FALSE);
}
VOID CCanvasWindow::finishDrawing()
{
- toolsModel.OnFinishDraw();
+ toolsModel.OnEndDraw(FALSE);
m_drawing = FALSE;
Invalidate(FALSE);
}
diff --git a/base/applications/mspaint/mouse.cpp b/base/applications/mspaint/mouse.cpp
index c7c19e16544..01379f97dc7 100644
--- a/base/applications/mspaint/mouse.cpp
+++ b/base/applications/mspaint/mouse.cpp
@@ -62,13 +62,7 @@ void ToolBase::reset()
}
}
-void ToolBase::OnCancelDraw()
-{
- reset();
- imageModel.NotifyImageChanged();
-}
-
-void ToolBase::OnFinishDraw()
+void ToolBase::OnEndDraw(BOOL bCancel)
{
reset();
imageModel.NotifyImageChanged();
@@ -175,16 +169,13 @@ struct FreeSelTool : ToolBase
return TRUE;
}
- void OnFinishDraw() override
+ void OnEndDraw(BOOL bCancel) override
{
- selectionModel.Landing();
- ToolBase::OnFinishDraw();
- }
-
- void OnCancelDraw() override
- {
- selectionModel.HideSelection();
- ToolBase::OnCancelDraw();
+ if (bCancel)
+ selectionModel.HideSelection();
+ else
+ selectionModel.Landing();
+ ToolBase::OnEndDraw(bCancel);
}
void OnSpecialTweak(BOOL bMinus) override
@@ -260,16 +251,13 @@ struct RectSelTool : ToolBase
return TRUE;
}
- void OnFinishDraw() override
+ void OnEndDraw(BOOL bCancel) override
{
- selectionModel.Landing();
- ToolBase::OnFinishDraw();
- }
-
- void OnCancelDraw() override
- {
- selectionModel.HideSelection();
- ToolBase::OnCancelDraw();
+ if (bCancel)
+ selectionModel.HideSelection();
+ else
+ selectionModel.Landing();
+ ToolBase::OnEndDraw(bCancel);
}
void OnSpecialTweak(BOOL bMinus) override
@@ -309,16 +297,10 @@ struct TwoPointDrawTool : ToolBase
return TRUE;
}
- void OnFinishDraw() override
- {
- m_bDrawing = FALSE;
- ToolBase::OnFinishDraw();
- }
-
- void OnCancelDraw() override
+ void OnEndDraw(BOOL bCancel) override
{
m_bDrawing = FALSE;
- ToolBase::OnCancelDraw();
+ ToolBase::OnEndDraw(bCancel);
}
void OnSpecialTweak(BOOL bMinus) override
@@ -471,21 +453,19 @@ struct SmoothDrawTool : ToolBase
}
draw(bLeftButton, x, y);
- OnFinishDraw();
+ OnEndDraw(FALSE);
return TRUE;
}
- void OnFinishDraw() override
- {
- ToolBase::OnFinishDraw();
- }
-
- void OnCancelDraw() override
+ void OnEndDraw(BOOL bCancel) override
{
- LONG x = 0, y = 0;
- OnButtonUp(FALSE, x, y);
- imageModel.Undo(TRUE);
- ToolBase::OnCancelDraw();
+ if (bCancel)
+ {
+ LONG x = 0, y = 0;
+ OnButtonUp(FALSE, x, y);
+ imageModel.Undo(TRUE);
+ }
+ ToolBase::OnEndDraw(bCancel);
}
};
@@ -799,22 +779,19 @@ struct TextTool : ToolBase
return TRUE;
}
- void OnFinishDraw() override
+ void OnEndDraw(BOOL bCancel) override
{
- if (::IsWindowVisible(textEditWindow) &&
- textEditWindow.GetWindowTextLength() > 0)
+ if (!bCancel)
{
- imageModel.PushImageForUndo();
- draw(m_hdc);
+ if (::IsWindowVisible(textEditWindow) &&
+ textEditWindow.GetWindowTextLength() > 0)
+ {
+ imageModel.PushImageForUndo();
+ draw(m_hdc);
+ }
}
quit();
- ToolBase::OnFinishDraw();
- }
-
- void OnCancelDraw() override
- {
- quit();
- ToolBase::OnCancelDraw();
+ ToolBase::OnEndDraw(bCancel);
}
};
@@ -902,25 +879,22 @@ struct BezierTool : ToolBase
s_pointStack[s_pointSP].y = y;
if (s_pointSP >= 3)
{
- OnFinishDraw();
+ OnEndDraw(FALSE);
return TRUE;
}
imageModel.NotifyImageChanged();
return TRUE;
}
- void OnCancelDraw() override
+ void OnEndDraw(BOOL bCancel) override
{
+ if (!bCancel)
+ {
+ imageModel.PushImageForUndo();
+ OnDrawOverlayOnImage(m_hdc);
+ }
m_bDrawing = FALSE;
- ToolBase::OnCancelDraw();
- }
-
- void OnFinishDraw() override
- {
- imageModel.PushImageForUndo();
- OnDrawOverlayOnImage(m_hdc);
- m_bDrawing = FALSE;
- ToolBase::OnFinishDraw();
+ ToolBase::OnEndDraw(bCancel);
}
void OnSpecialTweak(BOOL bMinus) override
@@ -983,7 +957,7 @@ struct ShapeTool : ToolBase
if (s_pointSP && bDoubleClick)
{
- OnFinishDraw();
+ OnEndDraw(FALSE);
return;
}
@@ -1017,7 +991,7 @@ struct ShapeTool : ToolBase
m_bClosed = FALSE;
if (nearlyEqualPoints(x, y, s_pointStack[0].x, s_pointStack[0].y))
{
- OnFinishDraw();
+ OnEndDraw(FALSE);
return TRUE;
}
else
@@ -1034,26 +1008,22 @@ struct ShapeTool : ToolBase
return TRUE;
}
- void OnCancelDraw() override
+ void OnEndDraw(BOOL bCancel) override
{
- ToolBase::OnCancelDraw();
- }
-
- void OnFinishDraw() override
- {
- if (s_pointSP)
+ if (!bCancel)
{
- --s_pointSP;
- m_bClosed = TRUE;
+ if (s_pointSP)
+ {
+ --s_pointSP;
+ m_bClosed = TRUE;
- imageModel.PushImageForUndo();
- OnDrawOverlayOnImage(m_hdc);
+ imageModel.PushImageForUndo();
+ OnDrawOverlayOnImage(m_hdc);
+ }
+ m_bClosed = FALSE;
+ s_pointSP = 0;
}
-
- m_bClosed = FALSE;
- s_pointSP = 0;
-
- ToolBase::OnFinishDraw();
+ ToolBase::OnEndDraw(bCancel);
}
void OnSpecialTweak(BOOL bMinus) override
diff --git a/base/applications/mspaint/textedit.cpp
b/base/applications/mspaint/textedit.cpp
index 39cc1ba40e3..5261da63a0e 100644
--- a/base/applications/mspaint/textedit.cpp
+++ b/base/applications/mspaint/textedit.cpp
@@ -104,7 +104,7 @@ LRESULT CTextEditWindow::OnKeyDown(UINT nMsg, WPARAM wParam, LPARAM
lParam, BOOL
{
if (wParam == VK_ESCAPE)
{
- toolsModel.OnCancelDraw();
+ toolsModel.OnEndDraw(TRUE);
return 0;
}
diff --git a/base/applications/mspaint/toolsmodel.cpp
b/base/applications/mspaint/toolsmodel.cpp
index dec101adc9e..a8a7b490803 100644
--- a/base/applications/mspaint/toolsmodel.cpp
+++ b/base/applications/mspaint/toolsmodel.cpp
@@ -145,7 +145,7 @@ TOOLTYPE ToolsModel::GetOldActiveTool() const
void ToolsModel::SetActiveTool(TOOLTYPE nActiveTool)
{
- OnFinishDraw();
+ OnEndDraw(FALSE);
selectionModel.Landing();
@@ -288,19 +288,11 @@ void ToolsModel::OnButtonUp(BOOL bLeftButton, LONG x, LONG y)
m_pToolObject->endEvent();
}
-void ToolsModel::OnCancelDraw()
+void ToolsModel::OnEndDraw(BOOL bCancel)
{
- ATLTRACE("ToolsModel::OnCancelDraw()\n");
+ ATLTRACE("ToolsModel::OnEndDraw(%d)\n", bCancel);
m_pToolObject->beginEvent();
- m_pToolObject->OnCancelDraw();
- m_pToolObject->endEvent();
-}
-
-void ToolsModel::OnFinishDraw()
-{
- ATLTRACE("ToolsModel::OnFinishDraw()\n");
- m_pToolObject->beginEvent();
- m_pToolObject->OnFinishDraw();
+ m_pToolObject->OnEndDraw(bCancel);
m_pToolObject->endEvent();
}
diff --git a/base/applications/mspaint/toolsmodel.h
b/base/applications/mspaint/toolsmodel.h
index d90faee117b..51ddb0d46d2 100644
--- a/base/applications/mspaint/toolsmodel.h
+++ b/base/applications/mspaint/toolsmodel.h
@@ -53,14 +53,13 @@ struct ToolBase
virtual BOOL OnMouseMove(BOOL bLeftButton, LONG& x, LONG& y) { return TRUE;
}
virtual BOOL OnButtonUp(BOOL bLeftButton, LONG& x, LONG& y) { return TRUE; }
- virtual void OnCancelDraw();
- virtual void OnFinishDraw();
-
virtual void OnDrawOverlayOnImage(HDC hdc) { }
virtual void OnDrawOverlayOnCanvas(HDC hdc) { }
virtual void OnSpecialTweak(BOOL bMinus) { }
+ virtual void OnEndDraw(BOOL bCancel);
+
void beginEvent();
void endEvent();
void reset();
@@ -135,8 +134,7 @@ public:
void OnButtonDown(BOOL bLeftButton, LONG x, LONG y, BOOL bDoubleClick);
void OnMouseMove(BOOL bLeftButton, LONG x, LONG y);
void OnButtonUp(BOOL bLeftButton, LONG x, LONG y);
- void OnCancelDraw();
- void OnFinishDraw();
+ void OnEndDraw(BOOL bCancel);
void OnDrawOverlayOnImage(HDC hdc);
void OnDrawOverlayOnCanvas(HDC hdc);