From deb61d087799d18cce97b1f0f99fe036d2214a42 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 12 Oct 2022 22:48:13 +0200 Subject: [PATCH] Allow dragging of the border between the controls and the preview (#2350). --- src/tools/dcpomatic.cc | 67 ++++++++++++++++++++++++++++++++++------- src/wx/content_panel.cc | 5 ++- src/wx/film_editor.cc | 2 +- 3 files changed, 61 insertions(+), 13 deletions(-) diff --git a/src/tools/dcpomatic.cc b/src/tools/dcpomatic.cc index adc7823c5..a10cb9b35 100644 --- a/src/tools/dcpomatic.cc +++ b/src/tools/dcpomatic.cc @@ -270,6 +270,43 @@ enum { }; +class LimitedFrameSplitter : public wxSplitterWindow +{ +public: + LimitedFrameSplitter(wxWindow* parent) + : wxSplitterWindow(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_NOBORDER | wxSP_3DSASH | wxSP_LIVE_UPDATE) + { + /* This value doesn't really mean much but we just want to stop double-click on the + divider from shrinking the left panel. + */ + SetMinimumPaneSize(64); + + Bind(wxEVT_SIZE, boost::bind(&LimitedFrameSplitter::sized, this, _1)); + } + + bool OnSashPositionChange(int new_position) override + { + /* Try to stop the left bit of the splitter getting too small */ + return new_position > _left_panel_minimum_size; + } + +private: + void sized(wxSizeEvent& ev) + { + if (GetSize().GetWidth() > _left_panel_minimum_size && GetSashPosition() < _left_panel_minimum_size) { + /* The window is now fairly big but the left panel is small; this happens when the DCP-o-matic window + * is shrunk and then made larger again. Try to set a sensible left panel size in this case. + */ + SetSashPosition(_left_panel_minimum_size); + } + + ev.Skip(); + } + + int const _left_panel_minimum_size = 200; +}; + + class DOMFrame : public wxFrame { public: @@ -278,8 +315,9 @@ public: /* Use a panel as the only child of the Frame so that we avoid the dark-grey background on Windows. */ - , _overall_panel(new wxPanel(this, wxID_ANY)) - , _film_viewer(_overall_panel) + , _splitter(new LimitedFrameSplitter(this)) + , _right_panel(new wxPanel(_splitter, wxID_ANY)) + , _film_viewer(_right_panel) { #if defined(DCPOMATIC_WINDOWS) if (Config::instance()->win32_console()) { @@ -353,18 +391,26 @@ public: Bind (wxEVT_CLOSE_WINDOW, boost::bind (&DOMFrame::close, this, _1)); Bind (wxEVT_SHOW, boost::bind (&DOMFrame::show, this, _1)); - _controls = new StandardControls(_overall_panel, _film_viewer, true); - _film_editor = new FilmEditor(_overall_panel, _film_viewer); - auto job_manager_view = new JobManagerView(_overall_panel, false); + auto left_panel = new wxPanel(_splitter, wxID_ANY); + + _film_editor = new FilmEditor(left_panel, _film_viewer); + + auto left_sizer = new wxBoxSizer(wxHORIZONTAL); + left_sizer->Add(_film_editor, 1, wxEXPAND); + + left_panel->SetSizerAndFit(left_sizer); + + _controls = new StandardControls(_right_panel, _film_viewer, true); + auto job_manager_view = new JobManagerView(_right_panel, false); auto right_sizer = new wxBoxSizer (wxVERTICAL); right_sizer->Add(_film_viewer.panel(), 2, wxEXPAND | wxALL, 6); right_sizer->Add (_controls, 0, wxEXPAND | wxALL, 6); right_sizer->Add (job_manager_view, 1, wxEXPAND | wxALL, 6); - wxBoxSizer* main_sizer = new wxBoxSizer (wxHORIZONTAL); - main_sizer->Add (_film_editor, 0, wxEXPAND | wxALL, 6); - main_sizer->Add (right_sizer, 1, wxEXPAND | wxALL, 6); + _right_panel->SetSizer(right_sizer); + + _splitter->SplitVertically(left_panel, _right_panel, left_panel->GetSize().GetWidth() + 8); set_menu_sensitivity (); @@ -373,8 +419,6 @@ public: JobManager::instance()->ActiveJobsChanged.connect(boost::bind(&DOMFrame::active_jobs_changed, this)); - _overall_panel->SetSizer(main_sizer); - UpdateChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::update_checker_state_changed, this)); FocusManager::instance()->SetFocus.connect (boost::bind (&DOMFrame::remove_accelerators, this)); @@ -1550,7 +1594,8 @@ private: } FilmEditor* _film_editor; - wxPanel* _overall_panel; + LimitedFrameSplitter* _splitter; + wxPanel* _right_panel; FilmViewer _film_viewer; StandardControls* _controls; VideoWaveformDialog* _video_waveform_dialog = nullptr; diff --git a/src/wx/content_panel.cc b/src/wx/content_panel.cc index af35e2d3b..df6308bea 100644 --- a/src/wx/content_panel.cc +++ b/src/wx/content_panel.cc @@ -112,7 +112,8 @@ public: private: void sized(wxSizeEvent& ev) { - if (_first_shown && GetSize().GetHeight() > _top_panel_minimum_size && GetSashPosition() < _top_panel_minimum_size) { + auto const height = GetSize().GetHeight(); + if (_first_shown && (!_last_height || *_last_height != height) && height > _top_panel_minimum_size && GetSashPosition() < _top_panel_minimum_size) { /* The window is now fairly big but the top panel is small; this happens when the DCP-o-matic window * is shrunk and then made larger again. Try to set a sensible top panel size in this case (#1839). */ @@ -120,10 +121,12 @@ private: } ev.Skip (); + _last_height = height; } bool _first_shown = false; int const _top_panel_minimum_size = 350; + boost::optional _last_height; }; diff --git a/src/wx/film_editor.cc b/src/wx/film_editor.cc index 70c4a7b24..e602f9333 100644 --- a/src/wx/film_editor.cc +++ b/src/wx/film_editor.cc @@ -55,7 +55,7 @@ FilmEditor::FilmEditor(wxWindow* parent, FilmViewer& viewer) auto s = new wxBoxSizer (wxVERTICAL); auto notebook = new wxNotebook(this, wxID_ANY); - s->Add(notebook, 1); + s->Add(notebook, 1, wxEXPAND); _content_panel = new ContentPanel(notebook, _film, viewer); notebook->AddPage(_content_panel->window(), _("Content"), true); -- 2.30.2