29b73eef67610e34baf6068615b2b1425ef460e5
[reactos.git] / reactos / base / applications / mspaint / sizebox.cpp
1 /*
2 * PROJECT: PAINT for ReactOS
3 * LICENSE: LGPL
4 * FILE: base/applications/mspaint/sizebox.cpp
5 * PURPOSE: Window procedure of the size boxes
6 * PROGRAMMERS: Benedikt Freisen
7 */
8
9 /* INCLUDES *********************************************************/
10
11 #include "precomp.h"
12
13 /* FUNCTIONS ********************************************************/
14
15 BOOL resizing = FALSE;
16 short xOrig;
17 short yOrig;
18
19 LRESULT CSizeboxWindow::OnSetCursor(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
20 {
21 if ((m_hWnd == sizeboxLeftTop.m_hWnd) || (m_hWnd == sizeboxRightBottom.m_hWnd))
22 SetCursor(LoadCursor(NULL, IDC_SIZENWSE));
23 if ((m_hWnd == sizeboxLeftBottom.m_hWnd) || (m_hWnd == sizeboxRightTop.m_hWnd))
24 SetCursor(LoadCursor(NULL, IDC_SIZENESW));
25 if ((m_hWnd == sizeboxLeftCenter.m_hWnd) || (m_hWnd == sizeboxRightCenter.m_hWnd))
26 SetCursor(LoadCursor(NULL, IDC_SIZEWE));
27 if ((m_hWnd == sizeboxCenterTop.m_hWnd) || (m_hWnd == sizeboxCenterBottom.m_hWnd))
28 SetCursor(LoadCursor(NULL, IDC_SIZENS));
29 return 0;
30 }
31
32 LRESULT CSizeboxWindow::OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
33 {
34 resizing = TRUE;
35 xOrig = GET_X_LPARAM(lParam);
36 yOrig = GET_Y_LPARAM(lParam);
37 SetCapture();
38 return 0;
39 }
40
41 LRESULT CSizeboxWindow::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
42 {
43 if (resizing)
44 {
45 TCHAR sizeStr[100];
46 short xRel;
47 short yRel;
48 int imgXRes = imageModel.GetWidth();
49 int imgYRes = imageModel.GetHeight();
50 xRel = (GET_X_LPARAM(lParam) - xOrig) * 1000 / toolsModel.GetZoom();
51 yRel = (GET_Y_LPARAM(lParam) - yOrig) * 1000 / toolsModel.GetZoom();
52 if (m_hWnd == sizeboxLeftTop.m_hWnd)
53 _stprintf(sizeStr, _T("%d x %d"), imgXRes - xRel, imgYRes - yRel);
54 if (m_hWnd == sizeboxCenterTop.m_hWnd)
55 _stprintf(sizeStr, _T("%d x %d"), imgXRes, imgYRes - yRel);
56 if (m_hWnd == sizeboxRightTop.m_hWnd)
57 _stprintf(sizeStr, _T("%d x %d"), imgXRes + xRel, imgYRes - yRel);
58 if (m_hWnd == sizeboxLeftCenter.m_hWnd)
59 _stprintf(sizeStr, _T("%d x %d"), imgXRes - xRel, imgYRes);
60 if (m_hWnd == sizeboxRightCenter.m_hWnd)
61 _stprintf(sizeStr, _T("%d x %d"), imgXRes + xRel, imgYRes);
62 if (m_hWnd == sizeboxLeftBottom.m_hWnd)
63 _stprintf(sizeStr, _T("%d x %d"), imgXRes - xRel, imgYRes + yRel);
64 if (m_hWnd == sizeboxCenterBottom.m_hWnd)
65 _stprintf(sizeStr, _T("%d x %d"), imgXRes, imgYRes + yRel);
66 if (m_hWnd == sizeboxRightBottom.m_hWnd)
67 _stprintf(sizeStr, _T("%d x %d"), imgXRes + xRel, imgYRes + yRel);
68 SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) sizeStr);
69 }
70 return 0;
71 }
72
73 LRESULT CSizeboxWindow::OnLButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
74 {
75 if (resizing)
76 {
77 short xRel;
78 short yRel;
79 ReleaseCapture();
80 resizing = FALSE;
81 int imgXRes = imageModel.GetWidth();
82 int imgYRes = imageModel.GetHeight();
83 xRel = (GET_X_LPARAM(lParam) - xOrig) * 1000 / toolsModel.GetZoom();
84 yRel = (GET_Y_LPARAM(lParam) - yOrig) * 1000 / toolsModel.GetZoom();
85 if (m_hWnd == sizeboxLeftTop)
86 imageModel.Crop(imgXRes - xRel, imgYRes - yRel, xRel, yRel);
87 if (m_hWnd == sizeboxCenterTop.m_hWnd)
88 imageModel.Crop(imgXRes, imgYRes - yRel, 0, yRel);
89 if (m_hWnd == sizeboxRightTop.m_hWnd)
90 imageModel.Crop(imgXRes + xRel, imgYRes - yRel, 0, yRel);
91 if (m_hWnd == sizeboxLeftCenter.m_hWnd)
92 imageModel.Crop(imgXRes - xRel, imgYRes, xRel, 0);
93 if (m_hWnd == sizeboxRightCenter.m_hWnd)
94 imageModel.Crop(imgXRes + xRel, imgYRes, 0, 0);
95 if (m_hWnd == sizeboxLeftBottom.m_hWnd)
96 imageModel.Crop(imgXRes - xRel, imgYRes + yRel, xRel, 0);
97 if (m_hWnd == sizeboxCenterBottom.m_hWnd)
98 imageModel.Crop(imgXRes, imgYRes + yRel, 0, 0);
99 if (m_hWnd == sizeboxRightBottom.m_hWnd)
100 imageModel.Crop(imgXRes + xRel, imgYRes + yRel, 0, 0);
101 SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) _T(""));
102 }
103 return 0;
104 }