15
15
// Aegisub Project http://www.aegisub.org/
16
16
17
17
#include " colour_button.h"
18
+ #include " compat.h"
18
19
#include " format.h"
19
20
#include " help_button.h"
20
21
#include " libresrc/libresrc.h"
@@ -40,7 +41,7 @@ namespace {
40
41
struct DialogDummyVideo {
41
42
wxDialog d;
42
43
43
- double fps = OPT_GET(" Video/Dummy/FPS" )->GetDouble ();
44
+ wxString fps = OPT_GET(" Video/Dummy/FPS String " )->GetString ();
44
45
int width = OPT_GET(" Video/Dummy/Last/Width" )->GetInt ();
45
46
int height = OPT_GET(" Video/Dummy/Last/Height" )->GetInt ();
46
47
int length = OPT_GET(" Video/Dummy/Last/Length" )->GetInt ();
@@ -54,7 +55,7 @@ struct DialogDummyVideo {
54
55
void AddCtrl (wxString const & label, T *ctrl);
55
56
56
57
void OnResolutionShortcut (wxCommandEvent &evt);
57
- void UpdateLengthDisplay ();
58
+ bool UpdateLengthDisplay ();
58
59
59
60
DialogDummyVideo (wxWindow *parent);
60
61
};
@@ -85,10 +86,6 @@ wxSpinCtrl *spin_ctrl(wxWindow *parent, int min, int max, int *value) {
85
86
return ctrl;
86
87
}
87
88
88
- wxControl *spin_ctrl (wxWindow *parent, double min, double max, double *value) {
89
- return new wxTextCtrl (parent, -1 , " " , wxDefaultPosition, wxSize (50 , -1 ), 0 , DoubleValidator (value, min, max));
90
- }
91
-
92
89
wxComboBox *resolution_shortcuts (wxWindow *parent, int width, int height) {
93
90
wxComboBox *ctrl = new wxComboBox (parent, -1 , " " , wxDefaultPosition, wxDefaultSize, 0 , nullptr , wxCB_READONLY);
94
91
@@ -120,7 +117,9 @@ DialogDummyVideo::DialogDummyVideo(wxWindow *parent)
120
117
AddCtrl (_ (" Video resolution:" ), resolution_shortcuts (&d, width, height));
121
118
AddCtrl (" " , res_sizer);
122
119
AddCtrl (_ (" Color:" ), color_sizer);
123
- AddCtrl (_ (" Frame rate (fps):" ), spin_ctrl (&d, .1 , 1000.0 , &fps));
120
+ wxTextValidator fpsVal (wxFILTER_INCLUDE_CHAR_LIST, &fps);
121
+ fpsVal.SetCharIncludes (" 0123456789./" );
122
+ AddCtrl (_ (" Frame rate (fps):" ), new wxTextCtrl (&d, -1 , " " , wxDefaultPosition, wxDefaultSize, 0 , fpsVal));
124
123
AddCtrl (_ (" Duration (frames):" ), spin_ctrl (&d, 2 , 36000000 , &length)); // Ten hours of 1k FPS
125
124
AddCtrl (" " , length_display = new wxStaticText (&d, -1 , " " ));
126
125
@@ -132,17 +131,19 @@ DialogDummyVideo::DialogDummyVideo(wxWindow *parent)
132
131
main_sizer->Add (new wxStaticLine (&d, wxHORIZONTAL), wxSizerFlags ().HorzBorder ().Expand ());
133
132
main_sizer->Add (btn_sizer, wxSizerFlags ().Expand ().Border ());
134
133
135
- UpdateLengthDisplay ();
134
+ btn_sizer-> GetAffirmativeButton ()-> Enable ( UpdateLengthDisplay () );
136
135
137
136
d.SetSizerAndFit (main_sizer);
138
137
d.CenterOnParent ();
139
138
140
139
d.Bind (wxEVT_COMBOBOX, &DialogDummyVideo::OnResolutionShortcut, this );
141
140
color_btn->Bind (EVT_COLOR, [=, this ](ValueEvent<agi::Color>& e) { color = e.Get (); });
142
- d. Bind (wxEVT_SPINCTRL, [& ](wxCommandEvent&) {
141
+ auto on_update = [&, btn_sizer ](wxCommandEvent&) {
143
142
d.TransferDataFromWindow ();
144
- UpdateLengthDisplay ();
145
- });
143
+ btn_sizer->GetAffirmativeButton ()->Enable (UpdateLengthDisplay ());
144
+ };
145
+ d.Bind (wxEVT_SPINCTRL, on_update);
146
+ d.Bind (wxEVT_TEXT, on_update);
146
147
}
147
148
148
149
static void add_label (wxWindow *parent, wxSizer *sizer, wxString const & label) {
@@ -166,8 +167,16 @@ void DialogDummyVideo::OnResolutionShortcut(wxCommandEvent &e) {
166
167
d.TransferDataToWindow ();
167
168
}
168
169
169
- void DialogDummyVideo::UpdateLengthDisplay () {
170
- length_display->SetLabel (fmt_tl (" Resulting duration: %s" , agi::Time (length / fps * 1000 ).GetAssFormatted (true )));
170
+ bool DialogDummyVideo::UpdateLengthDisplay () {
171
+ std::string dur = " -" ;
172
+ bool valid = false ;
173
+ auto fr = DummyVideoProvider::TryParseFramerate (from_wx (fps));
174
+ if (fr.has_value ()) {
175
+ dur = agi::Time (fr.value ().TimeAtFrame (length)).GetAssFormatted (true );
176
+ valid = true ;
177
+ }
178
+ length_display->SetLabel (fmt_tl (" Resulting duration: %s" , dur));
179
+ return valid;
171
180
}
172
181
}
173
182
@@ -176,12 +185,12 @@ std::string CreateDummyVideo(wxWindow *parent) {
176
185
if (dlg.d .ShowModal () != wxID_OK)
177
186
return " " ;
178
187
179
- OPT_SET (" Video/Dummy/FPS" )->SetDouble ( dlg.fps );
188
+ OPT_SET (" Video/Dummy/FPS String " )->SetString ( from_wx ( dlg.fps ) );
180
189
OPT_SET (" Video/Dummy/Last/Width" )->SetInt (dlg.width );
181
190
OPT_SET (" Video/Dummy/Last/Height" )->SetInt (dlg.height );
182
191
OPT_SET (" Video/Dummy/Last/Length" )->SetInt (dlg.length );
183
192
OPT_SET (" Colour/Video Dummy/Last Colour" )->SetColor (dlg.color );
184
193
OPT_SET (" Video/Dummy/Pattern" )->SetBool (dlg.pattern );
185
194
186
- return DummyVideoProvider::MakeFilename (dlg.fps , dlg.length , dlg.width , dlg.height , dlg.color , dlg.pattern );
195
+ return DummyVideoProvider::MakeFilename (from_wx ( dlg.fps ) , dlg.length , dlg.width , dlg.height , dlg.color , dlg.pattern );
187
196
}
0 commit comments