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(hSelMask
);
255 hSelMask
= CreateBitmap(rectSel_src
[2], rectSel_src
[3], 1, 1, NULL
);
256 DeleteObject(SelectObject(hSelDC
, hSelMask
));
257 Rect(hSelDC
, 0, 0, rectSel_src
[2], rectSel_src
[3], 0x00ffffff, 0x00ffffff, 1, 2);
258 SelectObject(hSelDC
, hSelBm
= CreateDIBWithProperties(rectSel_src
[2], rectSel_src
[3]));
260 BitBlt(hSelDC
, 0, 0, rectSel_src
[2], rectSel_src
[3], hDrawingDC
, rectSel_src
[0],
261 rectSel_src
[1], SRCCOPY
);
262 Rect(hdc
, rectSel_src
[0], rectSel_src
[1], rectSel_src
[0] + rectSel_src
[2],
263 rectSel_src
[1] + rectSel_src
[3], bgColor
, bgColor
, 0, TRUE
);
267 ShowWindow(hSelection
, SW_SHOW
);
271 Erase(hdc
, lastX
, lastY
, x
, y
, bg
, rubberRadius
);
274 Line(hdc
, lastX
, lastY
, x
, y
, fg
, 1);
275 SetPixel(hdc
, x
, y
, fg
);
279 Line(hdc
, startX
, startY
, x
, y
, fg
, lineWidth
);
288 Rect(hdc
, startX
, startY
, x
, y
, fg
, bg
, lineWidth
, shapeStyle
);
292 pointStack
[pointSP
].x
= x
;
293 pointStack
[pointSP
].y
= y
;
297 if ((pointStack
[0].x
- x
) * (pointStack
[0].x
- x
) +
298 (pointStack
[0].y
- y
) * (pointStack
[0].y
- y
) <= lineWidth
* lineWidth
+ 1)
300 Poly(hdc
, pointStack
, pointSP
, fg
, bg
, lineWidth
, shapeStyle
, TRUE
);
305 Poly(hdc
, pointStack
, pointSP
, fg
, bg
, lineWidth
, shapeStyle
, FALSE
);
313 Ellp(hdc
, startX
, startY
, x
, y
, fg
, bg
, lineWidth
, shapeStyle
);
317 RRect(hdc
, startX
, startY
, x
, y
, fg
, bg
, lineWidth
, shapeStyle
);
323 startPaintingR(HDC hdc
, short x
, short y
, int fg
, int bg
)
341 Replace(hdc
, x
, y
, x
, y
, fg
, bg
, rubberRadius
);
349 SetPixel(hdc
, x
, y
, bg
);
353 Brush(hdc
, x
, y
, x
, y
, bg
, brushStyle
);
357 Airbrush(hdc
, x
, y
, bg
, airBrushWidth
);
360 pointStack
[pointSP
].x
= x
;
361 pointStack
[pointSP
].y
= y
;
369 pointStack
[pointSP
].x
= x
;
370 pointStack
[pointSP
].y
= y
;
371 if (pointSP
+ 1 >= 2)
372 Poly(hdc
, pointStack
, pointSP
+ 1, bg
, fg
, lineWidth
, shapeStyle
, FALSE
);
383 whilePaintingR(HDC hdc
, short x
, short y
, int fg
, int bg
)
388 Replace(hdc
, lastX
, lastY
, x
, y
, fg
, bg
, rubberRadius
);
391 Line(hdc
, lastX
, lastY
, x
, y
, bg
, 1);
394 Brush(hdc
, lastX
, lastY
, x
, y
, bg
, brushStyle
);
397 Airbrush(hdc
, x
, y
, bg
, airBrushWidth
);
401 Line(hdc
, startX
, startY
, x
, y
, bg
, lineWidth
);
405 pointStack
[pointSP
].x
= x
;
406 pointStack
[pointSP
].y
= y
;
410 Line(hdc
, pointStack
[0].x
, pointStack
[0].y
, pointStack
[1].x
, pointStack
[1].y
, bg
,
414 Bezier(hdc
, pointStack
[0], pointStack
[2], pointStack
[2], pointStack
[1], bg
, lineWidth
);
417 Bezier(hdc
, pointStack
[0], pointStack
[2], pointStack
[3], pointStack
[1], bg
, lineWidth
);
423 Rect(hdc
, startX
, startY
, x
, y
, bg
, fg
, lineWidth
, shapeStyle
);
427 pointStack
[pointSP
].x
= x
;
428 pointStack
[pointSP
].y
= y
;
429 if (pointSP
+ 1 >= 2)
430 Poly(hdc
, pointStack
, pointSP
+ 1, bg
, fg
, lineWidth
, shapeStyle
, FALSE
);
434 Ellp(hdc
, startX
, startY
, x
, y
, bg
, fg
, lineWidth
, shapeStyle
);
438 RRect(hdc
, startX
, startY
, x
, y
, bg
, fg
, lineWidth
, shapeStyle
);
447 endPaintingR(HDC hdc
, short x
, short y
, int fg
, int bg
)
452 Replace(hdc
, lastX
, lastY
, x
, y
, fg
, bg
, rubberRadius
);
455 Line(hdc
, lastX
, lastY
, x
, y
, bg
, 1);
456 SetPixel(hdc
, x
, y
, bg
);
460 Line(hdc
, startX
, startY
, x
, y
, bg
, lineWidth
);
469 Rect(hdc
, startX
, startY
, x
, y
, bg
, fg
, lineWidth
, shapeStyle
);
473 pointStack
[pointSP
].x
= x
;
474 pointStack
[pointSP
].y
= y
;
478 if ((pointStack
[0].x
- x
) * (pointStack
[0].x
- x
) +
479 (pointStack
[0].y
- y
) * (pointStack
[0].y
- y
) <= lineWidth
* lineWidth
+ 1)
481 Poly(hdc
, pointStack
, pointSP
, bg
, fg
, lineWidth
, shapeStyle
, TRUE
);
486 Poly(hdc
, pointStack
, pointSP
, bg
, fg
, lineWidth
, shapeStyle
, FALSE
);
494 Ellp(hdc
, startX
, startY
, x
, y
, bg
, fg
, lineWidth
, shapeStyle
);
498 RRect(hdc
, startX
, startY
, x
, y
, bg
, fg
, lineWidth
, shapeStyle
);