-
Notifications
You must be signed in to change notification settings - Fork 1
/
toolsmodel.cpp
313 lines (268 loc) · 7.17 KB
/
toolsmodel.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
/*
* 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
* COPYRIGHT: Copyright 2015 Benedikt Freisen <b.freisen@gmx.net>
*/
#include "precomp.h"
ToolsModel toolsModel;
/* FUNCTIONS ********************************************************/
ToolsModel::ToolsModel()
{
m_lineWidth = m_penWidth = 1;
m_brushWidth = 4;
m_shapeStyle = 0;
m_brushStyle = BrushStyleRound;
m_oldActiveTool = m_activeTool = TOOL_PEN;
m_airBrushRadius = 5;
m_rubberRadius = 4;
m_transpBg = FALSE;
m_zoom = 1000;
m_pToolObject = GetOrCreateTool(m_activeTool);
}
ToolsModel::~ToolsModel()
{
delete m_pToolObject;
m_pToolObject = NULL;
}
ToolBase *ToolsModel::GetOrCreateTool(TOOLTYPE nTool)
{
delete m_pToolObject;
m_pToolObject = ToolBase::createToolObject(nTool);
return m_pToolObject;
}
BOOL ToolsModel::IsSelection() const
{
return (GetActiveTool() == TOOL_RECTSEL || GetActiveTool() == TOOL_FREESEL);
}
int ToolsModel::GetLineWidth() const
{
return m_lineWidth;
}
void ToolsModel::SetLineWidth(int nLineWidth)
{
m_lineWidth = nLineWidth;
NotifyToolSettingsChanged();
imageModel.NotifyImageChanged();
}
INT ToolsModel::GetPenWidth() const
{
return m_penWidth;
}
void ToolsModel::SetPenWidth(INT nPenWidth)
{
m_penWidth = nPenWidth;
NotifyToolSettingsChanged();
imageModel.NotifyImageChanged();
}
INT ToolsModel::GetBrushWidth() const
{
return m_brushWidth;
}
void ToolsModel::SetBrushWidth(INT nBrushWidth)
{
m_brushWidth = nBrushWidth;
NotifyToolSettingsChanged();
imageModel.NotifyImageChanged();
}
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));
}
void ToolsModel::MakeBrushThickerOrThinner(BOOL bThinner)
{
INT thickness = GetBrushWidth();
SetBrushWidth(bThinner ? max(1, thickness - 1) : (thickness + 1));
}
void ToolsModel::MakeAirBrushThickerOrThinner(BOOL bThinner)
{
INT thickness = GetAirBrushRadius();
SetAirBrushRadius(bThinner ? max(1, thickness - 1) : (thickness + 1));
}
void ToolsModel::MakeRubberThickerOrThinner(BOOL bThinner)
{
INT thickness = GetRubberRadius();
SetRubberRadius(bThinner ? max(1, thickness - 1) : (thickness + 1));
}
int ToolsModel::GetShapeStyle() const
{
return m_shapeStyle;
}
void ToolsModel::SetShapeStyle(int nShapeStyle)
{
m_shapeStyle = nShapeStyle;
NotifyToolSettingsChanged();
}
BrushStyle ToolsModel::GetBrushStyle() const
{
return m_brushStyle;
}
void ToolsModel::SetBrushStyle(BrushStyle nBrushStyle)
{
m_brushStyle = nBrushStyle;
NotifyToolSettingsChanged();
}
TOOLTYPE ToolsModel::GetActiveTool() const
{
return m_activeTool;
}
TOOLTYPE ToolsModel::GetOldActiveTool() const
{
return m_oldActiveTool;
}
void ToolsModel::SetActiveTool(TOOLTYPE nActiveTool)
{
OnEndDraw(FALSE);
selectionModel.Landing();
m_activeTool = nActiveTool;
switch (m_activeTool)
{
case TOOL_FREESEL:
case TOOL_RECTSEL:
case TOOL_COLOR:
case TOOL_ZOOM:
case TOOL_TEXT:
// The active tool is not an actually drawing tool
break;
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;
break;
}
m_pToolObject = GetOrCreateTool(m_activeTool);
NotifyToolChanged();
}
INT ToolsModel::GetAirBrushRadius() const
{
return m_airBrushRadius;
}
void ToolsModel::SetAirBrushRadius(INT nAirBrushRadius)
{
m_airBrushRadius = nAirBrushRadius;
NotifyToolSettingsChanged();
}
int ToolsModel::GetRubberRadius() const
{
return m_rubberRadius;
}
void ToolsModel::SetRubberRadius(int nRubberRadius)
{
m_rubberRadius = nRubberRadius;
NotifyToolSettingsChanged();
}
SIZE ToolsModel::GetToolSize() const
{
SIZE size;
switch (m_activeTool)
{
case TOOL_FREESEL:
case TOOL_RECTSEL:
size.cx = selectionModel.m_rc.Width();
size.cy = selectionModel.m_rc.Height();
break;
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;
}
BOOL ToolsModel::IsBackgroundTransparent() const
{
return m_transpBg;
}
void ToolsModel::SetBackgroundTransparent(BOOL bTransparent)
{
m_transpBg = bTransparent;
NotifyToolSettingsChanged();
imageModel.NotifyImageChanged();
}
int ToolsModel::GetZoom() const
{
return m_zoom;
}
void ToolsModel::SetZoom(int nZoom)
{
m_zoom = nZoom;
NotifyZoomChanged();
}
void ToolsModel::NotifyToolChanged()
{
if (toolBoxContainer.IsWindow())
toolBoxContainer.SendMessage(WM_TOOLSMODELTOOLCHANGED, m_activeTool);
if (toolSettingsWindow.IsWindow())
toolSettingsWindow.SendMessage(WM_TOOLSMODELTOOLCHANGED, m_activeTool);
if (fontsDialog.IsWindow())
fontsDialog.SendMessage(WM_TOOLSMODELTOOLCHANGED, m_activeTool);
if (textEditWindow.IsWindow())
textEditWindow.SendMessage(WM_TOOLSMODELTOOLCHANGED, m_activeTool);
}
void ToolsModel::NotifyToolSettingsChanged()
{
if (toolSettingsWindow.IsWindow())
toolSettingsWindow.SendMessage(WM_TOOLSMODELSETTINGSCHANGED);
if (textEditWindow.IsWindow())
textEditWindow.SendMessage(WM_TOOLSMODELSETTINGSCHANGED);
}
void ToolsModel::NotifyZoomChanged()
{
if (toolSettingsWindow.IsWindow())
toolSettingsWindow.SendMessage(WM_TOOLSMODELZOOMCHANGED);
if (textEditWindow.IsWindow())
textEditWindow.SendMessage(WM_TOOLSMODELZOOMCHANGED);
if (canvasWindow.IsWindow())
canvasWindow.SendMessage(WM_TOOLSMODELZOOMCHANGED);
}
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());
}