A Fast Bresenham Type Algorithm For Drawing Ellipses by John Kennedy
[xy_vsfilter.git] / src / apps / mplayerc / PlayerSeekBar.cpp
blobb8efe5e448d22e093848a0481fe945620013a684
1 /*
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)
8 * any later version.
9 *
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
25 #include "stdafx.h"
26 #include "mplayerc.h"
27 #include "PlayerSeekBar.h"
29 // CPlayerSeekBar
31 IMPLEMENT_DYNAMIC(CPlayerSeekBar, CDialogBar)
33 CPlayerSeekBar::CPlayerSeekBar() :
34 m_start(0), m_stop(100), m_pos(0), m_posreal(0),
35 m_fEnabled(false)
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))
46 return FALSE;
48 return TRUE;
51 BOOL CPlayerSeekBar::PreCreateWindow(CREATESTRUCT& cs)
53 if(!CDialogBar::PreCreateWindow(cs))
54 return FALSE;
56 m_dwStyle &= ~CBRS_BORDER_TOP;
57 m_dwStyle &= ~CBRS_BORDER_BOTTOM;
58 m_dwStyle |= CBRS_SIZE_FIXED;
60 return TRUE;
63 void CPlayerSeekBar::Enable(bool fEnable)
65 m_fEnabled = fEnable;
66 Invalidate();
69 void CPlayerSeekBar::GetRange(__int64& start, __int64& stop)
71 start = m_start;
72 stop = m_stop;
75 void CPlayerSeekBar::SetRange(__int64 start, __int64 stop)
77 if(start > stop) start ^= stop, stop ^= start, start ^= stop;
78 m_start = start;
79 m_stop = stop;
80 if(m_pos < m_start || m_pos >= m_stop) SetPos(m_start);
83 __int64 CPlayerSeekBar::GetPos()
85 return(m_pos);
88 __int64 CPlayerSeekBar::GetPosReal()
90 return(m_posreal);
93 void CPlayerSeekBar::SetPos(__int64 pos)
95 CWnd* w = GetCapture();
96 if(w && w->m_hWnd == m_hWnd) return;
98 SetPosInternal(pos);
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);
107 m_posreal = pos;
108 CRect after = GetThumbRect();
110 if(before != after) InvalidateRect(before | after);
113 CRect CPlayerSeekBar::GetChannelRect()
115 CRect r;
116 GetClientRect(&r);
117 r.DeflateRect(8, 9, 9, 0);
118 r.bottom = r.top + 5;
119 return(r);
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);
134 return(r);
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);
144 return(r);
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);
155 else
157 __int64 w = r.right - r.left;
158 if(m_start < m_stop)
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)
165 ON_WM_PAINT()
166 ON_WM_SIZE()
167 ON_WM_LBUTTONDOWN()
168 ON_WM_LBUTTONUP()
169 ON_WM_MOUSEMOVE()
170 ON_WM_ERASEBKGND()
171 //}}AFX_MSG_MAP
172 ON_COMMAND_EX(ID_PLAY_STOP, OnPlayStop)
173 END_MESSAGE_MAP()
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;
184 COLORREF
185 white = GetSysColor(COLOR_WINDOW),
186 shadow = GetSysColor(COLOR_3DSHADOW),
187 light = GetSysColor(COLOR_3DHILIGHT),
188 bkg = GetSysColor(COLOR_BTNFACE);
190 // thumb
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);
200 CBrush b(bkg);
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);
209 if(fEnabled)
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);
226 CRgn rgn1, rgn2;
227 rgn1.CreateRectRgnIndirect(&rt);
228 rgn2.CreateRectRgnIndirect(&rit);
229 ExtSelectClipRgn(dc, rgn1, RGN_DIFF);
230 ExtSelectClipRgn(dc, rgn2, RGN_OR);
234 // channel
236 CRect r = GetChannelRect();
238 dc.FillSolidRect(&r, fEnabled ? white : bkg);
239 r.InflateRect(1, 1);
240 dc.Draw3dRect(&r, shadow, light);
241 dc.ExcludeClipRect(&r);
244 // background
246 CRect r;
247 GetClientRect(&r);
248 CBrush b(bkg);
249 dc.FillRect(&r, &b);
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);
261 Invalidate();
264 void CPlayerSeekBar::OnLButtonDown(UINT nFlags, CPoint point)
266 if(m_fEnabled && (GetChannelRect() | GetThumbRect()).PtInRect(point))
268 SetCapture();
269 MoveThumb(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)
278 ReleaseCapture();
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))
288 MoveThumb(point);
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)
297 return TRUE;
300 BOOL CPlayerSeekBar::OnPlayStop(UINT nID)
302 SetPos(0);
303 return FALSE;