Make burnt-in subtitle outline width configurable (#940).
[dcpomatic.git] / src / wx / text_subtitle_appearance_dialog.cc
1 /*
2     Copyright (C) 2015-2016 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
21 #include "text_subtitle_appearance_dialog.h"
22 #include "lib/text_subtitle_content.h"
23 #include "lib/subtitle_content.h"
24 #include <wx/wx.h>
25 #include <wx/clrpicker.h>
26 #include <wx/spinctrl.h>
27
28 using boost::shared_ptr;
29 using boost::bind;
30
31 int const TextSubtitleAppearanceDialog::NONE = 0;
32 int const TextSubtitleAppearanceDialog::OUTLINE = 1;
33 int const TextSubtitleAppearanceDialog::SHADOW = 2;
34
35 TextSubtitleAppearanceDialog::TextSubtitleAppearanceDialog (wxWindow* parent, shared_ptr<Content> content)
36         : TableDialog (parent, _("Subtitle appearance"), 2, 1, true)
37         , _content (content)
38 {
39         add (_("Colour"), true);
40         _colour = new wxColourPickerCtrl (this, wxID_ANY);
41         add (_colour);
42
43         add (_("Effect"), true);
44         add (_effect = new wxChoice (this, wxID_ANY));
45
46         add (_("Outline / shadow colour"), true);
47         add (_effect_colour = new wxColourPickerCtrl (this, wxID_ANY));
48
49         add (_("Outline width"), true);
50         add (_outline_width = new wxSpinCtrl (this, wxID_ANY));
51
52         add (_("Fade in time"), true);
53         _fade_in = new Timecode<ContentTime> (this);
54         add (_fade_in);
55
56         add (_("Fade out time"), true);
57         _fade_out = new Timecode<ContentTime> (this);
58         add (_fade_out);
59
60         layout ();
61
62         /* Keep these Appends() up to date with NONE/OUTLINE/SHADOW variables */
63         _effect->Append (_("None"));
64         _effect->Append (_("Outline"));
65         _effect->Append (_("Shadow"));;
66
67         _colour->SetColour (wxColour (_content->subtitle->colour().r, _content->subtitle->colour().g, _content->subtitle->colour().b));
68         if (_content->subtitle->outline()) {
69                 _effect->SetSelection (OUTLINE);
70         } else if (_content->subtitle->shadow()) {
71                 _effect->SetSelection (SHADOW);
72         } else {
73                 _effect->SetSelection (NONE);
74         }
75         _effect_colour->SetColour (
76                 wxColour (_content->subtitle->effect_colour().r, _content->subtitle->effect_colour().g, _content->subtitle->effect_colour().b)
77                 );
78         _fade_in->set (_content->subtitle->fade_in(), _content->active_video_frame_rate ());
79         _fade_out->set (_content->subtitle->fade_out(), _content->active_video_frame_rate ());
80         _outline_width->SetValue (_content->subtitle->outline_width ());
81
82         _effect->Bind (wxEVT_COMMAND_CHOICE_SELECTED, bind (&TextSubtitleAppearanceDialog::setup_sensitivity, this));
83         _content_connection = _content->Changed.connect (bind (&TextSubtitleAppearanceDialog::setup_sensitivity, this));
84
85         setup_sensitivity ();
86 }
87
88 void
89 TextSubtitleAppearanceDialog::apply ()
90 {
91         wxColour const c = _colour->GetColour ();
92         _content->subtitle->set_colour (dcp::Colour (c.Red(), c.Green(), c.Blue()));
93         _content->subtitle->set_outline (_effect->GetSelection() == OUTLINE);
94         _content->subtitle->set_shadow (_effect->GetSelection() == SHADOW);
95         wxColour const ec = _effect_colour->GetColour ();
96         _content->subtitle->set_effect_colour (dcp::Colour (ec.Red(), ec.Green(), ec.Blue()));
97         _content->subtitle->set_fade_in (_fade_in->get (_content->active_video_frame_rate ()));
98         _content->subtitle->set_fade_out (_fade_out->get (_content->active_video_frame_rate ()));
99         _content->subtitle->set_outline_width (_outline_width->GetValue ());
100 }
101
102 void
103 TextSubtitleAppearanceDialog::setup_sensitivity ()
104 {
105         _effect_colour->Enable (_effect->GetSelection() != NONE);
106
107         bool const can_outline_width = _effect->GetSelection() == OUTLINE && _content->subtitle->burn ();
108         _outline_width->Enable (can_outline_width);
109         if (can_outline_width) {
110                 _outline_width->SetToolTip (_("Outline width cannot be set unless you are burning in subtitles"));
111         } else {
112                 _outline_width->UnsetToolTip ();
113         }
114 }