3636#include " project.h"
3737#include " resolution_resampler.h"
3838#include " validators.h"
39+ #include " video_controller.h"
3940
4041#include < boost/algorithm/string/predicate.hpp>
4142#include < vector>
@@ -59,13 +60,17 @@ class DialogProperties {
5960 wxComboBox *WrapStyle; // /< Wrapping style for long lines
6061 wxTextCtrl *ResX; // /< Script x resolution
6162 wxTextCtrl *ResY; // /< Script y resolution
63+ wxTextCtrl *LayoutResX; // /< Layout x resolution
64+ wxTextCtrl *LayoutResY; // /< Layout y resolution
6265 wxCheckBox *ScaleBorder; // /< If script resolution != video resolution how should borders be handled
6366 wxComboBox *YCbCrMatrix;
6467
6568 // / OK button handler
6669 void OnOK (wxCommandEvent &event);
6770 // / Set script resolution to video resolution button
6871 void OnSetFromVideo (wxCommandEvent &event);
72+ // / Set layout resolution to video resolution button
73+ void OnSetLayoutResFromVideo (wxCommandEvent &event);
6974 // / Set a script info field
7075 // / @param key Name of field
7176 // / @param value New value
@@ -119,18 +124,36 @@ DialogProperties::DialogProperties(agi::Context *c)
119124 ResX = new wxTextCtrl (&d,-1 ," " ,wxDefaultPosition,wxDefaultSize,0 ,IntValidator (c->ass ->GetScriptInfoAsInt (" PlayResX" )));
120125 ResY = new wxTextCtrl (&d,-1 ," " ,wxDefaultPosition,wxDefaultSize,0 ,IntValidator (c->ass ->GetScriptInfoAsInt (" PlayResY" )));
121126
127+ LayoutResX = new wxTextCtrl (&d,-1 ," " ,wxDefaultPosition,wxDefaultSize,0 ,IntValidator (c->ass ->GetScriptInfoAsInt (" LayoutResX" )));
128+ LayoutResY = new wxTextCtrl (&d,-1 ," " ,wxDefaultPosition,wxDefaultSize,0 ,IntValidator (c->ass ->GetScriptInfoAsInt (" LayoutResY" )));
129+
122130 wxButton *FromVideo = new wxButton (&d,-1 ,_ (" From &video" ));
123131 if (!c->project ->VideoProvider ())
124132 FromVideo->Enable (false );
125133 else
126134 FromVideo->Bind (wxEVT_BUTTON, &DialogProperties::OnSetFromVideo, this );
127135
128- auto res_sizer = new wxBoxSizer (wxHORIZONTAL);
129- res_sizer->Add (ResX, 1 , wxRIGHT | wxALIGN_CENTER_VERTICAL, 5 );
130- res_sizer->Add (new wxStaticText (&d, -1 , _ (L" \u00D7 " )), 0 , wxALIGN_CENTER | wxRIGHT, 5 ); // U+00D7 multiplication sign
131- res_sizer->Add (ResY, 1 , wxRIGHT | wxALIGN_CENTER_VERTICAL, 5 );
136+ auto res_sizer = new wxFlexGridSizer (5 , 5 , 5 );
137+ res_sizer->AddGrowableCol (1 , 1 );
138+ res_sizer->AddGrowableCol (3 , 1 );
139+ res_sizer->Add (new wxStaticText (&d, -1 , _ (" Script: " )), wxSizerFlags ().Center ().Left ());
140+ res_sizer->Add (ResX, 1 , wxRIGHT | wxALIGN_CENTER_VERTICAL | wxEXPAND, 2 );
141+ res_sizer->Add (new wxStaticText (&d, -1 , _ (L" \u00D7 " )), 0 , wxALIGN_CENTER | wxRIGHT, 2 ); // U+00D7 multiplication sign
142+ res_sizer->Add (ResY, 1 , wxRIGHT | wxALIGN_CENTER_VERTICAL | wxEXPAND, 2 );
132143 res_sizer->Add (FromVideo, 1 , 0 , 0 );
133144
145+ wxButton *LayoutResFromVideo = new wxButton (&d,-1 ,_ (" From video" ));
146+ if (!c->project ->VideoProvider ())
147+ LayoutResFromVideo->Enable (false );
148+ else
149+ LayoutResFromVideo->Bind (wxEVT_BUTTON, &DialogProperties::OnSetLayoutResFromVideo, this );
150+
151+ res_sizer->Add (new wxStaticText (&d, -1 , _ (" Layout: " )), wxSizerFlags ().Center ().Left ());
152+ res_sizer->Add (LayoutResX, 1 , wxRIGHT | wxALIGN_CENTER_VERTICAL | wxEXPAND, 2 );
153+ res_sizer->Add (new wxStaticText (&d, -1 , _ (L" \u00D7 " )), 0 , wxALIGN_CENTER | wxRIGHT, 2 ); // U+00D7 multiplication sign
154+ res_sizer->Add (LayoutResY, 1 , wxRIGHT | wxALIGN_CENTER_VERTICAL | wxEXPAND, 2 );
155+ res_sizer->Add (LayoutResFromVideo, 1 , 0 , 0 );
156+
134157 YCbCrMatrix = new wxComboBox (&d, -1 , to_wx (c->ass ->GetScriptInfo (" YCbCr Matrix" )),
135158 wxDefaultPosition, wxDefaultSize, to_wx (MatrixNames ()), wxCB_READONLY);
136159
@@ -189,6 +212,8 @@ void DialogProperties::OnOK(wxCommandEvent &) {
189212
190213 count += SetInfoIfDifferent (" PlayResX" , from_wx (ResX->GetValue ()));
191214 count += SetInfoIfDifferent (" PlayResY" , from_wx (ResY->GetValue ()));
215+ count += SetInfoIfDifferent (" LayoutResX" , from_wx (LayoutResX->GetValue ()));
216+ count += SetInfoIfDifferent (" LayoutResY" , from_wx (LayoutResY->GetValue ()));
192217 count += SetInfoIfDifferent (" WrapStyle" , std::to_string (WrapStyle->GetSelection ()));
193218 count += SetInfoIfDifferent (" ScaledBorderAndShadow" , ScaleBorder->GetValue () ? " yes" : " no" );
194219 count += SetInfoIfDifferent (" YCbCr Matrix" , from_wx (YCbCrMatrix->GetValue ()));
@@ -206,9 +231,28 @@ int DialogProperties::SetInfoIfDifferent(std::string_view key, std::string_view
206231 return 0 ;
207232}
208233
234+ std::pair<int , int > GetVideoDisplayResolution (agi::Context *c) {
235+ double dar = c->videoController ->GetAspectRatioValue ();
236+ int width = c->project ->VideoProvider ()->GetWidth ();
237+ int height = c->project ->VideoProvider ()->GetHeight ();
238+ double sar = double (width) / double (height);
239+
240+ return std::make_pair (
241+ width * std::max (1 ., dar / sar),
242+ height * std::max (1 ., sar / dar)
243+ );
244+ }
245+
209246void DialogProperties::OnSetFromVideo (wxCommandEvent &) {
210- ResX->SetValue (std::to_wstring (c->project ->VideoProvider ()->GetWidth ()));
211- ResY->SetValue (std::to_wstring (c->project ->VideoProvider ()->GetHeight ()));
247+ auto [width, height] = GetVideoDisplayResolution (c);
248+ ResX->SetValue (std::to_wstring (width));
249+ ResY->SetValue (std::to_wstring (height));
250+ }
251+
252+ void DialogProperties::OnSetLayoutResFromVideo (wxCommandEvent &) {
253+ auto [width, height] = GetVideoDisplayResolution (c);
254+ LayoutResX->SetValue (std::to_wstring (width));
255+ LayoutResY->SetValue (std::to_wstring (height));
212256}
213257}
214258
0 commit comments