Fix alignment.
[dcpomatic.git] / src / wx / video_waveform_dialog.cc
1 /*
2     Copyright (C) 2015-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 "video_waveform_dialog.h"
22 #include "video_waveform_plot.h"
23 #include "film_viewer.h"
24 #include "wx_util.h"
25 #include "static_text.h"
26 #include <boost/bind/bind.hpp>
27 #include <iostream>
28
29 using std::cout;
30 using boost::bind;
31 using std::weak_ptr;
32 using std::shared_ptr;
33 #if BOOST_VERSION >= 106100
34 using namespace boost::placeholders;
35 #endif
36
37
38 VideoWaveformDialog::VideoWaveformDialog (wxWindow* parent, weak_ptr<const Film> film, weak_ptr<FilmViewer> viewer)
39         : wxDialog (
40                 parent,
41                 wxID_ANY,
42                 _("Video Waveform"),
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         , _viewer (viewer)
55 {
56         wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
57
58         wxBoxSizer* controls = new wxBoxSizer (wxHORIZONTAL);
59
60         _component = new wxChoice (this, wxID_ANY);
61         _component->Append (wxT ("X"));
62         _component->Append (wxT ("Y"));
63         _component->Append (wxT ("Z"));
64         add_label_to_sizer (controls, this, _("Component"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL);
65         controls->Add (_component, 1, wxALL, DCPOMATIC_SIZER_X_GAP);
66
67         add_label_to_sizer (controls, this, _("Contrast"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL);
68         _contrast = new wxSlider (this, wxID_ANY, 0, 0, 256);
69         controls->Add (_contrast, 1, wxALL, DCPOMATIC_SIZER_X_GAP);
70
71         overall_sizer->Add (controls, 0, wxALL | wxEXPAND, DCPOMATIC_SIZER_X_GAP);
72
73         wxBoxSizer* position = new wxBoxSizer (wxHORIZONTAL);
74         add_label_to_sizer (position, this, _("Image X position"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL);
75         _x_position = new StaticText (this, "");
76         _x_position->SetMinSize (wxSize (64, -1));
77         position->Add (_x_position, 0, wxALL, DCPOMATIC_SIZER_X_GAP);
78         add_label_to_sizer (position, this, _("component value"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL);
79         _value = new StaticText (this, "");
80         _value->SetMinSize (wxSize (64, -1));
81         position->Add (_value, 0, wxALL, DCPOMATIC_SIZER_X_GAP);
82         overall_sizer->Add (position, 0, wxEXPAND | wxALL, DCPOMATIC_SIZER_Y_GAP);
83
84         _plot = new VideoWaveformPlot (this, film, _viewer);
85         overall_sizer->Add (_plot, 1, wxALL | wxEXPAND, 12);
86
87 #ifdef DCPOMATIC_LINUX
88         wxSizer* buttons = CreateSeparatedButtonSizer (wxCLOSE);
89         if (buttons) {
90                 overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
91         }
92 #endif
93
94         SetSizer (overall_sizer);
95         overall_sizer->Layout ();
96         overall_sizer->SetSizeHints (this);
97
98         Bind (wxEVT_SHOW, bind (&VideoWaveformDialog::shown, this, _1));
99         _component->Bind (wxEVT_CHOICE, bind (&VideoWaveformDialog::component_changed, this));
100         _contrast->Bind (wxEVT_SCROLL_THUMBTRACK, bind (&VideoWaveformDialog::contrast_changed, this));
101         _plot->MouseMoved.connect (bind (&VideoWaveformDialog::mouse_moved, this, _1, _2, _3, _4));
102
103         _component->SetSelection (0);
104         _contrast->SetValue (32);
105
106         component_changed ();
107         contrast_changed ();
108 }
109
110 void
111 VideoWaveformDialog::shown (wxShowEvent& ev)
112 {
113         _plot->set_enabled (ev.IsShown ());
114         if (ev.IsShown ()) {
115                 shared_ptr<FilmViewer> fv = _viewer.lock ();
116                 DCPOMATIC_ASSERT (fv);
117                 fv->slow_refresh ();
118         }
119 }
120
121 void
122 VideoWaveformDialog::component_changed ()
123 {
124         _plot->set_component (_component->GetCurrentSelection ());
125 }
126
127 void
128 VideoWaveformDialog::contrast_changed ()
129 {
130         _plot->set_contrast (_contrast->GetValue ());
131 }
132
133 void
134 VideoWaveformDialog::mouse_moved (int x1, int x2, int y1, int y2)
135 {
136         if (x1 != x2) {
137                 _x_position->SetLabel (wxString::Format ("%d-%d", x1, x2));
138         } else {
139                 _x_position->SetLabel (wxString::Format ("%d", x1));
140         }
141
142         if (y1 != y2) {
143                 _value->SetLabel (wxString::Format ("%d-%d", y1, y2));
144         } else {
145                 _value->SetLabel (wxString::Format ("%d", y1));
146         }
147 }