-
Notifications
You must be signed in to change notification settings - Fork 0
/
Paopao.cpp
174 lines (122 loc) · 3.33 KB
/
Paopao.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#include "stdafx.h"
#include "Paopao.h"
CPaopao::CPaopao()
{
nx=0;
ny=0;
fAngle = 0;
rRadius=0;
bAdd = TRUE;
color=RGB(0,0,0);
}
CPaopao::CPaopao(int xPos,int yPos, int r,int nx,int ny,COLORREF color){
rc.top=yPos-r;
rc.left=xPos-r;
rc.right=xPos+r;
rc.bottom=yPos+r;
fAngle = 0;
this->nx=nx;
this->ny=ny;
this->color=color;
}
void CPaopao::SetBitmapID(short nBitmapID){
nIdOfBitmap = nBitmapID;
}
void CPaopao::Draw(CDC &dc,int nDrawStyle,BOOL bPransparent){
CPen pen;
pen.CreatePen(0,1,color);
CPen *pOldPen=dc.SelectObject(&pen);
CBrush* pOldBrush=NULL;
CBrush brush;
CBitmap bmp;
CDC memDC;
if(bPransparent)
pOldBrush=(CBrush*)dc.SelectStockObject(NULL_BRUSH);
else{
brush.CreateSolidBrush(color);
pOldBrush=dc.SelectObject(&brush);
}
switch(nDrawStyle){
case 0:
{
dc.Ellipse(rc);
}
break;
case 1:
{
dc.Rectangle(rc);
}
break;
case 2:
{
bmp.LoadBitmap(nIdOfBitmap);
memDC.CreateCompatibleDC(&dc);
memDC.SelectObject(&bmp);
BITMAP bmpInfo;
bmp.GetBitmap(&bmpInfo);
// dc.BitBlt(rc.left,rc.top,rc.Width(),rc.Height(),&memDC,0,0,SRCCOPY);
dc.StretchBlt(rc.left, rc.top, rc.Width(), rc.Height(), &memDC, 0, 0, bmpInfo.bmWidth, bmpInfo.bmHeight, NOTSRCCOPY);
// TransparentBlt(dc.GetSafeHdc(),rc.left,rc.top,rc.Width(),rc.Height(),memDC.GetSafeHdc(),0,0,bmpInfo.bmWidth,bmpInfo.bmHeight,RGB(255, 255, 255));
}
break;
}
dc.SelectObject(pOldBrush);
dc.SelectObject(pOldPen);
}
void CPaopao::Run(CRect clientRc)
{
//位置信息
rc.top+=ny;
rc.bottom+=ny;
rc.left+=nx;
rc.right+=nx;
if(rc.top<0)
ny=abs(ny);
if(rc.bottom>clientRc.bottom)
ny=-abs(ny);
if(rc.left<0)
nx=abs(nx);
if(rc.right>clientRc.right)
nx=-abs(nx);
}
void CPaopao::RunSin(CRect clientRc, float fStartAngle, float fEndAngle)//正弦运动
{
CPoint ptCenter = clientRc.CenterPoint();
CPoint ptPaoPaoCenter = rc.CenterPoint();
// int nRadius =Distance(ptCenter, ptPaoPaoCenter);
long x = ptCenter.x + rRadius*cos(fAngle);
long y = ptCenter.y - rRadius*sin(fAngle);//折合成坐标
rc.OffsetRect( x-ptPaoPaoCenter.x, y-ptPaoPaoCenter.y);
if (bAdd)
fAngle += 0.1;
else
fAngle -= 0.1;
if (fAngle>fEndAngle)
bAdd = FALSE;
if (fAngle<fStartAngle)
bAdd = TRUE;
}
void CPaopao::RunCircle(CRect clientRc){
CPoint ptCenter = clientRc.CenterPoint();
CPoint ptPaoPaoCenter = rc.CenterPoint();
// int nRadius =Distance(ptCenter, ptPaoPaoCenter);
long x = ptCenter.x + rRadius*cos(fAngle);
long y = ptCenter.y - rRadius*sin(fAngle);
rc.OffsetRect(x-ptPaoPaoCenter.x, y-ptPaoPaoCenter.y );
fAngle += 0.03;
}
float CPaopao::Distance(CPoint pt1, CPoint pt2){
return sqrt((pt1.x - pt2.x)*(pt1.x - pt2.x)*1.0 + (pt1.y - pt2.y)*(pt1.y - pt2.y));
}
float CPaopao::GetAngle(CPoint centerPoint, CPoint pt){
int dx = (pt.x - centerPoint.x);
int dy = (centerPoint.y - pt.y);//折合成坐标
float rRadius = Distance(centerPoint, pt);
float angle = asin((double)dy / rRadius);
if (dx < 0)
angle = PAI - angle;
return angle;
}
CPaopao::~CPaopao(void)
{
}