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