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