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