From a6e27693613a72a36602d2abc45d71db4b6d096a Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 2 Jul 2018 23:52:01 +0100 Subject: [PATCH] Scroll labels view with zoom. --- src/wx/timeline.cc | 34 ++++++++++++++++++++-------------- src/wx/timeline.h | 2 +- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/wx/timeline.cc b/src/wx/timeline.cc index 2c14b651e..f68c98bda 100644 --- a/src/wx/timeline.cc +++ b/src/wx/timeline.cc @@ -55,7 +55,7 @@ using boost::optional; Timeline::Timeline (wxWindow* parent, ContentPanel* cp, shared_ptr film) : wxPanel (parent, wxID_ANY) - , _labels_panel (new wxPanel (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE)) + , _labels_canvas (new wxScrolledCanvas (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE)) , _main_canvas (new wxScrolledCanvas (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE)) , _content_panel (cp) , _film (film) @@ -74,23 +74,23 @@ Timeline::Timeline (wxWindow* parent, ContentPanel* cp, shared_ptr film) , _track_height (48) { #ifndef __WXOSX__ - _labels_panel->SetDoubleBuffered (true); + _labels_canvas->SetDoubleBuffered (true); _main_canvas->SetDoubleBuffered (true); #endif wxSizer* sizer = new wxBoxSizer (wxHORIZONTAL); - sizer->Add (_labels_panel, 0, wxEXPAND); - _labels_panel->SetMinSize (wxSize (_labels_view->bbox().width, -1)); + sizer->Add (_labels_canvas, 0, wxEXPAND); + _labels_canvas->SetMinSize (wxSize (_labels_view->bbox().width, -1)); sizer->Add (_main_canvas, 1, wxEXPAND); SetSizer (sizer); - _labels_panel->Bind (wxEVT_PAINT, boost::bind (&Timeline::paint_labels, this)); - _main_canvas->Bind (wxEVT_PAINT, boost::bind (&Timeline::paint_main, this)); - _main_canvas->Bind (wxEVT_LEFT_DOWN, boost::bind (&Timeline::left_down, this, _1)); - _main_canvas->Bind (wxEVT_LEFT_UP, boost::bind (&Timeline::left_up, this, _1)); - _main_canvas->Bind (wxEVT_RIGHT_DOWN, boost::bind (&Timeline::right_down, this, _1)); - _main_canvas->Bind (wxEVT_MOTION, boost::bind (&Timeline::mouse_moved, this, _1)); - _main_canvas->Bind (wxEVT_SIZE, boost::bind (&Timeline::resized, this)); + _labels_canvas->Bind (wxEVT_PAINT, boost::bind (&Timeline::paint_labels, this)); + _main_canvas->Bind (wxEVT_PAINT, boost::bind (&Timeline::paint_main, this)); + _main_canvas->Bind (wxEVT_LEFT_DOWN, boost::bind (&Timeline::left_down, this, _1)); + _main_canvas->Bind (wxEVT_LEFT_UP, boost::bind (&Timeline::left_up, this, _1)); + _main_canvas->Bind (wxEVT_RIGHT_DOWN, boost::bind (&Timeline::right_down, this, _1)); + _main_canvas->Bind (wxEVT_MOTION, boost::bind (&Timeline::mouse_moved, this, _1)); + _main_canvas->Bind (wxEVT_SIZE, boost::bind (&Timeline::resized, this)); film_changed (Film::CONTENT); @@ -102,19 +102,23 @@ Timeline::Timeline (wxWindow* parent, ContentPanel* cp, shared_ptr film) _pixels_per_second = max (0.01, static_cast(640) / film->length().seconds ()); setup_scrollbars (); - _main_canvas->EnableScrolling (true, true); + _labels_canvas->ShowScrollbars (wxSHOW_SB_NEVER, wxSHOW_SB_NEVER); } void Timeline::paint_labels () { - wxPaintDC dc (_labels_panel); + wxPaintDC dc (_labels_canvas); wxGraphicsContext* gc = wxGraphicsContext::Create (dc); if (!gc) { return; } + int vsx, vsy; + _labels_canvas->GetViewStart (&vsx, &vsy); + gc->Translate (-vsx * _x_scroll_rate, -vsy * _y_scroll_rate); + _labels_view->paint (gc, list >()); delete gc; @@ -378,6 +382,8 @@ Timeline::setup_scrollbars () if (!film || !_pixels_per_second) { return; } + _labels_canvas->SetVirtualSize (_labels_view->bbox().width, tracks() * track_height() + 96); + _labels_canvas->SetScrollRate (_x_scroll_rate, _y_scroll_rate); _main_canvas->SetVirtualSize (*_pixels_per_second * film->length().seconds(), tracks() * track_height() + 96); _main_canvas->SetScrollRate (_x_scroll_rate, _y_scroll_rate); } @@ -521,10 +527,10 @@ Timeline::left_up_zoom (wxMouseEvent& ev) double const tracks_top = double(top_left.y) / _track_height; double const tracks_bottom = double(bottom_right.y) / _track_height; _track_height = GetSize().GetHeight() / (tracks_bottom - tracks_top); - cout << tracks_top << " " << tracks_bottom << "\n"; setup_scrollbars (); _main_canvas->Scroll (time_left.seconds() * *_pixels_per_second / _x_scroll_rate, tracks_top * _track_height / _y_scroll_rate); + _labels_canvas->Scroll (0, tracks_top * _track_height / _y_scroll_rate); _zoom_point = optional (); Refresh (); diff --git a/src/wx/timeline.h b/src/wx/timeline.h index 6df44372b..1b75f7ab2 100644 --- a/src/wx/timeline.h +++ b/src/wx/timeline.h @@ -104,7 +104,7 @@ private: ContentList selected_content () const; void maybe_snap (DCPTime a, DCPTime b, boost::optional& nearest_distance) const; - wxPanel* _labels_panel; + wxScrolledCanvas* _labels_canvas; wxScrolledCanvas* _main_canvas; ContentPanel* _content_panel; boost::weak_ptr _film; -- 2.30.2