https://git.reactos.org/?p=reactos.git;a=commitdiff;h=78c8df8393c7164f9dc1b…
commit 78c8df8393c7164f9dc1b83ad9a81c8c7ed334f6
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Wed Jun 14 16:44:54 2023 +0900
Commit: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
CommitDate: Wed Jun 14 16:44:54 2023 +0900
[MSPAINT] drawing.cpp: Refactor Erase, Replace and Airbrush
CORE-18867
---
base/applications/mspaint/drawing.cpp | 51 ++++++++++++++++-------------------
1 file changed, 23 insertions(+), 28 deletions(-)
diff --git a/base/applications/mspaint/drawing.cpp
b/base/applications/mspaint/drawing.cpp
index 05599d2d2cc..40ff30bcb32 100644
--- a/base/applications/mspaint/drawing.cpp
+++ b/base/applications/mspaint/drawing.cpp
@@ -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