Move _state_timer into VideoView.
[dcpomatic.git] / src / wx / filter_editor.cc
1 /*
2     Copyright (C) 2012-2018 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 /** @file  src/filter_editor.cc
22  *  @brief A panel to select FFmpeg filters.
23  */
24
25 #include "filter_editor.h"
26 #include "wx_util.h"
27 #include "static_text.h"
28 #include "check_box.h"
29 #include "lib/filter.h"
30 #include <iostream>
31 #include <algorithm>
32
33 using namespace std;
34
35 FilterEditor::FilterEditor (wxWindow* parent, vector<Filter const *> const & active)
36         : wxPanel (parent)
37 {
38         wxBoxSizer* sizer = new wxBoxSizer (wxVERTICAL);
39         SetSizer (sizer);
40
41         vector<Filter const *> filters = Filter::all ();
42
43         typedef map<string, list<Filter const *> > CategoryMap;
44         CategoryMap categories;
45
46         for (vector<Filter const *>::iterator i = filters.begin(); i != filters.end(); ++i) {
47                 CategoryMap::iterator j = categories.find ((*i)->category ());
48                 if (j == categories.end ()) {
49                         list<Filter const *> c;
50                         c.push_back (*i);
51                         categories[(*i)->category()] = c;
52                 } else {
53                         j->second.push_back (*i);
54                 }
55         }
56
57         for (CategoryMap::iterator i = categories.begin(); i != categories.end(); ++i) {
58
59                 wxStaticText* c = new StaticText (this, std_to_wx(i->first));
60                 wxFont font = c->GetFont();
61                 font.SetWeight(wxFONTWEIGHT_BOLD);
62                 c->SetFont(font);
63                 sizer->Add (c);
64
65                 for (list<Filter const *>::iterator j = i->second.begin(); j != i->second.end(); ++j) {
66                         wxCheckBox* b = new CheckBox (this, std_to_wx ((*j)->name ()));
67                         bool const a = find (active.begin(), active.end(), *j) != active.end ();
68                         b->SetValue (a);
69                         _filters[*j] = b;
70                         b->Bind (wxEVT_CHECKBOX, boost::bind (&FilterEditor::filter_toggled, this));
71                         sizer->Add (b);
72                 }
73
74                 sizer->AddSpacer (6);
75         }
76 }
77
78 void
79 FilterEditor::filter_toggled ()
80 {
81         ActiveChanged ();
82 }
83
84 vector<Filter const*>
85 FilterEditor::active () const
86 {
87         vector<Filter const *> active;
88         for (map<Filter const *, wxCheckBox*>::const_iterator i = _filters.begin(); i != _filters.end(); ++i) {
89                 if (i->second->IsChecked ()) {
90                         active.push_back (i->first);
91                 }
92         }
93
94         return active;
95 }