TimelineDlg.cpp
上传用户:tuheem
上传日期:2007-05-01
资源大小:21889k
文件大小:6k
- // TimelineDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "XvidQuantsParser.h"
- #include "TimelineDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CTimelineDlg dialog
- CTimelineDlg::CTimelineDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CTimelineDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CTimelineDlg)
- m_left = 0;
- m_right = 0;
- m_maxql = 0;
- m_maxqr = 0;
- m_minql = 0;
- m_minqr = 0;
- m_maxfsl = 0;
- m_maxfsr = 0;
- m_minfsl = 0;
- m_minfsr = 0;
- //}}AFX_DATA_INIT
- qarray = NULL;
- }
- void CTimelineDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CTimelineDlg)
- DDX_Control(pDX, IDC_COMBO_MAXQUANT, m_maxquant);
- DDX_Control(pDX, IDC_COMBO_SCALE, m_scale);
- DDX_Control(pDX, IDC_SCROLL_QUANTS, m_scroll);
- DDX_Control(pDX, IDC_GRAPH_TIMELINE, m_graph);
- DDX_Text(pDX, IDC_EDIT_LEFT, m_left);
- DDX_Text(pDX, IDC_EDIT_RIGHT, m_right);
- DDX_Text(pDX, IDC_EDIT_MAXQL, m_maxql);
- DDX_Text(pDX, IDC_EDIT_MAXQR, m_maxqr);
- DDX_Text(pDX, IDC_EDIT_MINQL, m_minql);
- DDX_Text(pDX, IDC_EDIT_MINQR, m_minqr);
- DDX_Text(pDX, IDC_EDIT_MAXFSL, m_maxfsl);
- DDX_Text(pDX, IDC_EDIT_MAXFSR, m_maxfsr);
- DDX_Text(pDX, IDC_EDIT_MINFSL, m_minfsl);
- DDX_Text(pDX, IDC_EDIT_MINFSR, m_minfsr);
- DDX_Control(pDX, IDC_GRAPH_FRAMESIZE, m_graphfs);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CTimelineDlg, CDialog)
- //{{AFX_MSG_MAP(CTimelineDlg)
- ON_WM_HSCROLL()
- ON_CBN_SELCHANGE(IDC_COMBO_SCALE, OnSelchangeComboScale)
- ON_CBN_SELCHANGE(IDC_COMBO_MAXQUANT, OnSelchangeComboMaxquant)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CTimelineDlg message handlers
- //----------------------------------------------------------------------------------------------
- void CTimelineDlg::Init(CXvid::QUANTS *quants, int nframes, int maxq, int maxfs)
- {
- nelem = nframes;
- qarray = quants;
- qmax = maxq;
- fsmax = maxfs;
- }
- //----------------------------------------------------------------------------------------------
- BOOL CTimelineDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- scaleIsSet = false;
- maxIsSet = false;
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- //----------------------------------------------------------------------------------------------
- void CTimelineDlg::OnSelchangeComboScale()
- {
- scaleIsSet = true;
- CString selected;
- UpdateData(TRUE);
- m_scale.GetLBText(m_scale.GetCurSel(), selected);
- scale = atoi(selected);
- InitScroll(0, nelem-scale, m_left, (int)(nelem/1400), (int)(nelem/140));
- m_right = m_left + scale;
- if (scaleIsSet && maxIsSet)
- {
- InitGraph(scale, maxquant);
- DrawTimeline(m_left);
- }
- UpdateData(FALSE);
- }
- //----------------------------------------------------------------------------------------------
- void CTimelineDlg::OnSelchangeComboMaxquant()
- {
- maxIsSet = true;
- CString selected;
- UpdateData(TRUE);
- m_maxquant.GetLBText(m_maxquant.GetCurSel(), selected);
- if (selected == "Auto") maxquant = qmax;
- else maxquant = atoi(selected);
- if (scaleIsSet && maxIsSet)
- {
- InitGraph(scale, maxquant);
- DrawTimeline(m_left);
- }
- UpdateData(FALSE);
- }
- //----------------------------------------------------------------------------------------------
- void CTimelineDlg::InitGraph(int s, int mq)
- {
- m_graph.SetScale(0, 0, s, mq-1);
- m_graphfs.SetScale(0, 0, s, fsmax);
- m_minfsl = 0;
- m_minfsr = 0;
- m_maxfsl = fsmax;
- m_maxfsr = fsmax;
- m_minql = 2;
- m_minqr = 2;
- m_maxql = maxquant;
- m_maxqr = maxquant;
- UpdateData(FALSE);
- }
- //----------------------------------------------------------------------------------------------
- void CTimelineDlg::InitScroll(int minu, int maxu, int posu, int smallc, int largec)
- {
- min=0;max=10000;
- umin = minu;
- umax = maxu;
- upos = posu;
- pos = (int)(min+(max-min)*(upos-umin)/(umax-umin));
- schange = (int)((max-min)*(smallc)/(umax-umin));
- lchange = (int)((max-min)*(largec)/(umax-umin));
- m_scroll.SetScrollRange(min, max);
- m_scroll.SetScrollPos(pos);
- }
- //----------------------------------------------------------------------------------------------
- void CTimelineDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- int pos = pScrollBar->GetScrollPos();
- if (scaleIsSet && maxIsSet)
- {
- switch (nSBCode)
- {
- case SB_LINELEFT: pos -= schange;break;
- case SB_PAGELEFT: pos -= lchange;break;
- case SB_LINERIGHT: pos += schange;break;
- case SB_PAGERIGHT: pos += lchange;break;
- case SB_THUMBTRACK: pos=nPos;
- case SB_THUMBPOSITION: pos=nPos;
- }
- if (pos>max) pos = max;
- if (pos<min) pos = min;
- upos = umin + (umax-umin)*(double)((pos-min)/(max-min));
- pScrollBar->SetScrollPos(pos);
- m_left = (int)(pos*(umax/max));
- m_right= m_left + scale;
- DrawTimeline(m_left);
- UpdateData(FALSE);
- }
- CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
- }
- //----------------------------------------------------------------------------------------------
- void CTimelineDlg::DrawTimeline(int uscrollpos)
- {
- int sp = uscrollpos;
- m_graph.Clear();
- m_graphfs.Clear();
- //Gray lines for making scaling more "visual"
- m_graph.SetForeColor(RGB(175,175,175));
- for (int j=1; j<maxquant; j++)
- {
- m_graph.DrawLine(1,j,scale-1,j);
- }
- for (int i=sp; i<sp+scale; i++)
- {
- if (i < nelem)
- {
- if (qarray[i].isIFrame)
- {
- m_graph.SetForeColor(RGB(0,0,255)); //Blue (I-Frames)
- m_graphfs.SetForeColor(RGB(255,0,0));
- }
- else
- {
- m_graphfs.SetForeColor(RGB(0,0,255));
- SetColor(qarray[i].qvalue);
- }
- m_graph.DrawLine(i-sp, 0, i-sp, qarray[i].qvalue-1);
- m_graphfs.DrawLine(i-sp, 0, i-sp, qarray[i].framesize);
- }
- }
- }
- //----------------------------------------------------------------------------------------------
- void CTimelineDlg::SetColor(int qvalue)
- {
- if (qvalue == 2)
- {
- m_graph.SetForeColor(RGB(0,255,0)); //Light green (Q:2);
- }
- if (qvalue > 2 && qvalue < 6)
- {
- m_graph.SetForeColor(RGB(0,127,0)); //Darker green (Q:3-Q:5)
- }
- if (qvalue >= 6 && qvalue <10)
- {
- m_graph.SetForeColor(RGB(255,255,0)); //Yellow (Q:6-Q:9)
- }
-
- if (qvalue >= 10)
- {
- m_graph.SetForeColor(RGB(255,0,0)); //Red (Q:10+)
- }
- }