Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1092)

Side by Side Diff: ui/gfx/rect.h

Issue 10993094: Make adding and subtracting gfx:: point types simpler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 #if defined(OS_WIN) 61 #if defined(OS_WIN)
62 // Construct an equivalent Win32 RECT object. 62 // Construct an equivalent Win32 RECT object.
63 RECT ToRECT() const; 63 RECT ToRECT() const;
64 #elif defined(TOOLKIT_GTK) 64 #elif defined(TOOLKIT_GTK)
65 GdkRectangle ToGdkRectangle() const; 65 GdkRectangle ToGdkRectangle() const;
66 #elif defined(OS_MACOSX) 66 #elif defined(OS_MACOSX)
67 // Construct an equivalent CoreGraphics object. 67 // Construct an equivalent CoreGraphics object.
68 CGRect ToCGRect() const; 68 CGRect ToCGRect() const;
69 #endif 69 #endif
70 70
71 RectF ToRectF() const WARN_UNUSED_RESULT {
72 return RectF(origin().x(), origin().y(), size().width(), size().height());
73 }
74
75 RectF Scale(float scale) const WARN_UNUSED_RESULT { 71 RectF Scale(float scale) const WARN_UNUSED_RESULT {
76 return Scale(scale, scale); 72 return Scale(scale, scale);
77 } 73 }
78 74
79 RectF Scale(float x_scale, float y_scale) const WARN_UNUSED_RESULT { 75 RectF Scale(float x_scale, float y_scale) const WARN_UNUSED_RESULT {
80 return ToRectF().Scale(x_scale, y_scale); 76 return static_cast<RectF>(*this).Scale(x_scale, y_scale);
81 } 77 }
82 78
83 std::string ToString() const; 79 std::string ToString() const;
80
81 operator RectF() const {
sky 2012/10/01 21:02:20 Why is this better than ToRectF?
danakj 2012/10/01 21:55:34 So you don't have to cast all the ints to floats e
82 return RectF(origin().x(), origin().y(), size().width(), size().height());
83 }
84 }; 84 };
85 85
86 #if !defined(COMPILER_MSVC) 86 #if !defined(COMPILER_MSVC)
87 extern template class RectBase<Rect, Point, Size, Insets, int>; 87 extern template class RectBase<Rect, Point, Size, Insets, int>;
88 #endif 88 #endif
89 89
90 } // namespace gfx 90 } // namespace gfx
91 91
92 #endif // UI_GFX_RECT_H_ 92 #endif // UI_GFX_RECT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698