2 * PROJECT: PAINT for ReactOS
4 * FILE: base/applications/paint/mouse.c
5 * PURPOSE: Things which should not be in the mouse event handler itself
6 * PROGRAMMERS: Benedikt Freisen
9 /* INCLUDES *********************************************************/
11 #include "globalvar.h"
16 /* FUNCTIONS ********************************************************/
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);
28 POINT pointStack
[256];
30 POINT
*ptStack
= NULL
;
34 startPaintingL(HDC hdc
, short x
, short y
, int fg
, int bg
)
43 ShowWindow(hSelection
, SW_HIDE
);
45 HeapFree(GetProcessHeap(), 0, ptStack
);
46 ptStack
= HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS
, sizeof(POINT
) * 1024);
60 ShowWindow(hSelection
, SW_HIDE
);
61 rectSel_src
[2] = rectSel_src
[3] = 0;
65 Erase(hdc
, x
, y
, x
, y
, bg
, rubberRadius
);
73 SetPixel(hdc
, x
, y
, fg
);
77 Brush(hdc
, x
, y
, x
, y
, fg
, brushStyle
);
81 Airbrush(hdc
, x
, y
, fg
, airBrushWidth
);
84 pointStack
[pointSP
].x
= x
;
85 pointStack
[pointSP
].y
= y
;
93 pointStack
[pointSP
].x
= x
;
94 pointStack
[pointSP
].y
= y
;
96 Poly(hdc
, pointStack
, pointSP
+ 1, fg
, bg
, lineWidth
, shapeStyle
, FALSE
);
107 whilePaintingL(HDC hdc
, short x
, short y
, int fg
, int bg
)
115 if (ptSP
% 1024 == 0)
116 ptStack
= HeapReAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS
, ptStack
, sizeof(POINT
) * (ptSP
+ 1024));
117 ptStack
[ptSP
].x
= max(0, min(x
, imgXRes
));
118 ptStack
[ptSP
].y
= max(0, min(y
, imgYRes
));
120 Poly(hdc
, ptStack
, ptSP
+ 1, 0, 0, 2, 0, FALSE
);
127 tempX
= max(0, min(x
, imgXRes
));
128 tempY
= max(0, min(y
, imgYRes
));
129 rectSel_dest
[0] = rectSel_src
[0] = min(startX
, tempX
);
130 rectSel_dest
[1] = rectSel_src
[1] = min(startY
, tempY
);
131 rectSel_dest
[2] = rectSel_src
[2] = max(startX
, tempX
) - min(startX
, tempX
);
132 rectSel_dest
[3] = rectSel_src
[3] = max(startY
, tempY
) - min(startY
, tempY
);
133 RectSel(hdc
, startX
, startY
, tempX
, tempY
);
137 Erase(hdc
, lastX
, lastY
, x
, y
, bg
, rubberRadius
);
140 Line(hdc
, lastX
, lastY
, x
, y
, fg
, 1);
143 Brush(hdc
, lastX
, lastY
, x
, y
, fg
, brushStyle
);
146 Airbrush(hdc
, x
, y
, fg
, airBrushWidth
);
150 Line(hdc
, startX
, startY
, x
, y
, fg
, lineWidth
);
154 pointStack
[pointSP
].x
= x
;
155 pointStack
[pointSP
].y
= y
;
159 Line(hdc
, pointStack
[0].x
, pointStack
[0].y
, pointStack
[1].x
, pointStack
[1].y
, fg
,
163 Bezier(hdc
, pointStack
[0], pointStack
[2], pointStack
[2], pointStack
[1], fg
, lineWidth
);
166 Bezier(hdc
, pointStack
[0], pointStack
[2], pointStack
[3], pointStack
[1], fg
, lineWidth
);
172 Rect(hdc
, startX
, startY
, x
, y
, fg
, bg
, lineWidth
, shapeStyle
);
176 pointStack
[pointSP
].x
= x
;
177 pointStack
[pointSP
].y
= y
;
178 if (pointSP
+ 1 >= 2)
179 Poly(hdc
, pointStack
, pointSP
+ 1, fg
, bg
, lineWidth
, shapeStyle
, FALSE
);
183 Ellp(hdc
, startX
, startY
, x
, y
, fg
, bg
, lineWidth
, shapeStyle
);
187 RRect(hdc
, startX
, startY
, x
, y
, fg
, bg
, lineWidth
, shapeStyle
);
196 endPaintingL(HDC hdc
, short x
, short y
, int fg
, int bg
)
204 rectSel_src
[0] = rectSel_src
[1] = 0x7fffffff;
205 rectSel_src
[2] = rectSel_src
[3] = 0;
206 for (i
= 0; i
<= ptSP
; i
++)
208 if (ptStack
[i
].x
< rectSel_src
[0])
209 rectSel_src
[0] = ptStack
[i
].x
;
210 if (ptStack
[i
].y
< rectSel_src
[1])
211 rectSel_src
[1] = ptStack
[i
].y
;
212 if (ptStack
[i
].x
> rectSel_src
[2])
213 rectSel_src
[2] = ptStack
[i
].x
;
214 if (ptStack
[i
].y
> rectSel_src
[3])
215 rectSel_src
[3] = ptStack
[i
].y
;
217 rectSel_src
[2] += 1 - rectSel_src
[0];
218 rectSel_src
[3] += 1 - rectSel_src
[1];
219 rectSel_dest
[0] = rectSel_src
[0];
220 rectSel_dest
[1] = rectSel_src
[1];
221 rectSel_dest
[2] = rectSel_src
[2];
222 rectSel_dest
[3] = rectSel_src
[3];
225 DeleteObject(hSelMask
);
226 hSelMask
= CreateBitmap(rectSel_src
[2], rectSel_src
[3], 1, 1, NULL
);
227 DeleteObject(SelectObject(hSelDC
, hSelMask
));
228 ptStackCopy
= HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS
, sizeof(POINT
) * (ptSP
+ 1));
229 for (i
= 0; i
<= ptSP
; i
++)
231 ptStackCopy
[i
].x
= ptStack
[i
].x
- rectSel_src
[0];
232 ptStackCopy
[i
].y
= ptStack
[i
].y
- rectSel_src
[1];
234 Poly(hSelDC
, ptStackCopy
, ptSP
+ 1, 0x00ffffff, 0x00ffffff, 1, 2, TRUE
);
235 HeapFree(GetProcessHeap(), 0, ptStackCopy
);
236 SelectObject(hSelDC
, hSelBm
= CreateDIBWithProperties(rectSel_src
[2], rectSel_src
[3]));
238 MaskBlt(hSelDC
, 0, 0, rectSel_src
[2], rectSel_src
[3], hDrawingDC
, rectSel_src
[0],
239 rectSel_src
[1], hSelMask
, 0, 0, MAKEROP4(SRCCOPY
, WHITENESS
));
240 Poly(hdc
, ptStack
, ptSP
+ 1, bg
, bg
, 1, 2, TRUE
);
244 ShowWindow(hSelection
, SW_SHOW
);
246 HeapFree(GetProcessHeap(), 0, ptStack
);
252 if ((rectSel_src
[2] != 0) && (rectSel_src
[3] != 0))
254 DeleteObject(SelectObject
256 (HBITMAP
) CreateDIBWithProperties(rectSel_src
[2], rectSel_src
[3])));
257 DeleteObject(hSelMask
);
258 BitBlt(hSelDC
, 0, 0, rectSel_src
[2], rectSel_src
[3], hDrawingDC
, rectSel_src
[0],
259 rectSel_src
[1], SRCCOPY
);
260 Rect(hdc
, rectSel_src
[0], rectSel_src
[1], rectSel_src
[0] + rectSel_src
[2],
261 rectSel_src
[1] + rectSel_src
[3], bgColor
, bgColor
, 0, TRUE
);
264 ShowWindow(hSelection
, SW_SHOW
);
268 Erase(hdc
, lastX
, lastY
, x
, y
, bg
, rubberRadius
);
271 Line(hdc
, lastX
, lastY
, x
, y
, fg
, 1);
272 SetPixel(hdc
, x
, y
, fg
);
276 Line(hdc
, startX
, startY
, x
, y
, fg
, lineWidth
);
285 Rect(hdc
, startX
, startY
, x
, y
, fg
, bg
, lineWidth
, shapeStyle
);
289 pointStack
[pointSP
].x
= x
;
290 pointStack
[pointSP
].y
= y
;
294 if ((pointStack
[0].x
- x
) * (pointStack
[0].x
- x
) +
295 (pointStack
[0].y
- y
) * (pointStack
[0].y
- y
) <= lineWidth
* lineWidth
+ 1)
297 Poly(hdc
, pointStack
, pointSP
, fg
, bg
, lineWidth
, shapeStyle
, TRUE
);
302 Poly(hdc
, pointStack
, pointSP
, fg
, bg
, lineWidth
, shapeStyle
, FALSE
);
310 Ellp(hdc
, startX
, startY
, x
, y
, fg
, bg
, lineWidth
, shapeStyle
);
314 RRect(hdc
, startX
, startY
, x
, y
, fg
, bg
, lineWidth
, shapeStyle
);
320 startPaintingR(HDC hdc
, short x
, short y
, int fg
, int bg
)
338 Replace(hdc
, x
, y
, x
, y
, fg
, bg
, rubberRadius
);
346 SetPixel(hdc
, x
, y
, bg
);
350 Brush(hdc
, x
, y
, x
, y
, bg
, brushStyle
);
354 Airbrush(hdc
, x
, y
, bg
, airBrushWidth
);
357 pointStack
[pointSP
].x
= x
;
358 pointStack
[pointSP
].y
= y
;
366 pointStack
[pointSP
].x
= x
;
367 pointStack
[pointSP
].y
= y
;
368 if (pointSP
+ 1 >= 2)
369 Poly(hdc
, pointStack
, pointSP
+ 1, bg
, fg
, lineWidth
, shapeStyle
, FALSE
);
380 whilePaintingR(HDC hdc
, short x
, short y
, int fg
, int bg
)
385 Replace(hdc
, lastX
, lastY
, x
, y
, fg
, bg
, rubberRadius
);
388 Line(hdc
, lastX
, lastY
, x
, y
, bg
, 1);
391 Brush(hdc
, lastX
, lastY
, x
, y
, bg
, brushStyle
);
394 Airbrush(hdc
, x
, y
, bg
, airBrushWidth
);
398 Line(hdc
, startX
, startY
, x
, y
, bg
, lineWidth
);
402 pointStack
[pointSP
].x
= x
;
403 pointStack
[pointSP
].y
= y
;
407 Line(hdc
, pointStack
[0].x
, pointStack
[0].y
, pointStack
[1].x
, pointStack
[1].y
, bg
,
411 Bezier(hdc
, pointStack
[0], pointStack
[2], pointStack
[2], pointStack
[1], bg
, lineWidth
);
414 Bezier(hdc
, pointStack
[0], pointStack
[2], pointStack
[3], pointStack
[1], bg
, lineWidth
);
420 Rect(hdc
, startX
, startY
, x
, y
, bg
, fg
, lineWidth
, shapeStyle
);
424 pointStack
[pointSP
].x
= x
;
425 pointStack
[pointSP
].y
= y
;
426 if (pointSP
+ 1 >= 2)
427 Poly(hdc
, pointStack
, pointSP
+ 1, bg
, fg
, lineWidth
, shapeStyle
, FALSE
);
431 Ellp(hdc
, startX
, startY
, x
, y
, bg
, fg
, lineWidth
, shapeStyle
);
435 RRect(hdc
, startX
, startY
, x
, y
, bg
, fg
, lineWidth
, shapeStyle
);
444 endPaintingR(HDC hdc
, short x
, short y
, int fg
, int bg
)
449 Replace(hdc
, lastX
, lastY
, x
, y
, fg
, bg
, rubberRadius
);
452 Line(hdc
, lastX
, lastY
, x
, y
, bg
, 1);
453 SetPixel(hdc
, x
, y
, bg
);
457 Line(hdc
, startX
, startY
, x
, y
, bg
, lineWidth
);
466 Rect(hdc
, startX
, startY
, x
, y
, bg
, fg
, lineWidth
, shapeStyle
);
470 pointStack
[pointSP
].x
= x
;
471 pointStack
[pointSP
].y
= y
;
475 if ((pointStack
[0].x
- x
) * (pointStack
[0].x
- x
) +
476 (pointStack
[0].y
- y
) * (pointStack
[0].y
- y
) <= lineWidth
* lineWidth
+ 1)
478 Poly(hdc
, pointStack
, pointSP
, bg
, fg
, lineWidth
, shapeStyle
, TRUE
);
483 Poly(hdc
, pointStack
, pointSP
, bg
, fg
, lineWidth
, shapeStyle
, FALSE
);
491 Ellp(hdc
, startX
, startY
, x
, y
, bg
, fg
, lineWidth
, shapeStyle
);
495 RRect(hdc
, startX
, startY
, x
, y
, bg
, fg
, lineWidth
, shapeStyle
);