2 Copyright (C) 2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
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.
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.
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/>.
22 #include "auto_crop_dialog.h"
23 #include "dcpomatic_spin_ctrl.h"
25 #include "lib/config.h"
28 AutoCropDialog::AutoCropDialog (wxWindow* parent, Crop crop)
29 : TableDialog (parent, _("Auto crop"), 2, 1, true)
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));
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));
42 _left->SetRange(0, 4096);
43 _right->SetRange(0, 4096);
44 _top->SetRange(0, 4096);
45 _bottom->SetRange(0, 4096);
48 _threshold->SetValue (std::round(Config::instance()->auto_crop_threshold() * 100));
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); });
61 AutoCropDialog::get () const
63 return Crop(_left->GetValue(), _right->GetValue(), _top->GetValue(), _bottom->GetValue());
68 AutoCropDialog::set (Crop crop)
70 _left->SetValue (crop.left);
71 _right->SetValue (crop.right);
72 _top->SetValue (crop.top);
73 _bottom->SetValue (crop.bottom);