-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtoolsmodel.h
178 lines (139 loc) · 4.18 KB
/
toolsmodel.h
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
/*
* 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 <[email protected]>
*/
#pragma once
enum TOOLTYPE
{
TOOL_FREESEL = 1,
TOOL_RECTSEL = 2,
TOOL_RUBBER = 3,
TOOL_FILL = 4,
TOOL_COLOR = 5,
TOOL_ZOOM = 6,
TOOL_PEN = 7,
TOOL_BRUSH = 8,
TOOL_AIRBRUSH = 9,
TOOL_TEXT = 10,
TOOL_LINE = 11,
TOOL_BEZIER = 12,
TOOL_RECT = 13,
TOOL_SHAPE = 14,
TOOL_ELLIPSE = 15,
TOOL_RRECT = 16,
TOOL_MAX = TOOL_RRECT,
};
enum BrushStyle
{
BrushStyleRound,
BrushStyleSquare,
BrushStyleForeSlash,
BrushStyleBackSlash,
};
/* CLASSES **********************************************************/
struct ToolBase
{
HDC m_hdc;
COLORREF m_fg, m_bg;
ToolBase() : m_hdc(NULL) { }
virtual ~ToolBase() { }
virtual void OnButtonDown(BOOL bLeftButton, LONG x, LONG y, BOOL bDoubleClick) { }
virtual BOOL OnMouseMove(BOOL bLeftButton, LONG& x, LONG& y) { return TRUE; }
virtual BOOL OnButtonUp(BOOL bLeftButton, LONG& x, LONG& y) { return TRUE; }
virtual void OnDrawOverlayOnImage(HDC hdc) { }
virtual void OnDrawOverlayOnCanvas(HDC hdc) { }
virtual void OnSpecialTweak(BOOL bMinus) { }
virtual void OnEndDraw(BOOL bCancel);
void beginEvent();
void endEvent();
void reset();
static ToolBase* createToolObject(TOOLTYPE type);
};
class ToolsModel
{
private:
int m_lineWidth;
INT m_penWidth;
INT m_brushWidth;
int m_shapeStyle;
BrushStyle m_brushStyle;
TOOLTYPE m_activeTool;
TOOLTYPE m_oldActiveTool;
INT m_airBrushRadius;
int m_rubberRadius;
BOOL m_transpBg;
int m_zoom;
ToolBase *m_pToolObject;
ToolBase *GetOrCreateTool(TOOLTYPE nTool);
public:
ToolsModel();
~ToolsModel();
BOOL IsSelection() const;
int GetLineWidth() const;
void SetLineWidth(int nLineWidth);
void MakeLineThickerOrThinner(BOOL bThinner);
INT GetPenWidth() const;
void SetPenWidth(INT nPenWidth);
void MakePenThickerOrThinner(BOOL bThinner);
int GetShapeStyle() const;
void SetShapeStyle(int nShapeStyle);
INT GetBrushWidth() const;
void SetBrushWidth(INT nBrushWidth);
void MakeBrushThickerOrThinner(BOOL bThinner);
BrushStyle GetBrushStyle() const;
void SetBrushStyle(BrushStyle nBrushStyle);
TOOLTYPE GetActiveTool() const;
TOOLTYPE GetOldActiveTool() const;
void SetActiveTool(TOOLTYPE nActiveTool);
INT GetAirBrushRadius() const;
void SetAirBrushRadius(INT nAirBrushRadius);
void MakeAirBrushThickerOrThinner(BOOL bThinner);
int GetRubberRadius() const;
void SetRubberRadius(int nRubberRadius);
void MakeRubberThickerOrThinner(BOOL bThinner);
SIZE GetToolSize() const;
BOOL IsBackgroundTransparent() const;
void SetBackgroundTransparent(BOOL bTransparent);
int GetZoom() const;
void SetZoom(int nZoom);
void OnButtonDown(BOOL bLeftButton, LONG x, LONG y, BOOL bDoubleClick);
void OnMouseMove(BOOL bLeftButton, LONG x, LONG y);
void OnButtonUp(BOOL bLeftButton, LONG x, LONG y);
void OnEndDraw(BOOL bCancel);
void OnDrawOverlayOnImage(HDC hdc);
void OnDrawOverlayOnCanvas(HDC hdc);
void resetTool();
void selectAll();
void NotifyToolChanged();
void NotifyToolSettingsChanged();
void NotifyZoomChanged();
void SpecialTweak(BOOL bMinus);
void DrawWithMouseTool(POINT pt, WPARAM wParam);
};
extern ToolsModel toolsModel;
static inline int Zoomed(int xy)
{
return xy * toolsModel.GetZoom() / 1000;
}
static inline int UnZoomed(int xy)
{
return xy * 1000 / toolsModel.GetZoom();
}
static inline void Zoomed(POINT& pt)
{
pt = { Zoomed(pt.x), Zoomed(pt.y) };
}
static inline void Zoomed(RECT& rc)
{
rc = { Zoomed(rc.left), Zoomed(rc.top), Zoomed(rc.right), Zoomed(rc.bottom) };
}
static inline void UnZoomed(POINT& pt)
{
pt = { UnZoomed(pt.x), UnZoomed(pt.y) };
}
static inline void UnZoomed(RECT& rc)
{
rc = { UnZoomed(rc.left), UnZoomed(rc.top), UnZoomed(rc.right), UnZoomed(rc.bottom) };
}