Work around strange build error on Ubuntu 18.04
[dcpomatic.git] / src / wx / standard_controls.cc
1 /*
2     Copyright (C) 2018-2021 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
22 #include "film_viewer.h"
23 #include "standard_controls.h"
24 #include <dcp/warnings.h>
25 LIBDCP_DISABLE_WARNINGS
26 #include <wx/tglbtn.h>
27 #include <wx/wx.h>
28 LIBDCP_ENABLE_WARNINGS
29
30
31 using std::shared_ptr;
32
33
34 StandardControls::StandardControls (wxWindow* parent, shared_ptr<FilmViewer> viewer, bool editor_controls)
35         : Controls (parent, viewer, editor_controls)
36         , _play_button (new wxToggleButton(this, wxID_ANY, _("Play")))
37 {
38         _button_sizer->Add (_play_button, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
39         _play_button->Bind (wxEVT_TOGGLEBUTTON, boost::bind(&StandardControls::play_clicked, this));
40 }
41
42
43 void
44 StandardControls::started ()
45 {
46         Controls::started ();
47         _play_button->SetValue (true);
48 }
49
50
51 void
52 StandardControls::stopped ()
53 {
54         Controls::stopped ();
55         _play_button->SetValue (false);
56 }
57
58
59 void
60 StandardControls::play_clicked ()
61 {
62         check_play_state ();
63 }
64
65
66 void
67 StandardControls::check_play_state ()
68 {
69         auto viewer = _viewer.lock ();
70         if (!_film || _film->video_frame_rate() == 0 || !viewer) {
71                 return;
72         }
73
74         if (_play_button->GetValue()) {
75                 viewer->start ();
76         } else {
77                 viewer->stop ();
78         }
79 }
80
81
82 void
83 StandardControls::setup_sensitivity ()
84 {
85         Controls::setup_sensitivity ();
86         bool const active_job = _active_job && *_active_job != "examine_content";
87         _play_button->Enable (_film && !_film->content().empty() && !active_job);
88 }
89
90
91 void
92 StandardControls::play ()
93 {
94         _play_button->SetValue (true);
95         play_clicked ();
96 }
97
98
99 void
100 StandardControls::stop ()
101 {
102         _play_button->SetValue (false);
103         play_clicked ();
104 }