2 Copyright (C) 2015-2018 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
21 #include "subtitle_appearance_dialog.h"
22 #include "rgba_colour_picker.h"
23 #include "lib/string_text_file_content.h"
24 #include "lib/text_content.h"
25 #include "lib/ffmpeg_subtitle_stream.h"
26 #include "lib/ffmpeg_content.h"
28 #include <wx/clrpicker.h>
29 #include <wx/spinctrl.h>
30 #include <wx/gbsizer.h>
33 using boost::shared_ptr;
35 using boost::dynamic_pointer_cast;
36 using boost::optional;
38 int const SubtitleAppearanceDialog::NONE = 0;
39 int const SubtitleAppearanceDialog::OUTLINE = 1;
40 int const SubtitleAppearanceDialog::SHADOW = 2;
42 SubtitleAppearanceDialog::SubtitleAppearanceDialog (wxWindow* parent, shared_ptr<const Film> film, shared_ptr<Content> content, shared_ptr<TextContent> caption)
43 : wxDialog (parent, wxID_ANY, _("Caption appearance"))
48 shared_ptr<FFmpegContent> ff = dynamic_pointer_cast<FFmpegContent> (content);
50 _stream = ff->subtitle_stream ();
53 wxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
54 SetSizer (overall_sizer);
56 _table = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
58 overall_sizer->Add (_table, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
62 add_label_to_sizer (_table, this, _("Colour"), true, wxGBPosition (r, 0));
63 _force_colour = set_to (_colour = new wxColourPickerCtrl (this, wxID_ANY), r);
65 add_label_to_sizer (_table, this, _("Effect"), true, wxGBPosition (r, 0));
66 _force_effect = set_to (_effect = new wxChoice (this, wxID_ANY), r);
68 add_label_to_sizer (_table, this, _("Effect colour"), true, wxGBPosition (r, 0));
69 _force_effect_colour = set_to (_effect_colour = new wxColourPickerCtrl (this, wxID_ANY), r);
71 add_label_to_sizer (_table, this, _("Outline width"), true, wxGBPosition (r, 0));
72 _outline_width = new wxSpinCtrl (this, wxID_ANY);
73 _table->Add (_outline_width, wxGBPosition (r, 1));
76 add_label_to_sizer (_table, this, _("Fade in time"), true, wxGBPosition (r, 0));
77 _force_fade_in = set_to (_fade_in = new Timecode<ContentTime> (this), r);
79 add_label_to_sizer (_table, this, _("Fade out time"), true, wxGBPosition (r, 0));
80 _force_fade_out = set_to (_fade_out = new Timecode<ContentTime> (this), r);
83 wxScrolled<wxPanel>* colours_panel = new wxScrolled<wxPanel> (this);
84 colours_panel->EnableScrolling (false, true);
85 colours_panel->ShowScrollbars (wxSHOW_SB_NEVER, wxSHOW_SB_ALWAYS);
86 colours_panel->SetScrollRate (0, 16);
88 wxFlexGridSizer* table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
89 table->AddGrowableCol (1, 1);
91 map<RGBA, RGBA> colours = _stream->colours ();
93 wxStaticText* t = new wxStaticText (colours_panel, wxID_ANY, "");
94 t->SetLabelMarkup (_("<b>Original colour</b>"));
95 table->Add (t, 1, wxEXPAND);
96 t = new wxStaticText (colours_panel, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE_HORIZONTAL);
97 t->SetLabelMarkup (_("<b>New colour</b>"));
98 table->Add (t, 1, wxALIGN_CENTER);
100 for (map<RGBA, RGBA>::const_iterator i = colours.begin(); i != colours.end(); ++i) {
101 wxPanel* from = new wxPanel (colours_panel, wxID_ANY);
102 from->SetBackgroundColour (wxColour (i->first.r, i->first.g, i->first.b, i->first.a));
103 table->Add (from, 1, wxEXPAND);
104 RGBAColourPicker* to = new RGBAColourPicker (colours_panel, i->second);
105 table->Add (to, 1, wxEXPAND);
106 _pickers[i->first] = to;
109 colours_panel->SetSizer (table);
111 overall_sizer->Add (colours_panel, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
113 wxButton* restore = new wxButton (this, wxID_ANY, _("Restore to original colours"));
114 restore->Bind (wxEVT_BUTTON, bind (&SubtitleAppearanceDialog::restore, this));
115 overall_sizer->Add (restore, 0, wxALL, DCPOMATIC_SIZER_X_GAP);
118 wxSizer* buttons = CreateSeparatedButtonSizer (wxOK);
120 overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
123 overall_sizer->Layout ();
124 overall_sizer->SetSizeHints (this);
126 /* Keep these Appends() up to date with NONE/OUTLINE/SHADOW variables */
127 _effect->Append (_("None"));
128 _effect->Append (_("Outline"));
129 _effect->Append (_("Shadow"));;
131 optional<dcp::Colour> colour = _caption->colour();
132 _force_colour->SetValue (static_cast<bool>(colour));
134 _colour->SetColour (wxColour (colour->r, colour->g, colour->b));
136 _colour->SetColour (wxColour (255, 255, 255));
139 optional<dcp::Effect> effect = _caption->effect();
140 _force_effect->SetValue (static_cast<bool>(effect));
144 _effect->SetSelection (NONE);
147 _effect->SetSelection (OUTLINE);
150 _effect->SetSelection (SHADOW);
154 _effect->SetSelection (NONE);
157 optional<dcp::Colour> effect_colour = _caption->effect_colour();
158 _force_effect_colour->SetValue (static_cast<bool>(effect_colour));
160 _effect_colour->SetColour (wxColour (effect_colour->r, effect_colour->g, effect_colour->b));
162 _effect_colour->SetColour (wxColour (0, 0, 0));
165 optional<ContentTime> fade_in = _caption->fade_in();
166 _force_fade_in->SetValue (static_cast<bool>(fade_in));
168 _fade_in->set (*fade_in, _content->active_video_frame_rate(film));
170 _fade_in->set (ContentTime(), _content->active_video_frame_rate(film));
173 optional<ContentTime> fade_out = _caption->fade_out();
174 _force_fade_out->SetValue (static_cast<bool>(fade_out));
176 _fade_out->set (*fade_out, _content->active_video_frame_rate(film));
178 _fade_out->set (ContentTime(), _content->active_video_frame_rate(film));
181 _outline_width->SetValue (_caption->outline_width ());
183 _force_colour->Bind (wxEVT_CHECKBOX, bind (&SubtitleAppearanceDialog::setup_sensitivity, this));
184 _force_effect_colour->Bind (wxEVT_CHECKBOX, bind (&SubtitleAppearanceDialog::setup_sensitivity, this));
185 _force_effect->Bind (wxEVT_CHECKBOX, bind (&SubtitleAppearanceDialog::setup_sensitivity, this));
186 _force_fade_in->Bind (wxEVT_CHECKBOX, bind (&SubtitleAppearanceDialog::setup_sensitivity, this));
187 _force_fade_out->Bind (wxEVT_CHECKBOX, bind (&SubtitleAppearanceDialog::setup_sensitivity, this));
188 _effect->Bind (wxEVT_CHOICE, bind (&SubtitleAppearanceDialog::setup_sensitivity, this));
189 _content_connection = _content->Change.connect (bind (&SubtitleAppearanceDialog::content_change, this, _1));
191 setup_sensitivity ();
195 SubtitleAppearanceDialog::content_change (ChangeType type)
197 if (type == CHANGE_TYPE_DONE) {
198 setup_sensitivity ();
203 SubtitleAppearanceDialog::set_to (wxWindow* w, int& r)
205 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
206 wxCheckBox* set_to = new wxCheckBox (this, wxID_ANY, _("Set to"));
207 s->Add (set_to, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 8);
208 s->Add (w, 0, wxALIGN_CENTER_VERTICAL);
209 _table->Add (s, wxGBPosition (r, 1));
215 SubtitleAppearanceDialog::apply ()
217 shared_ptr<const Film> film = _film.lock ();
219 if (_force_colour->GetValue ()) {
220 wxColour const c = _colour->GetColour ();
221 _caption->set_colour (dcp::Colour (c.Red(), c.Green(), c.Blue()));
223 _caption->unset_colour ();
225 if (_force_effect->GetValue()) {
226 switch (_effect->GetSelection()) {
228 _caption->set_effect (dcp::NONE);
231 _caption->set_effect (dcp::BORDER);
234 _caption->set_effect (dcp::SHADOW);
238 _caption->unset_effect ();
240 if (_force_effect_colour->GetValue ()) {
241 wxColour const ec = _effect_colour->GetColour ();
242 _caption->set_effect_colour (dcp::Colour (ec.Red(), ec.Green(), ec.Blue()));
244 _caption->unset_effect_colour ();
246 if (_force_fade_in->GetValue ()) {
247 _caption->set_fade_in (_fade_in->get(_content->active_video_frame_rate(film)));
249 _caption->unset_fade_in ();
251 if (_force_fade_out->GetValue ()) {
252 _caption->set_fade_out (_fade_out->get(_content->active_video_frame_rate(film)));
254 _caption->unset_fade_out ();
256 _caption->set_outline_width (_outline_width->GetValue ());
259 for (map<RGBA, RGBAColourPicker*>::const_iterator i = _pickers.begin(); i != _pickers.end(); ++i) {
260 _stream->set_colour (i->first, i->second->colour ());
264 shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (_content);
266 fc->signal_subtitle_stream_changed ();
271 SubtitleAppearanceDialog::restore ()
273 for (map<RGBA, RGBAColourPicker*>::const_iterator i = _pickers.begin(); i != _pickers.end(); ++i) {
274 i->second->set (i->first);
279 SubtitleAppearanceDialog::setup_sensitivity ()
281 _colour->Enable (_force_colour->GetValue ());
282 _effect_colour->Enable (_force_effect_colour->GetValue ());
283 _effect->Enable (_force_effect->GetValue ());
284 _fade_in->Enable (_force_fade_in->GetValue ());
285 _fade_out->Enable (_force_fade_out->GetValue ());
287 bool const can_outline_width = _effect->GetSelection() == OUTLINE && _caption->burn ();
288 _outline_width->Enable (can_outline_width);
289 if (can_outline_width) {
290 _outline_width->UnsetToolTip ();
292 _outline_width->SetToolTip (_("Outline width cannot be set unless you are burning in captions"));