4dd18004bfcae15547363c413b99d59f93236a6a
[dcpomatic.git] / src / wx / filter_editor.cc
1 /*
2     Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 /** @file  src/filter_editor.cc
21  *  @brief A panel to select FFmpeg filters.
22  */
23
24 #include <iostream>
25 #include <algorithm>
26 #include "lib/filter.h"
27 #include "filter_editor.h"
28 #include "wx_util.h"
29
30 using namespace std;
31
32 FilterEditor::FilterEditor (wxWindow* parent, vector<Filter const *> const & active)
33         : wxPanel (parent)
34 {
35         wxBoxSizer* sizer = new wxBoxSizer (wxVERTICAL);
36         SetSizer (sizer);
37         
38         vector<Filter const *> filters = Filter::all ();
39
40         typedef map<string, list<Filter const *> > CategoryMap;
41         CategoryMap categories;
42
43         for (vector<Filter const *>::iterator i = filters.begin(); i != filters.end(); ++i) {
44                 CategoryMap::iterator j = categories.find ((*i)->category ());
45                 if (j == categories.end ()) {
46                         list<Filter const *> c;
47                         c.push_back (*i);
48                         categories[(*i)->category()] = c;
49                 } else {
50                         j->second.push_back (*i);
51                 }
52         }
53
54         for (CategoryMap::iterator i = categories.begin(); i != categories.end(); ++i) {
55
56                 wxStaticText* c = new wxStaticText (this, wxID_ANY, std_to_wx (i->first));
57                 wxFont font = c->GetFont();
58                 font.SetWeight(wxFONTWEIGHT_BOLD);
59                 c->SetFont(font);
60                 sizer->Add (c);
61
62                 for (list<Filter const *>::iterator j = i->second.begin(); j != i->second.end(); ++j) {
63                         wxCheckBox* b = new wxCheckBox (this, wxID_ANY, std_to_wx ((*j)->name ()));
64                         bool const a = find (active.begin(), active.end(), *j) != active.end ();
65                         b->SetValue (a);
66                         _filters[*j] = b;
67                         b->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&FilterEditor::filter_toggled, this));
68                         sizer->Add (b);
69                 }
70
71                 sizer->AddSpacer (6);
72         }
73 }
74
75 void
76 FilterEditor::filter_toggled ()
77 {
78         ActiveChanged ();
79 }
80
81 vector<Filter const*>
82 FilterEditor::active () const
83 {
84         vector<Filter const *> active;
85         for (map<Filter const *, wxCheckBox*>::const_iterator i = _filters.begin(); i != _filters.end(); ++i) {
86                 if (i->second->IsChecked ()) {
87                         active.push_back (i->first);
88                 }
89         }
90
91         return active;
92 }