A Fast Bresenham Type Algorithm For Drawing Ellipses by John Kennedy
[xy_vsfilter.git] / src / apps / mplayerc / PlayerStatusBar.cpp
blob56ae566d1818f6e54f22f24adce6b27b1bfaba74
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 // PlayerStatusBar.cpp : implementation file
25 #include "stdafx.h"
26 #include "mplayerc.h"
27 #include "PlayerStatusBar.h"
28 #include "MainFrm.h"
29 #include "..\..\DSUtil\DSUtil.h"
31 // CPlayerStatusBar
33 IMPLEMENT_DYNAMIC(CPlayerStatusBar, CDialogBar)
35 CPlayerStatusBar::CPlayerStatusBar()
36 : m_status(false, false)
37 , m_time(true, false)
38 , m_bmid(0)
39 , m_hIcon(0)
43 CPlayerStatusBar::~CPlayerStatusBar()
45 if(m_hIcon) DestroyIcon(m_hIcon);
48 BOOL CPlayerStatusBar::Create(CWnd* pParentWnd)
50 return CDialogBar::Create(pParentWnd, IDD_PLAYERSTATUSBAR, WS_CHILD|WS_VISIBLE|CBRS_ALIGN_BOTTOM, IDD_PLAYERSTATUSBAR);
53 BOOL CPlayerStatusBar::PreCreateWindow(CREATESTRUCT& cs)
55 if(!CDialogBar::PreCreateWindow(cs))
56 return FALSE;
58 m_dwStyle &= ~CBRS_BORDER_TOP;
59 m_dwStyle &= ~CBRS_BORDER_BOTTOM;
61 return TRUE;
64 int CPlayerStatusBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
66 if(CDialogBar::OnCreate(lpCreateStruct) == -1)
67 return -1;
69 CRect r;
70 r.SetRectEmpty();
72 m_type.Create(_T(""), WS_CHILD|WS_VISIBLE|SS_ICON,
73 r, this, IDC_STATIC1);
75 m_status.Create(_T(""), WS_CHILD|WS_VISIBLE|SS_OWNERDRAW,
76 r, this, IDC_PLAYERSTATUS);
78 m_time.Create(_T(""), WS_CHILD|WS_VISIBLE|SS_OWNERDRAW,
79 r, this, IDC_PLAYERTIME);
81 m_status.SetWindowPos(&m_time, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
83 Relayout();
85 return 0;
88 void CPlayerStatusBar::Relayout()
90 BITMAP bm;
91 memset(&bm, 0, sizeof(bm));
92 if(m_bm.m_hObject) m_bm.GetBitmap(&bm);
94 CRect r, r2;
95 GetClientRect(r);
97 r.DeflateRect(27, 5, bm.bmWidth + 8, 4);
98 int div = r.right - (m_time.IsWindowVisible() ? 140 : 0);
100 CString str;
101 m_time.GetWindowText(str);
102 if(CDC* pDC = m_time.GetDC())
104 CFont* pOld = pDC->SelectObject(&m_time.GetFont());
105 div = r.right - pDC->GetTextExtent(str).cx;
106 pDC->SelectObject(pOld);
107 m_time.ReleaseDC(pDC);
110 r2 = r;
111 r2.right = div - 2;
112 m_status.MoveWindow(&r2);
114 r2 = r;
115 r2.left = div;
116 m_time.MoveWindow(&r2);
118 GetClientRect(r);
119 r.SetRect(6, r.top+4, 22, r.bottom-4);
120 m_type.MoveWindow(r);
122 Invalidate();
125 void CPlayerStatusBar::Clear()
127 m_status.SetWindowText(_T(""));
128 m_time.SetWindowText(_T(""));
129 SetStatusBitmap(0);
130 SetStatusTypeIcon(0);
132 Relayout();
135 void CPlayerStatusBar::SetStatusBitmap(UINT id)
137 if(m_bmid == id) return;
139 if(m_bm.m_hObject) m_bm.DeleteObject();
140 if(id) m_bm.LoadBitmap(id);
141 m_bmid = id;
143 Relayout();
146 void CPlayerStatusBar::SetStatusTypeIcon(HICON hIcon)
148 if(m_hIcon == hIcon) return;
150 if(m_hIcon) DestroyIcon(m_hIcon);
151 m_type.SetIcon(m_hIcon = hIcon);
153 Relayout();
156 void CPlayerStatusBar::SetStatusMessage(CString str)
158 str.Trim();
159 m_status.SetWindowText(str);
162 void CPlayerStatusBar::SetStatusTimer(CString str)
164 CString tmp;
165 m_time.GetWindowText(tmp);
166 if(tmp == str) return;
168 str.Trim();
169 m_time.SetWindowText(str);
171 Relayout();
174 void CPlayerStatusBar::SetStatusTimer(REFERENCE_TIME rtNow, REFERENCE_TIME rtDur, bool fHighPrecision, const GUID* pTimeFormat)
176 ASSERT(pTimeFormat);
178 CString str;
179 CString posstr, durstr;
181 if(*pTimeFormat == TIME_FORMAT_MEDIA_TIME)
183 DVD_HMSF_TIMECODE tcNow = RT2HMSF(rtNow);
184 DVD_HMSF_TIMECODE tcDur = RT2HMSF(rtDur);
186 if(tcDur.bHours > 0 || (rtNow >= rtDur && tcNow.bHours > 0))
187 posstr.Format(_T("%02d:%02d:%02d"), tcNow.bHours, tcNow.bMinutes, tcNow.bSeconds);
188 else
189 posstr.Format(_T("%02d:%02d"), tcNow.bMinutes, tcNow.bSeconds);
191 if(tcDur.bHours > 0)
192 durstr.Format(_T("%02d:%02d:%02d"), tcDur.bHours, tcDur.bMinutes, tcDur.bSeconds);
193 else
194 durstr.Format(_T("%02d:%02d"), tcDur.bMinutes, tcDur.bSeconds);
196 if(fHighPrecision)
198 str.Format(_T("%s.%03d"), posstr, (rtNow/10000)%1000);
199 posstr = str;
200 str.Format(_T("%s.%03d"), durstr, (rtDur/10000)%1000);
201 durstr = str;
202 str.Empty();
205 else if(*pTimeFormat == TIME_FORMAT_FRAME)
207 posstr.Format(_T("%I64d"), rtNow);
208 durstr.Format(_T("%I64d"), rtDur);
211 str = (/*start <= 0 &&*/ rtDur <= 0) ? posstr : posstr + _T(" / ") + durstr;
213 SetStatusTimer(str);
216 void CPlayerStatusBar::ShowTimer(bool fShow)
218 m_time.ShowWindow(fShow ? SW_SHOW : SW_HIDE);
220 Relayout();
223 BEGIN_MESSAGE_MAP(CPlayerStatusBar, CDialogBar)
224 ON_WM_ERASEBKGND()
225 ON_WM_PAINT()
226 ON_WM_SIZE()
227 ON_WM_CREATE()
228 ON_WM_LBUTTONDOWN()
229 ON_WM_SETCURSOR()
230 ON_WM_CTLCOLOR()
231 END_MESSAGE_MAP()
234 // CPlayerStatusBar message handlers
237 BOOL CPlayerStatusBar::OnEraseBkgnd(CDC* pDC)
239 for(CWnd* pChild = GetWindow(GW_CHILD); pChild; pChild = pChild->GetNextWindow())
241 if(!pChild->IsWindowVisible()) continue;
243 CRect r;
244 pChild->GetClientRect(&r);
245 pChild->MapWindowPoints(this, &r);
246 pDC->ExcludeClipRect(&r);
249 CRect r;
250 GetClientRect(&r);
252 CMainFrame* pFrame = ((CMainFrame*)GetParentFrame());
254 if(pFrame->m_pLastBar != this || pFrame->m_fFullScreen)
255 r.InflateRect(0, 0, 0, 1);
257 if(pFrame->m_fFullScreen)
258 r.InflateRect(1, 0, 1, 0);
260 pDC->Draw3dRect(&r, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT));
262 r.DeflateRect(1, 1);
264 pDC->FillSolidRect(&r, 0);
266 return TRUE;
269 void CPlayerStatusBar::OnPaint()
271 CPaintDC dc(this); // device context for painting
273 CRect r;
275 if(m_bm.m_hObject)
277 BITMAP bm;
278 m_bm.GetBitmap(&bm);
279 CDC memdc;
280 memdc.CreateCompatibleDC(&dc);
281 memdc.SelectObject(&m_bm);
282 GetClientRect(&r);
283 dc.BitBlt(r.right-bm.bmWidth-1, (r.Height() - bm.bmHeight)/2, bm.bmWidth, bm.bmHeight, &memdc, 0, 0, SRCCOPY);
288 if(m_hIcon)
290 GetClientRect(&r);
291 r.SetRect(6, r.top+4, 22-1, r.bottom-4-1);
292 DrawIconEx(dc, r.left, r.top, m_hIcon, r.Width(), r.Height(), 0, NULL, DI_NORMAL|DI_COMPAT);
295 // Do not call CDialogBar::OnPaint() for painting messages
298 void CPlayerStatusBar::OnSize(UINT nType, int cx, int cy)
300 CDialogBar::OnSize(nType, cx, cy);
302 Relayout();
305 void CPlayerStatusBar::OnLButtonDown(UINT nFlags, CPoint point)
307 CMainFrame* pFrame = ((CMainFrame*)GetParentFrame());
309 WINDOWPLACEMENT wp;
310 wp.length = sizeof(wp);
311 pFrame->GetWindowPlacement(&wp);
313 if(!pFrame->m_fFullScreen && wp.showCmd != SW_SHOWMAXIMIZED)
315 CRect r;
316 GetClientRect(r);
317 CPoint p = point;
319 MapWindowPoints(pFrame, &point, 1);
320 pFrame->PostMessage(WM_NCLBUTTONDOWN,
321 // (p.x+p.y >= r.Width()) ? HTBOTTOMRIGHT : HTCAPTION,
322 (p.x >= r.Width()-r.Height()) ? HTBOTTOMRIGHT :
323 HTCAPTION,
324 MAKELPARAM(point.x, point.y));
328 BOOL CPlayerStatusBar::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
330 CMainFrame* pFrame = ((CMainFrame*)GetParentFrame());
332 WINDOWPLACEMENT wp;
333 wp.length = sizeof(wp);
334 pFrame->GetWindowPlacement(&wp);
336 if(!pFrame->m_fFullScreen && wp.showCmd != SW_SHOWMAXIMIZED)
338 CRect r;
339 GetClientRect(r);
340 CPoint p;
341 GetCursorPos(&p);
342 ScreenToClient(&p);
343 // if(p.x+p.y >= r.Width())
344 if(p.x >= r.Width()-r.Height())
346 SetCursor(LoadCursor(NULL, IDC_SIZENWSE));
347 return TRUE;
351 return CDialogBar::OnSetCursor(pWnd, nHitTest, message);
354 HBRUSH CPlayerStatusBar::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
356 HBRUSH hbr = CDialogBar::OnCtlColor(pDC, pWnd, nCtlColor);
358 if(*pWnd == m_type)
360 hbr = GetStockBrush(BLACK_BRUSH);
363 // TODO: Return a different brush if the default is not desired
364 return hbr;