OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Defines a simple integer rectangle class. The containment semantics | 5 // Defines a simple integer rectangle class. The containment semantics |
6 // are array-like; that is, the coordinate (x, y) is considered to be | 6 // are array-like; that is, the coordinate (x, y) is considered to be |
7 // contained by the rectangle, but the coordinate (x + width, y) is not. | 7 // contained by the rectangle, but the coordinate (x + width, y) is not. |
8 // The class will happily let you create malformed rectangles (that is, | 8 // The class will happily let you create malformed rectangles (that is, |
9 // rectangles with negative width and/or height), but there will be assertions | 9 // rectangles with negative width and/or height), but there will be assertions |
10 // in the operations (such as contain()) to complain in this case. | 10 // in the operations (such as contain()) to complain in this case. |
11 | 11 |
12 #ifndef BASE_GFX_RECT_H__ | 12 #ifndef BASE_GFX_RECT_H__ |
13 #define BASE_GFX_RECT_H__ | 13 #define BASE_GFX_RECT_H__ |
14 | 14 |
15 #include <iostream> | 15 #include <iostream> |
16 | 16 |
17 #include "base/gfx/point.h" | 17 #include "base/gfx/point.h" |
18 #include "base/gfx/size.h" | 18 #include "base/gfx/size.h" |
19 | 19 |
20 #if defined(OS_WIN) | 20 #if defined(OS_WIN) |
21 typedef struct tagRECT RECT; | 21 typedef struct tagRECT RECT; |
22 #elif defined(OS_LINUX) | 22 #elif defined(TOOLKIT_GTK) |
23 // It's wrong to hide GDK stuff behind OS_LINUX, but until we have a different | |
24 // linux target, this is less complex. | |
25 typedef struct _GdkRectangle GdkRectangle; | 23 typedef struct _GdkRectangle GdkRectangle; |
26 #endif | 24 #endif |
27 | 25 |
28 namespace gfx { | 26 namespace gfx { |
29 | 27 |
30 class Rect { | 28 class Rect { |
31 public: | 29 public: |
32 Rect(); | 30 Rect(); |
33 Rect(int width, int height); | 31 Rect(int width, int height); |
34 Rect(int x, int y, int width, int height); | 32 Rect(int x, int y, int width, int height); |
35 #if defined(OS_WIN) | 33 #if defined(OS_WIN) |
36 explicit Rect(const RECT& r); | 34 explicit Rect(const RECT& r); |
37 #elif defined(OS_MACOSX) | 35 #elif defined(OS_MACOSX) |
38 explicit Rect(const CGRect& r); | 36 explicit Rect(const CGRect& r); |
39 #elif defined(OS_LINUX) | 37 #elif defined(TOOLKIT_GTK) |
40 explicit Rect(const GdkRectangle& r); | 38 explicit Rect(const GdkRectangle& r); |
41 #endif | 39 #endif |
42 Rect(const gfx::Point& origin, const gfx::Size& size); | 40 Rect(const gfx::Point& origin, const gfx::Size& size); |
43 | 41 |
44 ~Rect() {} | 42 ~Rect() {} |
45 | 43 |
46 #if defined(OS_WIN) | 44 #if defined(OS_WIN) |
47 Rect& operator=(const RECT& r); | 45 Rect& operator=(const RECT& r); |
48 #elif defined(OS_MACOSX) | 46 #elif defined(OS_MACOSX) |
49 Rect& operator=(const CGRect& r); | 47 Rect& operator=(const CGRect& r); |
50 #elif defined(OS_LINUX) | 48 #elif defined(TOOLKIT_GTK) |
51 Rect& operator=(const GdkRectangle& r); | 49 Rect& operator=(const GdkRectangle& r); |
52 #endif | 50 #endif |
53 | 51 |
54 int x() const { return origin_.x(); } | 52 int x() const { return origin_.x(); } |
55 void set_x(int x) { origin_.set_x(x); } | 53 void set_x(int x) { origin_.set_x(x); } |
56 | 54 |
57 int y() const { return origin_.y(); } | 55 int y() const { return origin_.y(); } |
58 void set_y(int y) { origin_.set_y(y); } | 56 void set_y(int y) { origin_.set_y(y); } |
59 | 57 |
60 int width() const { return size_.width(); } | 58 int width() const { return size_.width(); } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 | 90 |
93 bool operator==(const Rect& other) const; | 91 bool operator==(const Rect& other) const; |
94 | 92 |
95 bool operator!=(const Rect& other) const { | 93 bool operator!=(const Rect& other) const { |
96 return !(*this == other); | 94 return !(*this == other); |
97 } | 95 } |
98 | 96 |
99 #if defined(OS_WIN) | 97 #if defined(OS_WIN) |
100 // Construct an equivalent Win32 RECT object. | 98 // Construct an equivalent Win32 RECT object. |
101 RECT ToRECT() const; | 99 RECT ToRECT() const; |
102 #elif defined(OS_LINUX) | 100 #elif defined(TOOLKIT_GTK) |
103 GdkRectangle ToGdkRectangle() const; | 101 GdkRectangle ToGdkRectangle() const; |
104 #elif defined(OS_MACOSX) | 102 #elif defined(OS_MACOSX) |
105 // Construct an equivalent CoreGraphics object. | 103 // Construct an equivalent CoreGraphics object. |
106 CGRect ToCGRect() const; | 104 CGRect ToCGRect() const; |
107 #endif | 105 #endif |
108 | 106 |
109 // Returns true if the point identified by point_x and point_y falls inside | 107 // Returns true if the point identified by point_x and point_y falls inside |
110 // this rectangle. The point (x, y) is inside the rectangle, but the | 108 // this rectangle. The point (x, y) is inside the rectangle, but the |
111 // point (x + width, y + height) is not. | 109 // point (x + width, y + height) is not. |
112 bool Contains(int point_x, int point_y) const; | 110 bool Contains(int point_x, int point_y) const; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 gfx::Size size_; | 153 gfx::Size size_; |
156 }; | 154 }; |
157 | 155 |
158 } // namespace gfx | 156 } // namespace gfx |
159 | 157 |
160 inline std::ostream& operator<<(std::ostream& out, const gfx::Rect& r) { | 158 inline std::ostream& operator<<(std::ostream& out, const gfx::Rect& r) { |
161 return out << r.origin() << " " << r.size(); | 159 return out << r.origin() << " " << r.size(); |
162 } | 160 } |
163 | 161 |
164 #endif // BASE_GFX_RECT_H__ | 162 #endif // BASE_GFX_RECT_H__ |
OLD | NEW |