change UIConfig to use accessor/setter methods like RCConfig so that ParameterChanged...
[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 namespace ArdourCanvas
29 {
30
31 typedef double Coord;
32 typedef double Distance;
33 typedef uint32_t Color;
34
35 extern Coord const COORD_MAX;
36 extern Coord const CAIRO_MAX;
37
38 struct Duple
39 {
40         Duple ()
41                 : x (0)
42                 , y (0)
43         {}
44         
45         Duple (Coord x_, Coord y_)
46                 : x (x_)
47                 , y (y_)
48         {}
49                      
50         Coord x;
51         Coord y;
52
53         Duple translate (Duple) const;
54 };
55
56
57 extern Duple operator- (Duple const &);
58 extern Duple operator+ (Duple const &, Duple const &);
59 extern Duple operator- (Duple const &, Duple const &);
60 extern Duple operator/ (Duple const &, double);
61 extern std::ostream & operator<< (std::ostream &, Duple const &);
62
63 struct Rect
64 {
65         Rect ()
66                 : x0 (0)
67                 , y0 (0)
68                 , x1 (0)
69                 , y1 (0)
70         {}
71         
72         Rect (Coord x0_, Coord y0_, Coord x1_, Coord y1_)
73                 : x0 (x0_)
74                 , y0 (y0_)
75                 , x1 (x1_)
76                 , y1 (y1_)
77         {}
78                 
79         Coord x0;
80         Coord y0;
81         Coord x1;
82         Coord y1;
83
84         boost::optional<Rect> intersection (Rect const &) const;
85         Rect extend (Rect const &) const;
86         Rect translate (Duple) const;
87         Rect expand (Distance) const;
88         bool contains (Duple) const;
89         Rect fix () const;
90
91         Distance width () const {
92                 return x1 - x0;
93         }
94
95         Distance height () const {
96                 return y1 - y0;
97         }
98 };
99
100 extern std::ostream & operator<< (std::ostream &, Rect const &);
101
102 typedef std::vector<Duple> Points;
103
104 }
105         
106 #endif