Merge branch 'master' into cairocanvas
[ardour.git] / libs / canvas / canvas / types.h
1 #ifndef __CANVAS_TYPES_H__
2 #define __CANVAS_TYPES_H__
3
4 #include <iostream>
5 #include <vector>
6 #include <stdint.h>
7 #include <boost/optional.hpp>
8
9 namespace ArdourCanvas
10 {
11
12 typedef double Coord;
13 typedef double Distance;
14 typedef uint32_t Color;
15
16 extern Coord const COORD_MAX;
17 extern Coord const CAIRO_MAX;
18
19 struct Duple
20 {
21         Duple ()
22                 : x (0)
23                 , y (0)
24         {}
25         
26         Duple (Coord x_, Coord y_)
27                 : x (x_)
28                 , y (y_)
29         {}
30                      
31         Coord x;
32         Coord y;
33
34         Duple translate (Duple) const;
35 };
36
37
38 extern Duple operator- (Duple const &);
39 extern Duple operator+ (Duple const &, Duple const &);
40 extern Duple operator- (Duple const &, Duple const &);
41 extern Duple operator/ (Duple const &, double);
42 extern std::ostream & operator<< (std::ostream &, Duple const &);
43
44 struct Rect
45 {
46         Rect ()
47                 : x0 (0)
48                 , y0 (0)
49                 , x1 (0)
50                 , y1 (0)
51         {}
52         
53         Rect (Coord x0_, Coord y0_, Coord x1_, Coord y1_)
54                 : x0 (x0_)
55                 , y0 (y0_)
56                 , x1 (x1_)
57                 , y1 (y1_)
58         {}
59                 
60         Coord x0;
61         Coord y0;
62         Coord x1;
63         Coord y1;
64
65         boost::optional<Rect> intersection (Rect const &) const;
66         Rect extend (Rect const &) const;
67         Rect translate (Duple) const;
68         Rect expand (Distance) const;
69         bool contains (Duple) const;
70         Rect fix () const;
71
72         Distance width () const {
73                 return x1 - x0;
74         }
75
76         Distance height () const {
77                 return y1 - y0;
78         }
79 };
80
81 extern std::ostream & operator<< (std::ostream &, Rect const &);
82
83 typedef std::vector<Duple> Points;
84
85 }
86         
87 #endif