2 * PROJECT: PAINT for ReactOS
4 * FILE: base/applications/paint/selection.c
5 * PURPOSE: Window procedure of the selection window
6 * PROGRAMMERS: Benedikt Freisen
9 /* INCLUDES *********************************************************/
12 #include "globalvar.h"
18 /* FUNCTIONS ********************************************************/
20 LPCTSTR cursors
[9] = { IDC_SIZEALL
, IDC_SIZENWSE
, IDC_SIZENS
, IDC_SIZENESW
,
21 IDC_SIZEWE
, IDC_SIZEWE
, IDC_SIZENESW
, IDC_SIZENS
, IDC_SIZENWSE
32 identifyCorner(short x
, short y
, short w
, short h
)
38 if ((x
< w
/ 2 + 2) && (x
>= w
/ 2 - 1))
43 if ((y
< h
/ 2 + 2) && (y
>= h
/ 2 - 1))
54 if ((x
< w
/ 2 + 2) && (x
>= w
/ 2 - 1))
63 SelectionWinProc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
71 HDC hDC
= GetDC(hwnd
);
72 DefWindowProc(hwnd
, message
, wParam
, lParam
);
73 SelectionFrame(hDC
, 1, 1, rectSel_dest
[2] * zoom
/ 1000 + 5,
74 rectSel_dest
[3] * zoom
/ 1000 + 5);
80 xPos
= LOWORD(lParam
);
81 yPos
= HIWORD(lParam
);
84 SetCursor(LoadCursor(NULL
, cursors
[action
]));
93 xFrac
+= (short)LOWORD(lParam
) - xPos
;
94 yFrac
+= (short)HIWORD(lParam
) - yPos
;
97 xDelta
= xFrac
* 1000 / zoom
;
99 yDelta
= yFrac
* 1000 / zoom
;
104 xDelta
= xFrac
* 1000 / zoom
;
105 xFrac
-= (xFrac
* 1000 / zoom
) * zoom
/ 1000;
106 yDelta
= yFrac
* 1000 / zoom
;
107 yFrac
-= (yFrac
* 1000 / zoom
) * zoom
/ 1000;
112 rectSel_dest
[0] += xDelta
;
113 rectSel_dest
[1] += yDelta
;
116 rectSel_dest
[0] += xDelta
;
117 rectSel_dest
[1] += yDelta
;
118 rectSel_dest
[2] -= xDelta
;
119 rectSel_dest
[3] -= yDelta
;
122 rectSel_dest
[1] += yDelta
;
123 rectSel_dest
[3] -= yDelta
;
126 rectSel_dest
[2] += xDelta
;
127 rectSel_dest
[1] += yDelta
;
130 rectSel_dest
[0] += xDelta
;
131 rectSel_dest
[2] -= xDelta
;
134 rectSel_dest
[2] += xDelta
;
137 rectSel_dest
[0] += xDelta
;
138 rectSel_dest
[2] -= xDelta
;
139 rectSel_dest
[3] += yDelta
;
142 rectSel_dest
[3] += yDelta
;
145 rectSel_dest
[2] += xDelta
;
146 rectSel_dest
[3] += yDelta
;
151 StretchBlt(hDrawingDC
, rectSel_dest
[0], rectSel_dest
[1], rectSel_dest
[2], rectSel_dest
[3], hSelDC
, 0, 0, GetDIBWidth(hSelBm
), GetDIBHeight(hSelBm
), SRCCOPY
);
154 MaskBlt(hDrawingDC
, rectSel_dest
[0], rectSel_dest
[1], rectSel_dest
[2], rectSel_dest
[3],
155 hSelDC
, 0, 0, hSelMask
, 0, 0, MAKEROP4(SRCCOPY
, SRCAND
));
161 tempMask
= CreateBitmap(rectSel_dest
[2], rectSel_dest
[3], 1, 1, NULL
);
162 oldBrush
= SelectObject(hSelDC
, CreateSolidBrush(bgColor
));
163 tempDC
= CreateCompatibleDC(hSelDC
);
164 SelectObject(tempDC
, tempMask
);
165 MaskBlt(tempDC
, 0, 0, rectSel_dest
[2], rectSel_dest
[3], hSelDC
, 0, 0, hSelMask
, 0, 0,
166 MAKEROP4(NOTSRCCOPY
, BLACKNESS
));
168 DeleteObject(SelectObject(hSelDC
, oldBrush
));
170 MaskBlt(hDrawingDC
, rectSel_dest
[0], rectSel_dest
[1], rectSel_dest
[2], rectSel_dest
[3],
171 hSelDC
, 0, 0, tempMask
, 0, 0, MAKEROP4(SRCCOPY
, SRCAND
));
172 DeleteObject(tempMask
);
174 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
175 xPos
= LOWORD(lParam
);
176 yPos
= HIWORD(lParam
);
177 //SendMessage(hwnd, WM_PAINT, 0, 0);
181 int w
= rectSel_dest
[2] * zoom
/ 1000 + 6;
182 int h
= rectSel_dest
[3] * zoom
/ 1000 + 6;
183 xPos
= LOWORD(lParam
);
184 yPos
= HIWORD(lParam
);
185 action
= identifyCorner(xPos
, yPos
, w
, h
);
187 SetCursor(LoadCursor(NULL
, cursors
[action
]));
199 hTempDC
= CreateCompatibleDC(hSelDC
);
200 hTempBm
= CreateDIBWithProperties(rectSel_dest
[2], rectSel_dest
[3]);
201 SelectObject(hTempDC
, hTempBm
);
202 SelectObject(hSelDC
, hSelBm
);
203 StretchBlt(hTempDC
, 0, 0, rectSel_dest
[2], rectSel_dest
[3], hSelDC
, 0, 0,
204 GetDIBWidth(hSelBm
), GetDIBHeight(hSelBm
), SRCCOPY
);
205 DeleteObject(hSelBm
);
207 hTempBm
= CreateBitmap(rectSel_dest
[2], rectSel_dest
[3], 1, 1, NULL
);
208 SelectObject(hTempDC
, hTempBm
);
209 SelectObject(hSelDC
, hSelMask
);
210 StretchBlt(hTempDC
, 0, 0, rectSel_dest
[2], rectSel_dest
[3], hSelDC
, 0, 0,
211 GetDIBWidth(hSelMask
), GetDIBHeight(hSelMask
), SRCCOPY
);
212 DeleteObject(hSelMask
);
214 SelectObject(hSelDC
, hSelBm
);
218 ShowWindow(hSelection
, SW_HIDE
);
219 ShowWindow(hSelection
, SW_SHOW
);
223 return DefWindowProc(hwnd
, message
, wParam
, lParam
);