More stack-allocated Dialog objects.
[dcpomatic.git] / src / wx / video_panel.cc
index c5a48f986e0931662741416683abe3f7e0557c4e..4f7c2db791400d8038efed8ab81499e69d5b6061 100644 (file)
 #include "lib/ratio.h"
 #include "lib/util.h"
 #include "lib/video_content.h"
+#include <dcp/warnings.h>
+LIBDCP_DISABLE_WARNINGS
 #include <wx/spinctrl.h>
 #include <wx/tglbtn.h>
+LIBDCP_ENABLE_WARNINGS
 #include <boost/functional/hash.hpp>
 #include <boost/unordered_set.hpp>
 #include <set>
@@ -64,6 +67,13 @@ using namespace boost::placeholders;
 
 VideoPanel::VideoPanel (ContentPanel* p)
        : ContentSubPanel (p, _("Video"))
+{
+
+}
+
+
+void
+VideoPanel::create ()
 {
        _reference = new CheckBox (this, _("Use this DCP's video as OV and make VF"));
        _reference_note = new StaticText (this, wxT(""));
@@ -111,13 +121,13 @@ VideoPanel::VideoPanel (ContentPanel* p)
                new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(crop_width, -1)),
                VideoContentProperty::CROP,
                &Content::video,
-               boost::mem_fn (&VideoContent::left_crop),
+               boost::mem_fn (&VideoContent::requested_left_crop),
                boost::mem_fn (&VideoContent::set_left_crop),
                boost::bind (&VideoPanel::left_crop_changed, this)
                );
 
        _left_right_link = new wxToggleButton (this, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(link_width, link_height));
-       _left_right_link->SetBitmap (wxBitmap(bitmap_path("link"), wxBITMAP_TYPE_PNG));
+       _left_right_link->SetBitmap (wxBitmap(bitmap_path("link.png"), wxBITMAP_TYPE_PNG));
 
        _right_crop_label = create_label (this, _("Right"), true);
        _right_crop = new ContentSpinCtrl<VideoContent> (
@@ -125,7 +135,7 @@ VideoPanel::VideoPanel (ContentPanel* p)
                new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(crop_width, -1)),
                VideoContentProperty::CROP,
                &Content::video,
-               boost::mem_fn (&VideoContent::right_crop),
+               boost::mem_fn (&VideoContent::requested_right_crop),
                boost::mem_fn (&VideoContent::set_right_crop),
                boost::bind (&VideoPanel::right_crop_changed, this)
                );
@@ -136,13 +146,13 @@ VideoPanel::VideoPanel (ContentPanel* p)
                new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(crop_width, -1)),
                VideoContentProperty::CROP,
                &Content::video,
-               boost::mem_fn (&VideoContent::top_crop),
+               boost::mem_fn (&VideoContent::requested_top_crop),
                boost::mem_fn (&VideoContent::set_top_crop),
                boost::bind (&VideoPanel::top_crop_changed, this)
                );
 
        _top_bottom_link = new wxToggleButton (this, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(link_width, link_height));
-       _top_bottom_link->SetBitmap (wxBitmap(bitmap_path("link"), wxBITMAP_TYPE_PNG));
+       _top_bottom_link->SetBitmap (wxBitmap(bitmap_path("link.png"), wxBITMAP_TYPE_PNG));
 
        _bottom_crop_label = create_label (this, _("Bottom"), true);
        _bottom_crop = new ContentSpinCtrl<VideoContent> (
@@ -150,7 +160,7 @@ VideoPanel::VideoPanel (ContentPanel* p)
                new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(crop_width, -1)),
                VideoContentProperty::CROP,
                &Content::video,
-               boost::mem_fn (&VideoContent::bottom_crop),
+               boost::mem_fn (&VideoContent::requested_bottom_crop),
                boost::mem_fn (&VideoContent::set_bottom_crop),
                boost::bind (&VideoPanel::bottom_crop_changed, this)
                );
@@ -210,7 +220,7 @@ VideoPanel::VideoPanel (ContentPanel* p)
        _fade_in->Changed.connect (boost::bind (&VideoPanel::fade_in_changed, this));
        _fade_out->Changed.connect (boost::bind (&VideoPanel::fade_out_changed, this));
 
-       _reference->Bind                     (wxEVT_CHECKBOX, boost::bind (&VideoPanel::reference_clicked, this));
+       _reference->bind(&VideoPanel::reference_clicked, this);
        _scale_fit->Bind                     (wxEVT_RADIOBUTTON, boost::bind (&VideoPanel::scale_fit_clicked, this));
        _scale_custom->Bind                  (wxEVT_RADIOBUTTON, boost::bind (&VideoPanel::scale_custom_clicked, this));
        _scale_custom_edit->Bind             (wxEVT_BUTTON,   boost::bind (&VideoPanel::scale_custom_edit_clicked, this));
@@ -221,6 +231,8 @@ VideoPanel::VideoPanel (ContentPanel* p)
        _top_bottom_link->Bind               (wxEVT_TOGGLEBUTTON, boost::bind(&VideoPanel::top_bottom_link_clicked, this));
 
        add_to_grid ();
+
+       _sizer->Layout ();
 }
 
 
@@ -375,7 +387,8 @@ VideoPanel::film_content_changed (int property)
        if (property == ContentProperty::VIDEO_FRAME_RATE ||
            property == VideoContentProperty::FRAME_TYPE ||
            property == VideoContentProperty::CROP ||
-           property == VideoContentProperty::SCALE) {
+           property == VideoContentProperty::CUSTOM_RATIO ||
+           property == VideoContentProperty::CUSTOM_SIZE) {
                setup_description ();
        } else if (property == VideoContentProperty::COLOUR_CONVERSION) {
                boost::unordered_set<optional<ColourConversion>> check;
@@ -528,17 +541,16 @@ VideoPanel::edit_colour_conversion_clicked ()
 {
        auto vc = _parent->selected_video ();
 
-       auto d = new ContentColourConversionDialog (this, vc.front()->video->yuv ());
-       d->set (vc.front()->video->colour_conversion().get_value_or (PresetColourConversion::all().front().conversion));
-       if (d->ShowModal() == wxID_OK) {
+       ContentColourConversionDialog dialog(this, vc.front()->video->yuv());
+       dialog.set(vc.front()->video->colour_conversion().get_value_or(PresetColourConversion::all().front().conversion));
+       if (dialog.ShowModal() == wxID_OK) {
                for (auto i: vc) {
-                       i->video->set_colour_conversion (d->get ());
+                       i->video->set_colour_conversion(dialog.get());
                }
        } else {
                /* Reset the colour conversion choice */
                film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
        }
-       d->Destroy ();
 }
 
 
@@ -690,7 +702,10 @@ VideoPanel::scale_fit_clicked ()
 {
        for (auto i: _parent->selected_video()) {
                i->video->set_custom_ratio (optional<float>());
+               i->video->set_custom_size (optional<dcp::Size>());
        }
+
+       setup_sensitivity ();
 }
 
 
@@ -700,6 +715,8 @@ VideoPanel::scale_custom_clicked ()
        if (!scale_custom_edit_clicked()) {
                _scale_fit->SetValue (true);
        }
+
+       setup_sensitivity ();
 }
 
 
@@ -707,16 +724,17 @@ bool
 VideoPanel::scale_custom_edit_clicked ()
 {
        auto vc = _parent->selected_video().front()->video;
-       auto d = new CustomScaleDialog (this, vc->size(), _parent->film()->frame_size(), vc->custom_ratio(), vc->custom_size());
-       int const r = d->ShowModal ();
-       if (r == wxID_OK) {
-               for (auto i: _parent->selected_video()) {
-                       i->video->set_custom_ratio (d->custom_ratio());
-                       i->video->set_custom_size (d->custom_size());
-               }
+       CustomScaleDialog dialog(this, vc->size(), _parent->film()->frame_size(), vc->custom_ratio(), vc->custom_size());
+       if (dialog.ShowModal() != wxID_OK) {
+               return false;
        }
-       d->Destroy ();
-       return r == wxID_OK;
+
+       for (auto i: _parent->selected_video()) {
+               i->video->set_custom_ratio(dialog.custom_ratio());
+               i->video->set_custom_size(dialog.custom_size());
+       }
+
+       return true;
 }
 
 
@@ -748,7 +766,7 @@ VideoPanel::left_crop_changed ()
        _left_changed_last = true;
        if (_left_right_link->GetValue()) {
                for (auto i: _parent->selected_video()) {
-                       i->video->set_right_crop (i->video->left_crop());
+                       i->video->set_right_crop (i->video->requested_left_crop());
                }
        }
 }
@@ -760,7 +778,7 @@ VideoPanel::right_crop_changed ()
        _left_changed_last = false;
        if (_left_right_link->GetValue()) {
                for (auto i: _parent->selected_video()) {
-                       i->video->set_left_crop (i->video->right_crop());
+                       i->video->set_left_crop (i->video->requested_right_crop());
                }
        }
 }
@@ -772,7 +790,7 @@ VideoPanel::top_crop_changed ()
        _top_changed_last = true;
        if (_top_bottom_link->GetValue()) {
                for (auto i: _parent->selected_video()) {
-                       i->video->set_bottom_crop (i->video->top_crop());
+                       i->video->set_bottom_crop (i->video->requested_top_crop());
                }
        }
 }
@@ -784,10 +802,9 @@ VideoPanel::bottom_crop_changed ()
        _top_changed_last = false;
        if (_top_bottom_link->GetValue()) {
                for (auto i: _parent->selected_video()) {
-                       i->video->set_top_crop (i->video->bottom_crop());
+                       i->video->set_top_crop (i->video->requested_bottom_crop());
                }
        }
 }
 
 
-