OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 Contains()) to complain in this case. | 10 // in the operations (such as Contains()) to complain in this case. |
(...skipping 17 matching lines...) Expand all Loading... |
28 #elif defined(OS_IOS) | 28 #elif defined(OS_IOS) |
29 #include <CoreGraphics/CoreGraphics.h> | 29 #include <CoreGraphics/CoreGraphics.h> |
30 #elif defined(OS_MACOSX) | 30 #elif defined(OS_MACOSX) |
31 #include <ApplicationServices/ApplicationServices.h> | 31 #include <ApplicationServices/ApplicationServices.h> |
32 #endif | 32 #endif |
33 | 33 |
34 namespace gfx { | 34 namespace gfx { |
35 | 35 |
36 class Insets; | 36 class Insets; |
37 | 37 |
38 class UI_EXPORT Rect | 38 class GFX_EXPORT Rect |
39 : public RectBase<Rect, Point, Size, Insets, Vector2d, int> { | 39 : public RectBase<Rect, Point, Size, Insets, Vector2d, int> { |
40 public: | 40 public: |
41 Rect() : RectBase<Rect, Point, Size, Insets, Vector2d, int>(Point()) {} | 41 Rect() : RectBase<Rect, Point, Size, Insets, Vector2d, int>(Point()) {} |
42 | 42 |
43 Rect(int width, int height) | 43 Rect(int width, int height) |
44 : RectBase<Rect, Point, Size, Insets, Vector2d, int> | 44 : RectBase<Rect, Point, Size, Insets, Vector2d, int> |
45 (Size(width, height)) {} | 45 (Size(width, height)) {} |
46 | 46 |
47 Rect(int x, int y, int width, int height) | 47 Rect(int x, int y, int width, int height) |
48 : RectBase<Rect, Point, Size, Insets, Vector2d, int> | 48 : RectBase<Rect, Point, Size, Insets, Vector2d, int> |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 }; | 82 }; |
83 | 83 |
84 inline bool operator==(const Rect& lhs, const Rect& rhs) { | 84 inline bool operator==(const Rect& lhs, const Rect& rhs) { |
85 return lhs.origin() == rhs.origin() && lhs.size() == rhs.size(); | 85 return lhs.origin() == rhs.origin() && lhs.size() == rhs.size(); |
86 } | 86 } |
87 | 87 |
88 inline bool operator!=(const Rect& lhs, const Rect& rhs) { | 88 inline bool operator!=(const Rect& lhs, const Rect& rhs) { |
89 return !(lhs == rhs); | 89 return !(lhs == rhs); |
90 } | 90 } |
91 | 91 |
92 UI_EXPORT Rect operator+(const Rect& lhs, const Vector2d& rhs); | 92 GFX_EXPORT Rect operator+(const Rect& lhs, const Vector2d& rhs); |
93 UI_EXPORT Rect operator-(const Rect& lhs, const Vector2d& rhs); | 93 GFX_EXPORT Rect operator-(const Rect& lhs, const Vector2d& rhs); |
94 | 94 |
95 inline Rect operator+(const Vector2d& lhs, const Rect& rhs) { | 95 inline Rect operator+(const Vector2d& lhs, const Rect& rhs) { |
96 return rhs + lhs; | 96 return rhs + lhs; |
97 } | 97 } |
98 | 98 |
99 UI_EXPORT Rect IntersectRects(const Rect& a, const Rect& b); | 99 GFX_EXPORT Rect IntersectRects(const Rect& a, const Rect& b); |
100 UI_EXPORT Rect UnionRects(const Rect& a, const Rect& b); | 100 GFX_EXPORT Rect UnionRects(const Rect& a, const Rect& b); |
101 UI_EXPORT Rect SubtractRects(const Rect& a, const Rect& b); | 101 GFX_EXPORT Rect SubtractRects(const Rect& a, const Rect& b); |
102 | 102 |
103 // Constructs a rectangle with |p1| and |p2| as opposite corners. | 103 // Constructs a rectangle with |p1| and |p2| as opposite corners. |
104 // | 104 // |
105 // This could also be thought of as "the smallest rect that contains both | 105 // This could also be thought of as "the smallest rect that contains both |
106 // points", except that we consider points on the right/bottom edges of the | 106 // points", except that we consider points on the right/bottom edges of the |
107 // rect to be outside the rect. So technically one or both points will not be | 107 // rect to be outside the rect. So technically one or both points will not be |
108 // contained within the rect, because they will appear on one of these edges. | 108 // contained within the rect, because they will appear on one of these edges. |
109 UI_EXPORT Rect BoundingRect(const Point& p1, const Point& p2); | 109 GFX_EXPORT Rect BoundingRect(const Point& p1, const Point& p2); |
110 | 110 |
111 inline Rect ScaleToEnclosingRect(const Rect& rect, | 111 inline Rect ScaleToEnclosingRect(const Rect& rect, |
112 float x_scale, | 112 float x_scale, |
113 float y_scale) { | 113 float y_scale) { |
114 int x = std::floor(rect.x() * x_scale); | 114 int x = std::floor(rect.x() * x_scale); |
115 int y = std::floor(rect.y() * y_scale); | 115 int y = std::floor(rect.y() * y_scale); |
116 int r = rect.width() == 0 ? x : std::ceil(rect.right() * x_scale); | 116 int r = rect.width() == 0 ? x : std::ceil(rect.right() * x_scale); |
117 int b = rect.height() == 0 ? y : std::ceil(rect.bottom() * y_scale); | 117 int b = rect.height() == 0 ? y : std::ceil(rect.bottom() * y_scale); |
118 return Rect(x, y, r - x, b - y); | 118 return Rect(x, y, r - x, b - y); |
119 } | 119 } |
(...skipping 16 matching lines...) Expand all Loading... |
136 return ScaleToEnclosedRect(rect, scale, scale); | 136 return ScaleToEnclosedRect(rect, scale, scale); |
137 } | 137 } |
138 | 138 |
139 #if !defined(COMPILER_MSVC) | 139 #if !defined(COMPILER_MSVC) |
140 extern template class RectBase<Rect, Point, Size, Insets, Vector2d, int>; | 140 extern template class RectBase<Rect, Point, Size, Insets, Vector2d, int>; |
141 #endif | 141 #endif |
142 | 142 |
143 } // namespace gfx | 143 } // namespace gfx |
144 | 144 |
145 #endif // UI_GFX_RECT_H_ | 145 #endif // UI_GFX_RECT_H_ |
OLD | NEW |