Basic zoom.
[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 <wx/graphics.h>
28 #include <iostream>
29 #include <list>
30
31 using std::list;
32 using std::cout;
33 using boost::shared_ptr;
34
35 TimelineDialog::TimelineDialog (ContentPanel* cp, shared_ptr<Film> film)
36         : wxDialog (
37                 cp->panel(),
38                 wxID_ANY,
39                 _("Timeline"),
40                 wxDefaultPosition,
41                 wxSize (640, 512),
42 #ifdef DCPOMATIC_OSX
43                 /* I can't get wxFRAME_FLOAT_ON_PARENT to work on OS X, and although wxSTAY_ON_TOP keeps
44                    the window above all others (and not just our own) it's better than nothing for now.
45                 */
46                 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxFULL_REPAINT_ON_RESIZE | wxSTAY_ON_TOP
47 #else
48                 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxFULL_REPAINT_ON_RESIZE | wxFRAME_FLOAT_ON_PARENT
49 #endif
50                 )
51         , _film (film)
52         , _timeline (this, cp, film)
53 {
54         wxBoxSizer* sizer = new wxBoxSizer (wxVERTICAL);
55
56         wxBoxSizer* controls = new wxBoxSizer (wxHORIZONTAL);
57         _snap = new wxCheckBox (this, wxID_ANY, _("Snap"));
58         controls->Add (_snap);
59         _sequence = new wxCheckBox (this, wxID_ANY, _("Keep video and subtitles in sequence"));
60         controls->Add (_sequence, 1, wxLEFT, 12);
61         wxToolBar* toolbar = new wxToolBar (this, wxID_ANY);
62
63 #ifdef DCPOMATIC_LINUX
64         wxBitmap select (wxString::Format (wxT ("%s/select.png"), std_to_wx (shared_path().string())), wxBITMAP_TYPE_PNG);
65         wxBitmap zoom (wxString::Format (wxT ("%s/zoom.png"), std_to_wx (shared_path().string())), wxBITMAP_TYPE_PNG);
66 #endif
67         toolbar->AddRadioTool ((int) Timeline::SELECT, _("Select"), select);
68         toolbar->AddRadioTool ((int) Timeline::ZOOM, _("Zoom"), zoom);
69         controls->Add (toolbar);
70         toolbar->Bind (wxEVT_TOOL, bind (&TimelineDialog::tool_changed, this, _1));
71
72         sizer->Add (controls, 0, wxALL, 12);
73         sizer->Add (&_timeline, 1, wxEXPAND | wxALL, 12);
74
75 #ifdef DCPOMATIC_LINUX
76         wxSizer* buttons = CreateSeparatedButtonSizer (wxCLOSE);
77         if (buttons) {
78                 sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
79         }
80 #endif
81
82         SetSizer (sizer);
83         sizer->Layout ();
84         sizer->SetSizeHints (this);
85
86         _snap->SetValue (_timeline.snap ());
87         _snap->Bind (wxEVT_CHECKBOX, boost::bind (&TimelineDialog::snap_toggled, this));
88         film_changed (Film::SEQUENCE);
89         _sequence->Bind (wxEVT_CHECKBOX, boost::bind (&TimelineDialog::sequence_toggled, this));
90
91         _film_changed_connection = film->Changed.connect (bind (&TimelineDialog::film_changed, this, _1));
92 }
93
94 void
95 TimelineDialog::snap_toggled ()
96 {
97         _timeline.set_snap (_snap->GetValue ());
98 }
99
100 void
101 TimelineDialog::sequence_toggled ()
102 {
103         shared_ptr<Film> film = _film.lock ();
104         if (!film) {
105                 return;
106         }
107
108         film->set_sequence (_sequence->GetValue ());
109 }
110
111 void
112 TimelineDialog::film_changed (Film::Property p)
113 {
114         shared_ptr<Film> film = _film.lock ();
115         if (!film) {
116                 return;
117         }
118
119         if (p == Film::SEQUENCE) {
120                 _sequence->SetValue (film->sequence ());
121         }
122 }
123
124 void
125 TimelineDialog::set_selection (ContentList selection)
126 {
127         _timeline.set_selection (selection);
128 }
129
130 void
131 TimelineDialog::tool_changed (wxCommandEvent& ev)
132 {
133         _timeline.set_tool ((Timeline::Tool) ev.GetId());
134 }