From: Carl Hetherington Date: Thu, 25 Feb 2016 22:24:39 +0000 (+0000) Subject: Basics of timeline track labels. X-Git-Tag: v2.6.26~11 X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=07789030fb4ec7d48d14c2cbee0b32f616d6d93d Basics of timeline track labels. --- diff --git a/src/wx/timeline.cc b/src/wx/timeline.cc index de2070531..a7b41eb98 100644 --- a/src/wx/timeline.cc +++ b/src/wx/timeline.cc @@ -21,6 +21,7 @@ #include "timeline.h" #include "timeline_time_axis_view.h" #include "timeline_reels_view.h" +#include "timeline_labels_view.h" #include "timeline_video_content_view.h" #include "timeline_audio_content_view.h" #include "timeline_subtitle_content_view.h" @@ -53,6 +54,7 @@ Timeline::Timeline (wxWindow* parent, ContentPanel* cp, shared_ptr film) , _film (film) , _time_axis_view (new TimelineTimeAxisView (*this, 64)) , _reels_view (new TimelineReelsView (*this, 32)) + , _labels_view (new TimelineLabelsView (*this)) , _tracks (0) , _left_down (false) , _down_view_position (0) @@ -75,6 +77,8 @@ Timeline::Timeline (wxWindow* parent, ContentPanel* cp, shared_ptr film) SetMinSize (wxSize (640, tracks() * track_height() + 96)); + _tracks_position = Position (_labels_view->bbox().width, 8); + _film_changed_connection = film->Changed.connect (bind (&Timeline::film_changed, this, _1)); _film_content_changed_connection = film->ContentChanged.connect (bind (&Timeline::film_content_changed, this, _2, _3)); } @@ -136,6 +140,7 @@ Timeline::recreate_views () _views.clear (); _views.push_back (_time_axis_view); _views.push_back (_reels_view); + _views.push_back (_labels_view); BOOST_FOREACH (shared_ptr i, film->content ()) { if (dynamic_pointer_cast (i)) { @@ -255,7 +260,7 @@ Timeline::setup_pixels_per_second () return; } - _pixels_per_second = static_cast(width() - x_offset() * 2) / film->length().seconds (); + _pixels_per_second = static_cast(width() - tracks_position().x * 2) / film->length().seconds (); } shared_ptr diff --git a/src/wx/timeline.h b/src/wx/timeline.h index c0a18ab0d..519f00afb 100644 --- a/src/wx/timeline.h +++ b/src/wx/timeline.h @@ -32,6 +32,7 @@ class ContentPanel; class TimelineView; class TimelineTimeAxisView; class TimelineReelsView; +class TimelineLabelsView; class Timeline : public wxPanel { @@ -42,10 +43,6 @@ public: void force_redraw (dcpomatic::Rect const &); - int x_offset () const { - return 8; - } - int width () const { return GetSize().GetWidth (); } @@ -59,7 +56,7 @@ public: } Position tracks_position () const { - return Position (8, 8); + return _tracks_position; } int tracks () const; @@ -100,6 +97,7 @@ private: TimelineViewList _views; boost::shared_ptr _time_axis_view; boost::shared_ptr _reels_view; + boost::shared_ptr _labels_view; int _tracks; boost::optional _pixels_per_second; bool _left_down; @@ -111,6 +109,7 @@ private: bool _snap; std::list _start_snaps; std::list _end_snaps; + Position _tracks_position; boost::signals2::scoped_connection _film_changed_connection; boost::signals2::scoped_connection _film_content_changed_connection; diff --git a/src/wx/timeline_labels_view.cc b/src/wx/timeline_labels_view.cc new file mode 100644 index 000000000..e5827f9c9 --- /dev/null +++ b/src/wx/timeline_labels_view.cc @@ -0,0 +1,63 @@ +/* + Copyright (C) 2016 Carl Hetherington + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + + +#include "timeline_labels_view.h" +#include "timeline.h" +#include +#include + +using std::list; +using std::max; + +TimelineLabelsView::TimelineLabelsView (Timeline& tl) + : TimelineView (tl) +{ + wxString labels[] = { + _("Video"), + _("Audio"), + _("Subtitles") + }; + + _width = 0; + + wxClientDC dc (&_timeline); + for (int i = 0; i < 3; ++i) { + wxSize size = dc.GetTextExtent (labels[i]); + _width = max (_width, size.GetWidth()); + } + + _width += 16; +} + +dcpomatic::Rect +TimelineLabelsView::bbox () const +{ + return dcpomatic::Rect (0, 0, _width, _timeline.tracks() * _timeline.track_height()); +} + +void +TimelineLabelsView::do_paint (wxGraphicsContext* gc, list >) +{ + int const h = _timeline.track_height (); + gc->SetFont (gc->CreateFont(*wxNORMAL_FONT, wxColour (0, 0, 0))); + gc->DrawText (_("Video"), 0, h / 2); + gc->DrawText (_("Subtitles"), 0, 3 * h / 2); + gc->DrawText (_("Audio"), 0, h + _timeline.tracks() * h / 2); +} diff --git a/src/wx/timeline_labels_view.h b/src/wx/timeline_labels_view.h new file mode 100644 index 000000000..96dd692af --- /dev/null +++ b/src/wx/timeline_labels_view.h @@ -0,0 +1,35 @@ +/* + Copyright (C) 2016 Carl Hetherington + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "timeline_view.h" + +class wxWindow; + +class TimelineLabelsView : public TimelineView +{ +public: + TimelineLabelsView (Timeline& tl); + + dcpomatic::Rect bbox () const; + +private: + void do_paint (wxGraphicsContext* gc, std::list > overlaps); + + int _width; +}; diff --git a/src/wx/timeline_reels_view.h b/src/wx/timeline_reels_view.h index 5f8ae1d38..7ef16d496 100644 --- a/src/wx/timeline_reels_view.h +++ b/src/wx/timeline_reels_view.h @@ -30,6 +30,5 @@ public: private: void do_paint (wxGraphicsContext* gc, std::list > overlaps); -private: int _y; }; diff --git a/src/wx/timeline_time_axis_view.cc b/src/wx/timeline_time_axis_view.cc index bbaf5fde2..ce37ec659 100644 --- a/src/wx/timeline_time_axis_view.cc +++ b/src/wx/timeline_time_axis_view.cc @@ -34,7 +34,7 @@ TimelineTimeAxisView::TimelineTimeAxisView (Timeline& tl, int y) dcpomatic::Rect TimelineTimeAxisView::bbox () const { - return dcpomatic::Rect (0, _y - 4, _timeline.width(), 24); + return dcpomatic::Rect (_timeline.tracks_position().x, _y - 4, _timeline.width(), 24); } void @@ -74,7 +74,7 @@ TimelineTimeAxisView::do_paint (wxGraphicsContext* gc, list } wxGraphicsPath path = gc->CreatePath (); - path.MoveToPoint (_timeline.x_offset(), _y); + path.MoveToPoint (_timeline.tracks_position().x, _y); path.AddLineToPoint (_timeline.width(), _y); gc->StrokePath (path); @@ -102,7 +102,7 @@ TimelineTimeAxisView::do_paint (wxGraphicsContext* gc, list wxDouble str_leading; gc->GetTextExtent (str, &str_width, &str_height, &str_descent, &str_leading); - int const tx = _timeline.x_offset() + t.seconds() * pps; + int const tx = _timeline.tracks_position().x + t.seconds() * pps; if ((tx + str_width) < _timeline.width()) { gc->DrawText (str, time_x (t), _y + 16); } diff --git a/src/wx/timeline_time_axis_view.h b/src/wx/timeline_time_axis_view.h index fbd7c5de9..d57d7b749 100644 --- a/src/wx/timeline_time_axis_view.h +++ b/src/wx/timeline_time_axis_view.h @@ -30,7 +30,6 @@ public: private: void do_paint (wxGraphicsContext* gc, std::list > overlaps); -private: int _y; }; diff --git a/src/wx/wscript b/src/wx/wscript index b78ccc928..2198a401a 100644 --- a/src/wx/wscript +++ b/src/wx/wscript @@ -83,6 +83,7 @@ sources = """ timeline_content_view.cc timeline_dialog.cc timeline_audio_content_view.cc + timeline_labels_view.cc timeline_subtitle_content_view.cc timeline_reels_view.cc timeline_time_axis_view.cc