Debugging message.
[dcpomatic.git] / src / wx / timeline_dialog.cc
1 /*
2     Copyright (C) 2013-2018 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
37 TimelineDialog::TimelineDialog (ContentPanel* cp, shared_ptr<Film> film)
38         : wxDialog (
39                 cp->panel(),
40                 wxID_ANY,
41                 _("Timeline"),
42                 wxDefaultPosition,
43                 wxSize (640, 512),
44 #ifdef DCPOMATIC_OSX
45                 /* I can't get wxFRAME_FLOAT_ON_PARENT to work on OS X, and although wxSTAY_ON_TOP keeps
46                    the window above all others (and not just our own) it's better than nothing for now.
47                 */
48                 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxFULL_REPAINT_ON_RESIZE | wxSTAY_ON_TOP
49 #else
50                 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxFULL_REPAINT_ON_RESIZE | wxFRAME_FLOAT_ON_PARENT
51 #endif
52                 )
53         , _film (film)
54         , _timeline (this, cp, film)
55 {
56         wxBoxSizer* sizer = new wxBoxSizer (wxVERTICAL);
57
58         wxBitmap select (bitmap_path("select"), wxBITMAP_TYPE_PNG);
59         wxBitmap zoom (bitmap_path("zoom"), wxBITMAP_TYPE_PNG);
60         wxBitmap zoom_all (bitmap_path("zoom_all"), wxBITMAP_TYPE_PNG);
61         wxBitmap snap (bitmap_path("snap"), wxBITMAP_TYPE_PNG);
62         wxBitmap sequence (bitmap_path("sequence"), wxBITMAP_TYPE_PNG);
63
64         _toolbar = new wxToolBar (this, wxID_ANY);
65         _toolbar->AddRadioTool ((int) Timeline::SELECT, _("Select"), select, wxNullBitmap, _("Select and move content"));
66         _toolbar->AddRadioTool ((int) Timeline::ZOOM, _("Zoom"), zoom, wxNullBitmap, _("Zoom in / out"));
67         _toolbar->AddTool ((int) Timeline::ZOOM_ALL, _("Zoom all"), zoom_all, _("Zoom out to whole film"));
68         _toolbar->AddCheckTool ((int) Timeline::SNAP, _("Snap"), snap, wxNullBitmap, _("Snap"));
69         _toolbar->AddCheckTool ((int) Timeline::SEQUENCE, _("Sequence"), sequence, wxNullBitmap, _("Keep video and subtitles in sequence"));
70
71         _toolbar->Bind (wxEVT_TOOL, bind (&TimelineDialog::tool_clicked, this, _1));
72
73         sizer->Add (_toolbar, 0, wxALL, 12);
74         sizer->Add (&_timeline, 1, wxEXPAND | wxALL, 12);
75
76 #ifdef DCPOMATIC_LINUX
77         wxSizer* buttons = CreateSeparatedButtonSizer (wxCLOSE);
78         if (buttons) {
79                 sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
80         }
81 #endif
82
83         SetSizer (sizer);
84         sizer->Layout ();
85         sizer->SetSizeHints (this);
86
87         _toolbar->ToggleTool ((int) Timeline::SNAP, _timeline.snap ());
88         film_changed (Film::SEQUENCE);
89
90         _film_changed_connection = film->Changed.connect (bind (&TimelineDialog::film_changed, this, _1));
91 }
92
93 wxString
94 TimelineDialog::bitmap_path (string name)
95 {
96         boost::filesystem::path p = shared_path() / String::compose("%1.png", name);
97         cout << "Loading " << p.string() << "\n";
98         return std_to_wx (p.string());
99 }
100
101 void
102 TimelineDialog::film_changed (Film::Property p)
103 {
104         shared_ptr<Film> film = _film.lock ();
105         if (!film) {
106                 return;
107         }
108
109         if (p == Film::SEQUENCE) {
110                 _toolbar->ToggleTool ((int) Timeline::SEQUENCE, film->sequence ());
111         }
112 }
113
114 void
115 TimelineDialog::set_selection (ContentList selection)
116 {
117         _timeline.set_selection (selection);
118 }
119
120 void
121 TimelineDialog::tool_clicked (wxCommandEvent& ev)
122 {
123         Timeline::Tool t = (Timeline::Tool) ev.GetId();
124         _timeline.tool_clicked (t);
125         if (t == Timeline::SNAP) {
126                 _timeline.set_snap (_snap->IsToggled());
127         } else if (t == Timeline::SEQUENCE) {
128                 shared_ptr<Film> film = _film.lock ();
129                 if (film) {
130                         film->set_sequence (_sequence->IsToggled());
131                 }
132         }
133 }