OLD | NEW |
1 // Copyright (c) 2009 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 <iosfwd> | 15 #include <iosfwd> |
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(USE_X11) |
23 typedef struct _GdkRectangle GdkRectangle; | 23 typedef struct _GdkRectangle GdkRectangle; |
24 #endif | 24 #endif |
25 | 25 |
26 namespace gfx { | 26 namespace gfx { |
27 | 27 |
28 class Rect { | 28 class Rect { |
29 public: | 29 public: |
30 Rect(); | 30 Rect(); |
31 Rect(int width, int height); | 31 Rect(int width, int height); |
32 Rect(int x, int y, int width, int height); | 32 Rect(int x, int y, int width, int height); |
33 #if defined(OS_WIN) | 33 #if defined(OS_WIN) |
34 explicit Rect(const RECT& r); | 34 explicit Rect(const RECT& r); |
35 #elif defined(OS_MACOSX) | 35 #elif defined(OS_MACOSX) |
36 explicit Rect(const CGRect& r); | 36 explicit Rect(const CGRect& r); |
37 #elif defined(OS_LINUX) | 37 #elif defined(USE_X11) |
38 explicit Rect(const GdkRectangle& r); | 38 explicit Rect(const GdkRectangle& r); |
39 #endif | 39 #endif |
40 Rect(const gfx::Point& origin, const gfx::Size& size); | 40 Rect(const gfx::Point& origin, const gfx::Size& size); |
41 | 41 |
42 ~Rect() {} | 42 ~Rect() {} |
43 | 43 |
44 #if defined(OS_WIN) | 44 #if defined(OS_WIN) |
45 Rect& operator=(const RECT& r); | 45 Rect& operator=(const RECT& r); |
46 #elif defined(OS_MACOSX) | 46 #elif defined(OS_MACOSX) |
47 Rect& operator=(const CGRect& r); | 47 Rect& operator=(const CGRect& r); |
48 #elif defined(OS_LINUX) | 48 #elif defined(USE_X11) |
49 Rect& operator=(const GdkRectangle& r); | 49 Rect& operator=(const GdkRectangle& r); |
50 #endif | 50 #endif |
51 | 51 |
52 int x() const { return origin_.x(); } | 52 int x() const { return origin_.x(); } |
53 void set_x(int x) { origin_.set_x(x); } | 53 void set_x(int x) { origin_.set_x(x); } |
54 | 54 |
55 int y() const { return origin_.y(); } | 55 int y() const { return origin_.y(); } |
56 void set_y(int y) { origin_.set_y(y); } | 56 void set_y(int y) { origin_.set_y(y); } |
57 | 57 |
58 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... |
90 | 90 |
91 bool operator==(const Rect& other) const; | 91 bool operator==(const Rect& other) const; |
92 | 92 |
93 bool operator!=(const Rect& other) const { | 93 bool operator!=(const Rect& other) const { |
94 return !(*this == other); | 94 return !(*this == other); |
95 } | 95 } |
96 | 96 |
97 #if defined(OS_WIN) | 97 #if defined(OS_WIN) |
98 // Construct an equivalent Win32 RECT object. | 98 // Construct an equivalent Win32 RECT object. |
99 RECT ToRECT() const; | 99 RECT ToRECT() const; |
100 #elif defined(OS_LINUX) | 100 #elif defined(USE_X11) |
101 GdkRectangle ToGdkRectangle() const; | 101 GdkRectangle ToGdkRectangle() const; |
102 #elif defined(OS_MACOSX) | 102 #elif defined(OS_MACOSX) |
103 // Construct an equivalent CoreGraphics object. | 103 // Construct an equivalent CoreGraphics object. |
104 CGRect ToCGRect() const; | 104 CGRect ToCGRect() const; |
105 #endif | 105 #endif |
106 | 106 |
107 // 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 |
108 // 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 |
109 // point (x + width, y + height) is not. | 109 // point (x + width, y + height) is not. |
110 bool Contains(int point_x, int point_y) const; | 110 bool Contains(int point_x, int point_y) const; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 private: | 151 private: |
152 gfx::Point origin_; | 152 gfx::Point origin_; |
153 gfx::Size size_; | 153 gfx::Size size_; |
154 }; | 154 }; |
155 | 155 |
156 } // namespace gfx | 156 } // namespace gfx |
157 | 157 |
158 std::ostream& operator<<(std::ostream& out, const gfx::Rect& r); | 158 std::ostream& operator<<(std::ostream& out, const gfx::Rect& r); |
159 | 159 |
160 #endif // BASE_GFX_RECT_H__ | 160 #endif // BASE_GFX_RECT_H__ |
OLD | NEW |