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