2 * Copyright (C) 2003-2006 Gabest
3 * http://www.gabest.org
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GNU Make; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
22 // PlayerSeekBar.cpp : implementation file
27 #include "PlayerSeekBar.h"
31 IMPLEMENT_DYNAMIC(CPlayerSeekBar
, CDialogBar
)
33 CPlayerSeekBar::CPlayerSeekBar() :
34 m_start(0), m_stop(100), m_pos(0), m_posreal(0),
39 CPlayerSeekBar::~CPlayerSeekBar()
43 BOOL
CPlayerSeekBar::Create(CWnd
* pParentWnd
)
45 if(!CDialogBar::Create(pParentWnd
, IDD_PLAYERSEEKBAR
, WS_CHILD
|WS_VISIBLE
|CBRS_ALIGN_BOTTOM
, IDD_PLAYERSEEKBAR
))
51 BOOL
CPlayerSeekBar::PreCreateWindow(CREATESTRUCT
& cs
)
53 if(!CDialogBar::PreCreateWindow(cs
))
56 m_dwStyle
&= ~CBRS_BORDER_TOP
;
57 m_dwStyle
&= ~CBRS_BORDER_BOTTOM
;
58 m_dwStyle
|= CBRS_SIZE_FIXED
;
63 void CPlayerSeekBar::Enable(bool fEnable
)
69 void CPlayerSeekBar::GetRange(__int64
& start
, __int64
& stop
)
75 void CPlayerSeekBar::SetRange(__int64 start
, __int64 stop
)
77 if(start
> stop
) start
^= stop
, stop
^= start
, start
^= stop
;
80 if(m_pos
< m_start
|| m_pos
>= m_stop
) SetPos(m_start
);
83 __int64
CPlayerSeekBar::GetPos()
88 __int64
CPlayerSeekBar::GetPosReal()
93 void CPlayerSeekBar::SetPos(__int64 pos
)
95 CWnd
* w
= GetCapture();
96 if(w
&& w
->m_hWnd
== m_hWnd
) return;
101 void CPlayerSeekBar::SetPosInternal(__int64 pos
)
103 if(m_pos
== pos
) return;
105 CRect before
= GetThumbRect();
106 m_pos
= min(max(pos
, m_start
), m_stop
);
108 CRect after
= GetThumbRect();
110 if(before
!= after
) InvalidateRect(before
| after
);
113 CRect
CPlayerSeekBar::GetChannelRect()
117 r
.DeflateRect(8, 9, 9, 0);
118 r
.bottom
= r
.top
+ 5;
122 CRect
CPlayerSeekBar::GetThumbRect()
124 // bool fEnabled = m_fEnabled || m_start >= m_stop;
126 CRect r
= GetChannelRect();
128 int x
= r
.left
+ (int)((m_start
< m_stop
/*&& fEnabled*/) ? (__int64
)r
.Width() * (m_pos
- m_start
) / (m_stop
- m_start
) : 0);
129 int y
= r
.CenterPoint().y
;
131 r
.SetRect(x
, y
, x
, y
);
132 r
.InflateRect(6, 7, 7, 8);
137 CRect
CPlayerSeekBar::GetInnerThumbRect()
139 CRect r
= GetThumbRect();
141 bool fEnabled
= m_fEnabled
&& m_start
< m_stop
;
142 r
.DeflateRect(3, fEnabled
? 5 : 4, 3, fEnabled
? 5 : 4);
147 void CPlayerSeekBar::MoveThumb(CPoint point
)
149 CRect r
= GetChannelRect();
151 if(r
.left
>= r
.right
) return;
153 if(point
.x
< r
.left
) SetPos(m_start
);
154 else if(point
.x
>= r
.right
) SetPos(m_stop
);
157 __int64 w
= r
.right
- r
.left
;
159 SetPosInternal(m_start
+ ((m_stop
- m_start
) * (point
.x
- r
.left
) + (w
/2)) / w
);
163 BEGIN_MESSAGE_MAP(CPlayerSeekBar
, CDialogBar
)
164 //{{AFX_MSG_MAP(CPlayerSeekBar)
172 ON_COMMAND_EX(ID_PLAY_STOP
, OnPlayStop
)
176 // CPlayerSeekBar message handlers
178 void CPlayerSeekBar::OnPaint()
180 CPaintDC
dc(this); // device context for painting
182 bool fEnabled
= m_fEnabled
&& m_start
< m_stop
;
185 white
= GetSysColor(COLOR_WINDOW
),
186 shadow
= GetSysColor(COLOR_3DSHADOW
),
187 light
= GetSysColor(COLOR_3DHILIGHT
),
188 bkg
= GetSysColor(COLOR_BTNFACE
);
192 CRect r
= GetThumbRect(), r2
= GetInnerThumbRect();
193 CRect rt
= r
, rit
= r2
;
195 dc
.Draw3dRect(&r
, light
, 0);
196 r
.DeflateRect(0, 0, 1, 1);
197 dc
.Draw3dRect(&r
, light
, shadow
);
198 r
.DeflateRect(1, 1, 1, 1);
202 dc
.FrameRect(&r
, &b
);
203 r
.DeflateRect(0, 1, 0, 1);
204 dc
.FrameRect(&r
, &b
);
206 r
.DeflateRect(1, 1, 0, 0);
207 dc
.Draw3dRect(&r
, shadow
, bkg
);
211 r
.DeflateRect(1, 1, 1, 2);
212 CPen
white(PS_INSIDEFRAME
, 1, white
);
213 CPen
* old
= dc
.SelectObject(&white
);
214 dc
.MoveTo(r
.left
, r
.top
);
215 dc
.LineTo(r
.right
, r
.top
);
216 dc
.MoveTo(r
.left
, r
.bottom
);
217 dc
.LineTo(r
.right
, r
.bottom
);
218 dc
.SelectObject(old
);
219 dc
.SetPixel(r
.CenterPoint().x
, r
.top
, 0);
220 dc
.SetPixel(r
.CenterPoint().x
, r
.bottom
, 0);
223 dc
.SetPixel(r
.CenterPoint().x
+5, r
.top
-4, bkg
);
227 rgn1
.CreateRectRgnIndirect(&rt
);
228 rgn2
.CreateRectRgnIndirect(&rit
);
229 ExtSelectClipRgn(dc
, rgn1
, RGN_DIFF
);
230 ExtSelectClipRgn(dc
, rgn2
, RGN_OR
);
236 CRect r
= GetChannelRect();
238 dc
.FillSolidRect(&r
, fEnabled
? white
: bkg
);
240 dc
.Draw3dRect(&r
, shadow
, light
);
241 dc
.ExcludeClipRect(&r
);
253 // Do not call CDialogBar::OnPaint() for painting messages
257 void CPlayerSeekBar::OnSize(UINT nType
, int cx
, int cy
)
259 CDialogBar::OnSize(nType
, cx
, cy
);
264 void CPlayerSeekBar::OnLButtonDown(UINT nFlags
, CPoint point
)
266 if(m_fEnabled
&& (GetChannelRect() | GetThumbRect()).PtInRect(point
))
270 GetParent()->PostMessage(WM_HSCROLL
, MAKEWPARAM((short)m_pos
, SB_THUMBPOSITION
), (LPARAM
)m_hWnd
);
273 CDialogBar::OnLButtonDown(nFlags
, point
);
276 void CPlayerSeekBar::OnLButtonUp(UINT nFlags
, CPoint point
)
280 CDialogBar::OnLButtonUp(nFlags
, point
);
283 void CPlayerSeekBar::OnMouseMove(UINT nFlags
, CPoint point
)
285 CWnd
* w
= GetCapture();
286 if(w
&& w
->m_hWnd
== m_hWnd
&& (nFlags
& MK_LBUTTON
))
289 GetParent()->PostMessage(WM_HSCROLL
, MAKEWPARAM((short)m_pos
, SB_THUMBTRACK
), (LPARAM
)m_hWnd
);
292 CDialogBar::OnMouseMove(nFlags
, point
);
295 BOOL
CPlayerSeekBar::OnEraseBkgnd(CDC
* pDC
)
300 BOOL
CPlayerSeekBar::OnPlayStop(UINT nID
)