Tidying.
[dcpomatic.git] / src / wx / timeline_time_axis_view.cc
1 /*
2     Copyright (C) 2013-2016 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
21 #include "timeline.h"
22 #include "timeline_time_axis_view.h"
23 #include "wx_util.h"
24 #include <wx/graphics.h>
25 #include <wx/wx.h>
26
27
28 using std::cout;
29 using std::list;
30 using namespace dcpomatic;
31
32
33 TimelineTimeAxisView::TimelineTimeAxisView (Timeline& tl, int y)
34         : TimelineView (tl)
35         , _y (y)
36 {
37
38 }
39
40
41 dcpomatic::Rect<int>
42 TimelineTimeAxisView::bbox () const
43 {
44         return dcpomatic::Rect<int> (0, _y - 4, _timeline.width(), 24);
45 }
46
47
48 /** @param y y position in tracks (not pixels) */
49 void
50 TimelineTimeAxisView::set_y (int y)
51 {
52         _y = y;
53         force_redraw ();
54 }
55
56
57 void
58 TimelineTimeAxisView::do_paint (wxGraphicsContext* gc, list<dcpomatic::Rect<int> >)
59 {
60         if (!_timeline.pixels_per_second()) {
61                 return;
62         }
63
64         double const pps = _timeline.pixels_per_second().get ();
65
66         gc->SetPen (*wxThePenList->FindOrCreatePen (wxColour (0, 0, 0), 1, wxPENSTYLE_SOLID));
67
68         double const mark_interval = calculate_mark_interval (rint (128 / pps));
69
70         int y = _y * _timeline.pixels_per_track() + 32;
71
72         wxGraphicsPath path = gc->CreatePath ();
73         path.MoveToPoint (0, y);
74         path.AddLineToPoint (_timeline.width(), y);
75         gc->StrokePath (path);
76
77         gc->SetFont (gc->CreateFont (*wxNORMAL_FONT));
78
79         /* Time in seconds */
80         DCPTime t;
81         while ((t.seconds() * pps) < _timeline.width()) {
82                 wxGraphicsPath path = gc->CreatePath ();
83                 path.MoveToPoint (time_x (t), y - 4);
84                 path.AddLineToPoint (time_x (t), y + 4);
85                 gc->StrokePath (path);
86
87                 double tc = t.seconds ();
88                 int const h = tc / 3600;
89                 tc -= h * 3600;
90                 int const m = tc / 60;
91                 tc -= m * 60;
92                 int const s = tc;
93
94                 wxString str = wxString::Format (wxT ("%02d:%02d:%02d"), h, m, s);
95                 wxDouble str_width;
96                 wxDouble str_height;
97                 wxDouble str_descent;
98                 wxDouble str_leading;
99                 gc->GetTextExtent (str, &str_width, &str_height, &str_descent, &str_leading);
100
101                 int const tx = t.seconds() * pps;
102                 if ((tx + str_width) < _timeline.width()) {
103                         gc->DrawText (str, time_x (t), y + 16);
104                 }
105
106                 t += DCPTime::from_seconds (mark_interval);
107         }
108 }