83adc00c914ed88f36406f29ec5ff75a7ac4a083
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 *********************************************************/
13 /* FUNCTIONS ********************************************************/
15 LPCTSTR cursors
[9] = { IDC_SIZEALL
, IDC_SIZENWSE
, IDC_SIZENS
, IDC_SIZENESW
,
16 IDC_SIZEWE
, IDC_SIZEWE
, IDC_SIZENESW
, IDC_SIZENS
, IDC_SIZENWSE
25 ColorKeyedMaskBlt(HDC hdcDest
, int nXDest
, int nYDest
, int nWidth
, int nHeight
, HDC hdcSrc
, int nXSrc
, int nYSrc
, HBITMAP hbmMask
, int xMask
, int yMask
, DWORD dwRop
, COLORREF keyColor
)
33 hTempDC
= CreateCompatibleDC(hdcSrc
);
34 hTempDC2
= CreateCompatibleDC(hdcSrc
);
35 hTempBm
= CreateCompatibleBitmap(hTempDC
, nWidth
, nHeight
);
36 SelectObject(hTempDC
, hTempBm
);
37 hTempBrush
= CreateSolidBrush(keyColor
);
38 SelectObject(hTempDC
, hTempBrush
);
39 BitBlt(hTempDC
, 0, 0, nWidth
, nHeight
, hdcSrc
, nXSrc
, nYSrc
, SRCCOPY
);
40 PatBlt(hTempDC
, 0, 0, nWidth
, nHeight
, PATINVERT
);
41 hTempMask
= CreateBitmap(nWidth
, nHeight
, 1, 1, NULL
);
42 SelectObject(hTempDC2
, hTempMask
);
43 BitBlt(hTempDC2
, 0, 0, nWidth
, nHeight
, hTempDC
, 0, 0, SRCCOPY
);
44 SelectObject(hTempDC
, hbmMask
);
45 BitBlt(hTempDC2
, 0, 0, nWidth
, nHeight
, hTempDC
, xMask
, yMask
, SRCAND
);
46 MaskBlt(hdcDest
, nXDest
, nYDest
, nWidth
, nHeight
, hdcSrc
, nXSrc
, nYSrc
, hTempMask
, xMask
, yMask
, dwRop
);
49 DeleteObject(hTempBm
);
50 DeleteObject(hTempBrush
);
51 DeleteObject(hTempMask
);
56 ForceRefreshSelectionContents()
58 if (IsWindowVisible(hSelection
))
60 SendMessage(hSelection
, WM_LBUTTONDOWN
, 0, MAKELPARAM(0, 0));
61 SendMessage(hSelection
, WM_MOUSEMOVE
, 0, MAKELPARAM(0, 0));
62 SendMessage(hSelection
, WM_LBUTTONUP
, 0, MAKELPARAM(0, 0));
67 identifyCorner(short x
, short y
, short w
, short h
)
73 if ((x
< w
/ 2 + 2) && (x
>= w
/ 2 - 1))
78 if ((y
< h
/ 2 + 2) && (y
>= h
/ 2 - 1))
89 if ((x
< w
/ 2 + 2) && (x
>= w
/ 2 - 1))
98 SelectionWinProc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
106 HDC hDC
= GetDC(hwnd
);
107 DefWindowProc(hwnd
, message
, wParam
, lParam
);
108 SelectionFrame(hDC
, 1, 1, RECT_WIDTH(rectSel_dest
) * zoom
/ 1000 + 5,
109 RECT_HEIGHT(rectSel_dest
) * zoom
/ 1000 + 5);
110 ReleaseDC(hwnd
, hDC
);
115 pos
.x
= GET_X_LPARAM(lParam
);
116 pos
.y
= GET_Y_LPARAM(lParam
);
119 SetCursor(LoadCursor(NULL
, cursors
[action
]));
128 frac
.x
+= GET_X_LPARAM(lParam
) - pos
.x
;
129 frac
.y
+= GET_Y_LPARAM(lParam
) - pos
.y
;
132 delta
.x
= frac
.x
* 1000 / zoom
;
134 delta
.y
= frac
.y
* 1000 / zoom
;
139 delta
.x
= frac
.x
* 1000 / zoom
;
140 frac
.x
-= (frac
.x
* 1000 / zoom
) * zoom
/ 1000;
141 delta
.y
= frac
.y
* 1000 / zoom
;
142 frac
.y
-= (frac
.y
* 1000 / zoom
) * zoom
/ 1000;
146 /* TODO: make sure that the selection is at least 1 pixel wide and high */
147 case 0: /* move selection */
148 OffsetRect(&rectSel_dest
, delta
.x
, delta
.y
);
150 case 1: /* resize at upper left corner */
151 rectSel_dest
.left
+= delta
.x
;
152 rectSel_dest
.top
+= delta
.y
;
154 case 2: /* resize at top edge */
155 rectSel_dest
.top
+= delta
.y
;
157 case 3: /* resize at upper right corner */
158 rectSel_dest
.top
+= delta
.y
;
159 rectSel_dest
.right
+= delta
.x
;
161 case 4: /* resize at left edge */
162 rectSel_dest
.left
+= delta
.x
;
164 case 5: /* resize at right edge */
165 rectSel_dest
.right
+= delta
.x
;
167 case 6: /* resize at lower left corner */
168 rectSel_dest
.left
+= delta
.x
;
169 rectSel_dest
.bottom
+= delta
.y
;
171 case 7: /* resize at bottom edge */
172 rectSel_dest
.bottom
+= delta
.y
;
174 case 8: /* resize at lower right corner */
175 rectSel_dest
.right
+= delta
.x
;
176 rectSel_dest
.bottom
+= delta
.y
;
180 _stprintf(sizeStr
, _T("%d x %d"), RECT_WIDTH(rectSel_dest
), RECT_HEIGHT(rectSel_dest
));
181 SendMessage(hStatusBar
, SB_SETTEXT
, 2, (LPARAM
) sizeStr
);
183 if (activeTool
== 10) /* text tool */
185 Text(hDrawingDC
, rectSel_dest
.left
, rectSel_dest
.top
, rectSel_dest
.right
, rectSel_dest
.bottom
, fgColor
, bgColor
, textToolText
, hfontTextFont
, transpBg
);
190 StretchBlt(hDrawingDC
, rectSel_dest
.left
, rectSel_dest
.top
, RECT_WIDTH(rectSel_dest
), RECT_HEIGHT(rectSel_dest
), hSelDC
, 0, 0, GetDIBWidth(hSelBm
), GetDIBHeight(hSelBm
), SRCCOPY
);
193 MaskBlt(hDrawingDC
, rectSel_dest
.left
, rectSel_dest
.top
, RECT_WIDTH(rectSel_dest
), RECT_HEIGHT(rectSel_dest
),
194 hSelDC
, 0, 0, hSelMask
, 0, 0, MAKEROP4(SRCCOPY
, SRCAND
));
197 ColorKeyedMaskBlt(hDrawingDC
, rectSel_dest
.left
, rectSel_dest
.top
, RECT_WIDTH(rectSel_dest
), RECT_HEIGHT(rectSel_dest
),
198 hSelDC
, 0, 0, hSelMask
, 0, 0, MAKEROP4(SRCCOPY
, SRCAND
), bgColor
);
201 InvalidateRect(hImageArea
, NULL
, FALSE
);
202 pos
.x
= GET_X_LPARAM(lParam
);
203 pos
.y
= GET_Y_LPARAM(lParam
);
204 //SendMessage(hwnd, WM_PAINT, 0, 0);
208 int w
= RECT_WIDTH(rectSel_dest
) * zoom
/ 1000 + 6;
209 int h
= RECT_HEIGHT(rectSel_dest
) * zoom
/ 1000 + 6;
210 pos
.x
= GET_X_LPARAM(lParam
);
211 pos
.y
= GET_Y_LPARAM(lParam
);
212 SendMessage(hStatusBar
, SB_SETTEXT
, 2, (LPARAM
) NULL
);
213 action
= identifyCorner(pos
.x
, pos
.y
, w
, h
);
215 SetCursor(LoadCursor(NULL
, cursors
[action
]));
225 if (activeTool
== 10) /* text tool */
233 hTempDC
= CreateCompatibleDC(hSelDC
);
234 hTempBm
= CreateDIBWithProperties(RECT_WIDTH(rectSel_dest
), RECT_HEIGHT(rectSel_dest
));
235 SelectObject(hTempDC
, hTempBm
);
236 SelectObject(hSelDC
, hSelBm
);
237 StretchBlt(hTempDC
, 0, 0, RECT_WIDTH(rectSel_dest
), RECT_HEIGHT(rectSel_dest
), hSelDC
, 0, 0,
238 GetDIBWidth(hSelBm
), GetDIBHeight(hSelBm
), SRCCOPY
);
239 DeleteObject(hSelBm
);
241 hTempBm
= CreateBitmap(RECT_WIDTH(rectSel_dest
), RECT_HEIGHT(rectSel_dest
), 1, 1, NULL
);
242 SelectObject(hTempDC
, hTempBm
);
243 SelectObject(hSelDC
, hSelMask
);
244 StretchBlt(hTempDC
, 0, 0, RECT_WIDTH(rectSel_dest
), RECT_HEIGHT(rectSel_dest
), hSelDC
, 0, 0,
245 GetDIBWidth(hSelMask
), GetDIBHeight(hSelMask
), SRCCOPY
);
246 DeleteObject(hSelMask
);
248 SelectObject(hSelDC
, hSelBm
);
253 ShowWindow(hSelection
, SW_HIDE
);
254 ShowWindow(hSelection
, SW_SHOW
);
258 return DefWindowProc(hwnd
, message
, wParam
, lParam
);