2 Copyright (C) 2013-2016 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
21 #include "timeline_time_axis_view.h"
24 #include <wx/graphics.h>
28 TimelineTimeAxisView::TimelineTimeAxisView (Timeline& tl, int y)
36 TimelineTimeAxisView::bbox () const
38 return dcpomatic::Rect<int> (_timeline.tracks_position().x, _y - 4, _timeline.width(), 24);
42 TimelineTimeAxisView::set_y (int y)
49 TimelineTimeAxisView::do_paint (wxGraphicsContext* gc, list<dcpomatic::Rect<int> >)
51 if (!_timeline.pixels_per_second()) {
55 double const pps = _timeline.pixels_per_second().get ();
57 gc->SetPen (*wxThePenList->FindOrCreatePen (wxColour (0, 0, 0), 1, wxPENSTYLE_SOLID));
59 double mark_interval = rint (128 / pps);
60 if (mark_interval > 5) {
61 mark_interval -= lrint (mark_interval) % 5;
63 if (mark_interval > 10) {
64 mark_interval -= lrint (mark_interval) % 10;
66 if (mark_interval > 60) {
67 mark_interval -= lrint (mark_interval) % 60;
69 if (mark_interval > 3600) {
70 mark_interval -= lrint (mark_interval) % 3600;
73 if (mark_interval < 1) {
77 wxGraphicsPath path = gc->CreatePath ();
78 path.MoveToPoint (_timeline.tracks_position().x, _y);
79 path.AddLineToPoint (_timeline.width(), _y);
80 gc->StrokePath (path);
82 gc->SetFont (gc->CreateFont (*wxNORMAL_FONT));
86 while ((t.seconds() * pps) < _timeline.width()) {
87 wxGraphicsPath path = gc->CreatePath ();
88 path.MoveToPoint (time_x (t), _y - 4);
89 path.AddLineToPoint (time_x (t), _y + 4);
90 gc->StrokePath (path);
92 double tc = t.seconds ();
93 int const h = tc / 3600;
95 int const m = tc / 60;
99 wxString str = wxString::Format (wxT ("%02d:%02d:%02d"), h, m, s);
102 wxDouble str_descent;
103 wxDouble str_leading;
104 gc->GetTextExtent (str, &str_width, &str_height, &str_descent, &str_leading);
106 int const tx = _timeline.tracks_position().x + t.seconds() * pps;
107 if ((tx + str_width) < _timeline.width()) {
108 gc->DrawText (str, time_x (t), _y + 16);
111 t += DCPTime::from_seconds (mark_interval);