summaryrefslogtreecommitdiff
path: root/src/wx/filter_dialog.cc
blob: 517978c746b145040422f86706c25ae224bd848a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
    Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>

    This file is part of DCP-o-matic.

    DCP-o-matic is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    DCP-o-matic is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.

*/


/** @file  src/filter_dialog.cc
 *  @brief A dialog to select FFmpeg filters.
 */


#include "check_box.h"
#include "filter_dialog.h"
#include "static_text.h"
#include "wx_util.h"
#include "lib/film.h"
#include "lib/filter.h"


using namespace std;
using boost::bind;


FilterDialog::FilterDialog(wxWindow* parent, vector<Filter> const& active)
	: wxDialog (parent, wxID_ANY, wxString(_("Filters")))
{
	auto panel = new wxPanel (this);
	auto sizer = new wxBoxSizer (wxVERTICAL);

	auto filters = Filter::all ();

	map<string, list<Filter>> categories;

	for (auto i: filters) {
		auto j = categories.find(i.category());
		if (j == categories.end ()) {
			categories[i.category()] = { i };
		} else {
			j->second.push_back (i);
		}
	}

	for (auto const& category: categories) {
		auto c = new StaticText(panel, std_to_wx(category.first));
		auto font = c->GetFont();
		font.SetWeight(wxFONTWEIGHT_BOLD);
		c->SetFont(font);
		sizer->Add (c, 1, wxTOP | wxBOTTOM, DCPOMATIC_SIZER_GAP);

		for (auto const& filter: category.second) {
			auto b = new CheckBox(panel, std_to_wx(filter.name()));
			bool const a = find(active.begin(), active.end(), filter) != active.end();
			b->SetValue (a);
			_filters[filter] = b;
			b->bind(&FilterDialog::filter_toggled, this);
			sizer->Add (b);
		}

		sizer->AddSpacer (6);
	}

	panel->SetSizer (sizer);

	auto overall_sizer = new wxBoxSizer (wxVERTICAL);
	overall_sizer->Add (panel, 1, wxTOP | wxLEFT | wxRIGHT, DCPOMATIC_SIZER_GAP);

	auto buttons = CreateSeparatedButtonSizer(wxOK);
	if (buttons) {
		overall_sizer->Add(buttons, wxSizerFlags().Expand().DoubleBorder());
	}

	SetSizerAndFit (overall_sizer);
}


void
FilterDialog::filter_toggled ()
{
	ActiveChanged (active());
}


vector<Filter>
FilterDialog::active () const
{
	vector<Filter> active;
	for (auto const& i: _filters) {
		if (i.second->IsChecked()) {
			active.push_back(i.first);
		}
	}

	return active;
}