Supporters update.
[dcpomatic.git] / src / wx / auto_crop_dialog.cc
1 /*
2     Copyright (C) 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 #include "auto_crop_dialog.h"
23 #include "dcpomatic_spin_ctrl.h"
24 #include "wx_util.h"
25 #include "lib/config.h"
26
27
28 AutoCropDialog::AutoCropDialog (wxWindow* parent, Crop crop)
29         : TableDialog (parent, _("Auto crop"), 2, 1, true)
30 {
31         add (_("Left"), true);
32         _left = add(new SpinCtrl(this, DCPOMATIC_SPIN_CTRL_WIDTH));
33         add (_("Right"), true);
34         _right = add(new SpinCtrl(this, DCPOMATIC_SPIN_CTRL_WIDTH));
35         add (_("Top"), true);
36         _top = add(new SpinCtrl(this, DCPOMATIC_SPIN_CTRL_WIDTH));
37         add (_("Bottom"), true);
38         _bottom = add(new SpinCtrl(this, DCPOMATIC_SPIN_CTRL_WIDTH));
39         add (_("Threshold"), true);
40         _threshold = add(new SpinCtrl(this, DCPOMATIC_SPIN_CTRL_WIDTH));
41
42         _left->SetRange(0, 4096);
43         _right->SetRange(0, 4096);
44         _top->SetRange(0, 4096);
45         _bottom->SetRange(0, 4096);
46
47         set (crop);
48         _threshold->SetValue (std::round(Config::instance()->auto_crop_threshold() * 100));
49
50         layout ();
51
52         _left->Bind (wxEVT_SPINCTRL, [this](wxSpinEvent&) { Changed(get()); });
53         _right->Bind (wxEVT_SPINCTRL, [this](wxSpinEvent&) { Changed(get()); });
54         _top->Bind (wxEVT_SPINCTRL, [this](wxSpinEvent&) { Changed(get()); });
55         _bottom->Bind (wxEVT_SPINCTRL, [this](wxSpinEvent&) { Changed(get()); });
56         _threshold->Bind (wxEVT_SPINCTRL, [](wxSpinEvent& ev) { Config::instance()->set_auto_crop_threshold(ev.GetPosition() / 100.0); });
57 }
58
59
60 Crop
61 AutoCropDialog::get () const
62 {
63         return Crop(_left->GetValue(), _right->GetValue(), _top->GetValue(), _bottom->GetValue());
64 }
65
66
67 void
68 AutoCropDialog::set (Crop crop)
69 {
70         _left->SetValue (crop.left);
71         _right->SetValue (crop.right);
72         _top->SetValue (crop.top);
73         _bottom->SetValue (crop.bottom);
74 }
75