mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 10:04:49 +00:00
[MSPAINT] drawing.cpp: Refactor Erase, Replace and Airbrush
CORE-18867
This commit is contained in:
parent
6d9b7f77ad
commit
78c8df8393
1 changed files with 23 additions and 28 deletions
|
@ -116,46 +116,41 @@ Fill(HDC hdc, LONG x, LONG y, COLORREF color)
|
|||
void
|
||||
Erase(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2, COLORREF color, LONG radius)
|
||||
{
|
||||
LONG a, b;
|
||||
HPEN oldPen;
|
||||
HBRUSH oldBrush = (HBRUSH) SelectObject(hdc, CreateSolidBrush(color));
|
||||
LONG cx = (x1 + x2) / 2, cy = (y1 + y2) / 2;
|
||||
RECT rc = { cx - radius, cy - radius, cx + radius, cy + radius };
|
||||
|
||||
b = max(1, max(abs(x2 - x1), abs(y2 - y1)));
|
||||
oldPen = (HPEN) SelectObject(hdc, CreatePen(PS_SOLID, 1, color));
|
||||
for(a = 0; a <= b; a++)
|
||||
Rectangle(hdc,
|
||||
(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);
|
||||
DeleteObject(SelectObject(hdc, oldBrush));
|
||||
DeleteObject(SelectObject(hdc, oldPen));
|
||||
HBRUSH hbr = ::CreateSolidBrush(color);
|
||||
::FillRect(hdc, &rc, hbr);
|
||||
::DeleteObject(hbr);
|
||||
}
|
||||
|
||||
void
|
||||
Replace(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2, COLORREF fg, COLORREF bg, LONG radius)
|
||||
{
|
||||
LONG a, b, x, y;
|
||||
b = max(1, max(abs(x2 - x1), abs(y2 - y1)));
|
||||
LONG cx = (x1 + x2) / 2, cy = (y1 + y2) / 2;
|
||||
RECT rc = { cx - radius, cy - radius, cx + radius, cy + radius };
|
||||
|
||||
for(a = 0; a <= b; a++)
|
||||
for(y = (y1 * (b - a) + y2 * a) / b - radius + 1;
|
||||
y < (y1 * (b - a) + y2 * a) / b + radius + 1; y++)
|
||||
for(x = (x1 * (b - a) + x2 * a) / b - radius + 1;
|
||||
x < (x1 * (b - a) + x2 * a) / b + radius + 1; x++)
|
||||
if (GetPixel(hdc, x, y) == fg)
|
||||
SetPixel(hdc, x, y, bg);
|
||||
for (LONG y = rc.top; y < rc.bottom; ++y)
|
||||
{
|
||||
for (LONG x = rc.left; x < rc.right; ++x)
|
||||
{
|
||||
if (::GetPixel(hdc, x, y) == fg)
|
||||
::SetPixelV(hdc, x, y, bg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Airbrush(HDC hdc, LONG x, LONG y, COLORREF color, LONG r)
|
||||
{
|
||||
LONG a, b;
|
||||
|
||||
for(b = -r; b <= r; b++)
|
||||
for(a = -r; a <= r; a++)
|
||||
if ((a * a + b * b <= r * r) && (rand() % 4 == 0))
|
||||
SetPixel(hdc, x + a, y + b, color);
|
||||
for (LONG dy = -r; dy <= r; dy++)
|
||||
{
|
||||
for (LONG dx = -r; dx <= r; dx++)
|
||||
{
|
||||
if ((dx * dx + dy * dy <= r * r) && (rand() % 4 == 0))
|
||||
::SetPixelV(hdc, x + dx, y + dy, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Reference in a new issue