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