2 Copyright (C) 2015-2017 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;
37 int const SubtitleAppearanceDialog::NONE = 0;
38 int const SubtitleAppearanceDialog::OUTLINE = 1;
39 int const SubtitleAppearanceDialog::SHADOW = 2;
41 SubtitleAppearanceDialog::SubtitleAppearanceDialog (wxWindow* parent, shared_ptr<Content> content)
42 : wxDialog (parent, wxID_ANY, _("Subtitle appearance"))
45 shared_ptr<FFmpegContent> ff = dynamic_pointer_cast<FFmpegContent> (content);
47 _stream = ff->subtitle_stream ();
50 wxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
51 SetSizer (overall_sizer);
53 _table = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
55 overall_sizer->Add (_table, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
59 add_label_to_sizer (_table, this, _("Colour"), true, wxGBPosition (r, 0));
60 _colour = new wxColourPickerCtrl (this, wxID_ANY);
61 _table->Add (_colour, wxGBPosition (r, 1));
64 add_label_to_sizer (_table, this, _("Effect"), true, wxGBPosition (r, 0));
65 _effect = new wxChoice (this, wxID_ANY);
66 _table->Add (_effect, wxGBPosition (r, 1));
69 add_label_to_sizer (_table, this, _("Effect colour"), true, wxGBPosition (r, 0));
70 _effect_colour = new wxColourPickerCtrl (this, wxID_ANY);
71 _table->Add (_effect_colour, wxGBPosition (r, 1));
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 _fade_in = new Timecode<ContentTime> (this);
81 _table->Add (_fade_in, wxGBPosition (r, 1));
84 add_label_to_sizer (_table, this, _("Fade out time"), true, wxGBPosition (r, 0));
85 _fade_out = new Timecode<ContentTime> (this);
86 _table->Add (_fade_out, wxGBPosition (r, 1));
90 wxScrolled<wxPanel>* colours_panel = new wxScrolled<wxPanel> (this);
91 colours_panel->EnableScrolling (false, true);
92 colours_panel->ShowScrollbars (wxSHOW_SB_NEVER, wxSHOW_SB_ALWAYS);
93 colours_panel->SetScrollRate (0, 16);
95 wxFlexGridSizer* table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
96 table->AddGrowableCol (1, 1);
98 map<RGBA, RGBA> colours = _stream->colours ();
100 wxStaticText* t = new wxStaticText (colours_panel, wxID_ANY, "");
101 t->SetLabelMarkup (_("<b>Original colour</b>"));
102 table->Add (t, 1, wxEXPAND);
103 t = new wxStaticText (colours_panel, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE_HORIZONTAL);
104 t->SetLabelMarkup (_("<b>New colour</b>"));
105 table->Add (t, 1, wxALIGN_CENTER);
107 for (map<RGBA, RGBA>::const_iterator i = colours.begin(); i != colours.end(); ++i) {
108 wxPanel* from = new wxPanel (colours_panel, wxID_ANY);
109 from->SetBackgroundColour (wxColour (i->first.r, i->first.g, i->first.b, i->first.a));
110 table->Add (from, 1, wxEXPAND);
111 RGBAColourPicker* to = new RGBAColourPicker (colours_panel, i->second);
112 table->Add (to, 1, wxEXPAND);
113 _pickers[i->first] = to;
116 colours_panel->SetSizer (table);
118 overall_sizer->Add (colours_panel, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
120 wxButton* restore = new wxButton (this, wxID_ANY, _("Restore to original colours"));
121 restore->Bind (wxEVT_BUTTON, bind (&SubtitleAppearanceDialog::restore, this));
122 overall_sizer->Add (restore, 0, wxALL, DCPOMATIC_SIZER_X_GAP);
125 wxSizer* buttons = CreateSeparatedButtonSizer (wxOK);
127 overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
130 overall_sizer->Layout ();
131 overall_sizer->SetSizeHints (this);
133 /* Keep these Appends() up to date with NONE/OUTLINE/SHADOW variables */
134 _effect->Append (_("None"));
135 _effect->Append (_("Outline"));
136 _effect->Append (_("Shadow"));;
138 _colour->SetColour (wxColour (_content->subtitle->colour().r, _content->subtitle->colour().g, _content->subtitle->colour().b));
139 if (_content->subtitle->outline()) {
140 _effect->SetSelection (OUTLINE);
141 } else if (_content->subtitle->shadow()) {
142 _effect->SetSelection (SHADOW);
144 _effect->SetSelection (NONE);
146 _effect_colour->SetColour (
147 wxColour (_content->subtitle->effect_colour().r, _content->subtitle->effect_colour().g, _content->subtitle->effect_colour().b)
149 _fade_in->set (_content->subtitle->fade_in(), _content->active_video_frame_rate ());
150 _fade_out->set (_content->subtitle->fade_out(), _content->active_video_frame_rate ());
151 _outline_width->SetValue (_content->subtitle->outline_width ());
153 _effect->Bind (wxEVT_CHOICE, bind (&SubtitleAppearanceDialog::setup_sensitivity, this));
154 _content_connection = _content->Changed.connect (bind (&SubtitleAppearanceDialog::setup_sensitivity, this));
156 setup_sensitivity ();
160 SubtitleAppearanceDialog::apply ()
162 wxColour const c = _colour->GetColour ();
163 _content->subtitle->set_colour (dcp::Colour (c.Red(), c.Green(), c.Blue()));
164 _content->subtitle->set_outline (_effect->GetSelection() == OUTLINE);
165 _content->subtitle->set_shadow (_effect->GetSelection() == SHADOW);
166 wxColour const ec = _effect_colour->GetColour ();
167 _content->subtitle->set_effect_colour (dcp::Colour (ec.Red(), ec.Green(), ec.Blue()));
168 _content->subtitle->set_fade_in (_fade_in->get (_content->active_video_frame_rate ()));
169 _content->subtitle->set_fade_out (_fade_out->get (_content->active_video_frame_rate ()));
170 _content->subtitle->set_outline_width (_outline_width->GetValue ());
173 for (map<RGBA, RGBAColourPicker*>::const_iterator i = _pickers.begin(); i != _pickers.end(); ++i) {
174 _stream->set_colour (i->first, i->second->colour ());
178 shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (_content);
180 fc->signal_subtitle_stream_changed ();
185 SubtitleAppearanceDialog::restore ()
187 for (map<RGBA, RGBAColourPicker*>::const_iterator i = _pickers.begin(); i != _pickers.end(); ++i) {
188 i->second->set (i->first);
193 SubtitleAppearanceDialog::setup_sensitivity ()
195 _effect_colour->Enable (_effect->GetSelection() != NONE);
197 bool const can_outline_width = _effect->GetSelection() == OUTLINE && _content->subtitle->burn ();
198 _outline_width->Enable (can_outline_width);
199 if (can_outline_width) {
200 _outline_width->UnsetToolTip ();
202 _outline_width->SetToolTip (_("Outline width cannot be set unless you are burning in subtitles"));