- Update to r53061
[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
13 /* FUNCTIONS ********************************************************/
14
15 extern void zoomTo(int, int, int);
16
17 LRESULT CALLBACK
18 SettingsWinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
19 {
20 switch (message)
21 {
22 case WM_VSCROLL:
23 zoomTo(125 << SendMessage(hTrackbarZoom, TBM_GETPOS, 0, 0), 0, 0);
24 break;
25 case WM_PAINT:
26 {
27 HDC hdc = GetDC(hwnd);
28 RECT rect1 = { 0, 0, 42, 66 };
29 RECT rect2 = { 0, 70, 42, 136 };
30
31 DefWindowProc(hwnd, message, wParam, lParam);
32
33 DrawEdge(hdc, &rect1, BDR_SUNKENOUTER, (activeTool == TOOL_ZOOM) ? BF_RECT : BF_RECT | BF_MIDDLE);
34 DrawEdge(hdc, &rect2, (activeTool >= TOOL_RECT) ? BDR_SUNKENOUTER : 0, BF_RECT | BF_MIDDLE);
35 switch (activeTool)
36 {
37 case TOOL_FREESEL:
38 case TOOL_RECTSEL:
39 case TOOL_TEXT:
40 {
41 HPEN oldPen = SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
42 SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT));
43 Rectangle(hdc, 2, transpBg * 31 + 2, 41, transpBg * 31 + 33);
44 DeleteObject(SelectObject(hdc, oldPen));
45 DrawIconEx(hdc, 1, 2, hNontranspIcon, 40, 30, 0, NULL, DI_NORMAL);
46 DrawIconEx(hdc, 1, 33, hTranspIcon, 40, 30, 0, NULL, DI_NORMAL);
47 break;
48 }
49 case TOOL_RUBBER:
50 {
51 int i;
52 HPEN oldPen = SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
53 for(i = 0; i < 4; i++)
54 {
55 if (rubberRadius == i + 2)
56 {
57 SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT));
58 Rectangle(hdc, 14, i * 15 + 2, 29, i * 15 + 17);
59 SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHTTEXT));
60 }
61 else
62 SelectObject(hdc, GetSysColorBrush(COLOR_WINDOWTEXT));
63 Rectangle(hdc, 19 - i, i * 14 + 7, 24 + i, i * 16 + 12);
64 }
65 DeleteObject(SelectObject(hdc, oldPen));
66 break;
67 }
68 case TOOL_BRUSH:
69 {
70 int i;
71 HPEN oldPen = SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
72 SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT));
73 Rectangle(hdc, brushStyle % 3 * 13 + 2, brushStyle / 3 * 15 + 2, brushStyle % 3 * 13 + 15,
74 brushStyle / 3 * 15 + 17);
75 DeleteObject(SelectObject(hdc, oldPen));
76 for(i = 0; i < 12; i++)
77 Brush(hdc, i % 3 * 13 + 7, i / 3 * 15 + 8, i % 3 * 13 + 7, i / 3 * 15 + 8,
78 GetSysColor((i == brushStyle) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT), i);
79 break;
80 }
81 case TOOL_AIRBRUSH:
82 {
83 HPEN oldPen = SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
84 SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT));
85 switch (airBrushWidth)
86 {
87 case 5:
88 Rectangle(hdc, 2, 2, 21, 31);
89 break;
90 case 8:
91 Rectangle(hdc, 20, 2, 41, 31);
92 break;
93 case 3:
94 Rectangle(hdc, 2, 30, 16, 61);
95 break;
96 case 12:
97 Rectangle(hdc, 15, 30, 41, 61);
98 break;
99 }
100 Airbrush(hdc, 10, 15,
101 GetSysColor((airBrushWidth == 5) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT), 5);
102 Airbrush(hdc, 30, 15,
103 GetSysColor((airBrushWidth == 8) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT), 8);
104 Airbrush(hdc, 8, 45,
105 GetSysColor((airBrushWidth == 3) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT), 3);
106 Airbrush(hdc, 27, 45,
107 GetSysColor((airBrushWidth == 12) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT), 12);
108 DeleteObject(SelectObject(hdc, oldPen));
109 break;
110 }
111 case TOOL_LINE:
112 case TOOL_BEZIER:
113 {
114 int i;
115 HPEN oldPen = SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
116 for(i = 0; i < 5; i++)
117 {
118 if (lineWidth == i + 1)
119 {
120 SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT));
121 Rectangle(hdc, 2, i * 12 + 2, 41, i * 12 + 14);
122 SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHTTEXT));
123 }
124 else
125 SelectObject(hdc, GetSysColorBrush(COLOR_WINDOWTEXT));
126 Rectangle(hdc, 5, i * 12 + 6, 38, i * 12 + 8 + i);
127 }
128 DeleteObject(SelectObject(hdc, oldPen));
129 break;
130 }
131 case TOOL_RECT:
132 case TOOL_SHAPE:
133 case TOOL_ELLIPSE:
134 case TOOL_RRECT:
135 {
136 int i;
137 HPEN oldPen = SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
138 for(i = 0; i < 3; i++)
139 {
140 if (shapeStyle == i)
141 {
142 SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT));
143 Rectangle(hdc, 2, i * 20 + 2, 41, i * 20 + 22);
144 }
145 }
146 Rect(hdc, 5, 6, 37, 16,
147 GetSysColor((shapeStyle == 0) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT),
148 GetSysColor(COLOR_APPWORKSPACE), 1, 0);
149 Rect(hdc, 5, 26, 37, 36,
150 GetSysColor((shapeStyle == 1) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT),
151 GetSysColor(COLOR_APPWORKSPACE), 1, 1);
152 Rect(hdc, 5, 46, 37, 56, GetSysColor(COLOR_APPWORKSPACE), GetSysColor(COLOR_APPWORKSPACE),
153 1, 1);
154 for(i = 0; i < 5; i++)
155 {
156 if (lineWidth == i + 1)
157 {
158 SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT));
159 Rectangle(hdc, 2, i * 12 + 72, 41, i * 12 + 84);
160 SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHTTEXT));
161 }
162 else
163 SelectObject(hdc, GetSysColorBrush(COLOR_WINDOWTEXT));
164 Rectangle(hdc, 5, i * 12 + 76, 38, i * 12 + 78 + i);
165 }
166 DeleteObject(SelectObject(hdc, oldPen));
167 break;
168 }
169 }
170 ReleaseDC(hwnd, hdc);
171 break;
172 }
173 case WM_LBUTTONDOWN:
174 {
175 switch (activeTool)
176 {
177 case TOOL_FREESEL:
178 case TOOL_RECTSEL:
179 case TOOL_TEXT:
180 if ((HIWORD(lParam) > 1) && (HIWORD(lParam) < 64))
181 {
182 transpBg = (HIWORD(lParam) - 2) / 31;
183 SendMessage(hwnd, WM_PAINT, 0, 0);
184 }
185 break;
186 case TOOL_RUBBER:
187 if ((HIWORD(lParam) > 1) && (HIWORD(lParam) < 62))
188 {
189 rubberRadius = (HIWORD(lParam) - 2) / 15 + 2;
190 SendMessage(hwnd, WM_PAINT, 0, 0);
191 }
192 break;
193 case TOOL_BRUSH:
194 if ((LOWORD(lParam) > 1) && (LOWORD(lParam) < 40) && (HIWORD(lParam) > 1)
195 && (HIWORD(lParam) < 62))
196 {
197 brushStyle = (HIWORD(lParam) - 2) / 15 * 3 + (LOWORD(lParam) - 2) / 13;
198 SendMessage(hwnd, WM_PAINT, 0, 0);
199 }
200 break;
201 case TOOL_AIRBRUSH:
202 if (HIWORD(lParam) < 62)
203 {
204 if (HIWORD(lParam) < 30)
205 {
206 if (LOWORD(lParam) < 20)
207 airBrushWidth = 5;
208 else
209 airBrushWidth = 8;
210 }
211 else
212 {
213 if (LOWORD(lParam) < 15)
214 airBrushWidth = 3;
215 else
216 airBrushWidth = 12;
217 }
218 SendMessage(hwnd, WM_PAINT, 0, 0);
219 }
220 break;
221 case TOOL_LINE:
222 case TOOL_BEZIER:
223 if (HIWORD(lParam) <= 62)
224 {
225 lineWidth = (HIWORD(lParam) - 2) / 12 + 1;
226 SendMessage(hwnd, WM_PAINT, 0, 0);
227 }
228 break;
229 case TOOL_RECT:
230 case TOOL_SHAPE:
231 case TOOL_ELLIPSE:
232 case TOOL_RRECT:
233 if (HIWORD(lParam) <= 60)
234 {
235 shapeStyle = (HIWORD(lParam) - 2) / 20;
236 SendMessage(hwnd, WM_PAINT, 0, 0);
237 }
238 if ((HIWORD(lParam) >= 70) && (HIWORD(lParam) <= 132))
239 {
240 lineWidth = (HIWORD(lParam) - 72) / 12 + 1;
241 SendMessage(hwnd, WM_PAINT, 0, 0);
242 }
243 break;
244 }
245 break;
246 }
247
248 default:
249 return DefWindowProc(hwnd, message, wParam, lParam);
250 }
251
252 return 0;
253 }