Note whether subtitle effect colour is forced or not.
authorCarl Hetherington <cth@carlh.net>
Fri, 12 Jan 2018 13:04:46 +0000 (13:04 +0000)
committerCarl Hetherington <cth@carlh.net>
Sat, 13 Jan 2018 00:06:28 +0000 (00:06 +0000)
src/lib/subtitle_content.cc
src/lib/subtitle_content.h
src/lib/subtitle_decoder.cc
src/wx/subtitle_appearance_dialog.cc
src/wx/subtitle_appearance_dialog.h

index b169cfb69beebd31a7e8a9ea0c4b46d2668db092..0083ff8a2baf85dfd65e891fbd19ac007c5c3ba4 100644 (file)
@@ -67,7 +67,6 @@ SubtitleContent::SubtitleContent (Content* parent)
        , _y_scale (1)
        , _outline (false)
        , _shadow (false)
-       , _effect_colour (0, 0, 0)
        , _line_spacing (1)
        , _outline_width (2)
 {
@@ -137,11 +136,12 @@ SubtitleContent::SubtitleContent (Content* parent, cxml::ConstNodePtr node, int
        }
 
        if (version >= 36) {
-               _effect_colour = dcp::Colour (
-                       node->optional_number_child<int>("EffectRed").get_value_or(255),
-                       node->optional_number_child<int>("EffectGreen").get_value_or(255),
-                       node->optional_number_child<int>("EffectBlue").get_value_or(255)
-                       );
+               optional<int> er = node->optional_number_child<int>("EffectRed");
+               optional<int> eg = node->optional_number_child<int>("EffectGreen");
+               optional<int> eb = node->optional_number_child<int>("EffectBlue");
+               if (er && eg && eb) {
+                       _effect_colour = dcp::Colour (*er, *eg, *eb);
+               }
        } else {
                _effect_colour = dcp::Colour (
                        node->optional_number_child<int>("OutlineRed").get_value_or(255),
@@ -258,9 +258,11 @@ SubtitleContent::as_xml (xmlpp::Node* root) const
        }
        root->add_child("Outline")->add_child_text (_outline ? "1" : "0");
        root->add_child("Shadow")->add_child_text (_shadow ? "1" : "0");
-       root->add_child("EffectRed")->add_child_text (raw_convert<string> (_effect_colour.r));
-       root->add_child("EffectGreen")->add_child_text (raw_convert<string> (_effect_colour.g));
-       root->add_child("EffectBlue")->add_child_text (raw_convert<string> (_effect_colour.b));
+       if (_effect_colour) {
+               root->add_child("EffectRed")->add_child_text (raw_convert<string> (_effect_colour->r));
+               root->add_child("EffectGreen")->add_child_text (raw_convert<string> (_effect_colour->g));
+               root->add_child("EffectBlue")->add_child_text (raw_convert<string> (_effect_colour->b));
+       }
        root->add_child("LineSpacing")->add_child_text (raw_convert<string> (_line_spacing));
        root->add_child("SubtitleFadeIn")->add_child_text (raw_convert<string> (_fade_in.get()));
        root->add_child("SubtitleFadeOut")->add_child_text (raw_convert<string> (_fade_out.get()));
@@ -356,6 +358,12 @@ SubtitleContent::set_effect_colour (dcp::Colour colour)
        maybe_set (_effect_colour, colour, SubtitleContentProperty::EFFECT_COLOUR);
 }
 
+void
+SubtitleContent::unset_effect_colour ()
+{
+       maybe_set (_effect_colour, optional<dcp::Colour>(), SubtitleContentProperty::EFFECT_COLOUR);
+}
+
 void
 SubtitleContent::set_use (bool u)
 {
@@ -439,7 +447,11 @@ SubtitleContent::take_settings_from (shared_ptr<const SubtitleContent> c)
        }
        set_outline (c->_outline);
        set_shadow (c->_shadow);
-       set_effect_colour (c->_effect_colour);
+       if (c->_effect_colour) {
+               set_effect_colour (*c->_effect_colour);
+       } else {
+               unset_effect_colour ();
+       }
        set_line_spacing (c->_line_spacing);
        set_fade_in (c->_fade_in);
        set_fade_out (c->_fade_out);
index b071824069282fc997fe52cd1fce873e0c08c023..baf412bb6aafb28ea3ad8af21b15c2d6b97ebddb 100644 (file)
@@ -79,6 +79,7 @@ public:
        void set_outline (bool);
        void set_shadow (bool);
        void set_effect_colour (dcp::Colour);
+       void unset_effect_colour ();
        void set_line_spacing (double s);
        void set_fade_in (ContentTime);
        void set_fade_out (ContentTime);
@@ -139,7 +140,7 @@ public:
                return _shadow;
        }
 
-       dcp::Colour effect_colour () const {
+       boost::optional<dcp::Colour> effect_colour () const {
                boost::mutex::scoped_lock lm (_mutex);
                return _effect_colour;
        }
@@ -197,7 +198,7 @@ private:
        boost::optional<dcp::Colour> _colour;
        bool _outline;
        bool _shadow;
-       dcp::Colour _effect_colour;
+       boost::optional<dcp::Colour> _effect_colour;
        /** scaling factor for line spacing; 1 is "standard", < 1 is closer together, > 1 is further apart */
        double _line_spacing;
        ContentTime _fade_in;
index eecfce19dde7f05a65fcee9200eab9f4536317cf..8badf5183892a19107678d7c4b532250dfd5a426 100644 (file)
@@ -79,7 +79,9 @@ SubtitleDecoder::emit_text_start (ContentTime from, list<dcp::SubtitleString> s)
                if (content()->colour()) {
                        i.set_colour (*content()->colour());
                }
-               i.set_effect_colour (content()->effect_colour());
+               if (content()->effect_colour()) {
+                       i.set_effect_colour (*content()->effect_colour());
+               }
                if (content()->outline()) {
                        i.set_effect (dcp::BORDER);
                } else if (content()->shadow()) {
index c72ef773625fa7eb96e7797678197365f1622dac..5cb668e7ba69b6466aef4981346b2a39d3fc8c60 100644 (file)
@@ -74,8 +74,14 @@ SubtitleAppearanceDialog::SubtitleAppearanceDialog (wxWindow* parent, shared_ptr
        ++r;
 
        add_label_to_sizer (_table, this, _("Effect colour"), true, wxGBPosition (r, 0));
-       _effect_colour = new wxColourPickerCtrl (this, wxID_ANY);
-       _table->Add (_effect_colour, wxGBPosition (r, 1));
+       {
+               wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
+               _force_effect_colour = new wxCheckBox (this, wxID_ANY, _("Set to"));
+               s->Add (_force_effect_colour, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 8);
+               _effect_colour = new wxColourPickerCtrl (this, wxID_ANY);
+               s->Add (_effect_colour, 0, wxALIGN_CENTER_VERTICAL);
+               _table->Add (s, wxGBPosition (r, 1));
+       }
        ++r;
 
        add_label_to_sizer (_table, this, _("Outline width"), true, wxGBPosition (r, 0));
@@ -158,14 +164,22 @@ SubtitleAppearanceDialog::SubtitleAppearanceDialog (wxWindow* parent, shared_ptr
        } else {
                _effect->SetSelection (NONE);
        }
-       _effect_colour->SetColour (
-               wxColour (_content->subtitle->effect_colour().r, _content->subtitle->effect_colour().g, _content->subtitle->effect_colour().b)
-               );
+
+       optional<dcp::Colour> effect_colour = _content->subtitle->effect_colour();
+       if (effect_colour) {
+               _force_effect_colour->SetValue (true);
+               _effect_colour->SetColour (wxColour (effect_colour->r, effect_colour->g, effect_colour->b));
+       } else {
+               _force_effect_colour->SetValue (false);
+               _effect_colour->SetColour (wxColour (0, 0, 0));
+       }
+
        _fade_in->set (_content->subtitle->fade_in(), _content->active_video_frame_rate ());
        _fade_out->set (_content->subtitle->fade_out(), _content->active_video_frame_rate ());
        _outline_width->SetValue (_content->subtitle->outline_width ());
 
        _force_colour->Bind (wxEVT_CHECKBOX, bind (&SubtitleAppearanceDialog::setup_sensitivity, this));
+       _force_effect_colour->Bind (wxEVT_CHECKBOX, bind (&SubtitleAppearanceDialog::setup_sensitivity, this));
        _effect->Bind (wxEVT_CHOICE, bind (&SubtitleAppearanceDialog::setup_sensitivity, this));
        _content_connection = _content->Changed.connect (bind (&SubtitleAppearanceDialog::setup_sensitivity, this));
 
@@ -183,8 +197,12 @@ SubtitleAppearanceDialog::apply ()
        }
        _content->subtitle->set_outline (_effect->GetSelection() == OUTLINE);
        _content->subtitle->set_shadow (_effect->GetSelection() == SHADOW);
-       wxColour const ec = _effect_colour->GetColour ();
-       _content->subtitle->set_effect_colour (dcp::Colour (ec.Red(), ec.Green(), ec.Blue()));
+       if (_force_effect_colour->GetValue ()) {
+               wxColour const ec = _effect_colour->GetColour ();
+               _content->subtitle->set_effect_colour (dcp::Colour (ec.Red(), ec.Green(), ec.Blue()));
+       } else {
+               _content->subtitle->unset_effect_colour ();
+       }
        _content->subtitle->set_fade_in (_fade_in->get (_content->active_video_frame_rate ()));
        _content->subtitle->set_fade_out (_fade_out->get (_content->active_video_frame_rate ()));
        _content->subtitle->set_outline_width (_outline_width->GetValue ());
@@ -213,7 +231,7 @@ void
 SubtitleAppearanceDialog::setup_sensitivity ()
 {
        _colour->Enable (_force_colour->GetValue ());
-       _effect_colour->Enable (_effect->GetSelection() != NONE);
+       _effect_colour->Enable (_force_effect_colour->GetValue ());
 
        bool const can_outline_width = _effect->GetSelection() == OUTLINE && _content->subtitle->burn ();
        _outline_width->Enable (can_outline_width);
index 8d36d4da83e27bb99f266959bacc0d7fa2b97e85..99eba133ab15b55b96bf78b65012d3fb7ae54a8e 100644 (file)
@@ -45,6 +45,7 @@ private:
        wxCheckBox* _force_colour;
        wxColourPickerCtrl* _colour;
        wxChoice* _effect;
+       wxCheckBox* _force_effect_colour;
        wxColourPickerCtrl* _effect_colour;
        Timecode<ContentTime>* _fade_in;
        Timecode<ContentTime>* _fade_out;