refactor Canvas so that all Items have children; add Container abstract base class...
[ardour.git] / libs / canvas / canvas / ruler.h
1 /*
2     Copyright (C) 2014 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19 #ifndef __CANVAS_RULER_H__
20 #define __CANVAS_RULER_H__
21
22 #include <string>
23 #include <vector>
24
25 #include <pangomm/fontdescription.h>
26
27 #include "canvas/rectangle.h"
28
29 namespace ArdourCanvas
30 {
31         
32 class LIBCANVAS_API Ruler : public Rectangle
33 {
34 public:
35         struct Mark {
36                 enum Style {
37                         Major,
38                         Minor,
39                         Micro
40                 };
41                 std::string label;
42                 double position;
43                 Style  style;
44         };
45         
46         struct Metric {
47                 Metric () : units_per_pixel (0) {}
48                 virtual ~Metric() {}
49
50                 double units_per_pixel;
51
52                 /* lower and upper and sample positions, which are also canvas coordinates
53                  */
54                 
55                 virtual void get_marks (std::vector<Mark>&, double lower, double upper, int maxchars) const = 0;
56         };
57         
58         Ruler (Canvas*, const Metric& m);
59         Ruler (Canvas*, const Metric& m, Rect const&);
60         Ruler (Item*, const Metric& m);
61         Ruler (Item*, const Metric& m, Rect const&);
62         
63         void set_range (double lower, double upper);
64         void set_font_description (Pango::FontDescription);
65         
66         void render (Rect const & area, Cairo::RefPtr<Cairo::Context>) const;
67         
68 private:
69         const Metric& _metric;
70
71         /* lower and upper and sample positions, which are also canvas coordinates
72          */
73
74         Coord         _lower;
75         Coord         _upper;
76
77         Pango::FontDescription* _font_description;
78         mutable std::vector<Mark> marks;
79         mutable bool _need_marks;
80 };
81
82 }
83
84
85 #endif