Supporters update.
[dcpomatic.git] / src / wx / filter_dialog.cc
1 /*
2     Copyright (C) 2012-2021 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
22 /** @file  src/filter_dialog.cc
23  *  @brief A dialog to select FFmpeg filters.
24  */
25
26
27 #include "check_box.h"
28 #include "filter_dialog.h"
29 #include "static_text.h"
30 #include "wx_util.h"
31 #include "lib/film.h"
32 #include "lib/filter.h"
33
34
35 using namespace std;
36 using boost::bind;
37
38
39 FilterDialog::FilterDialog(wxWindow* parent, vector<Filter> const& active)
40         : wxDialog (parent, wxID_ANY, wxString(_("Filters")))
41 {
42         auto panel = new wxPanel (this);
43         auto sizer = new wxBoxSizer (wxVERTICAL);
44
45         auto filters = Filter::all ();
46
47         map<string, list<Filter>> categories;
48
49         for (auto i: filters) {
50                 auto j = categories.find(i.category());
51                 if (j == categories.end ()) {
52                         categories[i.category()] = { i };
53                 } else {
54                         j->second.push_back (i);
55                 }
56         }
57
58         for (auto const& category: categories) {
59                 auto c = new StaticText(panel, std_to_wx(category.first));
60                 auto font = c->GetFont();
61                 font.SetWeight(wxFONTWEIGHT_BOLD);
62                 c->SetFont(font);
63                 sizer->Add (c, 1, wxTOP | wxBOTTOM, DCPOMATIC_SIZER_GAP);
64
65                 for (auto const& filter: category.second) {
66                         auto b = new CheckBox(panel, std_to_wx(filter.name()));
67                         bool const a = find(active.begin(), active.end(), filter) != active.end();
68                         b->SetValue (a);
69                         _filters[filter] = b;
70                         b->bind(&FilterDialog::filter_toggled, this);
71                         sizer->Add (b);
72                 }
73
74                 sizer->AddSpacer (6);
75         }
76
77         panel->SetSizer (sizer);
78
79         auto overall_sizer = new wxBoxSizer (wxVERTICAL);
80         overall_sizer->Add (panel, 1, wxTOP | wxLEFT | wxRIGHT, DCPOMATIC_SIZER_GAP);
81
82         auto buttons = CreateSeparatedButtonSizer(wxOK);
83         if (buttons) {
84                 overall_sizer->Add(buttons, wxSizerFlags().Expand().DoubleBorder());
85         }
86
87         SetSizerAndFit (overall_sizer);
88 }
89
90
91 void
92 FilterDialog::filter_toggled ()
93 {
94         ActiveChanged (active());
95 }
96
97
98 vector<Filter>
99 FilterDialog::active () const
100 {
101         vector<Filter> active;
102         for (auto const& i: _filters) {
103                 if (i.second->IsChecked()) {
104                         active.push_back(i.first);
105                 }
106         }
107
108         return active;
109 }
110