mirror of
https://github.com/reactos/reactos.git
synced 2024-08-21 02:43:48 +00:00
![Stanislav Motylkov](/assets/img/avatar_default.png)
According to Benedikt Freisen, he didn't port the code base to C++
until 2015. Addendum to 8f1f1c7a5a
. CORE-18867
131 lines
3.9 KiB
C++
131 lines
3.9 KiB
C++
/*
|
|
* PROJECT: PAINT for ReactOS
|
|
* LICENSE: LGPL-2.0-or-later (https://spdx.org/licenses/LGPL-2.0-or-later)
|
|
* PURPOSE: Window procedure of the size boxes
|
|
* COPYRIGHT: Copyright 2015 Benedikt Freisen <b.freisen@gmx.net>
|
|
* Copyright 2017 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
|
|
*/
|
|
|
|
#include "precomp.h"
|
|
|
|
static LPCWSTR s_cursor_shapes[] =
|
|
{
|
|
IDC_SIZENWSE, IDC_SIZENS, IDC_SIZENESW,
|
|
IDC_SIZEWE, IDC_SIZEWE,
|
|
IDC_SIZENESW, IDC_SIZENS, IDC_SIZENWSE,
|
|
};
|
|
|
|
/* FUNCTIONS ********************************************************/
|
|
|
|
BOOL setCursorOnSizeBox(HITTEST hit)
|
|
{
|
|
if (HIT_UPPER_LEFT <= hit && hit <= HIT_LOWER_RIGHT)
|
|
{
|
|
::SetCursor(::LoadCursor(NULL, s_cursor_shapes[hit - HIT_UPPER_LEFT]));
|
|
return TRUE;
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
BOOL getSizeBoxRect(LPRECT prc, HITTEST hit, LPCRECT prcBase)
|
|
{
|
|
switch (hit)
|
|
{
|
|
case HIT_UPPER_LEFT:
|
|
prc->left = prcBase->left;
|
|
prc->top = prcBase->top;
|
|
break;
|
|
case HIT_UPPER_CENTER:
|
|
prc->left = (prcBase->left + prcBase->right - GRIP_SIZE) / 2;
|
|
prc->top = prcBase->top;
|
|
break;
|
|
case HIT_UPPER_RIGHT:
|
|
prc->left = prcBase->right - GRIP_SIZE;
|
|
prc->top = prcBase->top;
|
|
break;
|
|
case HIT_MIDDLE_LEFT:
|
|
prc->left = prcBase->left;
|
|
prc->top = (prcBase->top + prcBase->bottom - GRIP_SIZE) / 2;
|
|
break;
|
|
case HIT_MIDDLE_RIGHT:
|
|
prc->left = prcBase->right - GRIP_SIZE;
|
|
prc->top = (prcBase->top + prcBase->bottom - GRIP_SIZE) / 2;
|
|
break;
|
|
case HIT_LOWER_LEFT:
|
|
prc->left = prcBase->left;
|
|
prc->top = prcBase->bottom - GRIP_SIZE;
|
|
break;
|
|
case HIT_LOWER_CENTER:
|
|
prc->left = (prcBase->left + prcBase->right - GRIP_SIZE) / 2;
|
|
prc->top = prcBase->bottom - GRIP_SIZE;
|
|
break;
|
|
case HIT_LOWER_RIGHT:
|
|
prc->left = prcBase->right - GRIP_SIZE;
|
|
prc->top = prcBase->bottom - GRIP_SIZE;
|
|
break;
|
|
case HIT_INNER:
|
|
*prc = *prcBase;
|
|
::InflateRect(prc, -GRIP_SIZE, -GRIP_SIZE);
|
|
return TRUE;
|
|
default:
|
|
::SetRectEmpty(prc);
|
|
return FALSE;
|
|
}
|
|
|
|
prc->right = prc->left + GRIP_SIZE;
|
|
prc->bottom = prc->top + GRIP_SIZE;
|
|
return TRUE;
|
|
}
|
|
|
|
HITTEST getSizeBoxHitTest(POINT pt, LPCRECT prcBase)
|
|
{
|
|
RECT rc;
|
|
|
|
if (!::PtInRect(prcBase, pt))
|
|
return HIT_NONE;
|
|
|
|
rc = *prcBase;
|
|
::InflateRect(&rc, -GRIP_SIZE, -GRIP_SIZE);
|
|
if (::PtInRect(&rc, pt))
|
|
return HIT_INNER;
|
|
|
|
for (INT i = HIT_UPPER_LEFT; i <= HIT_LOWER_RIGHT; ++i)
|
|
{
|
|
HITTEST hit = (HITTEST)i;
|
|
getSizeBoxRect(&rc, hit, prcBase);
|
|
if (::PtInRect(&rc, pt))
|
|
return hit;
|
|
}
|
|
|
|
return HIT_BORDER;
|
|
}
|
|
|
|
VOID drawSizeBoxes(HDC hdc, LPCRECT prcBase, BOOL bDrawFrame, LPCRECT prcPaint)
|
|
{
|
|
CRect rc, rcIntersect;
|
|
|
|
if (prcPaint && !::IntersectRect(&rcIntersect, prcPaint, prcBase))
|
|
return;
|
|
|
|
if (bDrawFrame)
|
|
{
|
|
rc = *prcBase;
|
|
::InflateRect(&rc, -GRIP_SIZE / 2, -GRIP_SIZE / 2);
|
|
|
|
LOGBRUSH logBrush = { BS_HOLLOW, 0, 0 };
|
|
COLORREF rgbHighlight = ::GetSysColor(COLOR_HIGHLIGHT);
|
|
HGDIOBJ oldPen = ::SelectObject(hdc, ::CreatePen(PS_DOT, 1, rgbHighlight));
|
|
HGDIOBJ oldBrush = ::SelectObject(hdc, ::CreateBrushIndirect(&logBrush));
|
|
::Rectangle(hdc, rc.left, rc.top, rc.right, rc.bottom);
|
|
::DeleteObject(::SelectObject(hdc, oldBrush));
|
|
::DeleteObject(::SelectObject(hdc, oldPen));
|
|
}
|
|
|
|
for (INT i = HIT_UPPER_LEFT; i <= HIT_LOWER_RIGHT; ++i)
|
|
{
|
|
getSizeBoxRect(&rc, (HITTEST)i, prcBase);
|
|
if (!prcPaint || ::IntersectRect(&rcIntersect, &rc, prcPaint))
|
|
::FillRect(hdc, &rc, (HBRUSH)(COLOR_HIGHLIGHT + 1));
|
|
}
|
|
}
|