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"
26 #include "lib/types.h"
29 AutoCropDialog::AutoCropDialog (wxWindow* parent, Crop crop)
30 : TableDialog (parent, _("Auto crop"), 2, 1, true)
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));
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));
43 _left->SetRange(0, 4096);
44 _right->SetRange(0, 4096);
45 _top->SetRange(0, 4096);
46 _bottom->SetRange(0, 4096);
49 _threshold->SetValue (std::round(Config::instance()->auto_crop_threshold() * 100));
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); });
62 AutoCropDialog::get () const
64 return Crop(_left->GetValue(), _right->GetValue(), _top->GetValue(), _bottom->GetValue());
69 AutoCropDialog::set (Crop crop)
71 _left->SetValue (crop.left);
72 _right->SetValue (crop.right);
73 _top->SetValue (crop.top);
74 _bottom->SetValue (crop.bottom);