X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fwx%2Fcontrols.cc;h=f16b494c91baef74be9120bac4f926e900c9ebbb;hb=HEAD;hp=a6f70c039528caa9c1197b6fe5e01c0804145034;hpb=d394f2a171235fcbd5bdaf07c3b9b91529368538;p=dcpomatic.git diff --git a/src/wx/controls.cc b/src/wx/controls.cc index a6f70c039..b6270f91a 100644 --- a/src/wx/controls.cc +++ b/src/wx/controls.cc @@ -33,6 +33,7 @@ #include "lib/cross.h" #include "lib/dcp_content.h" #include "lib/examine_content_job.h" +#include "lib/film.h" #include "lib/job.h" #include "lib/job_manager.h" #include "lib/player_video.h" @@ -64,15 +65,11 @@ using namespace boost::placeholders; using namespace dcpomatic; -Controls::Controls (wxWindow* parent, shared_ptr viewer, bool editor_controls) +Controls::Controls(wxWindow* parent, FilmViewer& viewer, bool editor_controls) : wxPanel (parent) , _markers (new MarkersPanel(this, viewer)) , _slider (new wxSlider(this, wxID_ANY, 0, 0, 4096)) , _viewer (viewer) - , _slider_being_moved (false) - , _outline_content (0) - , _eye (0) - , _jump_to_selected (0) , _rewind_button (new Button(this, wxT("|<"))) , _back_button (new Button(this, wxT("<"))) , _forward_button (new Button(this, wxT(">"))) @@ -105,12 +102,12 @@ Controls::Controls (wxWindow* parent, shared_ptr viewer, bool editor time_sizer->Add (_timecode, 0, wxEXPAND); h_sizer->Add (_rewind_button, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); - h_sizer->Add (time_sizer, 0, wxEXPAND); + h_sizer->Add (time_sizer, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); h_sizer->Add (_back_button, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); h_sizer->Add (_forward_button, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2); _button_sizer = new wxBoxSizer (wxHORIZONTAL); - h_sizer->Add (_button_sizer, 0, wxEXPAND); + h_sizer->Add(_button_sizer, 0, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_GAP); { auto box = new wxBoxSizer (wxVERTICAL); @@ -137,7 +134,7 @@ Controls::Controls (wxWindow* parent, shared_ptr viewer, bool editor _eye->Bind (wxEVT_CHOICE, boost::bind (&Controls::eye_changed, this)); } if (_outline_content) { - _outline_content->Bind (wxEVT_CHECKBOX, boost::bind (&Controls::outline_content_changed, this)); + _outline_content->bind(&Controls::outline_content_changed, this); } _slider->Bind (wxEVT_SCROLL_THUMBTRACK, boost::bind(&Controls::slider_moved, this, false)); @@ -150,26 +147,23 @@ Controls::Controls (wxWindow* parent, shared_ptr viewer, bool editor _frame_number->Bind (wxEVT_LEFT_DOWN, boost::bind(&Controls::frame_number_clicked, this)); _timecode->Bind (wxEVT_LEFT_DOWN, boost::bind(&Controls::timecode_clicked, this)); if (_jump_to_selected) { - _jump_to_selected->Bind (wxEVT_CHECKBOX, boost::bind (&Controls::jump_to_selected_clicked, this)); + _jump_to_selected->bind(&Controls::jump_to_selected_clicked, this); _jump_to_selected->SetValue (Config::instance()->jump_to_selected ()); } - viewer->Started.connect (boost::bind(&Controls::started, this)); - viewer->Stopped.connect (boost::bind(&Controls::stopped, this)); + viewer.Started.connect (boost::bind(&Controls::started, this)); + viewer.Stopped.connect (boost::bind(&Controls::stopped, this)); Bind (wxEVT_TIMER, boost::bind(&Controls::update_position, this)); _timer.Start (80, wxTIMER_CONTINUOUS); - set_film (viewer->film()); - - setup_sensitivity (); + set_film(viewer.film()); JobManager::instance()->ActiveJobsChanged.connect ( bind (&Controls::active_jobs_changed, this, _2) ); _config_changed_connection = Config::instance()->Changed.connect (bind(&Controls::config_changed, this, _1)); - config_changed (Config::OTHER); } void @@ -196,12 +190,7 @@ Controls::stopped () void Controls::update_position () { - auto viewer = _viewer.lock (); - if (!viewer) { - return; - } - - if (!_slider_being_moved && !viewer->pending_idle_get()) { + if (!_slider_being_moved && !_viewer.pending_idle_get()) { update_position_label (); update_position_slider (); } @@ -211,24 +200,14 @@ Controls::update_position () void Controls::eye_changed () { - auto viewer = _viewer.lock (); - if (!viewer) { - return; - } - - viewer->set_eyes (_eye->GetSelection() == 0 ? Eyes::LEFT : Eyes::RIGHT); + _viewer.set_eyes(_eye->GetSelection() == 0 ? Eyes::LEFT : Eyes::RIGHT); } void Controls::outline_content_changed () { - auto viewer = _viewer.lock (); - if (!viewer) { - return; - } - - viewer->set_outline_content (_outline_content->GetValue()); + _viewer.set_outline_content(_outline_content->GetValue()); } @@ -236,14 +215,13 @@ Controls::outline_content_changed () void Controls::slider_moved (bool page) { - auto viewer = _viewer.lock (); - if (!_film || !viewer) { + if (!_film) { return; } if (!page && !_slider_being_moved) { /* This is the first event of a drag; stop playback for the duration of the drag */ - viewer->suspend (); + _viewer.suspend(); _slider_being_moved = true; } @@ -254,10 +232,10 @@ Controls::slider_moved (bool page) */ bool accurate = false; if (t >= _film->length ()) { - t = _film->length() - viewer->one_video_frame(); + t = _film->length() - _viewer.one_video_frame(); accurate = true; } - viewer->seek (t, accurate); + _viewer.seek(t, accurate); update_position_label (); } @@ -265,13 +243,12 @@ Controls::slider_moved (bool page) void Controls::slider_released () { - auto viewer = _viewer.lock (); - if (!viewer) { + if (!_film) { return; } /* Restart after a drag */ - viewer->resume (); + _viewer.resume(); _slider_being_moved = false; } @@ -284,15 +261,10 @@ Controls::update_position_slider () return; } - auto viewer = _viewer.lock (); - if (!viewer) { - return; - } - auto const len = _film->length (); if (len.get ()) { - int const new_slider_position = 4096 * viewer->position().get() / len.get(); + int const new_slider_position = 4096 * _viewer.position().get() / len.get(); if (new_slider_position != _slider->GetValue()) { _slider->SetValue (new_slider_position); } @@ -309,15 +281,10 @@ Controls::update_position_label () return; } - auto viewer = _viewer.lock (); - if (!viewer) { - return; - } - double const fps = _film->video_frame_rate (); /* Count frame number from 1 ... not sure if this is the best idea */ - checked_set (_frame_number, wxString::Format (wxT("%ld"), lrint (viewer->position().seconds() * fps) + 1)); - checked_set (_timecode, time_to_timecode (viewer->position(), fps)); + checked_set(_frame_number, wxString::Format (wxT("%ld"), lrint(_viewer.position().seconds() * fps) + 1)); + checked_set(_timecode, time_to_timecode(_viewer.position(), fps)); } @@ -332,12 +299,7 @@ Controls::active_jobs_changed (optional j) DCPTime Controls::nudge_amount (wxKeyboardState& ev) { - auto viewer = _viewer.lock (); - if (!viewer) { - return {}; - } - - auto amount = viewer->one_video_frame (); + auto amount = _viewer.one_video_frame(); if (ev.ShiftDown() && !ev.ControlDown()) { amount = DCPTime::from_seconds (1); @@ -354,10 +316,7 @@ Controls::nudge_amount (wxKeyboardState& ev) void Controls::rewind_clicked (wxMouseEvent& ev) { - auto viewer = _viewer.lock (); - if (viewer) { - viewer->seek (DCPTime(), true); - } + _viewer.seek(DCPTime(), true); ev.Skip(); } @@ -365,40 +324,28 @@ Controls::rewind_clicked (wxMouseEvent& ev) void Controls::back_frame () { - auto viewer = _viewer.lock (); - if (viewer) { - viewer->seek_by (-viewer->one_video_frame(), true); - } + _viewer.seek_by(-_viewer.one_video_frame(), true); } void Controls::forward_frame () { - auto viewer = _viewer.lock (); - if (viewer) { - viewer->seek_by (viewer->one_video_frame(), true); - } + _viewer.seek_by(_viewer.one_video_frame(), true); } void Controls::back_clicked (wxKeyboardState& ev) { - auto viewer = _viewer.lock (); - if (viewer) { - viewer->seek_by (-nudge_amount(ev), true); - } + _viewer.seek_by(-nudge_amount(ev), true); } void Controls::forward_clicked (wxKeyboardState& ev) { - auto viewer = _viewer.lock (); - if (viewer) { - viewer->seek_by (nudge_amount(ev), true); - } + _viewer.seek_by(nudge_amount(ev), true); } @@ -431,32 +378,22 @@ Controls::setup_sensitivity () void Controls::timecode_clicked () { - auto viewer = _viewer.lock (); - if (!viewer) { - return; - } + auto dialog = make_wx(this, _viewer.position(), _film->video_frame_rate()); - auto dialog = new PlayheadToTimecodeDialog (this, viewer->position(), _film->video_frame_rate()); if (dialog->ShowModal() == wxID_OK) { - viewer->seek (dialog->get(), true); + _viewer.seek(dialog->get(), true); } - dialog->Destroy (); } void Controls::frame_number_clicked () { - auto viewer = _viewer.lock (); - if (!viewer) { - return; - } + auto dialog = make_wx(this, _viewer.position(), _film->video_frame_rate()); - auto dialog = new PlayheadToFrameDialog (this, viewer->position(), _film->video_frame_rate()); if (dialog->ShowModal() == wxID_OK) { - viewer->seek (dialog->get(), true); + _viewer.seek(dialog->get(), true); } - dialog->Destroy (); } @@ -497,14 +434,14 @@ Controls::film () const void -Controls::film_change (ChangeType type, Film::Property p) +Controls::film_change(ChangeType type, FilmProperty p) { if (type == ChangeType::DONE) { - if (p == Film::Property::CONTENT) { + if (p == FilmProperty::CONTENT) { setup_sensitivity (); update_position_label (); update_position_slider (); - } else if (p == Film::Property::THREE_D) { + } else if (p == FilmProperty::THREE_D) { setup_sensitivity (); } }