2 Copyright (C) 2015-2016 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 "text_subtitle_appearance_dialog.h"
22 #include "lib/text_subtitle_content.h"
23 #include "lib/subtitle_content.h"
25 #include <wx/clrpicker.h>
26 #include <wx/spinctrl.h>
27 #include <wx/gbsizer.h>
29 using boost::shared_ptr;
32 int const TextSubtitleAppearanceDialog::NONE = 0;
33 int const TextSubtitleAppearanceDialog::OUTLINE = 1;
34 int const TextSubtitleAppearanceDialog::SHADOW = 2;
36 TextSubtitleAppearanceDialog::TextSubtitleAppearanceDialog (wxWindow* parent, shared_ptr<Content> content)
37 : wxDialog (parent, wxID_ANY, _("Subtitle appearance"))
40 wxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
41 SetSizer (overall_sizer);
43 _table = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
45 overall_sizer->Add (_table, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
49 add_label_to_sizer (_table, this, _("Colour"), true, wxGBPosition (r, 0));
50 _colour = new wxColourPickerCtrl (this, wxID_ANY);
51 _table->Add (_colour, wxGBPosition (r, 1));
54 add_label_to_sizer (_table, this, _("Effect"), true, wxGBPosition (r, 0));
55 _effect = new wxChoice (this, wxID_ANY);
56 _table->Add (_effect, wxGBPosition (r, 1));
59 add_label_to_sizer (_table, this, _("Effect colour"), true, wxGBPosition (r, 0));
60 _effect_colour = new wxColourPickerCtrl (this, wxID_ANY);
61 _table->Add (_effect_colour, wxGBPosition (r, 1));
64 add_label_to_sizer (_table, this, _("Outline width"), true, wxGBPosition (r, 0));
65 _outline_width = new wxSpinCtrl (this, wxID_ANY);
66 _table->Add (_outline_width, wxGBPosition (r, 1));
69 add_label_to_sizer (_table, this, _("Fade in time"), true, wxGBPosition (r, 0));
70 _fade_in = new Timecode<ContentTime> (this);
71 _table->Add (_fade_in, wxGBPosition (r, 1));
74 add_label_to_sizer (_table, this, _("Fade out time"), true, wxGBPosition (r, 0));
75 _fade_out = new Timecode<ContentTime> (this);
76 _table->Add (_fade_out, wxGBPosition (r, 1));
79 wxSizer* buttons = CreateSeparatedButtonSizer (wxOK);
81 overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
84 overall_sizer->Layout ();
85 overall_sizer->SetSizeHints (this);
87 /* Keep these Appends() up to date with NONE/OUTLINE/SHADOW variables */
88 _effect->Append (_("None"));
89 _effect->Append (_("Outline"));
90 _effect->Append (_("Shadow"));;
92 _colour->SetColour (wxColour (_content->subtitle->colour().r, _content->subtitle->colour().g, _content->subtitle->colour().b));
93 if (_content->subtitle->outline()) {
94 _effect->SetSelection (OUTLINE);
95 } else if (_content->subtitle->shadow()) {
96 _effect->SetSelection (SHADOW);
98 _effect->SetSelection (NONE);
100 _effect_colour->SetColour (
101 wxColour (_content->subtitle->effect_colour().r, _content->subtitle->effect_colour().g, _content->subtitle->effect_colour().b)
103 _fade_in->set (_content->subtitle->fade_in(), _content->active_video_frame_rate ());
104 _fade_out->set (_content->subtitle->fade_out(), _content->active_video_frame_rate ());
105 _outline_width->SetValue (_content->subtitle->outline_width ());
107 _effect->Bind (wxEVT_CHOICE, bind (&TextSubtitleAppearanceDialog::setup_sensitivity, this));
108 _content_connection = _content->Changed.connect (bind (&TextSubtitleAppearanceDialog::setup_sensitivity, this));
110 setup_sensitivity ();
114 TextSubtitleAppearanceDialog::apply ()
116 wxColour const c = _colour->GetColour ();
117 _content->subtitle->set_colour (dcp::Colour (c.Red(), c.Green(), c.Blue()));
118 _content->subtitle->set_outline (_effect->GetSelection() == OUTLINE);
119 _content->subtitle->set_shadow (_effect->GetSelection() == SHADOW);
120 wxColour const ec = _effect_colour->GetColour ();
121 _content->subtitle->set_effect_colour (dcp::Colour (ec.Red(), ec.Green(), ec.Blue()));
122 _content->subtitle->set_fade_in (_fade_in->get (_content->active_video_frame_rate ()));
123 _content->subtitle->set_fade_out (_fade_out->get (_content->active_video_frame_rate ()));
124 _content->subtitle->set_outline_width (_outline_width->GetValue ());
128 TextSubtitleAppearanceDialog::setup_sensitivity ()
130 _effect_colour->Enable (_effect->GetSelection() != NONE);
132 bool const can_outline_width = _effect->GetSelection() == OUTLINE && _content->subtitle->burn ();
133 _outline_width->Enable (can_outline_width);
134 if (can_outline_width) {
135 _outline_width->UnsetToolTip ();
137 _outline_width->SetToolTip (_("Outline width cannot be set unless you are burning in subtitles"));