ReactOS 0.4.15-dev-7924-g5949c20
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{
77 m_brushWidth = nBrushWidth;
80}
81
83{
84 INT thickness = GetLineWidth();
85 SetLineWidth(bThinner ? max(1, thickness - 1) : (thickness + 1));
86}
87
89{
90 INT thickness = GetPenWidth();
91 SetPenWidth(bThinner ? max(1, thickness - 1) : (thickness + 1));
92}
93
95{
96 INT thickness = GetBrushWidth();
97 SetBrushWidth(bThinner ? max(1, thickness - 1) : (thickness + 1));
98}
99
101{
102 INT thickness = GetAirBrushRadius();
103 SetAirBrushRadius(bThinner ? max(1, thickness - 1) : (thickness + 1));
104}
105
107{
108 INT thickness = GetRubberRadius();
109 SetRubberRadius(bThinner ? max(1, thickness - 1) : (thickness + 1));
110}
111
113{
114 return m_shapeStyle;
115}
116
117void ToolsModel::SetShapeStyle(int nShapeStyle)
118{
119 m_shapeStyle = nShapeStyle;
121}
122
124{
125 return m_brushStyle;
126}
127
129{
130 m_brushStyle = nBrushStyle;
132}
133
135{
136 return m_activeTool;
137}
138
140{
141 return m_oldActiveTool;
142}
143
145{
147
149
150 m_activeTool = nActiveTool;
151
152 switch (m_activeTool)
153 {
154 case TOOL_FREESEL:
155 case TOOL_RECTSEL:
156 case TOOL_COLOR:
157 case TOOL_ZOOM:
158 case TOOL_TEXT:
159 // The active tool is not an actually drawing tool
160 break;
161
162 case TOOL_LINE:
163 case TOOL_BEZIER:
164 case TOOL_RECT:
165 case TOOL_SHAPE:
166 case TOOL_ELLIPSE:
167 case TOOL_FILL:
168 case TOOL_AIRBRUSH:
169 case TOOL_RRECT:
170 case TOOL_RUBBER:
171 case TOOL_BRUSH:
172 case TOOL_PEN:
173 // The active tool is an actually drawing tool. Save it for TOOL_COLOR to restore
174 m_oldActiveTool = nActiveTool;
175 break;
176 }
177
179
181}
182
184{
185 return m_airBrushRadius;
186}
187
189{
190 m_airBrushRadius = nAirBrushRadius;
192}
193
195{
196 return m_rubberRadius;
197}
198
199void ToolsModel::SetRubberRadius(int nRubberRadius)
200{
201 m_rubberRadius = nRubberRadius;
203}
204
206{
207 SIZE size;
208 switch (m_activeTool)
209 {
210 case TOOL_FREESEL:
211 case TOOL_RECTSEL:
214 break;
215 case TOOL_COLOR:
216 case TOOL_ZOOM:
217 case TOOL_TEXT:
218 case TOOL_FILL:
219 size.cx = size.cy = 1;
220 break;
221 case TOOL_LINE:
222 case TOOL_BEZIER:
223 case TOOL_RECT:
224 case TOOL_RRECT:
225 case TOOL_SHAPE:
226 case TOOL_ELLIPSE:
227 size.cx = size.cy = GetLineWidth();
228 break;
229 case TOOL_AIRBRUSH:
230 size.cx = size.cy = GetAirBrushRadius() * 2;
231 break;
232 case TOOL_RUBBER:
233 size.cx = size.cy = GetRubberRadius() * 2;
234 break;
235 case TOOL_BRUSH:
236 size.cx = size.cy = GetBrushWidth();
237 break;
238 case TOOL_PEN:
239 size.cx = size.cy = GetPenWidth();
240 break;
241 }
242 if (size.cx < 1)
243 size.cx = 1;
244 if (size.cy < 1)
245 size.cy = 1;
246 return size;
247}
248
250{
251 return m_transpBg;
252}
253
255{
256 m_transpBg = bTransparent;
259}
260
262{
263 return m_zoom;
264}
265
266void ToolsModel::SetZoom(int nZoom)
267{
268 m_zoom = nZoom;
270}
271
273{
274 if (toolBoxContainer.IsWindow())
276 if (toolSettingsWindow.IsWindow())
278 if (fontsDialog.IsWindow())
280 if (textEditWindow.IsWindow())
282}
283
285{
286 if (toolSettingsWindow.IsWindow())
288 if (textEditWindow.IsWindow())
290}
291
293{
294 if (toolSettingsWindow.IsWindow())
296 if (textEditWindow.IsWindow())
298 if (canvasWindow.IsWindow())
300}
301
303{
305}
306
308{
310 OnButtonDown(TRUE, 0, 0, FALSE);
313}
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:10
int Width() const noexcept
Definition: atltypes.h:461
int Height() const noexcept
Definition: atltypes.h:318
int GetWidth() const
Definition: history.cpp:253
void NotifyImageChanged()
Definition: history.cpp:23
int GetHeight() const
Definition: history.cpp:258
void MakeAirBrushThickerOrThinner(BOOL bThinner)
Definition: toolsmodel.cpp:100
void OnEndDraw(BOOL bCancel)
Definition: mouse.cpp:1178
void SetBrushStyle(BrushStyle nBrushStyle)
Definition: toolsmodel.cpp:128
void MakeBrushThickerOrThinner(BOOL bThinner)
Definition: toolsmodel.cpp:94
int GetZoom() const
Definition: toolsmodel.cpp:261
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:112
int m_rubberRadius
Definition: toolsmodel.h:78
int m_lineWidth
Definition: toolsmodel.h:70
void SetAirBrushRadius(INT nAirBrushRadius)
Definition: toolsmodel.cpp:188
void resetTool()
Definition: toolsmodel.cpp:302
BOOL m_transpBg
Definition: toolsmodel.h:79
int m_shapeStyle
Definition: toolsmodel.h:73
TOOLTYPE GetOldActiveTool() const
Definition: toolsmodel.cpp:139
void SetShapeStyle(int nShapeStyle)
Definition: toolsmodel.cpp:117
void SetActiveTool(TOOLTYPE nActiveTool)
Definition: toolsmodel.cpp:144
void SetRubberRadius(int nRubberRadius)
Definition: toolsmodel.cpp:199
void NotifyToolChanged()
Definition: toolsmodel.cpp:272
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:123
void OnButtonDown(BOOL bLeftButton, LONG x, LONG y, BOOL bDoubleClick)
Definition: mouse.cpp:1152
void MakeRubberThickerOrThinner(BOOL bThinner)
Definition: toolsmodel.cpp:106
BOOL IsBackgroundTransparent() const
Definition: toolsmodel.cpp:249
void SetZoom(int nZoom)
Definition: toolsmodel.cpp:266
void SetBackgroundTransparent(BOOL bTransparent)
Definition: toolsmodel.cpp:254
TOOLTYPE m_activeTool
Definition: toolsmodel.h:75
int GetRubberRadius() const
Definition: toolsmodel.cpp:194
ToolBase * m_pToolObject
Definition: toolsmodel.h:81
void NotifyToolSettingsChanged()
Definition: toolsmodel.cpp:284
ToolBase * GetOrCreateTool(TOOLTYPE nTool)
Definition: toolsmodel.cpp:34
void MakeLineThickerOrThinner(BOOL bThinner)
Definition: toolsmodel.cpp:82
TOOLTYPE GetActiveTool() const
Definition: toolsmodel.cpp:134
void MakePenThickerOrThinner(BOOL bThinner)
Definition: toolsmodel.cpp:88
void selectAll()
Definition: toolsmodel.cpp:307
void NotifyZoomChanged()
Definition: toolsmodel.cpp:292
void SetPenWidth(INT nPenWidth)
Definition: toolsmodel.cpp:63
void SetBrushWidth(INT nBrushWidth)
Definition: toolsmodel.cpp:75
INT GetAirBrushRadius() const
Definition: toolsmodel.cpp:183
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:205
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
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