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 "static_text.h"
24 #include "check_box.h"
25 #include "dcpomatic_button.h"
26 #include "lib/string_text_file_content.h"
27 #include "lib/text_content.h"
28 #include "lib/ffmpeg_subtitle_stream.h"
29 #include "lib/ffmpeg_content.h"
31 #include <wx/clrpicker.h>
32 #include <wx/spinctrl.h>
33 #include <wx/gbsizer.h>
36 using boost::shared_ptr;
38 using boost::dynamic_pointer_cast;
39 using boost::optional;
41 int const SubtitleAppearanceDialog::NONE = 0;
42 int const SubtitleAppearanceDialog::OUTLINE = 1;
43 int const SubtitleAppearanceDialog::SHADOW = 2;
45 SubtitleAppearanceDialog::SubtitleAppearanceDialog (wxWindow* parent, shared_ptr<const Film> film, shared_ptr<Content> content, shared_ptr<TextContent> caption)
46 : wxDialog (parent, wxID_ANY, _("Caption appearance"))
51 shared_ptr<FFmpegContent> ff = dynamic_pointer_cast<FFmpegContent> (content);
53 _stream = ff->subtitle_stream ();
56 wxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
57 SetSizer (overall_sizer);
59 _table = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
61 overall_sizer->Add (_table, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
65 add_label_to_sizer (_table, this, _("Colour"), true, wxGBPosition (r, 0));
66 _force_colour = set_to (_colour = new wxColourPickerCtrl (this, wxID_ANY), r);
68 add_label_to_sizer (_table, this, _("Effect"), true, wxGBPosition (r, 0));
69 _force_effect = set_to (_effect = new wxChoice (this, wxID_ANY), r);
71 add_label_to_sizer (_table, this, _("Effect colour"), true, wxGBPosition (r, 0));
72 _force_effect_colour = set_to (_effect_colour = new wxColourPickerCtrl (this, wxID_ANY), r);
74 add_label_to_sizer (_table, this, _("Outline width"), true, wxGBPosition (r, 0));
75 _outline_width = new wxSpinCtrl (this, wxID_ANY);
76 _table->Add (_outline_width, wxGBPosition (r, 1));
79 add_label_to_sizer (_table, this, _("Fade in time"), true, wxGBPosition (r, 0));
80 _force_fade_in = set_to (_fade_in = new Timecode<ContentTime> (this), r);
82 add_label_to_sizer (_table, this, _("Fade out time"), true, wxGBPosition (r, 0));
83 _force_fade_out = set_to (_fade_out = new Timecode<ContentTime> (this), r);
86 wxScrolled<wxPanel>* colours_panel = new wxScrolled<wxPanel> (this);
87 colours_panel->EnableScrolling (false, true);
88 colours_panel->ShowScrollbars (wxSHOW_SB_NEVER, wxSHOW_SB_ALWAYS);
89 colours_panel->SetScrollRate (0, 16);
91 wxFlexGridSizer* table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
92 table->AddGrowableCol (1, 1);
94 map<RGBA, RGBA> colours = _stream->colours ();
96 wxStaticText* t = new StaticText (colours_panel, "");
97 t->SetLabelMarkup (_("<b>Original colour</b>"));
98 table->Add (t, 1, wxEXPAND);
99 t = new StaticText (colours_panel, "", wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE_HORIZONTAL);
100 t->SetLabelMarkup (_("<b>New colour</b>"));
101 table->Add (t, 1, wxALIGN_CENTER);
103 for (map<RGBA, RGBA>::const_iterator i = colours.begin(); i != colours.end(); ++i) {
104 wxPanel* from = new wxPanel (colours_panel, wxID_ANY);
105 from->SetBackgroundColour (wxColour (i->first.r, i->first.g, i->first.b, i->first.a));
106 table->Add (from, 1, wxEXPAND);
107 RGBAColourPicker* to = new RGBAColourPicker (colours_panel, i->second);
108 table->Add (to, 1, wxEXPAND);
109 _pickers[i->first] = to;
112 colours_panel->SetSizer (table);
114 overall_sizer->Add (colours_panel, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
116 wxButton* restore = new Button (this, _("Restore to original colours"));
117 restore->Bind (wxEVT_BUTTON, bind (&SubtitleAppearanceDialog::restore, this));
118 overall_sizer->Add (restore, 0, wxALL, DCPOMATIC_SIZER_X_GAP);
121 wxSizer* buttons = CreateSeparatedButtonSizer (wxOK);
123 overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
126 overall_sizer->Layout ();
127 overall_sizer->SetSizeHints (this);
129 /* Keep these Appends() up to date with NONE/OUTLINE/SHADOW variables */
130 _effect->Append (_("None"));
131 _effect->Append (_("Outline"));
132 _effect->Append (_("Shadow"));;
134 optional<dcp::Colour> colour = _caption->colour();
135 _force_colour->SetValue (static_cast<bool>(colour));
137 _colour->SetColour (wxColour (colour->r, colour->g, colour->b));
139 _colour->SetColour (wxColour (255, 255, 255));
142 optional<dcp::Effect> effect = _caption->effect();
143 _force_effect->SetValue (static_cast<bool>(effect));
147 _effect->SetSelection (NONE);
150 _effect->SetSelection (OUTLINE);
153 _effect->SetSelection (SHADOW);
157 _effect->SetSelection (NONE);
160 optional<dcp::Colour> effect_colour = _caption->effect_colour();
161 _force_effect_colour->SetValue (static_cast<bool>(effect_colour));
163 _effect_colour->SetColour (wxColour (effect_colour->r, effect_colour->g, effect_colour->b));
165 _effect_colour->SetColour (wxColour (0, 0, 0));
168 optional<ContentTime> fade_in = _caption->fade_in();
169 _force_fade_in->SetValue (static_cast<bool>(fade_in));
171 _fade_in->set (*fade_in, _content->active_video_frame_rate(film));
173 _fade_in->set (ContentTime(), _content->active_video_frame_rate(film));
176 optional<ContentTime> fade_out = _caption->fade_out();
177 _force_fade_out->SetValue (static_cast<bool>(fade_out));
179 _fade_out->set (*fade_out, _content->active_video_frame_rate(film));
181 _fade_out->set (ContentTime(), _content->active_video_frame_rate(film));
184 _outline_width->SetValue (_caption->outline_width ());
186 _force_colour->Bind (wxEVT_CHECKBOX, bind (&SubtitleAppearanceDialog::setup_sensitivity, this));
187 _force_effect_colour->Bind (wxEVT_CHECKBOX, bind (&SubtitleAppearanceDialog::setup_sensitivity, this));
188 _force_effect->Bind (wxEVT_CHECKBOX, bind (&SubtitleAppearanceDialog::setup_sensitivity, this));
189 _force_fade_in->Bind (wxEVT_CHECKBOX, bind (&SubtitleAppearanceDialog::setup_sensitivity, this));
190 _force_fade_out->Bind (wxEVT_CHECKBOX, bind (&SubtitleAppearanceDialog::setup_sensitivity, this));
191 _effect->Bind (wxEVT_CHOICE, bind (&SubtitleAppearanceDialog::setup_sensitivity, this));
192 _content_connection = _content->Change.connect (bind (&SubtitleAppearanceDialog::content_change, this, _1));
194 setup_sensitivity ();
198 SubtitleAppearanceDialog::content_change (ChangeType type)
200 if (type == CHANGE_TYPE_DONE) {
201 setup_sensitivity ();
206 SubtitleAppearanceDialog::set_to (wxWindow* w, int& r)
208 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
209 wxCheckBox* set_to = new CheckBox (this, _("Set to"));
210 s->Add (set_to, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 8);
211 s->Add (w, 0, wxALIGN_CENTER_VERTICAL);
212 _table->Add (s, wxGBPosition (r, 1));
218 SubtitleAppearanceDialog::apply ()
220 shared_ptr<const Film> film = _film.lock ();
222 if (_force_colour->GetValue ()) {
223 wxColour const c = _colour->GetColour ();
224 _caption->set_colour (dcp::Colour (c.Red(), c.Green(), c.Blue()));
226 _caption->unset_colour ();
228 if (_force_effect->GetValue()) {
229 switch (_effect->GetSelection()) {
231 _caption->set_effect (dcp::NONE);
234 _caption->set_effect (dcp::BORDER);
237 _caption->set_effect (dcp::SHADOW);
241 _caption->unset_effect ();
243 if (_force_effect_colour->GetValue ()) {
244 wxColour const ec = _effect_colour->GetColour ();
245 _caption->set_effect_colour (dcp::Colour (ec.Red(), ec.Green(), ec.Blue()));
247 _caption->unset_effect_colour ();
249 if (_force_fade_in->GetValue ()) {
250 _caption->set_fade_in (_fade_in->get(_content->active_video_frame_rate(film)));
252 _caption->unset_fade_in ();
254 if (_force_fade_out->GetValue ()) {
255 _caption->set_fade_out (_fade_out->get(_content->active_video_frame_rate(film)));
257 _caption->unset_fade_out ();
259 _caption->set_outline_width (_outline_width->GetValue ());
262 for (map<RGBA, RGBAColourPicker*>::const_iterator i = _pickers.begin(); i != _pickers.end(); ++i) {
263 _stream->set_colour (i->first, i->second->colour ());
267 shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (_content);
269 fc->signal_subtitle_stream_changed ();
274 SubtitleAppearanceDialog::restore ()
276 for (map<RGBA, RGBAColourPicker*>::const_iterator i = _pickers.begin(); i != _pickers.end(); ++i) {
277 i->second->set (i->first);
282 SubtitleAppearanceDialog::setup_sensitivity ()
284 _colour->Enable (_force_colour->GetValue ());
285 _effect_colour->Enable (_force_effect_colour->GetValue ());
286 _effect->Enable (_force_effect->GetValue ());
287 _fade_in->Enable (_force_fade_in->GetValue ());
288 _fade_out->Enable (_force_fade_out->GetValue ());
290 bool const can_outline_width = _effect->GetSelection() == OUTLINE && _caption->burn ();
291 _outline_width->Enable (can_outline_width);
292 if (can_outline_width) {
293 _outline_width->UnsetToolTip ();
295 _outline_width->SetToolTip (_("Outline width cannot be set unless you are burning in captions"));