fix up size and drawing of measure lines, even when vertically scrolled
[ardour.git] / libs / canvas / canvas / types.h
1 /*
2     Copyright (C) 2011-2013 Paul Davis
3     Author: Carl Hetherington <cth@carlh.net>
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
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #ifndef __CANVAS_TYPES_H__
21 #define __CANVAS_TYPES_H__
22
23 #include <iostream>
24 #include <vector>
25 #include <stdint.h>
26 #include <boost/optional.hpp>
27
28 #include <cairomm/refptr.h>
29
30 namespace Cairo {
31         struct Context;
32 }
33
34 namespace ArdourCanvas
35 {
36
37 typedef double Coord;
38 typedef double Distance;
39 typedef uint32_t Color;
40
41 extern Coord const COORD_MAX;
42
43 struct Duple
44 {
45         Duple ()
46                 : x (0)
47                 , y (0)
48         {}
49         
50         Duple (Coord x_, Coord y_)
51                 : x (x_)
52                 , y (y_)
53         {}
54                      
55         Coord x;
56         Coord y;
57
58         Duple translate (Duple) const;
59 };
60
61
62 extern Duple operator- (Duple const &);
63 extern Duple operator+ (Duple const &, Duple const &);
64 extern bool operator== (Duple const &, Duple const &);
65 extern Duple operator- (Duple const &, Duple const &);
66 extern Duple operator/ (Duple const &, double);
67 extern std::ostream & operator<< (std::ostream &, Duple const &);
68
69 struct Rect
70 {
71         Rect ()
72                 : x0 (0)
73                 , y0 (0)
74                 , x1 (0)
75                 , y1 (0)
76         {}
77         
78         Rect (Coord x0_, Coord y0_, Coord x1_, Coord y1_)
79                 : x0 (x0_)
80                 , y0 (y0_)
81                 , x1 (x1_)
82                 , y1 (y1_)
83         {}
84                 
85         Coord x0;
86         Coord y0;
87         Coord x1;
88         Coord y1;
89
90         boost::optional<Rect> intersection (Rect const &) const;
91         Rect extend (Rect const &) const;
92         Rect translate (Duple) const;
93         Rect expand (Distance) const;
94         bool contains (Duple) const;
95         Rect fix () const;
96
97         Rect convert_to_device (Cairo::RefPtr<Cairo::Context>) const;
98         Rect convert_to_user (Cairo::RefPtr<Cairo::Context>) const;
99
100         Distance width () const {
101                 return x1 - x0;
102         }
103
104         Distance height () const {
105                 return y1 - y0;
106         }
107 };
108
109 extern std::ostream & operator<< (std::ostream &, Rect const &);
110
111 typedef std::vector<Duple> Points;
112
113 }
114         
115 #endif