summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2025-06-21 10:16:00 +0200
committerCarl Hetherington <cth@carlh.net>2025-07-10 23:13:14 +0200
commit09b4dcf460d6fbe69139eca40f1c890ea5f33a5d (patch)
treeb9f5ecb37e62baa21ae24bf671de3b939589d0e7
parent4e244c8a4b34268445123b7d6df54ff303561fa5 (diff)
Extract ratio setup UI to a separate class.
-rw-r--r--src/wx/player_config_dialog.cc99
-rw-r--r--src/wx/ratio_picker.cc158
-rw-r--r--src/wx/ratio_picker.h58
-rw-r--r--src/wx/wscript1
4 files changed, 226 insertions, 90 deletions
diff --git a/src/wx/player_config_dialog.cc b/src/wx/player_config_dialog.cc
index affe96bf0..90afdf3e6 100644
--- a/src/wx/player_config_dialog.cc
+++ b/src/wx/player_config_dialog.cc
@@ -38,6 +38,7 @@
#include "nag_dialog.h"
#include "name_format_editor.h"
#include "preferences_page.h"
+#include "ratio_picker.h"
#include "server_dialog.h"
#include "sound_preferences_page.h"
#include "static_text.h"
@@ -301,21 +302,9 @@ private:
table->AddGrowableCol(1, 1);
_panel->GetSizer()->Add(table, 1, wxALL | wxEXPAND, _border);
- _crop_output = new CheckBox(_panel, _("Crop output to"));
- table->Add(_crop_output, 0, wxEXPAND);
- auto s = new wxBoxSizer(wxHORIZONTAL);
- _crop_output_ratio_preset = new Choice(_panel);
- _crop_output_ratio_custom = new wxTextCtrl(_panel, wxID_ANY);
-
- s->Add(_crop_output_ratio_preset, 0, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_X_GAP);
- s->Add(_crop_output_ratio_custom, 0, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_X_GAP);
- add_label_to_sizer(s, _panel, _(":1"), false, 0, wxALIGN_CENTER_VERTICAL);
-
- for (auto ratio: Ratio::all()) {
- _crop_output_ratio_preset->add_entry(ratio.image_nickname(), ratio.id());
- }
- _crop_output_ratio_preset->add_entry(_("Custom"), "custom");
- table->Add(s, 1, wxEXPAND);
+ _crop_output = new RatioPicker(_panel, Config::instance()->player_crop_output_ratio());
+ table->Add(_crop_output->enable_checkbox(), 0, wxEXPAND);
+ table->Add(_crop_output, 1, wxEXPAND);
{
add_top_aligned_label_to_sizer(table, _panel, _("Log"));
@@ -351,13 +340,7 @@ private:
#ifdef DCPOMATIC_WINDOWS
_win32_console->bind(&PlayerAdvancedPage::win32_console_changed, this);
#endif
- _crop_output->bind(&PlayerAdvancedPage::crop_output_changed, this);
- _crop_output_ratio_preset->bind(&PlayerAdvancedPage::crop_output_ratio_preset_changed, this);
- _crop_output_ratio_custom->Bind(wxEVT_TEXT, boost::bind(&PlayerAdvancedPage::crop_output_ratio_custom_changed, this));
-
- checked_set(_crop_output, Config::instance()->player_crop_output_ratio().has_value());
- set_crop_output_ratio_preset_from_config();
- set_crop_output_ratio_custom_from_config();
+ _crop_output->Changed.connect(boost::bind(&PlayerAdvancedPage::crop_output_changed, this, _1));
}
void config_changed() override
@@ -379,32 +362,6 @@ private:
*/
}
- void set_crop_output_ratio_preset_from_config()
- {
- _ignore_crop_changes = true;
- dcp::ScopeGuard sg = [this]() { _ignore_crop_changes = false; };
-
- if (auto output_ratio = Config::instance()->player_crop_output_ratio()) {
- auto ratio = Ratio::from_ratio(*output_ratio);
- _crop_output_ratio_preset->set_by_data(ratio ? ratio->id() : "custom");
- } else {
- _crop_output_ratio_preset->set_by_data("185");
- }
- }
-
- void set_crop_output_ratio_custom_from_config()
- {
- _ignore_crop_changes = true;
- dcp::ScopeGuard sg = [this]() { _ignore_crop_changes = false; };
-
- if (auto output_ratio = Config::instance()->player_crop_output_ratio()) {
- auto ratio = Ratio::from_ratio(*output_ratio);
- _crop_output_ratio_custom->SetValue(wxString::Format(char_to_wx("%.2f"), ratio ? ratio->ratio() : *output_ratio));
- } else {
- _crop_output_ratio_custom->SetValue(_("185"));
- }
- }
-
void log_changed()
{
int types = 0;
@@ -429,48 +386,13 @@ private:
Config::instance()->set_log_types(types);
}
- void crop_output_changed()
- {
- if (_crop_output->get()) {
- Config::instance()->set_player_crop_output_ratio(1.85);
- set_crop_output_ratio_preset_from_config();
- set_crop_output_ratio_custom_from_config();
- } else {
- Config::instance()->unset_player_crop_output_ratio();
- }
- _crop_output_ratio_preset->Enable(_crop_output->get());
- _crop_output_ratio_custom->Enable(_crop_output->get());
- }
-
- void crop_output_ratio_preset_changed()
+ void crop_output_changed(optional<float> ratio)
{
- if (!_crop_output->get() || _ignore_crop_changes) {
- return;
- }
-
- optional<Ratio> ratio;
-
- if (auto data = _crop_output_ratio_preset->get_data()) {
- ratio = Ratio::from_id_if_exists(*data);
- }
-
if (ratio) {
- Config::instance()->set_player_crop_output_ratio(ratio->ratio());
+ Config::instance()->set_player_crop_output_ratio(*ratio);
} else {
- Config::instance()->set_player_crop_output_ratio(locale_convert<float>(wx_to_std(_crop_output_ratio_custom->GetValue())));
- }
-
- set_crop_output_ratio_custom_from_config();
- }
-
- void crop_output_ratio_custom_changed()
- {
- if (!_crop_output->get() || _ignore_crop_changes) {
- return;
+ Config::instance()->unset_player_crop_output_ratio();
}
-
- Config::instance()->set_player_crop_output_ratio(locale_convert<float>(wx_to_std(_crop_output_ratio_custom->GetValue())));
- set_crop_output_ratio_preset_from_config();
}
#ifdef DCPOMATIC_WINDOWS
@@ -480,10 +402,7 @@ private:
}
#endif
- CheckBox* _crop_output = nullptr;
- Choice* _crop_output_ratio_preset = nullptr;
- wxTextCtrl* _crop_output_ratio_custom = nullptr;
- bool _ignore_crop_changes = false;
+ RatioPicker* _crop_output = nullptr;
CheckBox* _log_general = nullptr;
CheckBox* _log_warning = nullptr;
CheckBox* _log_error = nullptr;
diff --git a/src/wx/ratio_picker.cc b/src/wx/ratio_picker.cc
new file mode 100644
index 000000000..39d2c4f2a
--- /dev/null
+++ b/src/wx/ratio_picker.cc
@@ -0,0 +1,158 @@
+/*
+ Copyright (C) 2025 Carl Hetherington <cth@carlh.net>
+
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic 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 2 of the License, or
+ (at your option) any later version.
+
+ DCP-o-matic 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 DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+
+#include "dcpomatic_choice.h"
+#include "check_box.h"
+#include "ratio_picker.h"
+#include "wx_util.h"
+#include "lib/ratio.h"
+#include <dcp/locale_convert.h>
+#include <dcp/scope_guard.h>
+
+
+using boost::optional;
+
+
+RatioPicker::RatioPicker(wxWindow* parent, optional<float> ratio)
+ : wxPanel(parent, wxID_ANY)
+{
+ _enable = new CheckBox(parent, _("Crop output to"));
+ _preset = new Choice(this);
+ _custom = new wxTextCtrl(this, wxID_ANY);
+
+ auto sizer = new wxBoxSizer(wxHORIZONTAL);
+ sizer->Add(_preset, 0, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_X_GAP);
+ sizer->Add(_custom, 0, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_X_GAP);
+ add_label_to_sizer(sizer, this, _(":1"), false, 0, wxALIGN_CENTER_VERTICAL);
+
+ for (auto ratio: Ratio::all()) {
+ _preset->add_entry(ratio.image_nickname(), ratio.id());
+ }
+ _preset->add_entry(_("Custom"), "custom");
+
+ SetSizer(sizer);
+ Layout();
+
+ set(ratio);
+
+ _enable->bind(&RatioPicker::enable_changed, this);
+ _preset->bind(&RatioPicker::preset_changed, this);
+ _custom->Bind(wxEVT_TEXT, boost::bind(&RatioPicker::custom_changed, this));
+
+ setup_sensitivity();
+}
+
+
+void
+RatioPicker::set(optional<float> ratio)
+{
+ _enable->set(ratio.has_value());
+ set_preset(ratio);
+ set_custom(ratio);
+}
+
+
+void
+RatioPicker::enable_changed()
+{
+ setup_sensitivity();
+ if (_enable->get()) {
+ Changed(1.85);
+ } else {
+ Changed({});
+ }
+}
+
+
+void
+RatioPicker::setup_sensitivity()
+{
+ _preset->Enable(_enable->get());
+ _custom->Enable(_enable->get());
+}
+
+
+void
+RatioPicker::preset_changed()
+{
+ if (!_enable->get() || _ignore_changes) {
+ return;
+ }
+
+ optional<Ratio> ratio;
+
+ if (auto data = _preset->get_data()) {
+ ratio = Ratio::from_id_if_exists(*data);
+ }
+
+ optional<float> new_value;
+ if (ratio) {
+ new_value = ratio->ratio();
+ } else {
+ new_value = dcp::locale_convert<float>(wx_to_std(_custom->GetValue()));
+ }
+
+ set_custom(new_value);
+ Changed(new_value);
+}
+
+
+void
+RatioPicker::custom_changed()
+{
+ if (!_enable->get() || _ignore_changes) {
+ return;
+ }
+
+ auto const new_value = dcp::locale_convert<float>(wx_to_std(_custom->GetValue()));
+ set_preset(new_value);
+ Changed(new_value);
+}
+
+
+void
+RatioPicker::set_preset(optional<float> ratio)
+{
+ _ignore_changes = true;
+ dcp::ScopeGuard sg = [this]() { _ignore_changes = false; };
+
+ if (ratio) {
+ auto preset = Ratio::from_ratio(*ratio);
+ _preset->set_by_data(preset ? preset->id() : "custom");
+ } else {
+ _preset->set_by_data("185");
+ }
+}
+
+
+void
+RatioPicker::set_custom(optional<float> ratio)
+{
+ _ignore_changes = true;
+ dcp::ScopeGuard sg = [this]() { _ignore_changes = false; };
+
+ if (ratio) {
+ auto preset = Ratio::from_ratio(*ratio);
+ _custom->SetValue(wxString::Format(char_to_wx("%.2f"), preset ? preset->ratio() : *ratio));
+ } else {
+ _custom->SetValue(_("1.85"));
+ }
+}
diff --git a/src/wx/ratio_picker.h b/src/wx/ratio_picker.h
new file mode 100644
index 000000000..93e78ae9f
--- /dev/null
+++ b/src/wx/ratio_picker.h
@@ -0,0 +1,58 @@
+/*
+ Copyright (C) 2025 Carl Hetherington <cth@carlh.net>
+
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic 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 2 of the License, or
+ (at your option) any later version.
+
+ DCP-o-matic 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 DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+
+#include <wx/wx.h>
+#include <boost/optional.hpp>
+#include <boost/signals2.hpp>
+
+
+class CheckBox;
+class Choice;
+
+
+class RatioPicker : public wxPanel
+{
+public:
+ RatioPicker(wxWindow* parent, boost::optional<float> ratio);
+
+ CheckBox* enable_checkbox() const {
+ return _enable;
+ }
+
+ void set(boost::optional<float> ratio);
+
+ boost::signals2::signal<void (boost::optional<float>)> Changed;
+
+private:
+ void enable_changed();
+ void preset_changed();
+ void custom_changed();
+
+ void set_preset(boost::optional<float> ratio);
+ void set_custom(boost::optional<float> ratio);
+ void setup_sensitivity();
+
+ CheckBox* _enable;
+ Choice* _preset;
+ wxTextCtrl* _custom;
+
+ bool _ignore_changes = false;
+};
diff --git a/src/wx/wscript b/src/wx/wscript
index 3dfc157e2..3049d842d 100644
--- a/src/wx/wscript
+++ b/src/wx/wscript
@@ -143,6 +143,7 @@ sources = """
question_dialog.cc
rating_dialog.cc
qube_certificate_panel.cc
+ ratio_picker.cc
recipients_panel.cc
recipient_dialog.cc
recreate_chain_dialog.cc