Add FilmViewer::time_until_next_frame.
[dcpomatic.git] / src / wx / standard_controls.cc
1 /*
2     Copyright (C) 2018 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 #include "standard_controls.h"
22 #include "film_viewer.h"
23 #include <wx/wx.h>
24 #include <wx/tglbtn.h>
25
26 using boost::shared_ptr;
27
28 StandardControls::StandardControls (wxWindow* parent, shared_ptr<FilmViewer> viewer, bool editor_controls)
29         : Controls (parent, viewer, editor_controls)
30         , _play_button (new wxToggleButton(this, wxID_ANY, _("Play")))
31 {
32         _button_sizer->Add (_play_button, 0, wxEXPAND);
33         _play_button->Bind (wxEVT_TOGGLEBUTTON, boost::bind(&StandardControls::play_clicked, this));
34 }
35
36 void
37 StandardControls::started ()
38 {
39         Controls::started ();
40         _play_button->SetValue (true);
41 }
42
43 void
44 StandardControls::stopped ()
45 {
46         Controls::stopped ();
47         _play_button->SetValue (false);
48 }
49
50 void
51 StandardControls::play_clicked ()
52 {
53         check_play_state ();
54 }
55
56 void
57 StandardControls::check_play_state ()
58 {
59         if (!_film || _film->video_frame_rate() == 0) {
60                 return;
61         }
62
63         if (_play_button->GetValue()) {
64                 _viewer->start ();
65         } else {
66                 _viewer->stop ();
67         }
68 }
69
70 void
71 StandardControls::setup_sensitivity ()
72 {
73         Controls::setup_sensitivity ();
74         bool const active_job = _active_job && *_active_job != "examine_content";
75         _play_button->Enable (_film && !_film->content().empty() && !active_job);
76 }