Ardour  9.0-pre0-844-g046623df59
ruler.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2015-2017 Robin Gareus <robin@gareus.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef __CANVAS_RULER_H__
21 #define __CANVAS_RULER_H__
22 
23 #include <string>
24 #include <vector>
25 
26 #include <pangomm/fontdescription.h>
27 
28 #include "canvas/rectangle.h"
29 
30 namespace ArdourCanvas
31 {
32 
34 {
35 public:
36  struct Mark {
37  enum Style {
40  Micro
41  };
42  std::string label;
43  double position;
45  };
46 
47  struct Metric {
48  Metric () : units_per_pixel (0) {}
49  virtual ~Metric() {}
50 
52 
53  /* lower and upper and sample positions, which are also canvas coordinates
54  */
55 
56  virtual void get_marks (std::vector<Mark>&, int64_t lower, int64_t upper, int maxchars) const = 0;
57  };
58 
59  Ruler (Canvas*, const Metric* m);
60  Ruler (Canvas*, const Metric* m, Rect const&);
61  Ruler (Item*, const Metric* m);
62  Ruler (Item*, const Metric* m, Rect const&);
63 
64  virtual ~Ruler () {
65  delete _font_description;
66  }
67 
68  void set_range (int64_t lower, int64_t upper);
69  void set_font_description (Pango::FontDescription);
70  void set_metric (const Metric *);
71 
72  void render (Rect const & area, Cairo::RefPtr<Cairo::Context>) const;
73 
75  void set_divide_height (double);
76 private:
77  const Metric* _metric;
78 
79  /* lower and upper and bounds for ruler */
80 
81  int64_t _lower;
82  int64_t _upper;
86 
87  Pango::FontDescription* _font_description;
88  mutable std::vector<Mark> marks;
89  mutable bool _need_marks;
90 };
91 
92 }
93 
94 
95 #endif
#define LIBCANVAS_API
int64_t _upper
Definition: ruler.h:82
virtual ~Ruler()
Definition: ruler.h:64
void set_divide_height(double)
Ruler(Item *, const Metric *m, Rect const &)
Ruler(Item *, const Metric *m)
void set_range(int64_t lower, int64_t upper)
void set_metric(const Metric *)
void render(Rect const &area, Cairo::RefPtr< Cairo::Context >) const
int64_t _lower
Definition: ruler.h:81
double _divide_height
Definition: ruler.h:83
Ruler(Canvas *, const Metric *m, Rect const &)
bool _need_marks
Definition: ruler.h:89
std::vector< Mark > marks
Definition: ruler.h:88
Gtkmm2ext::Color _divider_color_top
Definition: ruler.h:84
void set_font_description(Pango::FontDescription)
Pango::FontDescription * _font_description
Definition: ruler.h:87
void set_divide_colors(Gtkmm2ext::Color top, Gtkmm2ext::Color bottom)
Gtkmm2ext::Color _divider_color_bottom
Definition: ruler.h:85
const Metric * _metric
Definition: ruler.h:77
Ruler(Canvas *, const Metric *m)
uint32_t Color
Definition: colors.h:33
std::string label
Definition: ruler.h:42
virtual void get_marks(std::vector< Mark > &, int64_t lower, int64_t upper, int maxchars) const =0