xref: /haiku/src/add-ons/print/drivers/gutenprint/Rectangle.h (revision cbe0a0c436162d78cc3f92a305b64918c839d079)
1 /*
2 * Copyright 2010, Haiku. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		Michael Pfeiffer
7 */
8 #ifndef RECTANGLE_H
9 #define RECTANGLE_H
10 
11 
12 #include <SupportDefs.h>
13 
14 
15 template<typename T>
16 class Rectangle
17 {
18 public:
19 	Rectangle()
20 	:
21 	left(0),
22 	top(0),
23 	right(0),
24 	bottom(0)
25 	{
26 
27 	}
28 
29 
30 	Rectangle(const BRect& rect)
31 	:
32 	left(static_cast<T>(rect.left)),
33 	top(static_cast<T>(rect.top)),
34 	right(static_cast<T>(rect.right)),
35 	bottom(static_cast<T>(rect.bottom))
36 	{
37 	}
38 
39 
40 	Rectangle(T left, T top, T right, T bottom)
41 	:
42 	left(left),
43 	top(top),
44 	right(right),
45 	bottom(bottom)
46 	{
47 	}
48 
49 
50 	Rectangle<T>& operator=(const BRect& rect) {
51 		left = static_cast<T>(rect.left);
52 		top = static_cast<T>(rect.top);
53 		right = static_cast<T>(rect.right);
54 		bottom = static_cast<T>(rect.bottom);
55 		return *this;
56 	}
57 
58 
59 	T Width() const {
60 		return right - left;
61 	}
62 
63 
64 	T Height() const {
65 		return bottom - top;
66 	}
67 
68 
69 	T left;
70 	T top;
71 	T right;
72 	T bottom;
73 };
74 
75 
76 typedef Rectangle<int32> RectInt32;
77 
78 
79 #endif
80