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