ReactOS 0.4.17-dev-258-gb1f0478
toolsmodel.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: PAINT for ReactOS
3 * LICENSE: LGPL-2.0-or-later (https://spdx.org/licenses/LGPL-2.0-or-later)
4 * PURPOSE: Keep track of tool parameters, notify listeners
5 * COPYRIGHT: Copyright 2015 Benedikt Freisen <b.freisen@gmx.net>
6 */
7
8#include "precomp.h"
9
11
12/* FUNCTIONS ********************************************************/
13
15{
17 m_brushWidth = 4;
18 m_shapeStyle = 0;
24 m_zoom = 1000;
26}
27
29{
30 delete m_pToolObject;
32}
33
35{
36 delete m_pToolObject;
38 return m_pToolObject;
39}
40
42{
44}
45
47{
48 return m_lineWidth;
49}
50
51void ToolsModel::SetLineWidth(int nLineWidth)
52{
53 m_lineWidth = nLineWidth;
56}
57
59{
60 return m_penWidth;
61}
62
64{
65 m_penWidth = nPenWidth;
68}
69
71{
72 return m_brushWidth;
73}
74
76{
79}
80
82{
83 m_brushWidth = nBrushWidth;
87}
88
90{
91 INT thickness = GetLineWidth();
92 SetLineWidth(bThinner ? max(1, thickness - 1) : (thickness + 1));
93}
94
96{
97 INT thickness = GetPenWidth();
98 SetPenWidth(bThinner ? max(1, thickness - 1) : (thickness + 1));
99}
100
102{
103 INT thickness = GetBrushWidth();
104 SetBrushWidth(bThinner ? max(1, thickness - 1) : (thickness + 1));
105}
106
108{
109 INT thickness = GetAirBrushRadius();
110 SetAirBrushRadius(bThinner ? max(1, thickness - 1) : (thickness + 1));
111}
112
114{
115 INT thickness = GetRubberRadius();
116 SetRubberRadius(bThinner ? max(1, thickness - 1) : (thickness + 1));
117}
118
120{
121 return m_shapeStyle;
122}
123
124void ToolsModel::SetShapeStyle(int nShapeStyle)
125{
126 m_shapeStyle = nShapeStyle;
128}
129
131{
132 return m_brushStyle;
133}
134
136{
137 m_brushStyle = nBrushStyle;
140}
141
143{
144 return m_activeTool;
145}
146
148{
149 return m_oldActiveTool;
150}
151
153{
155
157
158 m_activeTool = nActiveTool;
159
160 switch (m_activeTool)
161 {
162 case TOOL_FREESEL:
163 case TOOL_RECTSEL:
164 case TOOL_COLOR:
165 case TOOL_ZOOM:
166 case TOOL_TEXT:
167 // The active tool is not an actually drawing tool
168 break;
169
170 case TOOL_LINE:
171 case TOOL_BEZIER:
172 case TOOL_RECT:
173 case TOOL_SHAPE:
174 case TOOL_ELLIPSE:
175 case TOOL_FILL:
176 case TOOL_AIRBRUSH:
177 case TOOL_RRECT:
178 case TOOL_RUBBER:
179 case TOOL_BRUSH:
180 case TOOL_PEN:
181 // The active tool is an actually drawing tool. Save it for TOOL_COLOR to restore
182 m_oldActiveTool = nActiveTool;
183 break;
184 }
185
187
189}
190
192{
193 return m_airBrushRadius;
194}
195
197{
198 m_airBrushRadius = nAirBrushRadius;
200}
201
203{
204 return m_rubberRadius;
205}
206
207void ToolsModel::SetRubberRadius(int nRubberRadius)
208{
209 m_rubberRadius = nRubberRadius;
212}
213
215{
216 SIZE size;
217 switch (m_activeTool)
218 {
219 case TOOL_FREESEL:
220 case TOOL_RECTSEL:
223 break;
224 case TOOL_COLOR:
225 case TOOL_ZOOM:
226 case TOOL_TEXT:
227 case TOOL_FILL:
228 size.cx = size.cy = 1;
229 break;
230 case TOOL_LINE:
231 case TOOL_BEZIER:
232 case TOOL_RECT:
233 case TOOL_RRECT:
234 case TOOL_SHAPE:
235 case TOOL_ELLIPSE:
236 size.cx = size.cy = GetLineWidth();
237 break;
238 case TOOL_AIRBRUSH:
239 size.cx = size.cy = GetAirBrushRadius() * 2;
240 break;
241 case TOOL_RUBBER:
242 size.cx = size.cy = GetRubberRadius() * 2;
243 break;
244 case TOOL_BRUSH:
245 size.cx = size.cy = GetBrushWidth();
246 break;
247 case TOOL_PEN:
248 size.cx = size.cy = GetPenWidth();
249 break;
250 }
251 if (size.cx < 1)
252 size.cx = 1;
253 if (size.cy < 1)
254 size.cy = 1;
255 return size;
256}
257
259{
260 return m_transpBg;
261}
262
264{
265 m_transpBg = bTransparent;
268}
269
271{
272 return m_zoom;
273}
274
275void ToolsModel::SetZoom(int nZoom)
276{
277 m_zoom = nZoom;
279}
280
282{
283 if (toolBoxContainer.IsWindow())
285 if (toolSettingsWindow.IsWindow())
287 if (fontsDialog.IsWindow())
289 if (textEditWindow.IsWindow())
291}
292
294{
295 if (toolSettingsWindow.IsWindow())
297 if (textEditWindow.IsWindow())
299}
300
302{
303 if (toolSettingsWindow.IsWindow())
305 if (textEditWindow.IsWindow())
307 if (canvasWindow.IsWindow())
309}
310
312{
314}
315
317{
319 OnButtonDown(TRUE, 0, 0, FALSE);
322}
CFontsDialog fontsDialog
Definition: dialogs.cpp:16
#define WM_TOOLSMODELZOOMCHANGED
Definition: precomp.h:51
SelectionModel selectionModel
CToolBox toolBoxContainer
Definition: toolbox.cpp:11
#define WM_TOOLSMODELTOOLCHANGED
Definition: precomp.h:49
#define WM_TOOLSMODELSETTINGSCHANGED
Definition: precomp.h:50
CTextEditWindow textEditWindow
Definition: textedit.cpp:12
CToolSettingsWindow toolSettingsWindow
CCanvasWindow canvasWindow
Definition: canvas.cpp:11
int Width() const noexcept
Definition: atltypes.h:461
int Height() const noexcept
Definition: atltypes.h:318
int GetWidth() const
Definition: history.cpp:254
void NotifyImageChanged()
Definition: history.cpp:23
int GetHeight() const
Definition: history.cpp:259
void MakeAirBrushThickerOrThinner(BOOL bThinner)
Definition: toolsmodel.cpp:107
void OnEndDraw(BOOL bCancel)
Definition: mouse.cpp:1178
void SetBrushStyle(BrushStyle nBrushStyle)
Definition: toolsmodel.cpp:135
void MakeBrushThickerOrThinner(BOOL bThinner)
Definition: toolsmodel.cpp:101
int GetZoom() const
Definition: toolsmodel.cpp:270
TOOLTYPE m_oldActiveTool
Definition: toolsmodel.h:76
int GetLineWidth() const
Definition: toolsmodel.cpp:46
INT m_airBrushRadius
Definition: toolsmodel.h:77
INT m_brushWidth
Definition: toolsmodel.h:72
BOOL IsSelection() const
Definition: toolsmodel.cpp:41
int GetShapeStyle() const
Definition: toolsmodel.cpp:119
void SendSetCursor()
Definition: toolsmodel.cpp:75
int m_rubberRadius
Definition: toolsmodel.h:78
int m_lineWidth
Definition: toolsmodel.h:70
void SetAirBrushRadius(INT nAirBrushRadius)
Definition: toolsmodel.cpp:196
void resetTool()
Definition: toolsmodel.cpp:311
BOOL m_transpBg
Definition: toolsmodel.h:79
int m_shapeStyle
Definition: toolsmodel.h:73
TOOLTYPE GetOldActiveTool() const
Definition: toolsmodel.cpp:147
void SetShapeStyle(int nShapeStyle)
Definition: toolsmodel.cpp:124
void SetActiveTool(TOOLTYPE nActiveTool)
Definition: toolsmodel.cpp:152
void SetRubberRadius(int nRubberRadius)
Definition: toolsmodel.cpp:207
void NotifyToolChanged()
Definition: toolsmodel.cpp:281
void OnMouseMove(BOOL bLeftButton, LONG x, LONG y)
Definition: mouse.cpp:1160
BrushStyle m_brushStyle
Definition: toolsmodel.h:74
INT GetPenWidth() const
Definition: toolsmodel.cpp:58
int m_zoom
Definition: toolsmodel.h:80
BrushStyle GetBrushStyle() const
Definition: toolsmodel.cpp:130
void OnButtonDown(BOOL bLeftButton, LONG x, LONG y, BOOL bDoubleClick)
Definition: mouse.cpp:1152
void MakeRubberThickerOrThinner(BOOL bThinner)
Definition: toolsmodel.cpp:113
BOOL IsBackgroundTransparent() const
Definition: toolsmodel.cpp:258
void SetZoom(int nZoom)
Definition: toolsmodel.cpp:275
void SetBackgroundTransparent(BOOL bTransparent)
Definition: toolsmodel.cpp:263
TOOLTYPE m_activeTool
Definition: toolsmodel.h:75
int GetRubberRadius() const
Definition: toolsmodel.cpp:202
ToolBase * m_pToolObject
Definition: toolsmodel.h:81
void NotifyToolSettingsChanged()
Definition: toolsmodel.cpp:293
ToolBase * GetOrCreateTool(TOOLTYPE nTool)
Definition: toolsmodel.cpp:34
void MakeLineThickerOrThinner(BOOL bThinner)
Definition: toolsmodel.cpp:89
TOOLTYPE GetActiveTool() const
Definition: toolsmodel.cpp:142
void MakePenThickerOrThinner(BOOL bThinner)
Definition: toolsmodel.cpp:95
void selectAll()
Definition: toolsmodel.cpp:316
void NotifyZoomChanged()
Definition: toolsmodel.cpp:301
void SetPenWidth(INT nPenWidth)
Definition: toolsmodel.cpp:63
void SetBrushWidth(INT nBrushWidth)
Definition: toolsmodel.cpp:81
INT GetAirBrushRadius() const
Definition: toolsmodel.cpp:191
void OnButtonUp(BOOL bLeftButton, LONG x, LONG y)
Definition: mouse.cpp:1169
void SetLineWidth(int nLineWidth)
Definition: toolsmodel.cpp:51
INT GetBrushWidth() const
Definition: toolsmodel.cpp:70
SIZE GetToolSize() const
Definition: toolsmodel.cpp:214
INT m_penWidth
Definition: toolsmodel.h:71
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
GLsizeiptr size
Definition: glext.h:5919
ImageModel imageModel
Definition: history.cpp:11
UINT_PTR WPARAM
Definition: minwindef.h:174
void reset()
Definition: mouse.cpp:106
static ToolBase * createToolObject(TOOLTYPE type)
Definition: mouse.cpp:1127
#define max(a, b)
Definition: svc.c:63
ToolsModel toolsModel
Definition: toolsmodel.cpp:10
TOOLTYPE
Definition: toolsmodel.h:11
@ TOOL_AIRBRUSH
Definition: toolsmodel.h:20
@ TOOL_COLOR
Definition: toolsmodel.h:16
@ TOOL_SHAPE
Definition: toolsmodel.h:25
@ TOOL_RUBBER
Definition: toolsmodel.h:14
@ TOOL_BRUSH
Definition: toolsmodel.h:19
@ TOOL_RECT
Definition: toolsmodel.h:24
@ TOOL_BEZIER
Definition: toolsmodel.h:23
@ TOOL_FILL
Definition: toolsmodel.h:15
@ TOOL_TEXT
Definition: toolsmodel.h:21
@ TOOL_PEN
Definition: toolsmodel.h:18
@ TOOL_LINE
Definition: toolsmodel.h:22
@ TOOL_FREESEL
Definition: toolsmodel.h:12
@ TOOL_ZOOM
Definition: toolsmodel.h:17
@ TOOL_ELLIPSE
Definition: toolsmodel.h:26
@ TOOL_RRECT
Definition: toolsmodel.h:27
@ TOOL_RECTSEL
Definition: toolsmodel.h:13
BrushStyle
Definition: toolsmodel.h:32
@ BrushStyleRound
Definition: toolsmodel.h:33
int32_t INT
Definition: typedefs.h:58
#define MAKELPARAM(l, h)
Definition: winuser.h:4116
#define WM_MOUSEMOVE
Definition: winuser.h:1803
#define HTCLIENT
Definition: winuser.h:2511
#define WM_SETCURSOR
Definition: winuser.h:1664