Create a branch for console restructuration work.
[reactos.git] / base / applications / mspaint / toolsettings.c
1 /*
2 * PROJECT: PAINT for ReactOS
3 * LICENSE: LGPL
4 * FILE: base/applications/paint/toolsettings.c
5 * PURPOSE: Window procedure of the tool settings window
6 * PROGRAMMERS: Benedikt Freisen
7 */
8
9 /* INCLUDES *********************************************************/
10
11 #include "precomp.h"
12 #include "toolsettings.h"
13
14 /* FUNCTIONS ********************************************************/
15
16 extern void zoomTo(int, int, int);
17
18 void RegisterWclSettings()
19 {
20 WNDCLASSEX wclSettings;
21 /* initializing and registering the window class for the settings window */
22 wclSettings.hInstance = hProgInstance;
23 wclSettings.lpszClassName = _T("ToolSettings");
24 wclSettings.lpfnWndProc = SettingsWinProc;
25 wclSettings.style = CS_DBLCLKS;
26 wclSettings.cbSize = sizeof(WNDCLASSEX);
27 wclSettings.hIcon = NULL;
28 wclSettings.hIconSm = NULL;
29 wclSettings.hCursor = LoadCursor(NULL, IDC_ARROW);
30 wclSettings.lpszMenuName = NULL;
31 wclSettings.cbClsExtra = 0;
32 wclSettings.cbWndExtra = 0;
33 wclSettings.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
34 RegisterClassEx (&wclSettings);
35 }
36
37 LRESULT CALLBACK
38 SettingsWinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
39 {
40 switch (message)
41 {
42 case WM_VSCROLL:
43 zoomTo(125 << SendMessage(hTrackbarZoom, TBM_GETPOS, 0, 0), 0, 0);
44 break;
45 case WM_PAINT:
46 {
47 HDC hdc = GetDC(hwnd);
48 RECT rect1 = { 0, 0, 42, 66 };
49 RECT rect2 = { 0, 70, 42, 136 };
50
51 DefWindowProc(hwnd, message, wParam, lParam);
52
53 DrawEdge(hdc, &rect1, BDR_SUNKENOUTER, (activeTool == TOOL_ZOOM) ? BF_RECT : BF_RECT | BF_MIDDLE);
54 DrawEdge(hdc, &rect2, (activeTool >= TOOL_RECT) ? BDR_SUNKENOUTER : 0, BF_RECT | BF_MIDDLE);
55 switch (activeTool)
56 {
57 case TOOL_FREESEL:
58 case TOOL_RECTSEL:
59 case TOOL_TEXT:
60 {
61 HPEN oldPen = SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
62 SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT));
63 Rectangle(hdc, 2, transpBg * 31 + 2, 41, transpBg * 31 + 33);
64 DeleteObject(SelectObject(hdc, oldPen));
65 DrawIconEx(hdc, 1, 2, hNontranspIcon, 40, 30, 0, NULL, DI_NORMAL);
66 DrawIconEx(hdc, 1, 33, hTranspIcon, 40, 30, 0, NULL, DI_NORMAL);
67 break;
68 }
69 case TOOL_RUBBER:
70 {
71 int i;
72 HPEN oldPen = SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
73 for(i = 0; i < 4; i++)
74 {
75 if (rubberRadius == i + 2)
76 {
77 SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT));
78 Rectangle(hdc, 14, i * 15 + 2, 29, i * 15 + 17);
79 SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHTTEXT));
80 }
81 else
82 SelectObject(hdc, GetSysColorBrush(COLOR_WINDOWTEXT));
83 Rectangle(hdc, 19 - i, i * 14 + 7, 24 + i, i * 16 + 12);
84 }
85 DeleteObject(SelectObject(hdc, oldPen));
86 break;
87 }
88 case TOOL_BRUSH:
89 {
90 int i;
91 HPEN oldPen = SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
92 SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT));
93 Rectangle(hdc, brushStyle % 3 * 13 + 2, brushStyle / 3 * 15 + 2, brushStyle % 3 * 13 + 15,
94 brushStyle / 3 * 15 + 17);
95 DeleteObject(SelectObject(hdc, oldPen));
96 for(i = 0; i < 12; i++)
97 Brush(hdc, i % 3 * 13 + 7, i / 3 * 15 + 8, i % 3 * 13 + 7, i / 3 * 15 + 8,
98 GetSysColor((i == brushStyle) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT), i);
99 break;
100 }
101 case TOOL_AIRBRUSH:
102 {
103 HPEN oldPen = SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
104 SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT));
105 switch (airBrushWidth)
106 {
107 case 5:
108 Rectangle(hdc, 2, 2, 21, 31);
109 break;
110 case 8:
111 Rectangle(hdc, 20, 2, 41, 31);
112 break;
113 case 3:
114 Rectangle(hdc, 2, 30, 16, 61);
115 break;
116 case 12:
117 Rectangle(hdc, 15, 30, 41, 61);
118 break;
119 }
120 Airbrush(hdc, 10, 15,
121 GetSysColor((airBrushWidth == 5) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT), 5);
122 Airbrush(hdc, 30, 15,
123 GetSysColor((airBrushWidth == 8) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT), 8);
124 Airbrush(hdc, 8, 45,
125 GetSysColor((airBrushWidth == 3) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT), 3);
126 Airbrush(hdc, 27, 45,
127 GetSysColor((airBrushWidth == 12) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT), 12);
128 DeleteObject(SelectObject(hdc, oldPen));
129 break;
130 }
131 case TOOL_LINE:
132 case TOOL_BEZIER:
133 {
134 int i;
135 HPEN oldPen = SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
136 for(i = 0; i < 5; i++)
137 {
138 if (lineWidth == i + 1)
139 {
140 SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT));
141 Rectangle(hdc, 2, i * 12 + 2, 41, i * 12 + 14);
142 SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHTTEXT));
143 }
144 else
145 SelectObject(hdc, GetSysColorBrush(COLOR_WINDOWTEXT));
146 Rectangle(hdc, 5, i * 12 + 6, 38, i * 12 + 8 + i);
147 }
148 DeleteObject(SelectObject(hdc, oldPen));
149 break;
150 }
151 case TOOL_RECT:
152 case TOOL_SHAPE:
153 case TOOL_ELLIPSE:
154 case TOOL_RRECT:
155 {
156 int i;
157 HPEN oldPen = SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
158 for(i = 0; i < 3; i++)
159 {
160 if (shapeStyle == i)
161 {
162 SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT));
163 Rectangle(hdc, 2, i * 20 + 2, 41, i * 20 + 22);
164 }
165 }
166 Rect(hdc, 5, 6, 37, 16,
167 GetSysColor((shapeStyle == 0) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT),
168 GetSysColor(COLOR_APPWORKSPACE), 1, 0);
169 Rect(hdc, 5, 26, 37, 36,
170 GetSysColor((shapeStyle == 1) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT),
171 GetSysColor(COLOR_APPWORKSPACE), 1, 1);
172 Rect(hdc, 5, 46, 37, 56, GetSysColor(COLOR_APPWORKSPACE), GetSysColor(COLOR_APPWORKSPACE),
173 1, 1);
174 for(i = 0; i < 5; i++)
175 {
176 if (lineWidth == i + 1)
177 {
178 SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT));
179 Rectangle(hdc, 2, i * 12 + 72, 41, i * 12 + 84);
180 SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHTTEXT));
181 }
182 else
183 SelectObject(hdc, GetSysColorBrush(COLOR_WINDOWTEXT));
184 Rectangle(hdc, 5, i * 12 + 76, 38, i * 12 + 78 + i);
185 }
186 DeleteObject(SelectObject(hdc, oldPen));
187 break;
188 }
189 }
190 ReleaseDC(hwnd, hdc);
191 break;
192 }
193 case WM_LBUTTONDOWN:
194 {
195 int x = GET_X_LPARAM(lParam);
196 int y = GET_Y_LPARAM(lParam);
197 switch (activeTool)
198 {
199 case TOOL_FREESEL:
200 case TOOL_RECTSEL:
201 case TOOL_TEXT:
202 if ((y > 1) && (y < 64))
203 {
204 transpBg = (y - 2) / 31;
205 InvalidateRect(hwnd, NULL, TRUE);
206
207 ForceRefreshSelectionContents();
208 }
209 break;
210 case TOOL_RUBBER:
211 if ((y > 1) && (y < 62))
212 {
213 rubberRadius = (y - 2) / 15 + 2;
214 InvalidateRect(hwnd, NULL, TRUE);
215 }
216 break;
217 case TOOL_BRUSH:
218 if ((x > 1) && (x < 40) && (y > 1)
219 && (y < 62))
220 {
221 brushStyle = (y - 2) / 15 * 3 + (x - 2) / 13;
222 InvalidateRect(hwnd, NULL, TRUE);
223 }
224 break;
225 case TOOL_AIRBRUSH:
226 if (y < 62)
227 {
228 if (y < 30)
229 {
230 if (x < 20)
231 airBrushWidth = 5;
232 else
233 airBrushWidth = 8;
234 }
235 else
236 {
237 if (x < 15)
238 airBrushWidth = 3;
239 else
240 airBrushWidth = 12;
241 }
242 InvalidateRect(hwnd, NULL, TRUE);
243 }
244 break;
245 case TOOL_LINE:
246 case TOOL_BEZIER:
247 if (y <= 62)
248 {
249 lineWidth = (y - 2) / 12 + 1;
250 InvalidateRect(hwnd, NULL, TRUE);
251 }
252 break;
253 case TOOL_RECT:
254 case TOOL_SHAPE:
255 case TOOL_ELLIPSE:
256 case TOOL_RRECT:
257 if (y <= 60)
258 {
259 shapeStyle = (y - 2) / 20;
260 InvalidateRect(hwnd, NULL, TRUE);
261 }
262 if ((y >= 70) && (y <= 132))
263 {
264 lineWidth = (y - 72) / 12 + 1;
265 InvalidateRect(hwnd, NULL, TRUE);
266 }
267 break;
268 }
269 break;
270 }
271
272 default:
273 return DefWindowProc(hwnd, message, wParam, lParam);
274 }
275
276 return 0;
277 }