a4eaf6b52d2e7095931e6a800fbef343c6817c59
2 * PROJECT: PAINT for ReactOS
4 * FILE: base/applications/mspaint_new/mouse.cpp
5 * PURPOSE: Things which should not be in the mouse event handler itself
6 * PROGRAMMERS: Benedikt Freisen
9 /* INCLUDES *********************************************************/
13 /* FUNCTIONS ********************************************************/
18 selectionWindow
.MoveWindow(selectionModel
.GetDestRectLeft() * toolsModel
.GetZoom() / 1000, selectionModel
.GetDestRectTop() * toolsModel
.GetZoom() / 1000,
19 selectionModel
.GetDestRectWidth() * toolsModel
.GetZoom() / 1000 + 6, selectionModel
.GetDestRectHeight() * toolsModel
.GetZoom() / 1000 + 6, TRUE
);
20 selectionWindow
.BringWindowToTop();
21 imageArea
.InvalidateRect(NULL
, FALSE
);
25 regularize(LONG x0
, LONG y0
, LONG
& x1
, LONG
& y1
)
27 if (abs(x1
- x0
) >= abs(y1
- y0
))
28 y1
= y0
+ (y1
> y0
? abs(x1
- x0
) : -abs(x1
- x0
));
30 x1
= x0
+ (x1
> x0
? abs(y1
- y0
) : -abs(y1
- y0
));
34 roundTo8Directions(LONG x0
, LONG y0
, LONG
& x1
, LONG
& y1
)
36 if (abs(x1
- x0
) >= abs(y1
- y0
))
38 if (abs(y1
- y0
) * 5 < abs(x1
- x0
) * 2)
41 y1
= y0
+ (y1
> y0
? abs(x1
- x0
) : -abs(x1
- x0
));
45 if (abs(x1
- x0
) * 5 < abs(y1
- y0
) * 2)
48 x1
= x0
+ (x1
> x0
? abs(y1
- y0
) : -abs(y1
- y0
));
52 POINT pointStack
[256];
56 startPaintingL(HDC hdc
, LONG x
, LONG y
, COLORREF fg
, COLORREF bg
)
62 switch (toolsModel
.GetActiveTool())
65 selectionWindow
.ShowWindow(SW_HIDE
);
66 selectionModel
.ResetPtStack();
67 selectionModel
.PushToPtStack(x
, y
);
73 imageModel
.CopyPrevious();
77 imageModel
.CopyPrevious();
78 selectionWindow
.ShowWindow(SW_HIDE
);
79 selectionModel
.SetSrcRectSizeToZero();
82 imageModel
.CopyPrevious();
83 Erase(hdc
, x
, y
, x
, y
, bg
, toolsModel
.GetRubberRadius());
86 imageModel
.CopyPrevious();
90 imageModel
.CopyPrevious();
91 SetPixel(hdc
, x
, y
, fg
);
94 imageModel
.CopyPrevious();
95 Brush(hdc
, x
, y
, x
, y
, fg
, toolsModel
.GetBrushStyle());
98 imageModel
.CopyPrevious();
99 Airbrush(hdc
, x
, y
, fg
, toolsModel
.GetAirBrushWidth());
102 pointStack
[pointSP
].x
= x
;
103 pointStack
[pointSP
].y
= y
;
106 imageModel
.CopyPrevious();
111 pointStack
[pointSP
].x
= x
;
112 pointStack
[pointSP
].y
= y
;
113 if (pointSP
+ 1 >= 2)
114 Poly(hdc
, pointStack
, pointSP
+ 1, fg
, bg
, toolsModel
.GetLineWidth(), toolsModel
.GetShapeStyle(), FALSE
, FALSE
);
117 imageModel
.CopyPrevious();
125 whilePaintingL(HDC hdc
, LONG x
, LONG y
, COLORREF fg
, COLORREF bg
)
127 switch (toolsModel
.GetActiveTool())
130 if (selectionModel
.PtStackSize() == 1)
131 imageModel
.CopyPrevious();
132 selectionModel
.PushToPtStack(max(0, min(x
, imageModel
.GetWidth())), max(0, min(y
, imageModel
.GetHeight())));
133 imageModel
.ResetToPrevious();
134 selectionModel
.DrawFramePoly(hdc
);
140 imageModel
.ResetToPrevious();
141 temp
.x
= max(0, min(x
, imageModel
.GetWidth()));
142 temp
.y
= max(0, min(y
, imageModel
.GetHeight()));
143 selectionModel
.SetSrcAndDestRectFromPoints(start
, temp
);
144 RectSel(hdc
, start
.x
, start
.y
, temp
.x
, temp
.y
);
148 Erase(hdc
, last
.x
, last
.y
, x
, y
, bg
, toolsModel
.GetRubberRadius());
151 Line(hdc
, last
.x
, last
.y
, x
, y
, fg
, 1);
154 Brush(hdc
, last
.x
, last
.y
, x
, y
, fg
, toolsModel
.GetBrushStyle());
157 Airbrush(hdc
, x
, y
, fg
, toolsModel
.GetAirBrushWidth());
160 imageModel
.ResetToPrevious();
161 if (GetAsyncKeyState(VK_SHIFT
) < 0)
162 roundTo8Directions(start
.x
, start
.y
, x
, y
);
163 Line(hdc
, start
.x
, start
.y
, x
, y
, fg
, toolsModel
.GetLineWidth());
166 imageModel
.ResetToPrevious();
167 pointStack
[pointSP
].x
= x
;
168 pointStack
[pointSP
].y
= y
;
172 Line(hdc
, pointStack
[0].x
, pointStack
[0].y
, pointStack
[1].x
, pointStack
[1].y
, fg
,
173 toolsModel
.GetLineWidth());
176 Bezier(hdc
, pointStack
[0], pointStack
[2], pointStack
[2], pointStack
[1], fg
, toolsModel
.GetLineWidth());
179 Bezier(hdc
, pointStack
[0], pointStack
[2], pointStack
[3], pointStack
[1], fg
, toolsModel
.GetLineWidth());
184 imageModel
.ResetToPrevious();
185 if (GetAsyncKeyState(VK_SHIFT
) < 0)
186 regularize(start
.x
, start
.y
, x
, y
);
187 Rect(hdc
, start
.x
, start
.y
, x
, y
, fg
, bg
, toolsModel
.GetLineWidth(), toolsModel
.GetShapeStyle());
190 imageModel
.ResetToPrevious();
191 pointStack
[pointSP
].x
= x
;
192 pointStack
[pointSP
].y
= y
;
193 if ((pointSP
> 0) && (GetAsyncKeyState(VK_SHIFT
) < 0))
194 roundTo8Directions(pointStack
[pointSP
- 1].x
, pointStack
[pointSP
- 1].y
,
195 pointStack
[pointSP
].x
, pointStack
[pointSP
].y
);
196 if (pointSP
+ 1 >= 2)
197 Poly(hdc
, pointStack
, pointSP
+ 1, fg
, bg
, toolsModel
.GetLineWidth(), toolsModel
.GetShapeStyle(), FALSE
, FALSE
);
200 imageModel
.ResetToPrevious();
201 if (GetAsyncKeyState(VK_SHIFT
) < 0)
202 regularize(start
.x
, start
.y
, x
, y
);
203 Ellp(hdc
, start
.x
, start
.y
, x
, y
, fg
, bg
, toolsModel
.GetLineWidth(), toolsModel
.GetShapeStyle());
206 imageModel
.ResetToPrevious();
207 if (GetAsyncKeyState(VK_SHIFT
) < 0)
208 regularize(start
.x
, start
.y
, x
, y
);
209 RRect(hdc
, start
.x
, start
.y
, x
, y
, fg
, bg
, toolsModel
.GetLineWidth(), toolsModel
.GetShapeStyle());
218 endPaintingL(HDC hdc
, LONG x
, LONG y
, COLORREF fg
, COLORREF bg
)
220 switch (toolsModel
.GetActiveTool())
224 selectionModel
.CalculateBoundingBoxAndContents(hdc
);
225 if (selectionModel
.PtStackSize() > 1)
227 selectionModel
.DrawBackgroundPoly(hdc
, bg
);
228 imageModel
.CopyPrevious();
230 selectionModel
.DrawSelection(hdc
);
233 selectionWindow
.ShowWindow(SW_SHOW
);
234 ForceRefreshSelectionContents();
236 selectionModel
.ResetPtStack();
240 imageModel
.ResetToPrevious();
241 if (selectionModel
.IsSrcRectSizeNonzero())
243 selectionModel
.CalculateContents(hdc
);
244 selectionModel
.DrawBackgroundRect(hdc
, bg
);
245 imageModel
.CopyPrevious();
247 selectionModel
.DrawSelection(hdc
);
250 selectionWindow
.ShowWindow(SW_SHOW
);
251 ForceRefreshSelectionContents();
255 imageModel
.ResetToPrevious();
256 if (selectionModel
.IsSrcRectSizeNonzero())
258 imageModel
.CopyPrevious();
261 selectionWindow
.ShowWindow(SW_SHOW
);
262 ForceRefreshSelectionContents();
266 Erase(hdc
, last
.x
, last
.y
, x
, y
, bg
, toolsModel
.GetRubberRadius());
269 Line(hdc
, last
.x
, last
.y
, x
, y
, fg
, 1);
270 SetPixel(hdc
, x
, y
, fg
);
273 imageModel
.ResetToPrevious();
274 if (GetAsyncKeyState(VK_SHIFT
) < 0)
275 roundTo8Directions(start
.x
, start
.y
, x
, y
);
276 Line(hdc
, start
.x
, start
.y
, x
, y
, fg
, toolsModel
.GetLineWidth());
284 imageModel
.ResetToPrevious();
285 if (GetAsyncKeyState(VK_SHIFT
) < 0)
286 regularize(start
.x
, start
.y
, x
, y
);
287 Rect(hdc
, start
.x
, start
.y
, x
, y
, fg
, bg
, toolsModel
.GetLineWidth(), toolsModel
.GetShapeStyle());
290 imageModel
.ResetToPrevious();
291 pointStack
[pointSP
].x
= x
;
292 pointStack
[pointSP
].y
= y
;
293 if ((pointSP
> 0) && (GetAsyncKeyState(VK_SHIFT
) < 0))
294 roundTo8Directions(pointStack
[pointSP
- 1].x
, pointStack
[pointSP
- 1].y
,
295 pointStack
[pointSP
].x
, pointStack
[pointSP
].y
);
299 if ((pointStack
[0].x
- x
) * (pointStack
[0].x
- x
) +
300 (pointStack
[0].y
- y
) * (pointStack
[0].y
- y
) <= toolsModel
.GetLineWidth() * toolsModel
.GetLineWidth() + 1)
302 Poly(hdc
, pointStack
, pointSP
, fg
, bg
, toolsModel
.GetLineWidth(), toolsModel
.GetShapeStyle(), TRUE
, FALSE
);
307 Poly(hdc
, pointStack
, pointSP
, fg
, bg
, toolsModel
.GetLineWidth(), toolsModel
.GetShapeStyle(), FALSE
, FALSE
);
314 imageModel
.ResetToPrevious();
315 if (GetAsyncKeyState(VK_SHIFT
) < 0)
316 regularize(start
.x
, start
.y
, x
, y
);
317 Ellp(hdc
, start
.x
, start
.y
, x
, y
, fg
, bg
, toolsModel
.GetLineWidth(), toolsModel
.GetShapeStyle());
320 imageModel
.ResetToPrevious();
321 if (GetAsyncKeyState(VK_SHIFT
) < 0)
322 regularize(start
.x
, start
.y
, x
, y
);
323 RRect(hdc
, start
.x
, start
.y
, x
, y
, fg
, bg
, toolsModel
.GetLineWidth(), toolsModel
.GetShapeStyle());
329 startPaintingR(HDC hdc
, LONG x
, LONG y
, COLORREF fg
, COLORREF bg
)
335 switch (toolsModel
.GetActiveTool())
343 imageModel
.CopyPrevious();
346 imageModel
.CopyPrevious();
347 Replace(hdc
, x
, y
, x
, y
, fg
, bg
, toolsModel
.GetRubberRadius());
350 imageModel
.CopyPrevious();
354 imageModel
.CopyPrevious();
355 SetPixel(hdc
, x
, y
, bg
);
358 imageModel
.CopyPrevious();
359 Brush(hdc
, x
, y
, x
, y
, bg
, toolsModel
.GetBrushStyle());
362 imageModel
.CopyPrevious();
363 Airbrush(hdc
, x
, y
, bg
, toolsModel
.GetAirBrushWidth());
366 pointStack
[pointSP
].x
= x
;
367 pointStack
[pointSP
].y
= y
;
370 imageModel
.CopyPrevious();
375 pointStack
[pointSP
].x
= x
;
376 pointStack
[pointSP
].y
= y
;
377 if (pointSP
+ 1 >= 2)
378 Poly(hdc
, pointStack
, pointSP
+ 1, bg
, fg
, toolsModel
.GetLineWidth(), toolsModel
.GetShapeStyle(), FALSE
, FALSE
);
381 imageModel
.CopyPrevious();
389 whilePaintingR(HDC hdc
, LONG x
, LONG y
, COLORREF fg
, COLORREF bg
)
391 switch (toolsModel
.GetActiveTool())
394 Replace(hdc
, last
.x
, last
.y
, x
, y
, fg
, bg
, toolsModel
.GetRubberRadius());
397 Line(hdc
, last
.x
, last
.y
, x
, y
, bg
, 1);
400 Brush(hdc
, last
.x
, last
.y
, x
, y
, bg
, toolsModel
.GetBrushStyle());
403 Airbrush(hdc
, x
, y
, bg
, toolsModel
.GetAirBrushWidth());
406 imageModel
.ResetToPrevious();
407 if (GetAsyncKeyState(VK_SHIFT
) < 0)
408 roundTo8Directions(start
.x
, start
.y
, x
, y
);
409 Line(hdc
, start
.x
, start
.y
, x
, y
, bg
, toolsModel
.GetLineWidth());
412 imageModel
.ResetToPrevious();
413 pointStack
[pointSP
].x
= x
;
414 pointStack
[pointSP
].y
= y
;
418 Line(hdc
, pointStack
[0].x
, pointStack
[0].y
, pointStack
[1].x
, pointStack
[1].y
, bg
,
419 toolsModel
.GetLineWidth());
422 Bezier(hdc
, pointStack
[0], pointStack
[2], pointStack
[2], pointStack
[1], bg
, toolsModel
.GetLineWidth());
425 Bezier(hdc
, pointStack
[0], pointStack
[2], pointStack
[3], pointStack
[1], bg
, toolsModel
.GetLineWidth());
430 imageModel
.ResetToPrevious();
431 if (GetAsyncKeyState(VK_SHIFT
) < 0)
432 regularize(start
.x
, start
.y
, x
, y
);
433 Rect(hdc
, start
.x
, start
.y
, x
, y
, bg
, fg
, toolsModel
.GetLineWidth(), toolsModel
.GetShapeStyle());
436 imageModel
.ResetToPrevious();
437 pointStack
[pointSP
].x
= x
;
438 pointStack
[pointSP
].y
= y
;
439 if ((pointSP
> 0) && (GetAsyncKeyState(VK_SHIFT
) < 0))
440 roundTo8Directions(pointStack
[pointSP
- 1].x
, pointStack
[pointSP
- 1].y
,
441 pointStack
[pointSP
].x
, pointStack
[pointSP
].y
);
442 if (pointSP
+ 1 >= 2)
443 Poly(hdc
, pointStack
, pointSP
+ 1, bg
, fg
, toolsModel
.GetLineWidth(), toolsModel
.GetShapeStyle(), FALSE
, FALSE
);
446 imageModel
.ResetToPrevious();
447 if (GetAsyncKeyState(VK_SHIFT
) < 0)
448 regularize(start
.x
, start
.y
, x
, y
);
449 Ellp(hdc
, start
.x
, start
.y
, x
, y
, bg
, fg
, toolsModel
.GetLineWidth(), toolsModel
.GetShapeStyle());
452 imageModel
.ResetToPrevious();
453 if (GetAsyncKeyState(VK_SHIFT
) < 0)
454 regularize(start
.x
, start
.y
, x
, y
);
455 RRect(hdc
, start
.x
, start
.y
, x
, y
, bg
, fg
, toolsModel
.GetLineWidth(), toolsModel
.GetShapeStyle());
464 endPaintingR(HDC hdc
, LONG x
, LONG y
, COLORREF fg
, COLORREF bg
)
466 switch (toolsModel
.GetActiveTool())
469 Replace(hdc
, last
.x
, last
.y
, x
, y
, fg
, bg
, toolsModel
.GetRubberRadius());
472 Line(hdc
, last
.x
, last
.y
, x
, y
, bg
, 1);
473 SetPixel(hdc
, x
, y
, bg
);
476 imageModel
.ResetToPrevious();
477 if (GetAsyncKeyState(VK_SHIFT
) < 0)
478 roundTo8Directions(start
.x
, start
.y
, x
, y
);
479 Line(hdc
, start
.x
, start
.y
, x
, y
, bg
, toolsModel
.GetLineWidth());
487 imageModel
.ResetToPrevious();
488 if (GetAsyncKeyState(VK_SHIFT
) < 0)
489 regularize(start
.x
, start
.y
, x
, y
);
490 Rect(hdc
, start
.x
, start
.y
, x
, y
, bg
, fg
, toolsModel
.GetLineWidth(), toolsModel
.GetShapeStyle());
493 imageModel
.ResetToPrevious();
494 pointStack
[pointSP
].x
= x
;
495 pointStack
[pointSP
].y
= y
;
496 if ((pointSP
> 0) && (GetAsyncKeyState(VK_SHIFT
) < 0))
497 roundTo8Directions(pointStack
[pointSP
- 1].x
, pointStack
[pointSP
- 1].y
,
498 pointStack
[pointSP
].x
, pointStack
[pointSP
].y
);
502 if ((pointStack
[0].x
- x
) * (pointStack
[0].x
- x
) +
503 (pointStack
[0].y
- y
) * (pointStack
[0].y
- y
) <= toolsModel
.GetLineWidth() * toolsModel
.GetLineWidth() + 1)
505 Poly(hdc
, pointStack
, pointSP
, bg
, fg
, toolsModel
.GetLineWidth(), toolsModel
.GetShapeStyle(), TRUE
, FALSE
);
510 Poly(hdc
, pointStack
, pointSP
, bg
, fg
, toolsModel
.GetLineWidth(), toolsModel
.GetShapeStyle(), FALSE
, FALSE
);
517 imageModel
.ResetToPrevious();
518 if (GetAsyncKeyState(VK_SHIFT
) < 0)
519 regularize(start
.x
, start
.y
, x
, y
);
520 Ellp(hdc
, start
.x
, start
.y
, x
, y
, bg
, fg
, toolsModel
.GetLineWidth(), toolsModel
.GetShapeStyle());
523 imageModel
.ResetToPrevious();
524 if (GetAsyncKeyState(VK_SHIFT
) < 0)
525 regularize(start
.x
, start
.y
, x
, y
);
526 RRect(hdc
, start
.x
, start
.y
, x
, y
, bg
, fg
, toolsModel
.GetLineWidth(), toolsModel
.GetShapeStyle());