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

CORE-18867
This commit is contained in:
Katayama Hirofumi MZ 2023-06-14 17:14:41 +09:00
parent 0334498068
commit 3b4422b41b

View file

@ -117,16 +117,13 @@ void
Erase(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2, COLORREF color, LONG radius)
{
LONG b = max(1, max(abs(x2 - x1), abs(y2 - y1)));
RECT rc;
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);
LONG cx = (x1 * (b - a) + x2 * a) / b;
LONG cy = (y1 * (b - a) + y2 * a) / b;
RECT rc = { cx - radius, cy - radius, cx + radius, cy + radius };
::FillRect(hdc, &rc, hbr);
}
@ -137,14 +134,12 @@ void
Replace(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2, COLORREF fg, COLORREF bg, LONG radius)
{
LONG b = max(1, max(abs(x2 - x1), abs(y2 - y1)));
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);
LONG cx = (x1 * (b - a) + x2 * a) / b;
LONG cy = (y1 * (b - a) + y2 * a) / b;
RECT rc = { cx - radius, cy - radius, cx + radius, cy + radius };
for (LONG y = rc.top; y < rc.bottom; ++y)
{
for (LONG x = rc.left; x < rc.right; ++x)