87cee6c027a41f5d866e9084b4ddbba021513789
[reactos.git] / reactos / base / applications / paint / mouse.c
1 /*
2 * PROJECT: PAINT for ReactOS
3 * LICENSE: LGPL
4 * FILE: base/applications/paint/mouse.c
5 * PURPOSE: Things which should not be in the mouse event handler itself
6 * PROGRAMMERS: Benedikt Freisen
7 */
8
9 /* INCLUDES *********************************************************/
10
11 #include "globalvar.h"
12 #include "dib.h"
13 #include "drawing.h"
14 #include "history.h"
15
16 /* FUNCTIONS ********************************************************/
17
18 void
19 placeSelWin()
20 {
21 MoveWindow(hSelection, rectSel_dest[0] * zoom / 1000, rectSel_dest[1] * zoom / 1000,
22 rectSel_dest[2] * zoom / 1000 + 6, rectSel_dest[3] * zoom / 1000 + 6, TRUE);
23 BringWindowToTop(hSelection);
24 SendMessage(hImageArea, WM_PAINT, 0, 0);
25 //SendMessage(hSelection, WM_PAINT, 0, 0);
26 }
27
28 POINT pointStack[256];
29 short pointSP;
30
31 void
32 startPaintingL(HDC hdc, short x, short y, int fg, int bg)
33 {
34 startX = x;
35 startY = y;
36 lastX = x;
37 lastY = y;
38 switch (activeTool)
39 {
40 case 1:
41 case 10:
42 case 11:
43 case 13:
44 case 15:
45 case 16:
46 newReversible();
47 case 2:
48 newReversible();
49 ShowWindow(hSelection, SW_HIDE);
50 break;
51 case 3:
52 newReversible();
53 Erase(hdc, x, y, x, y, bg, rubberRadius);
54 break;
55 case 4:
56 newReversible();
57 Fill(hdc, x, y, fg);
58 break;
59 case 7:
60 newReversible();
61 SetPixel(hdc, x, y, fg);
62 break;
63 case 8:
64 newReversible();
65 Brush(hdc, x, y, x, y, fg, brushStyle);
66 break;
67 case 9:
68 newReversible();
69 Airbrush(hdc, x, y, fg, airBrushWidth);
70 break;
71 case 12:
72 pointStack[pointSP].x = x;
73 pointStack[pointSP].y = y;
74 if (pointSP == 0)
75 {
76 newReversible();
77 pointSP++;
78 }
79 break;
80 case 14:
81 pointStack[pointSP].x = x;
82 pointStack[pointSP].y = y;
83 if (pointSP + 1 >= 2)
84 Poly(hdc, pointStack, pointSP + 1, fg, bg, lineWidth, shapeStyle, FALSE);
85 if (pointSP == 0)
86 {
87 newReversible();
88 pointSP++;
89 }
90 break;
91 }
92 }
93
94 void
95 whilePaintingL(HDC hdc, short x, short y, int fg, int bg)
96 {
97 switch (activeTool)
98 {
99 case 2:
100 {
101 short tempX;
102 short tempY;
103 resetToU1();
104 tempX = max(0, min(x, imgXRes));
105 tempY = max(0, min(y, imgYRes));
106 rectSel_dest[0] = rectSel_src[0] = min(startX, tempX);
107 rectSel_dest[1] = rectSel_src[1] = min(startY, tempY);
108 rectSel_dest[2] = rectSel_src[2] = max(startX, tempX) - min(startX, tempX);
109 rectSel_dest[3] = rectSel_src[3] = max(startY, tempY) - min(startY, tempY);
110 RectSel(hdc, startX, startY, tempX, tempY);
111 break;
112 }
113 case 3:
114 Erase(hdc, lastX, lastY, x, y, bg, rubberRadius);
115 break;
116 case 7:
117 Line(hdc, lastX, lastY, x, y, fg, 1);
118 break;
119 case 8:
120 Brush(hdc, lastX, lastY, x, y, fg, brushStyle);
121 break;
122 case 9:
123 Airbrush(hdc, x, y, fg, airBrushWidth);
124 break;
125 case 11:
126 resetToU1();
127 Line(hdc, startX, startY, x, y, fg, lineWidth);
128 break;
129 case 12:
130 resetToU1();
131 pointStack[pointSP].x = x;
132 pointStack[pointSP].y = y;
133 switch (pointSP)
134 {
135 case 1:
136 Line(hdc, pointStack[0].x, pointStack[0].y, pointStack[1].x, pointStack[1].y, fg,
137 lineWidth);
138 break;
139 case 2:
140 Bezier(hdc, pointStack[0], pointStack[2], pointStack[2], pointStack[1], fg, lineWidth);
141 break;
142 case 3:
143 Bezier(hdc, pointStack[0], pointStack[2], pointStack[3], pointStack[1], fg, lineWidth);
144 break;
145 }
146 break;
147 case 13:
148 resetToU1();
149 Rect(hdc, startX, startY, x, y, fg, bg, lineWidth, shapeStyle);
150 break;
151 case 14:
152 resetToU1();
153 pointStack[pointSP].x = x;
154 pointStack[pointSP].y = y;
155 if (pointSP + 1 >= 2)
156 Poly(hdc, pointStack, pointSP + 1, fg, bg, lineWidth, shapeStyle, FALSE);
157 break;
158 case 15:
159 resetToU1();
160 Ellp(hdc, startX, startY, x, y, fg, bg, lineWidth, shapeStyle);
161 break;
162 case 16:
163 resetToU1();
164 RRect(hdc, startX, startY, x, y, fg, bg, lineWidth, shapeStyle);
165 break;
166 }
167
168 lastX = x;
169 lastY = y;
170 }
171
172 void
173 endPaintingL(HDC hdc, short x, short y, int fg, int bg)
174 {
175 switch (activeTool)
176 {
177 case 2:
178 resetToU1();
179 if ((rectSel_src[2] != 0) && (rectSel_src[3] != 0))
180 {
181 DeleteObject(SelectObject
182 (hSelDC, hSelBm =
183 (HBITMAP) CreateDIBWithProperties(rectSel_src[2], rectSel_src[3])));
184 BitBlt(hSelDC, 0, 0, rectSel_src[2], rectSel_src[3], hDrawingDC, rectSel_src[0],
185 rectSel_src[1], SRCCOPY);
186 placeSelWin();
187 ShowWindow(hSelection, SW_SHOW);
188 }
189 break;
190 case 3:
191 Erase(hdc, lastX, lastY, x, y, bg, rubberRadius);
192 break;
193 case 7:
194 Line(hdc, lastX, lastY, x, y, fg, 1);
195 SetPixel(hdc, x, y, fg);
196 break;
197 case 11:
198 resetToU1();
199 Line(hdc, startX, startY, x, y, fg, lineWidth);
200 break;
201 case 12:
202 pointSP++;
203 if (pointSP == 4)
204 pointSP = 0;
205 break;
206 case 13:
207 resetToU1();
208 Rect(hdc, startX, startY, x, y, fg, bg, lineWidth, shapeStyle);
209 break;
210 case 14:
211 resetToU1();
212 pointStack[pointSP].x = x;
213 pointStack[pointSP].y = y;
214 pointSP++;
215 if (pointSP >= 2)
216 {
217 if ((pointStack[0].x - x) * (pointStack[0].x - x) +
218 (pointStack[0].y - y) * (pointStack[0].y - y) <= lineWidth * lineWidth + 1)
219 {
220 Poly(hdc, pointStack, pointSP, fg, bg, lineWidth, shapeStyle, TRUE);
221 pointSP = 0;
222 }
223 else
224 {
225 Poly(hdc, pointStack, pointSP, fg, bg, lineWidth, shapeStyle, FALSE);
226 }
227 }
228 if (pointSP == 255)
229 pointSP--;
230 break;
231 case 15:
232 resetToU1();
233 Ellp(hdc, startX, startY, x, y, fg, bg, lineWidth, shapeStyle);
234 break;
235 case 16:
236 resetToU1();
237 RRect(hdc, startX, startY, x, y, fg, bg, lineWidth, shapeStyle);
238 break;
239 }
240 }
241
242 void
243 startPaintingR(HDC hdc, short x, short y, int fg, int bg)
244 {
245 startX = x;
246 startY = y;
247 lastX = x;
248 lastY = y;
249 switch (activeTool)
250 {
251 case 1:
252 case 10:
253 case 11:
254 case 13:
255 case 15:
256 case 16:
257 newReversible();
258 case 3:
259 newReversible();
260 Replace(hdc, x, y, x, y, fg, bg, rubberRadius);
261 break;
262 case 4:
263 newReversible();
264 Fill(hdc, x, y, bg);
265 break;
266 case 7:
267 newReversible();
268 SetPixel(hdc, x, y, bg);
269 break;
270 case 8:
271 newReversible();
272 Brush(hdc, x, y, x, y, bg, brushStyle);
273 break;
274 case 9:
275 newReversible();
276 Airbrush(hdc, x, y, bg, airBrushWidth);
277 break;
278 case 12:
279 pointStack[pointSP].x = x;
280 pointStack[pointSP].y = y;
281 if (pointSP == 0)
282 {
283 newReversible();
284 pointSP++;
285 }
286 break;
287 case 14:
288 pointStack[pointSP].x = x;
289 pointStack[pointSP].y = y;
290 if (pointSP + 1 >= 2)
291 Poly(hdc, pointStack, pointSP + 1, bg, fg, lineWidth, shapeStyle, FALSE);
292 if (pointSP == 0)
293 {
294 newReversible();
295 pointSP++;
296 }
297 break;
298 }
299 }
300
301 void
302 whilePaintingR(HDC hdc, short x, short y, int fg, int bg)
303 {
304 switch (activeTool)
305 {
306 case 3:
307 Replace(hdc, lastX, lastY, x, y, fg, bg, rubberRadius);
308 break;
309 case 7:
310 Line(hdc, lastX, lastY, x, y, bg, 1);
311 break;
312 case 8:
313 Brush(hdc, lastX, lastY, x, y, bg, brushStyle);
314 break;
315 case 9:
316 Airbrush(hdc, x, y, bg, airBrushWidth);
317 break;
318 case 11:
319 resetToU1();
320 Line(hdc, startX, startY, x, y, bg, lineWidth);
321 break;
322 case 12:
323 resetToU1();
324 pointStack[pointSP].x = x;
325 pointStack[pointSP].y = y;
326 switch (pointSP)
327 {
328 case 1:
329 Line(hdc, pointStack[0].x, pointStack[0].y, pointStack[1].x, pointStack[1].y, bg,
330 lineWidth);
331 break;
332 case 2:
333 Bezier(hdc, pointStack[0], pointStack[2], pointStack[2], pointStack[1], bg, lineWidth);
334 break;
335 case 3:
336 Bezier(hdc, pointStack[0], pointStack[2], pointStack[3], pointStack[1], bg, lineWidth);
337 break;
338 }
339 break;
340 case 13:
341 resetToU1();
342 Rect(hdc, startX, startY, x, y, bg, fg, lineWidth, shapeStyle);
343 break;
344 case 14:
345 resetToU1();
346 pointStack[pointSP].x = x;
347 pointStack[pointSP].y = y;
348 if (pointSP + 1 >= 2)
349 Poly(hdc, pointStack, pointSP + 1, bg, fg, lineWidth, shapeStyle, FALSE);
350 break;
351 case 15:
352 resetToU1();
353 Ellp(hdc, startX, startY, x, y, bg, fg, lineWidth, shapeStyle);
354 break;
355 case 16:
356 resetToU1();
357 RRect(hdc, startX, startY, x, y, bg, fg, lineWidth, shapeStyle);
358 break;
359 }
360
361 lastX = x;
362 lastY = y;
363 }
364
365 void
366 endPaintingR(HDC hdc, short x, short y, int fg, int bg)
367 {
368 switch (activeTool)
369 {
370 case 3:
371 Replace(hdc, lastX, lastY, x, y, fg, bg, rubberRadius);
372 break;
373 case 7:
374 Line(hdc, lastX, lastY, x, y, bg, 1);
375 SetPixel(hdc, x, y, bg);
376 break;
377 case 11:
378 resetToU1();
379 Line(hdc, startX, startY, x, y, bg, lineWidth);
380 break;
381 case 12:
382 pointSP++;
383 if (pointSP == 4)
384 pointSP = 0;
385 break;
386 case 13:
387 resetToU1();
388 Rect(hdc, startX, startY, x, y, bg, fg, lineWidth, shapeStyle);
389 break;
390 case 14:
391 resetToU1();
392 pointStack[pointSP].x = x;
393 pointStack[pointSP].y = y;
394 pointSP++;
395 if (pointSP >= 2)
396 {
397 if ((pointStack[0].x - x) * (pointStack[0].x - x) +
398 (pointStack[0].y - y) * (pointStack[0].y - y) <= lineWidth * lineWidth + 1)
399 {
400 Poly(hdc, pointStack, pointSP, bg, fg, lineWidth, shapeStyle, TRUE);
401 pointSP = 0;
402 }
403 else
404 {
405 Poly(hdc, pointStack, pointSP, bg, fg, lineWidth, shapeStyle, FALSE);
406 }
407 }
408 if (pointSP == 255)
409 pointSP--;
410 break;
411 case 15:
412 resetToU1();
413 Ellp(hdc, startX, startY, x, y, bg, fg, lineWidth, shapeStyle);
414 break;
415 case 16:
416 resetToU1();
417 RRect(hdc, startX, startY, x, y, bg, fg, lineWidth, shapeStyle);
418 break;
419 }
420 }