1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
/*
* $Id$
*
* (C) 2003-2006 Gabest
* (C) 2006-2010 see AUTHORS
*
* This file is part of mplayerc.
*
* Mplayerc is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Mplayerc is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "stdafx.h"
#include "mplayerc.h"
#include "GoToDlg.h"
#include <atlrx.h>
#include "SettingsDefines.h"
// CGoToDlg dialog
IMPLEMENT_DYNAMIC(CGoToDlg, CDialog)
CGoToDlg::CGoToDlg(int time, float fps, CWnd* pParent /*=NULL*/)
: CDialog(CGoToDlg::IDD, pParent)
, m_timestr(_T(""))
, m_framestr(_T(""))
, m_time(time)
, m_fps(fps)
{
if(m_fps == 0) {
CString str = AfxGetApp()->GetProfileString(IDS_R_SETTINGS, _T("fps"), _T("0"));
if(_stscanf_s(str, _T("%f"), &m_fps) != 1) {
m_fps = 0;
}
}
}
CGoToDlg::~CGoToDlg()
{
}
void CGoToDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT1, m_timestr);
DDX_Text(pDX, IDC_EDIT2, m_framestr);
DDX_Control(pDX, IDC_EDIT1, m_timeedit);
DDX_Control(pDX, IDC_EDIT2, m_frameedit);
}
BOOL CGoToDlg::OnInitDialog()
{
CDialog::OnInitDialog();
if(m_time >= 0) {
m_timestr.Format(_T("%02d:%02d:%02d.%03d"),
(m_time/(1000*60*60))%60, (m_time/(1000*60))%60, (m_time/1000)%60, m_time%1000);
if(m_fps > 0) {
m_framestr.Format(_T("%d, %.3f"), (int)(m_fps*m_time/1000), m_fps);
}
UpdateData(FALSE);
switch(AfxGetApp()->GetProfileInt(IDS_R_SETTINGS, _T("gotoluf"), 0)) {
default:
case 0:
m_timeedit.SetFocus();
m_timeedit.SetSel(0, 0);
break;
case 1:
m_frameedit.SetFocus();
m_frameedit.SetSel(0, m_framestr.Find(','));
break;
}
}
return FALSE;
// return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
BEGIN_MESSAGE_MAP(CGoToDlg, CDialog)
ON_BN_CLICKED(IDC_OK1, OnBnClickedOk1)
ON_BN_CLICKED(IDC_OK2, OnBnClickedOk2)
END_MESSAGE_MAP()
// CGoToDlg message handlers
void CGoToDlg::OnBnClickedOk1()
{
UpdateData();
int hh, mm, ss, ms;
hh = mm = ss = ms = 0;
CAtlRegExp<> re;
REParseError status = re.Parse(_T("{\\z}"), FALSE);
if(REPARSE_ERROR_OK == status) {
m_timestr += 'A'; // HACK: Without this the while loop below would keep going on X64 on release builds...
CAtlREMatchContext<> mc;
const CAtlREMatchContext<>::RECHAR* s = m_timestr.GetBuffer();
const CAtlREMatchContext<>::RECHAR* e = NULL;
while(s && re.Match(s, &mc, &e)) {
const CAtlREMatchContext<>::RECHAR* szStart = 0;
const CAtlREMatchContext<>::RECHAR* szEnd = 0;
mc.GetMatch(0, &szStart, &szEnd);
if(hh != 0 || hh > 59 || mm > 59 || ss > 59) {
AfxMessageBox(_T("Error parsing entered time!"));
return;
}
hh = mm;
mm = ss;
ss = ms;
ms = _tcstol(szStart, (TCHAR**)&szStart, 10);
s = e;
}
m_time = ((hh*60+mm)*60+ss)*1000+ms;
AfxGetApp()->WriteProfileInt(IDS_R_SETTINGS, _T("gotoluf"), 0);
OnOK();
}
}
void CGoToDlg::OnBnClickedOk2()
{
UpdateData();
int frame = 0;
float fps = 0;
CAtlRegExp<> re;
REParseError status = re.Parse(_T("{\\z}[^0-9\\.]+{[0-9\\.]+}"), FALSE);
if(REPARSE_ERROR_OK == status) {
CAtlREMatchContext<> mc;
const CAtlREMatchContext<>::RECHAR* s = m_framestr.GetBuffer();
const CAtlREMatchContext<>::RECHAR* e = NULL;
if(re.Match(s, &mc, &e)) {
const CAtlREMatchContext<>::RECHAR* szStart = 0;
const CAtlREMatchContext<>::RECHAR* szEnd = 0;
mc.GetMatch(0, &szStart, &szEnd);
frame = _tcstol(szStart, (TCHAR**)&szStart, 10);
mc.GetMatch(1, &szStart, &szEnd);
if(_stscanf_s(szStart, _T("%f"), &fps) != 1) {
fps = 0;
} else {
AfxGetApp()->WriteProfileString(IDS_R_SETTINGS, _T("fps"), szStart);
}
} else {
AfxMessageBox(_T("Error parsing entered text!"));
return;
}
if(fps == 0) {
AfxMessageBox(_T("Error parsing entered frame rate!"));
return;
}
m_time = (int)(1000.0*frame/fps) + 1;
AfxGetApp()->WriteProfileInt(IDS_R_SETTINGS, _T("gotoluf"), 1);
OnOK();
}
}
BOOL CGoToDlg::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN) {
if(*GetFocus() == m_timeedit) {
OnBnClickedOk1();
} else if(*GetFocus() == m_frameedit) {
OnBnClickedOk2();
}
return TRUE;
}
return __super::PreTranslateMessage(pMsg);
}
|