Supporters update.
[dcpomatic.git] / src / wx / timeline_dialog.cc
1 /*
2     Copyright (C) 2013-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 "content_panel.h"
23 #include "film_editor.h"
24 #include "timeline_dialog.h"
25 #include "wx_util.h"
26 #include "lib/compose.hpp"
27 #include "lib/cross.h"
28 #include "lib/film.h"
29 #include "lib/playlist.h"
30 #include <dcp/warnings.h>
31 LIBDCP_DISABLE_WARNINGS
32 #include <wx/graphics.h>
33 LIBDCP_ENABLE_WARNINGS
34 #include <list>
35
36
37 using std::list;
38 using std::shared_ptr;
39 using std::string;
40 using std::weak_ptr;
41 #if BOOST_VERSION >= 106100
42 using namespace boost::placeholders;
43 #endif
44
45
46 TimelineDialog::TimelineDialog(ContentPanel* cp, shared_ptr<Film> film, FilmViewer& viewer)
47         : wxDialog (
48                 cp->window(),
49                 wxID_ANY,
50                 _("Timeline"),
51                 wxDefaultPosition,
52                 wxSize (640, 512),
53 #ifdef DCPOMATIC_OSX
54                 /* I can't get wxFRAME_FLOAT_ON_PARENT to work on OS X, and although wxSTAY_ON_TOP keeps
55                    the window above all others (and not just our own) it's better than nothing for now.
56                 */
57                 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxFULL_REPAINT_ON_RESIZE | wxSTAY_ON_TOP
58 #else
59                 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxFULL_REPAINT_ON_RESIZE | wxFRAME_FLOAT_ON_PARENT
60 #endif
61                 )
62         , _film (film)
63         , _timeline (this, cp, film, viewer)
64 {
65         auto sizer = new wxBoxSizer (wxVERTICAL);
66
67         wxBitmap select(icon_path("select"), wxBITMAP_TYPE_PNG);
68         wxBitmap zoom(icon_path("zoom"), wxBITMAP_TYPE_PNG);
69         wxBitmap zoom_all(icon_path("zoom_all"), wxBITMAP_TYPE_PNG);
70         wxBitmap snap(icon_path("snap"), wxBITMAP_TYPE_PNG);
71         wxBitmap sequence(icon_path("sequence"), wxBITMAP_TYPE_PNG);
72
73         _toolbar = new wxToolBar (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTB_HORIZONTAL);
74         _toolbar->SetMargins (4, 4);
75         _toolbar->SetToolBitmapSize (wxSize(32, 32));
76         _toolbar->AddRadioTool ((int) Timeline::SELECT, _("Select"), select, wxNullBitmap, _("Select and move content"));
77         _toolbar->AddRadioTool ((int) Timeline::ZOOM, _("Zoom"), zoom, wxNullBitmap, _("Zoom in / out"));
78         _toolbar->AddTool ((int) Timeline::ZOOM_ALL, _("Zoom all"), zoom_all, _("Zoom out to whole film"));
79         _toolbar->AddCheckTool ((int) Timeline::SNAP, _("Snap"), snap, wxNullBitmap, _("Snap"));
80         _toolbar->AddCheckTool ((int) Timeline::SEQUENCE, _("Sequence"), sequence, wxNullBitmap, _("Keep video and subtitles in sequence"));
81         _toolbar->Realize ();
82
83         _toolbar->Bind (wxEVT_TOOL, bind (&TimelineDialog::tool_clicked, this, _1));
84
85         sizer->Add (_toolbar, 0, wxALL, 12);
86         sizer->Add (&_timeline, 1, wxEXPAND | wxALL, 12);
87
88 #ifdef DCPOMATIC_LINUX
89         auto buttons = CreateSeparatedButtonSizer (wxCLOSE);
90         if (buttons) {
91                 sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
92         }
93 #endif
94
95         SetSizer (sizer);
96         sizer->Layout ();
97         sizer->SetSizeHints (this);
98
99         Bind(wxEVT_CHAR_HOOK, boost::bind(&TimelineDialog::keypress, this, _1));
100
101         _toolbar->ToggleTool ((int) Timeline::SNAP, _timeline.snap ());
102         film_change(ChangeType::DONE, FilmProperty::SEQUENCE);
103
104         _film_changed_connection = film->Change.connect (bind (&TimelineDialog::film_change, this, _1, _2));
105 }
106
107
108 void
109 TimelineDialog::film_change(ChangeType type, FilmProperty p)
110 {
111         if (type != ChangeType::DONE) {
112                 return;
113         }
114
115         auto film = _film.lock ();
116         if (!film) {
117                 return;
118         }
119
120         if (p == FilmProperty::SEQUENCE) {
121                 _toolbar->ToggleTool ((int) Timeline::SEQUENCE, film->sequence ());
122         }
123 }
124
125
126 void
127 TimelineDialog::set_selection (ContentList selection)
128 {
129         _timeline.set_selection (selection);
130 }
131
132
133 void
134 TimelineDialog::tool_clicked (wxCommandEvent& ev)
135 {
136         Timeline::Tool t = static_cast<Timeline::Tool>(ev.GetId());
137         _timeline.tool_clicked (t);
138         if (t == Timeline::SNAP) {
139                 _timeline.set_snap (_toolbar->GetToolState(static_cast<int>(t)));
140         } else if (t == Timeline::SEQUENCE) {
141                 auto film = _film.lock ();
142                 if (film) {
143                         film->set_sequence (_toolbar->GetToolState(static_cast<int>(t)));
144                 }
145         }
146 }
147
148
149 void
150 TimelineDialog::keypress(wxKeyEvent const& event)
151 {
152         _timeline.keypress(event);
153 }