2 Copyright (C) 2013-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 #ifndef DCPOMATIC_WX_TIMECODE_H
23 #define DCPOMATIC_WX_TIMECODE_H
27 #include "lib/dcpomatic_time.h"
28 #include <dcp/raw_convert.h>
29 #include <dcp/warnings.h>
30 LIBDCP_DISABLE_WARNINGS
32 LIBDCP_ENABLE_WARNINGS
33 #include <boost/signals2.hpp>
36 class TimecodeBase : public wxPanel
39 TimecodeBase (wxWindow *, bool set_button);
43 void set_editable (bool);
46 boost::signals2::signal<void ()> Changed;
48 static wxSize size (wxWindow* parent);
53 virtual bool valid() const = 0;
61 wxButton* _set_button;
64 bool _ignore_changed = false;
69 class Timecode : public TimecodeBase
72 Timecode (wxWindow* parent, bool set_button = true)
73 : TimecodeBase (parent, set_button)
78 void set (T t, float fps)
80 auto const hmsf = t.split (fps);
82 checked_set (_hours, dcp::raw_convert<std::string>(hmsf.h));
83 checked_set (_minutes, dcp::raw_convert<std::string>(hmsf.m));
84 checked_set (_seconds, dcp::raw_convert<std::string>(hmsf.s));
85 checked_set (_frames, dcp::raw_convert<std::string>(hmsf.f));
87 checked_set (_fixed, t.timecode (fps));
90 void set_hint (T t, float fps)
92 auto hmsf = t.split (fps);
94 _hours->SetHint (std_to_wx(dcp::raw_convert<std::string>(hmsf.h)));
95 _minutes->SetHint (std_to_wx(dcp::raw_convert<std::string>(hmsf.m)));
96 _seconds->SetHint (std_to_wx(dcp::raw_convert<std::string>(hmsf.s)));
97 _frames->SetHint (std_to_wx(dcp::raw_convert<std::string>(hmsf.f)));
100 void set_maximum(dcpomatic::HMSF maximum)
102 _maximum = std::move(maximum);
105 dcpomatic::HMSF get () const
107 auto value_or_hint = [](wxTextCtrl const * t) {
108 auto s = wx_to_std (t->GetValue().IsEmpty() ? t->GetHint() : t->GetValue());
112 return dcp::raw_convert<int>(s);
115 return { value_or_hint(_hours),
116 value_or_hint(_minutes),
117 value_or_hint(_seconds),
118 value_or_hint(_frames) };
121 T get (float fps) const
123 return T(get(), fps);
127 bool valid() const override {
128 return !_maximum || get() <= *_maximum;
131 boost::optional<dcpomatic::HMSF> _maximum;