-
Notifications
You must be signed in to change notification settings - Fork 2
/
Circle.cpp
146 lines (118 loc) · 3.66 KB
/
Circle.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include "stdafx.h"
#include "Circle.h"
Circle::Circle(CWnd* cWnd, int r):
m_Percent(r), m_nPenWidth(5), m_pdlgcWnd(cWnd), m_isShowPercentCount(FALSE), m_isShowLabel(FALSE), m_Visible(TRUE)
{
m_Info1.pCircle = this;
}
void Circle::SetCenter(const int& x, const int& y)
{
ASSERT(x >= 0 && y >= 0);
m_nCenter.x = x;
m_nCenter.y = y;
m_Label.BindCircle(GetRadius(), GetCenter());
}
void Circle::SetRadius(const int& r)
{
ASSERT(r > 0);
m_nRadius = r;
m_Label.BindCircle(GetRadius(), GetCenter());
}
void Circle::SetArcColor(const ColorRef& clr)
{
m_arcColor = clr;
m_Pen.DeleteObject();
m_Pen.CreatePen(PS_SOLID, m_nPenWidth, m_arcColor.oRGB());//變色
tracePen = &m_Pen;
}
void Circle::SetPrcntColor(const ColorRef clr)
{ m_percentColor = clr; }
void Circle::Draw(CPaintDC &dc)
{
if (m_Visible)
{
drawCircle(dc);
if (m_isShowPercentCount)
drawPercentCount(dc);
if (m_isShowLabel)
m_Label.Draw(dc);
}
}
void Circle::drawCircle(CPaintDC &dc)
{
//設定畫筆
CPen* OldPen;
OldPen = dc.SelectObject(&m_Pen);
drawPercent(dc);
CPen* tempPen;
tempPen = dc.SelectObject(OldPen);
ASSERT(tracePen == tempPen);
}
void Circle::ShowLabel(const BOOL& _B)
{ m_isShowLabel = _B; }
void Circle::drawPercent(CPaintDC& dc)
{
int oX(0), oY(0);
if (m_Percent > 0 && m_Percent <= 25)
{
oX = (int)(m_nRadius / cos(0.0628318 * (m_Percent+50)));
oY = (int)(m_nRadius / sin(0.0628318 * (m_Percent+50)));
}
else if (m_Percent > 25 && m_Percent <= 50)
{
oX = (int)(m_nRadius / cos(0.0628318 * m_Percent));
oY = (int)(m_nRadius / sin(0.0628318 * m_Percent));
}
else if (m_Percent > 50 && m_Percent <= 75)
{
oX = (int)(m_nRadius / cos(0.0628318 * (m_Percent-50)));
oY = (int)(m_nRadius / sin(0.0628318 * (m_Percent-50)));
}
else if (m_Percent > 75 && m_Percent < 100)
{
oX = (int)(m_nRadius / cos(0.0628318 * m_Percent));
oY = (int)(m_nRadius / sin(0.0628318 * m_Percent));
}
CPoint StartPoint(GetCenter().x, GetCenter().y - m_nRadius);
CPoint EndPoint(GetCenter().x, GetCenter().y - m_nRadius);
EndPoint.x = oX + EndPoint.x;
EndPoint.y = oY + EndPoint.y;
dc.Arc(m_DrawCircleRect, StartPoint, EndPoint);
}
void Circle::drawPercentCount(CPaintDC &dc)
{
dc.SetTextColor(m_percentColor.oRGB());
CString percent;
percent.Format("%3d%%", GetPercent());
TextOut(dc, GetCenter().x - 15, GetCenter().y - (GetRadius()+20) , (LPCSTR)percent, percent.GetLength()); //上
TextOut(dc, GetCenter().x - 15, GetCenter().y + (GetRadius()+2 ) , (LPCSTR)percent, percent.GetLength()); //下
TextOut(dc, GetCenter().x - (GetRadius()+40), GetCenter().y -7 , (LPCSTR)percent, percent.GetLength()); //左
TextOut(dc, GetCenter().x + (GetRadius()+2) , GetCenter().y -7 , (LPCSTR)percent, percent.GetLength()); //右
}
void Circle::readRadius(const int& dyR)
{
if (m_MaxRadius < dyR)
m_MaxRadius = dyR;
m_reDeawRect = r2rect(m_MaxRadius);
m_nRadius = dyR;
m_DrawCircleRect = r2rect(m_nRadius);
}
const CRect Circle::r2rect(const int& expnd)
{
CRect _rect((long)(m_nCenter.x - expnd), (long)(m_nCenter.y - expnd),
(long)(m_nCenter.x + expnd), (long)(m_nCenter.y + expnd));
return _rect;
}
void Circle::SetData(const Bullet& blt)
{
m_Label.SetData(blt);
}
#ifdef _DEBUG
CString Circle::showMe() const
{
CString str;
str.Format("中心點(%d, %d), 顏色(%d, %d, %d), 半徑 = %d, 百分比 = %d%% 圖形範圍 = %d, %d", \
GetCenter().x, GetCenter().y, m_arcColor.R(), m_arcColor.G(), m_arcColor.B(), m_nRadius, m_Percent, m_DrawCircleRect.right - m_DrawCircleRect.left, m_DrawCircleRect.bottom - m_DrawCircleRect.top);
return str;
}
#endif