ReactOS 0.4.17-dev-523-gf6fcb59
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{
16 if (m_hBrush)
18}
19
21{
22 if (m_hBrush &&
23 m_palette == palette &&
24 m_rgbColor == rgbColor)
25 {
26 return m_hBrush;
27 }
28
29 if (m_hBrush)
30 ::DeleteObject(m_hBrush);
31
32 m_hBrush = ToolsModel::CreateBrush(palette, rgbColor);
33 m_palette = palette;
34 m_rgbColor = rgbColor;
35 return m_hBrush;
36}
37
39{
41 m_brushWidth = 4;
42 m_shapeStyle = 0;
50}
51
53{
54 delete m_pToolObject;
56}
57
59{
60 delete m_pToolObject;
62 return m_pToolObject;
63}
64
66{
68}
69
71{
72 return m_lineWidth;
73}
74
75void ToolsModel::SetLineWidth(int nLineWidth)
76{
77 m_lineWidth = nLineWidth;
80}
81
83{
84 return m_penWidth;
85}
86
88{
89 m_penWidth = nPenWidth;
92}
93
95{
96 return m_brushWidth;
97}
98
100{
103}
104
106{
107 m_brushWidth = nBrushWidth;
111}
112
114{
115 INT thickness = GetLineWidth();
116 SetLineWidth(bThinner ? max(1, thickness - 1) : (thickness + 1));
117}
118
120{
121 INT thickness = GetPenWidth();
122 SetPenWidth(bThinner ? max(1, thickness - 1) : (thickness + 1));
123}
124
126{
127 INT thickness = GetBrushWidth();
128 SetBrushWidth(bThinner ? max(1, thickness - 1) : (thickness + 1));
129}
130
132{
133 INT thickness = GetAirBrushRadius();
134 SetAirBrushRadius(bThinner ? max(1, thickness - 1) : (thickness + 1));
135}
136
138{
139 INT thickness = GetRubberRadius();
140 SetRubberRadius(bThinner ? max(1, thickness - 1) : (thickness + 1));
141}
142
144{
145 return m_shapeStyle;
146}
147
148void ToolsModel::SetShapeStyle(int nShapeStyle)
149{
150 m_shapeStyle = nShapeStyle;
152}
153
155{
156 return m_brushStyle;
157}
158
160{
161 m_brushStyle = nBrushStyle;
164}
165
167{
168 return m_activeTool;
169}
170
172{
173 return m_oldActiveTool;
174}
175
177{
179
181
182 m_activeTool = nActiveTool;
183
184 switch (m_activeTool)
185 {
186 case TOOL_FREESEL:
187 case TOOL_RECTSEL:
188 case TOOL_COLOR:
189 case TOOL_ZOOM:
190 case TOOL_TEXT:
191 // The active tool is not an actually drawing tool
192 break;
193
194 case TOOL_LINE:
195 case TOOL_BEZIER:
196 case TOOL_RECT:
197 case TOOL_SHAPE:
198 case TOOL_ELLIPSE:
199 case TOOL_FILL:
200 case TOOL_AIRBRUSH:
201 case TOOL_RRECT:
202 case TOOL_RUBBER:
203 case TOOL_BRUSH:
204 case TOOL_PEN:
205 // The active tool is an actually drawing tool. Save it for TOOL_COLOR to restore
206 m_oldActiveTool = nActiveTool;
207 break;
208 }
209
211
213}
214
216{
217 return m_airBrushRadius;
218}
219
221{
222 m_airBrushRadius = nAirBrushRadius;
224}
225
227{
228 return m_rubberRadius;
229}
230
231void ToolsModel::SetRubberRadius(int nRubberRadius)
232{
233 m_rubberRadius = nRubberRadius;
236}
237
239{
240 SIZE size;
241 switch (m_activeTool)
242 {
243 case TOOL_FREESEL:
244 case TOOL_RECTSEL:
247 break;
248 case TOOL_COLOR:
249 case TOOL_ZOOM:
250 case TOOL_TEXT:
251 case TOOL_FILL:
252 size.cx = size.cy = 1;
253 break;
254 case TOOL_LINE:
255 case TOOL_BEZIER:
256 case TOOL_RECT:
257 case TOOL_RRECT:
258 case TOOL_SHAPE:
259 case TOOL_ELLIPSE:
260 size.cx = size.cy = GetLineWidth();
261 break;
262 case TOOL_AIRBRUSH:
263 size.cx = size.cy = GetAirBrushRadius() * 2;
264 break;
265 case TOOL_RUBBER:
266 size.cx = size.cy = GetRubberRadius() * 2;
267 break;
268 case TOOL_BRUSH:
269 size.cx = size.cy = GetBrushWidth();
270 break;
271 case TOOL_PEN:
272 size.cx = size.cy = GetPenWidth();
273 break;
274 }
275 if (size.cx < 1)
276 size.cx = 1;
277 if (size.cy < 1)
278 size.cy = 1;
279 return size;
280}
281
283{
284 return m_transpBg;
285}
286
288{
289 m_transpBg = bTransparent;
292}
293
295{
296 return m_zoom;
297}
298
299void ToolsModel::SetZoom(int nZoom)
300{
301 m_zoom = nZoom;
304}
305
307{
308 if (toolBoxContainer.IsWindow())
310 if (toolSettingsWindow.IsWindow())
312 if (fontsDialog.IsWindow())
314 if (textEditWindow.IsWindow())
316}
317
319{
320 if (toolSettingsWindow.IsWindow())
322 if (textEditWindow.IsWindow())
324}
325
327{
328 if (toolSettingsWindow.IsWindow())
330 if (textEditWindow.IsWindow())
332 if (canvasWindow.IsWindow())
334}
335
337{
339}
340
342{
344 OnButtonDown(TRUE, 0, 0, FALSE);
347}
348
350{
351 if (palette == PAL_MONOCHROME)
352 return CreateDitherBrush(color, RGB(0, 0, 0), RGB(255, 255, 255));
353 else
354 return ::CreateSolidBrush(color);
355}
356
358{
360}
361
363{
365}
CFontsDialog fontsDialog
Definition: dialogs.cpp:16
#define DEFAULT_ZOOM
Definition: precomp.h:46
#define WM_TOOLSMODELZOOMCHANGED
Definition: precomp.h:53
SelectionModel selectionModel
CToolBox toolBoxContainer
Definition: toolbox.cpp:11
#define WM_TOOLSMODELTOOLCHANGED
Definition: precomp.h:50
#define WM_TOOLSMODELSETTINGSCHANGED
Definition: precomp.h:51
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
PAL_TYPE SelectedPalette()
COLORREF GetBgColor() const
COLORREF GetFgColor() const
HBRUSH GetBrush(PAL_TYPE palette, COLORREF rgbColor)
Definition: toolsmodel.cpp:20
void MakeAirBrushThickerOrThinner(BOOL bThinner)
Definition: toolsmodel.cpp:131
void OnEndDraw(BOOL bCancel)
Definition: mouse.cpp:1182
void SetBrushStyle(BrushStyle nBrushStyle)
Definition: toolsmodel.cpp:159
HBRUSH GetFgBrush()
Definition: toolsmodel.cpp:357
void MakeBrushThickerOrThinner(BOOL bThinner)
Definition: toolsmodel.cpp:125
int GetZoom() const
Definition: toolsmodel.cpp:294
TOOLTYPE m_oldActiveTool
Definition: toolsmodel.h:89
int GetLineWidth() const
Definition: toolsmodel.cpp:70
HBRUSH GetBgBrush()
Definition: toolsmodel.cpp:362
INT m_airBrushRadius
Definition: toolsmodel.h:90
INT m_brushWidth
Definition: toolsmodel.h:85
BOOL IsSelection() const
Definition: toolsmodel.cpp:65
int GetShapeStyle() const
Definition: toolsmodel.cpp:143
void SendSetCursor()
Definition: toolsmodel.cpp:99
int m_rubberRadius
Definition: toolsmodel.h:91
int m_lineWidth
Definition: toolsmodel.h:83
void SetAirBrushRadius(INT nAirBrushRadius)
Definition: toolsmodel.cpp:220
void resetTool()
Definition: toolsmodel.cpp:336
BOOL m_transpBg
Definition: toolsmodel.h:92
int m_shapeStyle
Definition: toolsmodel.h:86
TOOLTYPE GetOldActiveTool() const
Definition: toolsmodel.cpp:171
void SetShapeStyle(int nShapeStyle)
Definition: toolsmodel.cpp:148
void SetActiveTool(TOOLTYPE nActiveTool)
Definition: toolsmodel.cpp:176
void SetRubberRadius(int nRubberRadius)
Definition: toolsmodel.cpp:231
void NotifyToolChanged()
Definition: toolsmodel.cpp:306
void OnMouseMove(BOOL bLeftButton, LONG x, LONG y)
Definition: mouse.cpp:1164
BrushStyle m_brushStyle
Definition: toolsmodel.h:87
INT GetPenWidth() const
Definition: toolsmodel.cpp:82
int m_zoom
Definition: toolsmodel.h:93
BrushStyle GetBrushStyle() const
Definition: toolsmodel.cpp:154
void OnButtonDown(BOOL bLeftButton, LONG x, LONG y, BOOL bDoubleClick)
Definition: mouse.cpp:1156
void MakeRubberThickerOrThinner(BOOL bThinner)
Definition: toolsmodel.cpp:137
BOOL IsBackgroundTransparent() const
Definition: toolsmodel.cpp:282
void SetZoom(int nZoom)
Definition: toolsmodel.cpp:299
void SetBackgroundTransparent(BOOL bTransparent)
Definition: toolsmodel.cpp:287
TOOLTYPE m_activeTool
Definition: toolsmodel.h:88
VirtualBrush m_bgBrush
Definition: toolsmodel.h:96
int GetRubberRadius() const
Definition: toolsmodel.cpp:226
ToolBase * m_pToolObject
Definition: toolsmodel.h:94
void NotifyToolSettingsChanged()
Definition: toolsmodel.cpp:318
VirtualBrush m_fgBrush
Definition: toolsmodel.h:95
ToolBase * GetOrCreateTool(TOOLTYPE nTool)
Definition: toolsmodel.cpp:58
void MakeLineThickerOrThinner(BOOL bThinner)
Definition: toolsmodel.cpp:113
TOOLTYPE GetActiveTool() const
Definition: toolsmodel.cpp:166
void MakePenThickerOrThinner(BOOL bThinner)
Definition: toolsmodel.cpp:119
static HBRUSH CreateBrush(PAL_TYPE palette, COLORREF color)
Definition: toolsmodel.cpp:349
void selectAll()
Definition: toolsmodel.cpp:341
void NotifyZoomChanged()
Definition: toolsmodel.cpp:326
void SetPenWidth(INT nPenWidth)
Definition: toolsmodel.cpp:87
void SetBrushWidth(INT nBrushWidth)
Definition: toolsmodel.cpp:105
INT GetAirBrushRadius() const
Definition: toolsmodel.cpp:215
void OnButtonUp(BOOL bLeftButton, LONG x, LONG y)
Definition: mouse.cpp:1173
void SetLineWidth(int nLineWidth)
Definition: toolsmodel.cpp:75
INT GetBrushWidth() const
Definition: toolsmodel.cpp:94
SIZE GetToolSize() const
Definition: toolsmodel.cpp:238
INT m_penWidth
Definition: toolsmodel.h:84
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
HBRUSH CreateDitherBrush(COLORREF color, COLORREF monoColor0, COLORREF monoColor1)
Definition: drawing.cpp:650
#define RGB(r, g, b)
Definition: precomp.h:67
unsigned int BOOL
Definition: ntddk_ex.h:94
pKey DeleteObject()
GLsizeiptr size
Definition: glext.h:5919
GLuint color
Definition: glext.h:6243
ImageModel imageModel
Definition: history.cpp:11
UINT_PTR WPARAM
Definition: minwindef.h:174
static HPALETTE palette
Definition: clipboard.c:1457
PaletteModel paletteModel
PAL_TYPE
Definition: palettemodel.h:13
@ PAL_MONOCHROME
Definition: palettemodel.h:17
void reset()
Definition: mouse.cpp:106
static ToolBase * createToolObject(TOOLTYPE type)
Definition: mouse.cpp:1131
#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
DWORD COLORREF
Definition: windef.h:100
#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