2015-07-07 11:15:24 +00:00
|
|
|
/*
|
2023-06-23 11:04:32 +00:00
|
|
|
* PROJECT: PAINT for ReactOS
|
|
|
|
* LICENSE: LGPL-2.0-or-later (https://spdx.org/licenses/LGPL-2.0-or-later)
|
|
|
|
* PURPOSE: Keep track of tool parameters, notify listeners
|
2023-06-27 18:22:21 +00:00
|
|
|
* COPYRIGHT: Copyright 2015 Benedikt Freisen <b.freisen@gmx.net>
|
2015-07-07 11:15:24 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precomp.h"
|
|
|
|
|
2023-03-28 13:31:26 +00:00
|
|
|
ToolsModel toolsModel;
|
|
|
|
|
2015-07-07 11:15:24 +00:00
|
|
|
/* FUNCTIONS ********************************************************/
|
|
|
|
|
|
|
|
ToolsModel::ToolsModel()
|
|
|
|
{
|
2023-09-28 07:32:36 +00:00
|
|
|
m_lineWidth = m_penWidth = 1;
|
2023-09-28 12:30:34 +00:00
|
|
|
m_brushWidth = 4;
|
2015-07-07 11:15:24 +00:00
|
|
|
m_shapeStyle = 0;
|
2023-09-28 12:30:34 +00:00
|
|
|
m_brushStyle = BrushStyleRound;
|
2022-01-01 13:02:36 +00:00
|
|
|
m_oldActiveTool = m_activeTool = TOOL_PEN;
|
2023-11-16 06:45:06 +00:00
|
|
|
m_airBrushRadius = 5;
|
2015-07-07 11:15:24 +00:00
|
|
|
m_rubberRadius = 4;
|
|
|
|
m_transpBg = FALSE;
|
|
|
|
m_zoom = 1000;
|
2022-01-01 13:02:36 +00:00
|
|
|
m_pToolObject = GetOrCreateTool(m_activeTool);
|
|
|
|
}
|
|
|
|
|
|
|
|
ToolsModel::~ToolsModel()
|
|
|
|
{
|
2023-11-03 07:49:13 +00:00
|
|
|
delete m_pToolObject;
|
|
|
|
m_pToolObject = NULL;
|
2022-01-01 13:02:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ToolBase *ToolsModel::GetOrCreateTool(TOOLTYPE nTool)
|
|
|
|
{
|
2023-11-03 07:49:13 +00:00
|
|
|
delete m_pToolObject;
|
|
|
|
m_pToolObject = ToolBase::createToolObject(nTool);
|
|
|
|
return m_pToolObject;
|
2015-07-07 11:15:24 +00:00
|
|
|
}
|
|
|
|
|
2023-06-19 00:56:02 +00:00
|
|
|
BOOL ToolsModel::IsSelection() const
|
|
|
|
{
|
|
|
|
return (GetActiveTool() == TOOL_RECTSEL || GetActiveTool() == TOOL_FREESEL);
|
|
|
|
}
|
|
|
|
|
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();
|
2023-09-28 07:32:36 +00:00
|
|
|
imageModel.NotifyImageChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
INT ToolsModel::GetPenWidth() const
|
|
|
|
{
|
|
|
|
return m_penWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToolsModel::SetPenWidth(INT nPenWidth)
|
|
|
|
{
|
|
|
|
m_penWidth = nPenWidth;
|
|
|
|
NotifyToolSettingsChanged();
|
|
|
|
imageModel.NotifyImageChanged();
|
|
|
|
}
|
|
|
|
|
2023-09-28 12:30:34 +00:00
|
|
|
INT ToolsModel::GetBrushWidth() const
|
|
|
|
{
|
|
|
|
return m_brushWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToolsModel::SetBrushWidth(INT nBrushWidth)
|
|
|
|
{
|
|
|
|
m_brushWidth = nBrushWidth;
|
|
|
|
NotifyToolSettingsChanged();
|
|
|
|
imageModel.NotifyImageChanged();
|
|
|
|
}
|
|
|
|
|
2023-09-28 07:32:36 +00:00
|
|
|
void ToolsModel::MakeLineThickerOrThinner(BOOL bThinner)
|
|
|
|
{
|
|
|
|
INT thickness = GetLineWidth();
|
|
|
|
SetLineWidth(bThinner ? max(1, thickness - 1) : (thickness + 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToolsModel::MakePenThickerOrThinner(BOOL bThinner)
|
|
|
|
{
|
|
|
|
INT thickness = GetPenWidth();
|
|
|
|
SetPenWidth(bThinner ? max(1, thickness - 1) : (thickness + 1));
|
2015-07-07 11:15:24 +00:00
|
|
|
}
|
|
|
|
|
2023-09-28 12:30:34 +00:00
|
|
|
void ToolsModel::MakeBrushThickerOrThinner(BOOL bThinner)
|
|
|
|
{
|
|
|
|
INT thickness = GetBrushWidth();
|
|
|
|
SetBrushWidth(bThinner ? max(1, thickness - 1) : (thickness + 1));
|
|
|
|
}
|
|
|
|
|
2023-09-28 12:54:32 +00:00
|
|
|
void ToolsModel::MakeAirBrushThickerOrThinner(BOOL bThinner)
|
|
|
|
{
|
2023-11-16 06:45:06 +00:00
|
|
|
INT thickness = GetAirBrushRadius();
|
|
|
|
SetAirBrushRadius(bThinner ? max(1, thickness - 1) : (thickness + 1));
|
2023-09-28 12:54:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ToolsModel::MakeRubberThickerOrThinner(BOOL bThinner)
|
|
|
|
{
|
|
|
|
INT thickness = GetRubberRadius();
|
|
|
|
SetRubberRadius(bThinner ? max(1, thickness - 1) : (thickness + 1));
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-09-28 12:30:34 +00:00
|
|
|
BrushStyle ToolsModel::GetBrushStyle() const
|
2015-07-07 11:15:24 +00:00
|
|
|
{
|
|
|
|
return m_brushStyle;
|
|
|
|
}
|
|
|
|
|
2023-09-28 12:30:34 +00:00
|
|
|
void ToolsModel::SetBrushStyle(BrushStyle nBrushStyle)
|
2015-07-07 11:15:24 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
{
|
2023-11-03 07:20:03 +00:00
|
|
|
OnEndDraw(FALSE);
|
2022-01-30 03:05:23 +00:00
|
|
|
|
2023-09-28 07:32:36 +00:00
|
|
|
selectionModel.Landing();
|
|
|
|
|
|
|
|
m_activeTool = nActiveTool;
|
|
|
|
|
2022-01-01 13:02:36 +00:00
|
|
|
switch (m_activeTool)
|
|
|
|
{
|
|
|
|
case TOOL_FREESEL:
|
|
|
|
case TOOL_RECTSEL:
|
|
|
|
case TOOL_COLOR:
|
|
|
|
case TOOL_ZOOM:
|
|
|
|
case TOOL_TEXT:
|
2023-09-28 07:32:36 +00:00
|
|
|
// The active tool is not an actually drawing tool
|
2022-01-01 13:02:36 +00:00
|
|
|
break;
|
2022-01-05 07:26:05 +00:00
|
|
|
|
2023-09-28 07:32:36 +00:00
|
|
|
case TOOL_LINE:
|
|
|
|
case TOOL_BEZIER:
|
|
|
|
case TOOL_RECT:
|
|
|
|
case TOOL_SHAPE:
|
|
|
|
case TOOL_ELLIPSE:
|
|
|
|
case TOOL_FILL:
|
|
|
|
case TOOL_AIRBRUSH:
|
|
|
|
case TOOL_RRECT:
|
|
|
|
case TOOL_RUBBER:
|
|
|
|
case TOOL_BRUSH:
|
|
|
|
case TOOL_PEN:
|
|
|
|
// The active tool is an actually drawing tool. Save it for TOOL_COLOR to restore
|
|
|
|
m_oldActiveTool = nActiveTool;
|
2022-01-01 13:02:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pToolObject = GetOrCreateTool(m_activeTool);
|
2023-09-28 07:32:36 +00:00
|
|
|
|
2015-07-07 11:44:50 +00:00
|
|
|
NotifyToolChanged();
|
2015-07-07 11:15:24 +00:00
|
|
|
}
|
|
|
|
|
2023-11-16 06:45:06 +00:00
|
|
|
INT ToolsModel::GetAirBrushRadius() const
|
2015-07-07 11:15:24 +00:00
|
|
|
{
|
2023-11-16 06:45:06 +00:00
|
|
|
return m_airBrushRadius;
|
2015-07-07 11:15:24 +00:00
|
|
|
}
|
|
|
|
|
2023-11-16 06:45:06 +00:00
|
|
|
void ToolsModel::SetAirBrushRadius(INT nAirBrushRadius)
|
2015-07-07 11:15:24 +00:00
|
|
|
{
|
2023-11-16 06:45:06 +00:00
|
|
|
m_airBrushRadius = nAirBrushRadius;
|
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
|
|
|
}
|
|
|
|
|
2023-11-19 03:59:39 +00:00
|
|
|
SIZE ToolsModel::GetToolSize() const
|
|
|
|
{
|
|
|
|
SIZE size;
|
|
|
|
switch (m_activeTool)
|
|
|
|
{
|
|
|
|
case TOOL_FREESEL:
|
|
|
|
case TOOL_RECTSEL:
|
2023-11-25 04:44:31 +00:00
|
|
|
size.cx = selectionModel.m_rc.Width();
|
|
|
|
size.cy = selectionModel.m_rc.Height();
|
|
|
|
break;
|
2023-11-19 03:59:39 +00:00
|
|
|
case TOOL_COLOR:
|
|
|
|
case TOOL_ZOOM:
|
|
|
|
case TOOL_TEXT:
|
|
|
|
case TOOL_FILL:
|
|
|
|
size.cx = size.cy = 1;
|
|
|
|
break;
|
|
|
|
case TOOL_LINE:
|
|
|
|
case TOOL_BEZIER:
|
|
|
|
case TOOL_RECT:
|
|
|
|
case TOOL_RRECT:
|
|
|
|
case TOOL_SHAPE:
|
|
|
|
case TOOL_ELLIPSE:
|
|
|
|
size.cx = size.cy = GetLineWidth();
|
|
|
|
break;
|
|
|
|
case TOOL_AIRBRUSH:
|
|
|
|
size.cx = size.cy = GetAirBrushRadius() * 2;
|
|
|
|
break;
|
|
|
|
case TOOL_RUBBER:
|
|
|
|
size.cx = size.cy = GetRubberRadius() * 2;
|
|
|
|
break;
|
|
|
|
case TOOL_BRUSH:
|
|
|
|
size.cx = size.cy = GetBrushWidth();
|
|
|
|
break;
|
|
|
|
case TOOL_PEN:
|
|
|
|
size.cx = size.cy = GetPenWidth();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (size.cx < 1)
|
|
|
|
size.cx = 1;
|
|
|
|
if (size.cy < 1)
|
|
|
|
size.cy = 1;
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
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();
|
2023-06-14 09:51:40 +00:00
|
|
|
imageModel.NotifyImageChanged();
|
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);
|
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);
|
2023-04-08 13:25:27 +00:00
|
|
|
if (canvasWindow.IsWindow())
|
|
|
|
canvasWindow.SendMessage(WM_TOOLSMODELZOOMCHANGED);
|
2015-07-07 11:15:24 +00:00
|
|
|
}
|
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());
|
|
|
|
}
|