0d102f23939d86901514f4a22c8dc214b9717be5
[dcpomatic.git] / src / wx / image_subtitle_colour_dialog.cc
1 /*
2     Copyright (C) 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 "image_subtitle_colour_dialog.h"
22 #include "rgba_colour_picker.h"
23 #include "wx_util.h"
24 #include "lib/ffmpeg_subtitle_stream.h"
25 #include "lib/ffmpeg_content.h"
26
27 using std::map;
28 using std::cout;
29 using boost::shared_ptr;
30 using boost::bind;
31
32 ImageSubtitleColourDialog::ImageSubtitleColourDialog (wxWindow* parent, shared_ptr<FFmpegContent> content, shared_ptr<FFmpegSubtitleStream> stream)
33         : wxDialog (parent, wxID_ANY, _("Subtitle colours"))
34         , _content (content)
35         , _stream (stream)
36 {
37         wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
38         SetSizer (overall_sizer);
39
40         wxScrolled<wxPanel>* colours_panel = new wxScrolled<wxPanel> (this);
41         colours_panel->EnableScrolling (false, true);
42         colours_panel->ShowScrollbars (wxSHOW_SB_NEVER, wxSHOW_SB_ALWAYS);
43         colours_panel->SetScrollRate (0, 16);
44
45         wxFlexGridSizer* table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
46         table->AddGrowableCol (1, 1);
47
48         map<RGBA, RGBA> colours = _stream->colours ();
49
50         wxStaticText* t = new wxStaticText (colours_panel, wxID_ANY, "");
51         t->SetLabelMarkup (_("<b>Original colour</b>"));
52         table->Add (t, 1, wxEXPAND);
53         t = new wxStaticText (colours_panel, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE_HORIZONTAL);
54         t->SetLabelMarkup (_("<b>New colour</b>"));
55         table->Add (t, 1, wxALIGN_CENTER);
56
57         for (map<RGBA, RGBA>::const_iterator i = colours.begin(); i != colours.end(); ++i) {
58                 wxPanel* from = new wxPanel (colours_panel, wxID_ANY);
59                 from->SetBackgroundColour (wxColour (i->first.r, i->first.g, i->first.b, i->first.a));
60                 table->Add (from, 1, wxEXPAND);
61                 RGBAColourPicker* to = new RGBAColourPicker (colours_panel, i->second);
62                 table->Add (to, 1, wxEXPAND);
63                 _pickers[i->first] = to;
64         }
65
66         colours_panel->SetSizer (table);
67
68         overall_sizer->Add (colours_panel, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
69
70         wxButton* restore = new wxButton (this, wxID_ANY, _("Restore to original colours"));
71         restore->Bind (wxEVT_BUTTON, bind (&ImageSubtitleColourDialog::restore, this));
72         overall_sizer->Add (restore, 0, wxALL, DCPOMATIC_SIZER_X_GAP);
73
74         wxSizer* buttons = CreateSeparatedButtonSizer (wxOK | wxCANCEL);
75         if (buttons) {
76                 overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
77         }
78 }
79
80 void
81 ImageSubtitleColourDialog::apply ()
82 {
83         for (map<RGBA, RGBAColourPicker*>::const_iterator i = _pickers.begin(); i != _pickers.end(); ++i) {
84                 _stream->set_colour (i->first, i->second->colour ());
85         }
86
87         _content->signal_subtitle_stream_changed ();
88 }
89
90 void
91 ImageSubtitleColourDialog::restore ()
92 {
93         for (map<RGBA, RGBAColourPicker*>::const_iterator i = _pickers.begin(); i != _pickers.end(); ++i) {
94                 i->second->set (i->first);
95         }
96 }