1 // ProgressBar.cpp : implementation file
2 //
3 
4 #include "stdafx.h"
5 #include "Osmo4.h"
6 #include "ProgressBar.h"
7 
8 #ifdef _DEBUG
9 #define new DEBUG_NEW
10 #undef THIS_FILE
11 static char THIS_FILE[] = __FILE__;
12 #endif
13 
14 /////////////////////////////////////////////////////////////////////////////
15 // ProgressBar dialog
16 
17 
ProgressBar(CWnd * pParent)18 ProgressBar::ProgressBar(CWnd* pParent /*=NULL*/)
19 	: CDialog(ProgressBar::IDD, pParent)
20 {
21 	//{{AFX_DATA_INIT(ProgressBar)
22 	//}}AFX_DATA_INIT
23 
24 	m_grabbed = 0;
25 	m_range_invalidated = 0;
26 }
27 
28 
DoDataExchange(CDataExchange * pDX)29 void ProgressBar::DoDataExchange(CDataExchange* pDX)
30 {
31 	CDialog::DoDataExchange(pDX);
32 	//{{AFX_DATA_MAP(ProgressBar)
33 	DDX_Control(pDX, IDC_TIME, m_Time);
34 	DDX_Control(pDX, IDC_SLIDER, m_Slider);
35 	//}}AFX_DATA_MAP
36 }
37 
38 
BEGIN_MESSAGE_MAP(ProgressBar,CDialog)39 BEGIN_MESSAGE_MAP(ProgressBar, CDialog)
40 	//{{AFX_MSG_MAP(ProgressBar)
41 	ON_WM_SIZE()
42 	ON_WM_HSCROLL()
43 	//}}AFX_MSG_MAP
44 END_MESSAGE_MAP()
45 
46 /////////////////////////////////////////////////////////////////////////////
47 // ProgressBar message handlers
48 #define TEXT_RIGHT_PAD	2
49 void ProgressBar::OnSize(UINT nType, int cx, int cy)
50 {
51 	u32 tw;
52 	CDialog::OnSize(nType, cx, cy);
53 
54 	if (!m_Slider.m_hWnd) return;
55 
56 	RECT rc;
57 	m_Time.GetClientRect(&rc);
58 	tw = rc.right-rc.left;
59 	rc.left = cx - tw - TEXT_RIGHT_PAD;
60 	rc.right = cx - TEXT_RIGHT_PAD;
61 	m_Time.MoveWindow(&rc);
62 	m_Slider.GetClientRect(&rc);
63 	rc.left = 0;
64 	rc.right = cx - tw - TEXT_RIGHT_PAD;
65 	m_Slider.MoveWindow(&rc);
66 }
67 
OnHScroll(UINT nSBCode,UINT nPos,CScrollBar * pScrollBar)68 void ProgressBar::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
69 {
70 	COsmo4 *app = GetApp();
71 
72 	if (pScrollBar->GetDlgCtrlID() == IDC_SLIDER) {
73 		if (!app->m_can_seek) return;
74 		switch (nSBCode) {
75 		case TB_LINEUP:
76 		case TB_LINEDOWN:
77 		case TB_PAGEUP:
78 		case TB_PAGEDOWN:
79 		case TB_THUMBPOSITION:
80 		case TB_THUMBTRACK:
81 		case TB_TOP:
82 		case TB_BOTTOM:
83 			m_grabbed = 1;
84 			break;
85 		case TB_ENDTRACK:
86 			if (!app->m_open) {
87 				SetPosition(0);
88 			} else {
89 				u32 seek_to = m_Slider.GetPos();
90 				gf_term_play_from_time(app->m_term, seek_to, 0);
91 			}
92 			m_grabbed = 0;
93 			return;
94 		}
95 	}
96 	CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
97 }
98 
SetPosition(u32 now)99 void ProgressBar::SetPosition(u32 now)
100 {
101 	TCHAR swText[20];
102 	u32 nb_s, nb_m;
103 	COsmo4 *app = GetApp();
104 
105 	if (m_range_invalidated) {
106 		if (app->m_can_seek) {
107 			m_Slider.SetRangeMin(0);
108 			m_Slider.SetRangeMax(app->m_duration);
109 			m_Slider.ShowWindow(SW_SHOWNORMAL);
110 			m_Slider.EnableWindow(TRUE);
111 		} else {
112 			m_Slider.ShowWindow(SW_SHOWNORMAL);
113 			m_Slider.EnableWindow(FALSE);
114 
115 		}
116 		m_range_invalidated = 0;
117 	}
118 	if (now==m_prev_time) return;
119 
120 	if (now<m_prev_time) m_prev_time = 0;
121 
122 	if (!m_prev_time || (m_prev_time + 500 <= now)) {
123 		m_FPS = gf_term_get_framerate(app->m_term, 0);
124 		m_prev_time = now;
125 	}
126 	nb_s = now/1000;
127 	nb_m = nb_s/60;
128 	nb_s -= nb_m*60;
129 	wsprintf(swText, _T("%02d:%02d FPS %02.2f"), nb_m, nb_s, m_FPS);
130 	m_Time.SetWindowText(swText);
131 
132 	if (!m_grabbed) m_Slider.SetPos(now);
133 }
134