Add go-to-position dialogue when clicking on preview timecode.
[dcpomatic.git] / src / wx / timecode.h
1 /*
2     Copyright (C) 2013-2016 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 #ifndef DCPOMATIC_WX_TIMECODE_H
22 #define DCPOMATIC_WX_TIMECODE_H
23
24 #include "wx_util.h"
25 #include "lib/types.h"
26 #include <wx/wx.h>
27 #include <boost/signals2.hpp>
28 #include <boost/lexical_cast.hpp>
29
30 class TimecodeBase : public wxPanel
31 {
32 public:
33         TimecodeBase (wxWindow *, bool set_button);
34
35         void clear ();
36
37         void set_editable (bool);
38
39         boost::signals2::signal<void ()> Changed;
40
41         static wxSize size (wxWindow* parent);
42
43 protected:
44         void changed ();
45         void set_clicked ();
46
47         wxSizer* _sizer;
48         wxPanel* _editable;
49         wxTextCtrl* _hours;
50         wxTextCtrl* _minutes;
51         wxTextCtrl* _seconds;
52         wxTextCtrl* _frames;
53         wxButton* _set_button;
54         wxStaticText* _fixed;
55 };
56
57 template <class T>
58 class Timecode : public TimecodeBase
59 {
60 public:
61         Timecode (wxWindow* parent, bool set_button = true)
62                 : TimecodeBase (parent, set_button)
63         {
64
65         }
66
67         void set (T t, float fps)
68         {
69                 int h;
70                 int m;
71                 int s;
72                 int f;
73                 t.split (fps, h, m, s, f);
74
75                 checked_set (_hours, boost::lexical_cast<std::string> (h));
76                 checked_set (_minutes, boost::lexical_cast<std::string> (m));
77                 checked_set (_seconds, boost::lexical_cast<std::string> (s));
78                 checked_set (_frames, boost::lexical_cast<std::string> (f));
79
80                 checked_set (_fixed, t.timecode (fps));
81         }
82
83         T get (int fps) const
84         {
85                 T t;
86                 std::string const h = wx_to_std (_hours->GetValue ());
87                 t += T::from_seconds (boost::lexical_cast<int> (h.empty() ? "0" : h) * 3600);
88                 std::string const m = wx_to_std (_minutes->GetValue());
89                 t += T::from_seconds (boost::lexical_cast<int> (m.empty() ? "0" : m) * 60);
90                 std::string const s = wx_to_std (_seconds->GetValue());
91                 t += T::from_seconds (boost::lexical_cast<int> (s.empty() ? "0" : s));
92                 std::string const f = wx_to_std (_frames->GetValue());
93                 t += T::from_seconds (boost::lexical_cast<double> (f.empty() ? "0" : f) / fps);
94
95                 return t;
96         }
97 };
98
99 #endif