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/text_subtitle_content.h"
24 #include "lib/subtitle_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<Content> content)
43 : wxDialog (parent, wxID_ANY, _("Subtitle appearance"))
46 shared_ptr<FFmpegContent> ff = dynamic_pointer_cast<FFmpegContent> (content);
48 _stream = ff->subtitle_stream ();
51 wxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
52 SetSizer (overall_sizer);
54 _table = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
56 overall_sizer->Add (_table, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
60 add_label_to_sizer (_table, this, _("Colour"), true, wxGBPosition (r, 0));
62 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
63 _force_colour = new wxCheckBox (this, wxID_ANY, _("Set to"));
64 s->Add (_force_colour, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 8);
65 _colour = new wxColourPickerCtrl (this, wxID_ANY);
66 s->Add (_colour, 0, wxALIGN_CENTER_VERTICAL);
67 _table->Add (s, wxGBPosition (r, 1));
71 add_label_to_sizer (_table, this, _("Effect"), true, wxGBPosition (r, 0));
72 _effect = new wxChoice (this, wxID_ANY);
73 _table->Add (_effect, wxGBPosition (r, 1));
76 add_label_to_sizer (_table, this, _("Effect colour"), true, wxGBPosition (r, 0));
77 _effect_colour = new wxColourPickerCtrl (this, wxID_ANY);
78 _table->Add (_effect_colour, wxGBPosition (r, 1));
81 add_label_to_sizer (_table, this, _("Outline width"), true, wxGBPosition (r, 0));
82 _outline_width = new wxSpinCtrl (this, wxID_ANY);
83 _table->Add (_outline_width, wxGBPosition (r, 1));
86 add_label_to_sizer (_table, this, _("Fade in time"), true, wxGBPosition (r, 0));
87 _fade_in = new Timecode<ContentTime> (this);
88 _table->Add (_fade_in, wxGBPosition (r, 1));
91 add_label_to_sizer (_table, this, _("Fade out time"), true, wxGBPosition (r, 0));
92 _fade_out = new Timecode<ContentTime> (this);
93 _table->Add (_fade_out, wxGBPosition (r, 1));
97 wxScrolled<wxPanel>* colours_panel = new wxScrolled<wxPanel> (this);
98 colours_panel->EnableScrolling (false, true);
99 colours_panel->ShowScrollbars (wxSHOW_SB_NEVER, wxSHOW_SB_ALWAYS);
100 colours_panel->SetScrollRate (0, 16);
102 wxFlexGridSizer* table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
103 table->AddGrowableCol (1, 1);
105 map<RGBA, RGBA> colours = _stream->colours ();
107 wxStaticText* t = new wxStaticText (colours_panel, wxID_ANY, "");
108 t->SetLabelMarkup (_("<b>Original colour</b>"));
109 table->Add (t, 1, wxEXPAND);
110 t = new wxStaticText (colours_panel, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE_HORIZONTAL);
111 t->SetLabelMarkup (_("<b>New colour</b>"));
112 table->Add (t, 1, wxALIGN_CENTER);
114 for (map<RGBA, RGBA>::const_iterator i = colours.begin(); i != colours.end(); ++i) {
115 wxPanel* from = new wxPanel (colours_panel, wxID_ANY);
116 from->SetBackgroundColour (wxColour (i->first.r, i->first.g, i->first.b, i->first.a));
117 table->Add (from, 1, wxEXPAND);
118 RGBAColourPicker* to = new RGBAColourPicker (colours_panel, i->second);
119 table->Add (to, 1, wxEXPAND);
120 _pickers[i->first] = to;
123 colours_panel->SetSizer (table);
125 overall_sizer->Add (colours_panel, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
127 wxButton* restore = new wxButton (this, wxID_ANY, _("Restore to original colours"));
128 restore->Bind (wxEVT_BUTTON, bind (&SubtitleAppearanceDialog::restore, this));
129 overall_sizer->Add (restore, 0, wxALL, DCPOMATIC_SIZER_X_GAP);
132 wxSizer* buttons = CreateSeparatedButtonSizer (wxOK);
134 overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
137 overall_sizer->Layout ();
138 overall_sizer->SetSizeHints (this);
140 /* Keep these Appends() up to date with NONE/OUTLINE/SHADOW variables */
141 _effect->Append (_("None"));
142 _effect->Append (_("Outline"));
143 _effect->Append (_("Shadow"));;
145 optional<dcp::Colour> colour = _content->subtitle->colour();
147 _force_colour->SetValue (true);
148 _colour->SetColour (wxColour (colour->r, colour->g, colour->b));
150 _force_colour->SetValue (false);
151 _colour->SetColour (wxColour (255, 255, 255));
154 if (_content->subtitle->outline()) {
155 _effect->SetSelection (OUTLINE);
156 } else if (_content->subtitle->shadow()) {
157 _effect->SetSelection (SHADOW);
159 _effect->SetSelection (NONE);
161 _effect_colour->SetColour (
162 wxColour (_content->subtitle->effect_colour().r, _content->subtitle->effect_colour().g, _content->subtitle->effect_colour().b)
164 _fade_in->set (_content->subtitle->fade_in(), _content->active_video_frame_rate ());
165 _fade_out->set (_content->subtitle->fade_out(), _content->active_video_frame_rate ());
166 _outline_width->SetValue (_content->subtitle->outline_width ());
168 _force_colour->Bind (wxEVT_CHECKBOX, bind (&SubtitleAppearanceDialog::setup_sensitivity, this));
169 _effect->Bind (wxEVT_CHOICE, bind (&SubtitleAppearanceDialog::setup_sensitivity, this));
170 _content_connection = _content->Changed.connect (bind (&SubtitleAppearanceDialog::setup_sensitivity, this));
172 setup_sensitivity ();
176 SubtitleAppearanceDialog::apply ()
178 if (_force_colour->GetValue ()) {
179 wxColour const c = _colour->GetColour ();
180 _content->subtitle->set_colour (dcp::Colour (c.Red(), c.Green(), c.Blue()));
182 _content->subtitle->unset_colour ();
184 _content->subtitle->set_outline (_effect->GetSelection() == OUTLINE);
185 _content->subtitle->set_shadow (_effect->GetSelection() == SHADOW);
186 wxColour const ec = _effect_colour->GetColour ();
187 _content->subtitle->set_effect_colour (dcp::Colour (ec.Red(), ec.Green(), ec.Blue()));
188 _content->subtitle->set_fade_in (_fade_in->get (_content->active_video_frame_rate ()));
189 _content->subtitle->set_fade_out (_fade_out->get (_content->active_video_frame_rate ()));
190 _content->subtitle->set_outline_width (_outline_width->GetValue ());
193 for (map<RGBA, RGBAColourPicker*>::const_iterator i = _pickers.begin(); i != _pickers.end(); ++i) {
194 _stream->set_colour (i->first, i->second->colour ());
198 shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (_content);
200 fc->signal_subtitle_stream_changed ();
205 SubtitleAppearanceDialog::restore ()
207 for (map<RGBA, RGBAColourPicker*>::const_iterator i = _pickers.begin(); i != _pickers.end(); ++i) {
208 i->second->set (i->first);
213 SubtitleAppearanceDialog::setup_sensitivity ()
215 _colour->Enable (_force_colour->GetValue ());
216 _effect_colour->Enable (_effect->GetSelection() != NONE);
218 bool const can_outline_width = _effect->GetSelection() == OUTLINE && _content->subtitle->burn ();
219 _outline_width->Enable (can_outline_width);
220 if (can_outline_width) {
221 _outline_width->UnsetToolTip ();
223 _outline_width->SetToolTip (_("Outline width cannot be set unless you are burning in subtitles"));