Merge branch 'master' into cairocanvas
[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 #include "canvas/visibility.h"
31
32 namespace Cairo {
33         struct Context;
34 }
35
36 namespace ArdourCanvas
37 {
38
39 typedef double Coord;
40 typedef double Distance;
41 typedef uint32_t Color;
42
43 extern LIBCANVAS_API Coord const COORD_MAX;
44
45 struct LIBCANVAS_API Duple
46 {
47         Duple ()
48                 : x (0)
49                 , y (0)
50         {}
51         
52         Duple (Coord x_, Coord y_)
53                 : x (x_)
54                 , y (y_)
55         {}
56                      
57         Coord x;
58         Coord y;
59
60         Duple translate (Duple) const;
61 };
62
63
64 extern LIBCANVAS_API Duple operator- (Duple const &);
65 extern LIBCANVAS_API Duple operator+ (Duple const &, Duple const &);
66 extern LIBCANVAS_API bool operator== (Duple const &, Duple const &);
67 extern LIBCANVAS_API Duple operator- (Duple const &, Duple const &);
68 extern LIBCANVAS_API Duple operator/ (Duple const &, double);
69 extern LIBCANVAS_API std::ostream & operator<< (std::ostream &, Duple const &);
70
71 struct LIBCANVAS_API Rect
72 {
73         Rect ()
74                 : x0 (0)
75                 , y0 (0)
76                 , x1 (0)
77                 , y1 (0)
78         {}
79         
80         Rect (Coord x0_, Coord y0_, Coord x1_, Coord y1_)
81                 : x0 (x0_)
82                 , y0 (y0_)
83                 , x1 (x1_)
84                 , y1 (y1_)
85         {}
86                 
87         Coord x0;
88         Coord y0;
89         Coord x1;
90         Coord y1;
91
92         boost::optional<Rect> intersection (Rect const &) const;
93         Rect extend (Rect const &) const;
94         Rect translate (Duple) const;
95         Rect expand (Distance) const;
96         bool contains (Duple) const;
97         Rect fix () const;
98         bool empty() const { return (x0 == x1 && y0 == y1); }
99
100         Distance width () const {
101                 return x1 - x0;
102         }
103
104         Distance height () const {
105                 return y1 - y0;
106         }
107 };
108
109 extern LIBCANVAS_API std::ostream & operator<< (std::ostream &, Rect const &);
110
111 typedef std::vector<Duple> Points;
112
113 }
114         
115 #endif