From c04fdc939123a8b22b38159e2a88e1cb7c1938de Mon Sep 17 00:00:00 2001 From: Xi Xu Date: Tue, 1 Oct 2024 21:17:21 +0800 Subject: [PATCH] Update NationalFlagView.cpp --- .../NationalFlag/NationalFlagView.cpp | 106 +----------------- 1 file changed, 3 insertions(+), 103 deletions(-) diff --git a/NationalFlag/NationalFlag/NationalFlagView.cpp b/NationalFlag/NationalFlag/NationalFlagView.cpp index 401e53e..31f12dd 100644 --- a/NationalFlag/NationalFlag/NationalFlagView.cpp +++ b/NationalFlag/NationalFlag/NationalFlagView.cpp @@ -100,102 +100,6 @@ CNationalFlagDoc *CNationalFlagView::GetDocument() const // non-debug version is } #endif //_DEBUG -void CNationalFlagView::DrawWuLine(CDC *pDC, CPoint begin, CPoint end) { - COLORREF foreColor = RGB(255, 255, 0); - COLORREF backColor = RGB(238, 28, 37); - CPoint temp; - LONG dx = end.x - begin.x, dy = end.y - begin.y; - int totalSteps = max(abs(dx), abs(dy)); - auto downPixelColor = [&](COLORREF foreColor, double e) -> COLORREF { - BYTE r = static_cast((GetRValue(backColor) - GetRValue(foreColor)) * e + GetRValue(foreColor)); - BYTE g = static_cast((GetGValue(backColor) - GetGValue(foreColor)) * e + GetGValue(foreColor)); - BYTE b = static_cast((GetBValue(backColor) - GetBValue(foreColor)) * e + GetBValue(foreColor)); - return RGB(r, g, b); - }; - auto upPixelColor = [&](COLORREF foreColor, double e) -> COLORREF { - BYTE r = static_cast((GetRValue(backColor) - GetRValue(foreColor)) * (1 - e) + GetRValue(foreColor)); - BYTE g = static_cast((GetGValue(backColor) - GetGValue(foreColor)) * (1 - e) + GetGValue(foreColor)); - BYTE b = static_cast((GetBValue(backColor) - GetBValue(foreColor)) * (1 - e) + GetBValue(foreColor)); - return RGB(r, g, b); - }; - if (begin.x == end.x) { - if (begin.y > end.y) { - temp = begin; - begin = end; - end = temp; - } - for (int y = begin.y; y < end.y; y++) - pDC->SetPixelV(begin.x, y, foreColor); - } - else { - double k = (double)dy / dx, e; - if (k >= 0.0 && k <= 1.0) { - if (begin.x > end.x) { - temp = begin; - begin = end; - end = temp; - } - for (temp = begin, e = k; temp.x < end.x; temp.x++) { - pDC->SetPixelV(temp.x, temp.y, downPixelColor(foreColor, e)); - pDC->SetPixelV(temp.x, temp.y + 1, upPixelColor(foreColor, e)); - e += k; - if (e >= 1.0) { - temp.y++; - e--; - } - } - } - else if (k > 1.0) { - if (begin.y > end.y) { - temp = begin; - begin = end; - end = temp; - } - for (temp = begin, e = 1 / k; temp.y < end.y; temp.y++) { - pDC->SetPixelV(temp.x, temp.y, downPixelColor(foreColor, e)); - pDC->SetPixelV(temp.x + 1, temp.y, upPixelColor(foreColor, e)); - e += 1 / k; - if (e >= 1.0) { - temp.x++; - e--; - } - } - } - else if (k < 0.0 && k >= -1.0) { - if (begin.x > end.x) { - temp = begin; - begin = end; - end = temp; - } - for (temp = begin, e = -k; temp.x < end.x; temp.x++) { - pDC->SetPixelV(temp.x, temp.y, downPixelColor(foreColor, e)); - pDC->SetPixelV(temp.x, temp.y - 1, upPixelColor(foreColor, e)); - e -= k; - if (e >= 1.0) { - temp.y--; - e--; - } - } - } - else { - if (begin.y < end.y) { - temp = begin; - begin = end; - end = temp; - } - for (temp = begin, e = -1 / k; temp.y > end.y; temp.y--) { - pDC->SetPixelV(temp.x, temp.y, downPixelColor(foreColor, e)); - pDC->SetPixelV(temp.x + 1, temp.y, upPixelColor(foreColor, e)); - e -= 1 / k; - if (e >= 1.0) { - temp.x++; - e--; - } - } - } - } -} - void CNationalFlagView::DrawFlag(CDC *pDC, CPoint center, int height) { int width = ROUND(height * 1.5); CPen NewPen, *pOldPen; @@ -218,20 +122,16 @@ void CNationalFlagView::DrawFlag(CDC *pDC, CPoint center, int height) { } void CNationalFlagView::DrawStar(CDC *pDC, CPoint center, double angle, int radius) { - CPoint points[10]; + CPi2 points[10]; for (int i = 0; i < 10; i++) { double theta = angle + i * 36.0 * M_PI / 180.0 - M_PI / 2; double r = (i % 2 == 0) ? radius : radius * 0.382; points[i].x = ROUND(center.x + r * cos(theta)); points[i].y = ROUND(center.y - r * sin(theta)); - } - for (int i = 0; i < 10; i++) { - P[i].x = points[i].x; - P[i].y = points[i].y; - P[i].c = CRGB(1, 1, 0); + points[i].c = CRGB(1, 1, 0); } CFill *pFill = new CFill(); - pFill->SetPoint(P, 10); + pFill->SetPoint(points, 10); pFill->CreateBucket(); pFill->CreateEdge(); pFill->Gouraud(pDC);