A Fast Bresenham Type Algorithm For Drawing Ellipses by John Kennedy
[xy_vsfilter.git] / src / apps / mplayerc / GoToDlg.cpp
blobaebe09d46d179b565e32e096c03acfda5091c679
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 // GoToDlg.cpp : implementation file
25 #include "stdafx.h"
26 #include "mplayerc.h"
27 #include "GoToDlg.h"
29 #include <atlrx.h>
32 // CGoToDlg dialog
34 IMPLEMENT_DYNAMIC(CGoToDlg, CDialog)
35 CGoToDlg::CGoToDlg(int time, float fps, CWnd* pParent /*=NULL*/)
36 : CDialog(CGoToDlg::IDD, pParent)
37 , m_timestr(_T(""))
38 , m_framestr(_T(""))
39 , m_time(time)
40 , m_fps(fps)
42 if(m_fps == 0)
44 CString str = AfxGetApp()->GetProfileString(ResStr(IDS_R_SETTINGS), _T("fps"), _T("0"));
45 if(_stscanf(str, _T("%f"), &m_fps) != 1) m_fps = 0;
49 CGoToDlg::~CGoToDlg()
53 void CGoToDlg::DoDataExchange(CDataExchange* pDX)
55 CDialog::DoDataExchange(pDX);
56 DDX_Text(pDX, IDC_EDIT1, m_timestr);
57 DDX_Text(pDX, IDC_EDIT2, m_framestr);
58 DDX_Control(pDX, IDC_EDIT1, m_timeedit);
59 DDX_Control(pDX, IDC_EDIT2, m_frameedit);
62 BOOL CGoToDlg::OnInitDialog()
64 CDialog::OnInitDialog();
66 if(m_time >= 0)
68 m_timestr.Format(_T("%02d:%02d:%02d.%03d"),
69 (m_time/(1000*60*60))%60, (m_time/(1000*60))%60, (m_time/1000)%60, m_time%1000);
71 if(m_fps > 0)
73 m_framestr.Format(_T("%d, %.3f"), (int)(m_fps*m_time/1000), m_fps);
76 UpdateData(FALSE);
78 switch(AfxGetApp()->GetProfileInt(ResStr(IDS_R_SETTINGS), _T("gotoluf"), 0))
80 default:
81 case 0: m_timeedit.SetFocus(); m_timeedit.SetSel(0, 0); break;
82 case 1: m_frameedit.SetFocus(); m_frameedit.SetSel(0, m_framestr.Find(',')); break;
87 return FALSE;
89 // return TRUE; // return TRUE unless you set the focus to a control
90 // EXCEPTION: OCX Property Pages should return FALSE
94 BEGIN_MESSAGE_MAP(CGoToDlg, CDialog)
95 ON_BN_CLICKED(IDC_OK1, OnBnClickedOk1)
96 ON_BN_CLICKED(IDC_OK2, OnBnClickedOk2)
97 END_MESSAGE_MAP()
100 // CGoToDlg message handlers
102 void CGoToDlg::OnBnClickedOk1()
104 UpdateData();
106 int hh, mm, ss, ms;
107 hh = mm = ss = ms = 0;
109 CAtlRegExp<> re;
111 REParseError status = re.Parse(_T("{\\z}"), FALSE);
112 if(REPARSE_ERROR_OK == status)
114 CAtlREMatchContext<> mc;
115 const CAtlREMatchContext<>::RECHAR* s = m_timestr.GetBuffer();
116 const CAtlREMatchContext<>::RECHAR* e = NULL;
117 while(s && re.Match(s, &mc, &e))
119 const CAtlREMatchContext<>::RECHAR* szStart = 0;
120 const CAtlREMatchContext<>::RECHAR* szEnd = 0;
121 mc.GetMatch(0, &szStart, &szEnd);
123 if(hh != 0 || hh > 59 || mm > 59 || ss > 59)
125 AfxMessageBox(_T("Error parsing entered time!"));
126 return;
129 hh = mm;
130 mm = ss;
131 ss = ms;
132 ms = _tcstol(szStart, (TCHAR**)&szStart, 10);
134 s = e;
137 m_time = ((hh*60+mm)*60+ss)*1000+ms;
139 AfxGetApp()->WriteProfileInt(ResStr(IDS_R_SETTINGS), _T("gotoluf"), 0);
141 OnOK();
146 void CGoToDlg::OnBnClickedOk2()
148 UpdateData();
150 int frame = 0;
151 float fps = 0;
153 CAtlRegExp<> re;
155 REParseError status = re.Parse(_T("{\\z}[^0-9\\.]+{[0-9\\.]+}"), FALSE);
156 if(REPARSE_ERROR_OK == status)
158 CAtlREMatchContext<> mc;
159 const CAtlREMatchContext<>::RECHAR* s = m_framestr.GetBuffer();
160 const CAtlREMatchContext<>::RECHAR* e = NULL;
161 if(re.Match(s, &mc, &e))
163 const CAtlREMatchContext<>::RECHAR* szStart = 0;
164 const CAtlREMatchContext<>::RECHAR* szEnd = 0;
166 mc.GetMatch(0, &szStart, &szEnd);
167 frame = _tcstol(szStart, (TCHAR**)&szStart, 10);
169 mc.GetMatch(1, &szStart, &szEnd);
170 if(_stscanf(szStart, _T("%f"), &fps) != 1) fps = 0;
171 else AfxGetApp()->WriteProfileString(ResStr(IDS_R_SETTINGS), _T("fps"), szStart);
173 else
175 AfxMessageBox(_T("Error parsing entered text!"));
176 return;
179 if(fps == 0)
181 AfxMessageBox(_T("Error parsing entered frame-rate!"));
182 return;
185 m_time = (int)(1000.0*frame/fps) + 1;
187 AfxGetApp()->WriteProfileInt(ResStr(IDS_R_SETTINGS), _T("gotoluf"), 1);
189 OnOK();
193 BOOL CGoToDlg::PreTranslateMessage(MSG* pMsg)
195 if(pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN)
197 if(*GetFocus() == m_timeedit) OnBnClickedOk1();
198 else if(*GetFocus() == m_frameedit) OnBnClickedOk2();
200 return TRUE;
203 return __super::PreTranslateMessage(pMsg);