[MSPAINT] drawing.cpp: Refactor Erase, Replace and Airbrush 2

CORE-18867
This commit is contained in:
Katayama Hirofumi MZ 2023-06-14 17:03:22 +09:00
parent 78c8df8393
commit 0334498068

View file

@ -116,20 +116,35 @@ Fill(HDC hdc, LONG x, LONG y, COLORREF color)
void void
Erase(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2, COLORREF color, LONG radius) Erase(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2, COLORREF color, LONG radius)
{ {
LONG cx = (x1 + x2) / 2, cy = (y1 + y2) / 2; LONG b = max(1, max(abs(x2 - x1), abs(y2 - y1)));
RECT rc = { cx - radius, cy - radius, cx + radius, cy + radius }; RECT rc;
HBRUSH hbr = ::CreateSolidBrush(color); HBRUSH hbr = ::CreateSolidBrush(color);
for (LONG a = 0; a <= b; a++)
{
::SetRect(&rc, (x1 * (b - a) + x2 * a) / b - radius,
(y1 * (b - a) + y2 * a) / b - radius,
(x1 * (b - a) + x2 * a) / b + radius,
(y1 * (b - a) + y2 * a) / b + radius);
::FillRect(hdc, &rc, hbr); ::FillRect(hdc, &rc, hbr);
}
::DeleteObject(hbr); ::DeleteObject(hbr);
} }
void void
Replace(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2, COLORREF fg, COLORREF bg, LONG radius) Replace(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2, COLORREF fg, COLORREF bg, LONG radius)
{ {
LONG cx = (x1 + x2) / 2, cy = (y1 + y2) / 2; LONG b = max(1, max(abs(x2 - x1), abs(y2 - y1)));
RECT rc = { cx - radius, cy - radius, cx + radius, cy + radius }; RECT rc;
for (LONG a = 0; a <= b; a++)
{
::SetRect(&rc, (x1 * (b - a) + x2 * a) / b - radius,
(y1 * (b - a) + y2 * a) / b - radius,
(x1 * (b - a) + x2 * a) / b + radius,
(y1 * (b - a) + y2 * a) / b + radius);
for (LONG y = rc.top; y < rc.bottom; ++y) for (LONG y = rc.top; y < rc.bottom; ++y)
{ {
for (LONG x = rc.left; x < rc.right; ++x) for (LONG x = rc.left; x < rc.right; ++x)
@ -139,6 +154,7 @@ Replace(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2, COLORREF fg, COLORREF bg, L
} }
} }
} }
}
void void
Airbrush(HDC hdc, LONG x, LONG y, COLORREF color, LONG r) Airbrush(HDC hdc, LONG x, LONG y, COLORREF color, LONG r)