2015-05-08 16:02:36 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: PAINT for ReactOS
|
|
|
|
* LICENSE: LGPL
|
2015-09-09 13:13:35 +00:00
|
|
|
* FILE: base/applications/mspaint/sizebox.cpp
|
2015-05-08 16:02:36 +00:00
|
|
|
* PURPOSE: Window procedure of the size boxes
|
|
|
|
* PROGRAMMERS: Benedikt Freisen
|
2017-07-27 09:29:42 +00:00
|
|
|
* Katayama Hirofumi MZ
|
2015-05-08 16:02:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *********************************************************/
|
|
|
|
|
|
|
|
#include "precomp.h"
|
|
|
|
|
|
|
|
/* FUNCTIONS ********************************************************/
|
|
|
|
|
2017-06-07 10:00:04 +00:00
|
|
|
static BOOL resizing = FALSE;
|
|
|
|
static short xOrig;
|
|
|
|
static short yOrig;
|
2015-05-08 16:02:36 +00:00
|
|
|
|
2015-07-07 10:42:49 +00:00
|
|
|
LRESULT CSizeboxWindow::OnSetCursor(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2015-07-07 10:42:49 +00:00
|
|
|
if ((m_hWnd == sizeboxLeftTop.m_hWnd) || (m_hWnd == sizeboxRightBottom.m_hWnd))
|
|
|
|
SetCursor(LoadCursor(NULL, IDC_SIZENWSE));
|
|
|
|
if ((m_hWnd == sizeboxLeftBottom.m_hWnd) || (m_hWnd == sizeboxRightTop.m_hWnd))
|
|
|
|
SetCursor(LoadCursor(NULL, IDC_SIZENESW));
|
|
|
|
if ((m_hWnd == sizeboxLeftCenter.m_hWnd) || (m_hWnd == sizeboxRightCenter.m_hWnd))
|
|
|
|
SetCursor(LoadCursor(NULL, IDC_SIZEWE));
|
|
|
|
if ((m_hWnd == sizeboxCenterTop.m_hWnd) || (m_hWnd == sizeboxCenterBottom.m_hWnd))
|
|
|
|
SetCursor(LoadCursor(NULL, IDC_SIZENS));
|
|
|
|
return 0;
|
2015-05-08 16:02:36 +00:00
|
|
|
}
|
|
|
|
|
2015-07-07 10:42:49 +00:00
|
|
|
LRESULT CSizeboxWindow::OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2015-07-07 10:42:49 +00:00
|
|
|
resizing = TRUE;
|
|
|
|
xOrig = GET_X_LPARAM(lParam);
|
|
|
|
yOrig = GET_Y_LPARAM(lParam);
|
|
|
|
SetCapture();
|
|
|
|
return 0;
|
|
|
|
}
|
2015-05-08 16:02:36 +00:00
|
|
|
|
2015-07-07 10:42:49 +00:00
|
|
|
LRESULT CSizeboxWindow::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
|
|
|
if (resizing)
|
|
|
|
{
|
2016-10-09 11:42:37 +00:00
|
|
|
CString strSize;
|
2015-07-07 10:42:49 +00:00
|
|
|
short xRel;
|
|
|
|
short yRel;
|
2015-07-07 11:56:37 +00:00
|
|
|
int imgXRes = imageModel.GetWidth();
|
|
|
|
int imgYRes = imageModel.GetHeight();
|
2015-07-07 11:15:24 +00:00
|
|
|
xRel = (GET_X_LPARAM(lParam) - xOrig) * 1000 / toolsModel.GetZoom();
|
|
|
|
yRel = (GET_Y_LPARAM(lParam) - yOrig) * 1000 / toolsModel.GetZoom();
|
2015-07-07 10:42:49 +00:00
|
|
|
if (m_hWnd == sizeboxLeftTop.m_hWnd)
|
2016-10-09 11:42:37 +00:00
|
|
|
strSize.Format(_T("%d x %d"), imgXRes - xRel, imgYRes - yRel);
|
2015-07-07 10:42:49 +00:00
|
|
|
if (m_hWnd == sizeboxCenterTop.m_hWnd)
|
2016-10-09 11:42:37 +00:00
|
|
|
strSize.Format(_T("%d x %d"), imgXRes, imgYRes - yRel);
|
2015-07-07 10:42:49 +00:00
|
|
|
if (m_hWnd == sizeboxRightTop.m_hWnd)
|
2016-10-09 11:42:37 +00:00
|
|
|
strSize.Format(_T("%d x %d"), imgXRes + xRel, imgYRes - yRel);
|
2015-07-07 10:42:49 +00:00
|
|
|
if (m_hWnd == sizeboxLeftCenter.m_hWnd)
|
2016-10-09 11:42:37 +00:00
|
|
|
strSize.Format(_T("%d x %d"), imgXRes - xRel, imgYRes);
|
2015-07-07 10:42:49 +00:00
|
|
|
if (m_hWnd == sizeboxRightCenter.m_hWnd)
|
2016-10-09 11:42:37 +00:00
|
|
|
strSize.Format(_T("%d x %d"), imgXRes + xRel, imgYRes);
|
2015-07-07 10:42:49 +00:00
|
|
|
if (m_hWnd == sizeboxLeftBottom.m_hWnd)
|
2016-10-09 11:42:37 +00:00
|
|
|
strSize.Format(_T("%d x %d"), imgXRes - xRel, imgYRes + yRel);
|
2015-07-07 10:42:49 +00:00
|
|
|
if (m_hWnd == sizeboxCenterBottom.m_hWnd)
|
2016-10-09 11:42:37 +00:00
|
|
|
strSize.Format(_T("%d x %d"), imgXRes, imgYRes + yRel);
|
2015-07-07 10:42:49 +00:00
|
|
|
if (m_hWnd == sizeboxRightBottom.m_hWnd)
|
2016-10-09 11:42:37 +00:00
|
|
|
strSize.Format(_T("%d x %d"), imgXRes + xRel, imgYRes + yRel);
|
|
|
|
SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) (LPCTSTR) strSize);
|
2015-05-08 16:02:36 +00:00
|
|
|
}
|
2015-07-07 10:42:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2015-05-08 16:02:36 +00:00
|
|
|
|
2015-07-07 10:42:49 +00:00
|
|
|
LRESULT CSizeboxWindow::OnLButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
|
|
|
if (resizing)
|
|
|
|
{
|
|
|
|
short xRel;
|
|
|
|
short yRel;
|
2015-07-07 11:56:37 +00:00
|
|
|
int imgXRes = imageModel.GetWidth();
|
|
|
|
int imgYRes = imageModel.GetHeight();
|
2015-07-07 11:15:24 +00:00
|
|
|
xRel = (GET_X_LPARAM(lParam) - xOrig) * 1000 / toolsModel.GetZoom();
|
|
|
|
yRel = (GET_Y_LPARAM(lParam) - yOrig) * 1000 / toolsModel.GetZoom();
|
2015-07-07 10:42:49 +00:00
|
|
|
if (m_hWnd == sizeboxLeftTop)
|
2015-07-07 11:56:37 +00:00
|
|
|
imageModel.Crop(imgXRes - xRel, imgYRes - yRel, xRel, yRel);
|
2015-07-07 10:42:49 +00:00
|
|
|
if (m_hWnd == sizeboxCenterTop.m_hWnd)
|
2015-07-07 11:56:37 +00:00
|
|
|
imageModel.Crop(imgXRes, imgYRes - yRel, 0, yRel);
|
2015-07-07 10:42:49 +00:00
|
|
|
if (m_hWnd == sizeboxRightTop.m_hWnd)
|
2015-07-07 11:56:37 +00:00
|
|
|
imageModel.Crop(imgXRes + xRel, imgYRes - yRel, 0, yRel);
|
2015-07-07 10:42:49 +00:00
|
|
|
if (m_hWnd == sizeboxLeftCenter.m_hWnd)
|
2015-07-07 11:56:37 +00:00
|
|
|
imageModel.Crop(imgXRes - xRel, imgYRes, xRel, 0);
|
2015-07-07 10:42:49 +00:00
|
|
|
if (m_hWnd == sizeboxRightCenter.m_hWnd)
|
2015-07-07 11:56:37 +00:00
|
|
|
imageModel.Crop(imgXRes + xRel, imgYRes, 0, 0);
|
2015-07-07 10:42:49 +00:00
|
|
|
if (m_hWnd == sizeboxLeftBottom.m_hWnd)
|
2015-07-07 11:56:37 +00:00
|
|
|
imageModel.Crop(imgXRes - xRel, imgYRes + yRel, xRel, 0);
|
2015-07-07 10:42:49 +00:00
|
|
|
if (m_hWnd == sizeboxCenterBottom.m_hWnd)
|
2015-07-07 11:56:37 +00:00
|
|
|
imageModel.Crop(imgXRes, imgYRes + yRel, 0, 0);
|
2015-07-07 10:42:49 +00:00
|
|
|
if (m_hWnd == sizeboxRightBottom.m_hWnd)
|
2015-07-07 11:56:37 +00:00
|
|
|
imageModel.Crop(imgXRes + xRel, imgYRes + yRel, 0, 0);
|
2015-07-07 10:42:49 +00:00
|
|
|
SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) _T(""));
|
|
|
|
}
|
2017-06-07 10:00:04 +00:00
|
|
|
resizing = FALSE;
|
2017-07-27 09:29:42 +00:00
|
|
|
ReleaseCapture();
|
2017-06-07 10:00:04 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-27 09:29:42 +00:00
|
|
|
LRESULT CSizeboxWindow::OnCaptureChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
2017-06-07 10:00:04 +00:00
|
|
|
{
|
|
|
|
resizing = FALSE;
|
2015-05-08 16:02:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2017-07-27 09:29:42 +00:00
|
|
|
|
|
|
|
LRESULT CSizeboxWindow::OnKeyDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
|
|
|
if (wParam == VK_ESCAPE)
|
|
|
|
{
|
|
|
|
if (GetCapture() == m_hWnd)
|
|
|
|
{
|
|
|
|
ReleaseCapture();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|