Update NationalFlagView.cpp

This commit is contained in:
xixu-me committed 2024-10-01 21:17:21 +08:00
1 parent 3157488875
commit c04fdc9391
1 file changed
+3 -103
+3 -103
View File
@@ -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<BYTE>((GetRValue(backColor) - GetRValue(foreColor)) * e + GetRValue(foreColor));
BYTE g = static_cast<BYTE>((GetGValue(backColor) - GetGValue(foreColor)) * e + GetGValue(foreColor));
BYTE b = static_cast<BYTE>((GetBValue(backColor) - GetBValue(foreColor)) * e + GetBValue(foreColor));
return RGB(r, g, b);
};
auto upPixelColor = [&](COLORREF foreColor, double e) -> COLORREF {
BYTE r = static_cast<BYTE>((GetRValue(backColor) - GetRValue(foreColor)) * (1 - e) + GetRValue(foreColor));
BYTE g = static_cast<BYTE>((GetGValue(backColor) - GetGValue(foreColor)) * (1 - e) + GetGValue(foreColor));
BYTE b = static_cast<BYTE>((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);