2015-07-07 11:15:24 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: PAINT for ReactOS
|
|
|
|
* LICENSE: LGPL
|
2015-09-09 13:13:35 +00:00
|
|
|
* FILE: base/applications/mspaint/toolsmodel.cpp
|
2015-07-07 11:15:24 +00:00
|
|
|
* PURPOSE: Keep track of tool parameters, notify listeners
|
|
|
|
* PROGRAMMERS: Benedikt Freisen
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *********************************************************/
|
|
|
|
|
|
|
|
#include "precomp.h"
|
|
|
|
|
|
|
|
/* FUNCTIONS ********************************************************/
|
|
|
|
|
|
|
|
ToolsModel::ToolsModel()
|
|
|
|
{
|
|
|
|
m_lineWidth = 1;
|
|
|
|
m_shapeStyle = 0;
|
|
|
|
m_brushStyle = 0;
|
2022-01-01 13:02:36 +00:00
|
|
|
m_oldActiveTool = m_activeTool = TOOL_PEN;
|
2015-07-07 11:15:24 +00:00
|
|
|
m_airBrushWidth = 5;
|
|
|
|
m_rubberRadius = 4;
|
|
|
|
m_transpBg = FALSE;
|
|
|
|
m_zoom = 1000;
|
2022-01-01 13:02:36 +00:00
|
|
|
ZeroMemory(&m_tools, sizeof(m_tools));
|
|
|
|
m_pToolObject = GetOrCreateTool(m_activeTool);
|
|
|
|
}
|
|
|
|
|
|
|
|
ToolsModel::~ToolsModel()
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < TOOL_MAX + 1; ++i)
|
|
|
|
delete m_tools[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
ToolBase *ToolsModel::GetOrCreateTool(TOOLTYPE nTool)
|
|
|
|
{
|
|
|
|
if (!m_tools[nTool])
|
|
|
|
m_tools[nTool] = ToolBase::createToolObject(nTool);
|
|
|
|
|
|
|
|
return m_tools[nTool];
|
2015-07-07 11:15:24 +00:00
|
|
|
}
|
|
|
|
|
2021-12-27 11:08:07 +00:00
|
|
|
int ToolsModel::GetLineWidth() const
|
2015-07-07 11:15:24 +00:00
|
|
|
{
|
|
|
|
return m_lineWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToolsModel::SetLineWidth(int nLineWidth)
|
|
|
|
{
|
|
|
|
m_lineWidth = nLineWidth;
|
2015-07-07 11:44:50 +00:00
|
|
|
NotifyToolSettingsChanged();
|
2015-07-07 11:15:24 +00:00
|
|
|
}
|
|
|
|
|
2021-12-27 11:08:07 +00:00
|
|
|
int ToolsModel::GetShapeStyle() const
|
2015-07-07 11:15:24 +00:00
|
|
|
{
|
|
|
|
return m_shapeStyle;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToolsModel::SetShapeStyle(int nShapeStyle)
|
|
|
|
{
|
|
|
|
m_shapeStyle = nShapeStyle;
|
2015-07-07 11:44:50 +00:00
|
|
|
NotifyToolSettingsChanged();
|
2015-07-07 11:15:24 +00:00
|
|
|
}
|
|
|
|
|
2021-12-27 11:08:07 +00:00
|
|
|
int ToolsModel::GetBrushStyle() const
|
2015-07-07 11:15:24 +00:00
|
|
|
{
|
|
|
|
return m_brushStyle;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToolsModel::SetBrushStyle(int nBrushStyle)
|
|
|
|
{
|
|
|
|
m_brushStyle = nBrushStyle;
|
2015-07-07 11:44:50 +00:00
|
|
|
NotifyToolSettingsChanged();
|
2015-07-07 11:15:24 +00:00
|
|
|
}
|
|
|
|
|
2021-12-27 14:23:32 +00:00
|
|
|
TOOLTYPE ToolsModel::GetActiveTool() const
|
2015-07-07 11:15:24 +00:00
|
|
|
{
|
|
|
|
return m_activeTool;
|
|
|
|
}
|
|
|
|
|
2022-01-01 13:02:36 +00:00
|
|
|
TOOLTYPE ToolsModel::GetOldActiveTool() const
|
|
|
|
{
|
|
|
|
return m_oldActiveTool;
|
|
|
|
}
|
|
|
|
|
2021-12-27 14:23:32 +00:00
|
|
|
void ToolsModel::SetActiveTool(TOOLTYPE nActiveTool)
|
2015-07-07 11:15:24 +00:00
|
|
|
{
|
2022-01-30 03:05:23 +00:00
|
|
|
OnFinishDraw();
|
|
|
|
|
|
|
|
if (m_activeTool == nActiveTool)
|
|
|
|
return;
|
|
|
|
|
2022-01-01 13:02:36 +00:00
|
|
|
switch (m_activeTool)
|
|
|
|
{
|
|
|
|
case TOOL_FREESEL:
|
|
|
|
case TOOL_RECTSEL:
|
|
|
|
case TOOL_RUBBER:
|
|
|
|
case TOOL_COLOR:
|
|
|
|
case TOOL_ZOOM:
|
|
|
|
case TOOL_TEXT:
|
|
|
|
break;
|
2022-01-05 07:26:05 +00:00
|
|
|
|
2022-01-01 13:02:36 +00:00
|
|
|
default:
|
|
|
|
m_oldActiveTool = m_activeTool;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-07-07 11:15:24 +00:00
|
|
|
m_activeTool = nActiveTool;
|
2022-01-01 13:02:36 +00:00
|
|
|
m_pToolObject = GetOrCreateTool(m_activeTool);
|
2015-07-07 11:44:50 +00:00
|
|
|
NotifyToolChanged();
|
2015-07-07 11:15:24 +00:00
|
|
|
}
|
|
|
|
|
2021-12-27 11:08:07 +00:00
|
|
|
int ToolsModel::GetAirBrushWidth() const
|
2015-07-07 11:15:24 +00:00
|
|
|
{
|
|
|
|
return m_airBrushWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToolsModel::SetAirBrushWidth(int nAirBrushWidth)
|
|
|
|
{
|
|
|
|
m_airBrushWidth = nAirBrushWidth;
|
2015-07-07 11:44:50 +00:00
|
|
|
NotifyToolSettingsChanged();
|
2015-07-07 11:15:24 +00:00
|
|
|
}
|
|
|
|
|
2021-12-27 11:08:07 +00:00
|
|
|
int ToolsModel::GetRubberRadius() const
|
2015-07-07 11:15:24 +00:00
|
|
|
{
|
|
|
|
return m_rubberRadius;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToolsModel::SetRubberRadius(int nRubberRadius)
|
|
|
|
{
|
|
|
|
m_rubberRadius = nRubberRadius;
|
2015-07-07 11:44:50 +00:00
|
|
|
NotifyToolSettingsChanged();
|
2015-07-07 11:15:24 +00:00
|
|
|
}
|
|
|
|
|
2021-12-27 11:08:07 +00:00
|
|
|
BOOL ToolsModel::IsBackgroundTransparent() const
|
2015-07-07 11:15:24 +00:00
|
|
|
{
|
|
|
|
return m_transpBg;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToolsModel::SetBackgroundTransparent(BOOL bTransparent)
|
|
|
|
{
|
|
|
|
m_transpBg = bTransparent;
|
2015-07-07 11:44:50 +00:00
|
|
|
NotifyToolSettingsChanged();
|
2022-02-14 03:08:34 +00:00
|
|
|
if (selectionWindow.IsWindow())
|
|
|
|
selectionWindow.ForceRefreshSelectionContents();
|
2015-07-07 11:15:24 +00:00
|
|
|
}
|
|
|
|
|
2021-12-26 10:49:56 +00:00
|
|
|
int ToolsModel::GetZoom() const
|
2015-07-07 11:15:24 +00:00
|
|
|
{
|
|
|
|
return m_zoom;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToolsModel::SetZoom(int nZoom)
|
|
|
|
{
|
|
|
|
m_zoom = nZoom;
|
2015-07-07 11:44:50 +00:00
|
|
|
NotifyZoomChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToolsModel::NotifyToolChanged()
|
|
|
|
{
|
2022-01-22 15:59:12 +00:00
|
|
|
if (toolBoxContainer.IsWindow())
|
|
|
|
toolBoxContainer.SendMessage(WM_TOOLSMODELTOOLCHANGED, m_activeTool);
|
|
|
|
if (toolSettingsWindow.IsWindow())
|
|
|
|
toolSettingsWindow.SendMessage(WM_TOOLSMODELTOOLCHANGED, m_activeTool);
|
2022-01-05 07:26:05 +00:00
|
|
|
if (fontsDialog.IsWindow())
|
|
|
|
fontsDialog.SendMessage(WM_TOOLSMODELTOOLCHANGED, m_activeTool);
|
2022-01-22 15:59:12 +00:00
|
|
|
if (textEditWindow.IsWindow())
|
|
|
|
textEditWindow.SendMessage(WM_TOOLSMODELTOOLCHANGED, m_activeTool);
|
2015-07-07 11:44:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ToolsModel::NotifyToolSettingsChanged()
|
|
|
|
{
|
2022-01-30 03:05:23 +00:00
|
|
|
if (toolSettingsWindow.IsWindow())
|
|
|
|
toolSettingsWindow.SendMessage(WM_TOOLSMODELSETTINGSCHANGED);
|
|
|
|
if (selectionWindow.IsWindow())
|
|
|
|
selectionWindow.SendMessage(WM_TOOLSMODELSETTINGSCHANGED);
|
2022-01-05 07:26:05 +00:00
|
|
|
if (textEditWindow.IsWindow())
|
|
|
|
textEditWindow.SendMessage(WM_TOOLSMODELSETTINGSCHANGED);
|
2015-07-07 11:44:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ToolsModel::NotifyZoomChanged()
|
|
|
|
{
|
2022-01-30 03:05:23 +00:00
|
|
|
if (toolSettingsWindow.IsWindow())
|
|
|
|
toolSettingsWindow.SendMessage(WM_TOOLSMODELZOOMCHANGED);
|
2022-01-05 07:26:05 +00:00
|
|
|
if (textEditWindow.IsWindow())
|
|
|
|
textEditWindow.SendMessage(WM_TOOLSMODELZOOMCHANGED);
|
2022-01-10 12:41:00 +00:00
|
|
|
if (selectionWindow.IsWindow())
|
|
|
|
selectionWindow.SendMessage(WM_TOOLSMODELZOOMCHANGED);
|
2015-07-07 11:15:24 +00:00
|
|
|
}
|
2022-01-01 13:02:36 +00:00
|
|
|
|
|
|
|
void ToolsModel::OnButtonDown(BOOL bLeftButton, LONG x, LONG y, BOOL bDoubleClick)
|
|
|
|
{
|
|
|
|
m_pToolObject->beginEvent();
|
|
|
|
updateStartAndLast(x, y);
|
|
|
|
m_pToolObject->OnButtonDown(bLeftButton, x, y, bDoubleClick);
|
|
|
|
m_pToolObject->endEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToolsModel::OnMouseMove(BOOL bLeftButton, LONG x, LONG y)
|
|
|
|
{
|
|
|
|
m_pToolObject->beginEvent();
|
|
|
|
m_pToolObject->OnMouseMove(bLeftButton, x, y);
|
|
|
|
updateLast(x, y);
|
|
|
|
m_pToolObject->endEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToolsModel::OnButtonUp(BOOL bLeftButton, LONG x, LONG y)
|
|
|
|
{
|
|
|
|
m_pToolObject->beginEvent();
|
|
|
|
m_pToolObject->OnButtonUp(bLeftButton, x, y);
|
|
|
|
updateLast(x, y);
|
|
|
|
m_pToolObject->endEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToolsModel::OnCancelDraw()
|
|
|
|
{
|
2022-01-30 03:05:23 +00:00
|
|
|
ATLTRACE("ToolsModel::OnCancelDraw()\n");
|
2022-01-01 13:02:36 +00:00
|
|
|
m_pToolObject->beginEvent();
|
|
|
|
m_pToolObject->OnCancelDraw();
|
|
|
|
m_pToolObject->endEvent();
|
|
|
|
}
|
|
|
|
|
2022-01-30 03:05:23 +00:00
|
|
|
void ToolsModel::OnFinishDraw()
|
|
|
|
{
|
|
|
|
ATLTRACE("ToolsModel::OnFinishDraw()\n");
|
|
|
|
m_pToolObject->beginEvent();
|
|
|
|
m_pToolObject->OnFinishDraw();
|
|
|
|
m_pToolObject->endEvent();
|
|
|
|
}
|
|
|
|
|
2022-01-01 13:02:36 +00:00
|
|
|
void ToolsModel::resetTool()
|
|
|
|
{
|
|
|
|
m_pToolObject->reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToolsModel::selectAll()
|
|
|
|
{
|
|
|
|
SetActiveTool(TOOL_RECTSEL);
|
|
|
|
OnButtonDown(TRUE, 0, 0, FALSE);
|
|
|
|
OnMouseMove(TRUE, imageModel.GetWidth(), imageModel.GetHeight());
|
|
|
|
OnButtonUp(TRUE, imageModel.GetWidth(), imageModel.GetHeight());
|
|
|
|
}
|