-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayPauseButton.cpp
More file actions
235 lines (183 loc) · 5.25 KB
/
PlayPauseButton.cpp
File metadata and controls
235 lines (183 loc) · 5.25 KB
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
// DrawButton.cpp : implementation file
//
#include "stdafx.h"
#include "MediaPlayer.h"
#include "PlayPauseButton.h"
#include "MediaPlayerDialog.h"
// CDrawButton
IMPLEMENT_DYNAMIC(CPlayPauseButton, CButton)
CPlayPauseButton::CPlayPauseButton()
{
m_bPlay = false;
m_bMp4Opened = false;
m_pMediaPlayDlg = nullptr;
}
CPlayPauseButton::~CPlayPauseButton()
{
}
BEGIN_MESSAGE_MAP(CPlayPauseButton, CButton)
ON_WM_LBUTTONDOWN()
ON_MESSAGE(WM_DRAWCIRCULARBTN, OnDrawCircularButton)
END_MESSAGE_MAP()
// CDrawButton message handlers
BOOL CPlayPauseButton::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Add your specialized code here and/or call the base class
ModifyStyle(0, GetStyle() | BS_OWNERDRAW);
return CButton::PreCreateWindow(cs);
}
void CPlayPauseButton::DrawCircularButton(CDC& dc, const CPoint& ptBegin,
const CPoint& ptEnd, COLORREF color)
{
dc.SetBkMode(TRANSPARENT);
CPen LightBluePen(PS_SOLID, 2, color);
CPen* pOldPen = dc.SelectObject(&LightBluePen);
dc.Ellipse(ptBegin.x, ptBegin.y, ptEnd.x, ptEnd.y);
if (pOldPen)
{
dc.SelectObject(pOldPen);
}
if (m_bPlay)
{
DrawPauseIcon(dc, ptBegin, ptEnd, color);
}
else
{
DrawPlayIcon(dc, ptBegin, ptEnd, color);
}
}
void CPlayPauseButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: Add your code to draw the specified item
CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
RECT rect = lpDrawItemStruct->rcItem;
int nSubWidth = rect.right - rect.left;
int nSubHeight = rect.bottom - rect.top;
if (nSubWidth < nSubHeight)
{
rect.top += (nSubHeight - nSubWidth) / 2;
rect.bottom = rect.top + nSubWidth;
}
if (nSubWidth > nSubHeight)
{
rect.left += (nSubWidth - nSubHeight) / 2;
rect.right = rect.left + nSubHeight;
}
UINT uStyle = DFCS_BUTTONPUSH;
// This code only works with buttons.
ASSERT(lpDrawItemStruct->CtlType == ODT_BUTTON);
COLORREF BlackColor = RGB(0, 0, 0);
// If drawing selected, add the pushed style to DrawFrameControl.
if (lpDrawItemStruct->itemState & ODS_SELECTED)
{
CRect rtPressed = rect;
rtPressed.top += 2;
rtPressed.left += 2;
rtPressed.right -= 2;
rtPressed.bottom -= 2;
DrawCircularButton(*pDC, CPoint(rtPressed.left, rtPressed.top),
CPoint(rtPressed.right, rtPressed.bottom), BlackColor);
}
else
{
DrawCircularButton(*pDC, CPoint(rect.left, rect.top),
CPoint(rect.right, rect.bottom), BlackColor);
}
}
void CPlayPauseButton::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CRect rect;
GetClientRect(&rect);
InvalidateRect(&rect);
const CString& strMp4Path = m_pMediaPlayDlg->GetMp4Path();
if (strMp4Path.IsEmpty())
{
return;
}
if (!m_bPlay)
{
if (!m_bMp4Opened)
{
CVLCPlayer::Instance()->OpenMedia(strMp4Path);
}
CVLCPlayer::Instance()->Play();
m_bPlay = true;
::PostMessage(m_pMediaPlayDlg->GetSafeHwnd(), WM_RESETBTNSTATUS, NULL, NULL);
}
else
{
m_bMp4Opened = true;
m_bPlay = false;
CVLCPlayer::Instance()->Pause();
}
CButton::OnLButtonDown(nFlags, point);
}
void CPlayPauseButton::DrawPlayIcon(CDC& dc, const CPoint& ptBegin,
const CPoint& ptEnd, COLORREF color)
{
long lStart = ptBegin.x + (ptEnd.x - ptBegin.x) / 5*2;
long lEnd = lStart + (ptEnd.x - ptBegin.x) / 7 * 3;
long lCenter = (ptEnd.y - ptBegin.y) / 6 * 3;
long lCentUp = lCenter;
long lCentDown = lCenter;
dc.MoveTo(lStart, lCenter);
dc.LineTo(lEnd, lCenter);
while (true)
{
if (lEnd <= lStart)
{
break;
}
dc.MoveTo(lStart, --lCentUp);
dc.LineTo(lEnd-=2, lCentUp);
dc.MoveTo(lStart, ++lCentDown);
dc.LineTo(lEnd, lCentDown);
}
}
void CPlayPauseButton::DrawPauseIcon(CDC& dc, const CPoint& ptBegin,
const CPoint& ptEnd, COLORREF color)
{
long lHeight = (ptEnd.y - ptBegin.y) / 2;
long lCenter_x = ptBegin.x + (ptEnd.x - ptBegin.x) / 3 - 2;
long lCenter_y = ptBegin.y + (ptEnd.y - ptBegin.y) / 2;
long ly1 = lCenter_y - lHeight / 2;
long ly2 = lCenter_y + lHeight / 2;
for (int i = 0; i < 6; i++)
{
dc.MoveTo(lCenter_x, ly1);
dc.LineTo(lCenter_x, ly2);
lCenter_x += 1;
}
lCenter_x += 3;
for (int i = 0; i < 6; i++)
{
dc.MoveTo(lCenter_x, ly1);
dc.LineTo(lCenter_x, ly2);
lCenter_x += 1;
}
}
void CPlayPauseButton::SetParentDlg(CMediaPlayerDialog* pDlg)
{
if (pDlg)
{
m_pMediaPlayDlg = pDlg;
}
}
LRESULT CPlayPauseButton::OnDrawCircularButton(WPARAM wParam, LPARAM lParam)
{
CClientDC dc(this);
CRect rect;
GetClientRect(&rect);
COLORREF BlackColor = RGB(0, 0, 0);
CRect rtPressed = rect;
rtPressed.top += 2;
rtPressed.left += 2;
rtPressed.right -= 2;
rtPressed.bottom -= 2;
m_bPlay = bool(wParam);
InvalidateRect(NULL);
DrawCircularButton(dc, CPoint(rtPressed.left, rtPressed.top),
CPoint(rtPressed.right, rtPressed.bottom), BlackColor);
return 0;
}