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

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

Issue 11269022: Add Vector2d classes that represent offsets, instead of using Point. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: vector length and conversion to size Created 8 years, 1 month 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 #ifndef UI_GFX_POINT_H_ 5 #ifndef UI_GFX_POINT_H_
6 #define UI_GFX_POINT_H_ 6 #define UI_GFX_POINT_H_
7 7
8 #include "ui/base/ui_export.h" 8 #include "ui/base/ui_export.h"
9 #include "ui/gfx/point_base.h" 9 #include "ui/gfx/point_base.h"
10 #include "ui/gfx/point_f.h" 10 #include "ui/gfx/point_f.h"
11 #include "ui/gfx/vector2d.h"
11 12
12 #if defined(OS_WIN) 13 #if defined(OS_WIN)
13 typedef unsigned long DWORD; 14 typedef unsigned long DWORD;
14 typedef struct tagPOINT POINT; 15 typedef struct tagPOINT POINT;
15 #elif defined(OS_IOS) 16 #elif defined(OS_IOS)
16 #include <CoreGraphics/CoreGraphics.h> 17 #include <CoreGraphics/CoreGraphics.h>
17 #elif defined(OS_MACOSX) 18 #elif defined(OS_MACOSX)
18 #include <ApplicationServices/ApplicationServices.h> 19 #include <ApplicationServices/ApplicationServices.h>
19 #endif 20 #endif
20 21
21 namespace gfx { 22 namespace gfx {
22 23
23 // A point has an x and y coordinate. 24 // A point has an x and y coordinate.
24 class UI_EXPORT Point : public PointBase<Point, int> { 25 class UI_EXPORT Point : public PointBase<Point, int, Vector2d> {
25 public: 26 public:
26 Point(); 27 Point();
27 Point(int x, int y); 28 Point(int x, int y);
28 #if defined(OS_WIN) 29 #if defined(OS_WIN)
29 // |point| is a DWORD value that contains a coordinate. The x-coordinate is 30 // |point| is a DWORD value that contains a coordinate. The x-coordinate is
30 // the low-order short and the y-coordinate is the high-order short. This 31 // the low-order short and the y-coordinate is the high-order short. This
31 // value is commonly acquired from GetMessagePos/GetCursorPos. 32 // value is commonly acquired from GetMessagePos/GetCursorPos.
32 explicit Point(DWORD point); 33 explicit Point(DWORD point);
33 explicit Point(const POINT& point); 34 explicit Point(const POINT& point);
34 Point& operator=(const POINT& point); 35 Point& operator=(const POINT& point);
(...skipping 26 matching lines...) Expand all
61 }; 62 };
62 63
63 inline bool operator==(const Point& lhs, const Point& rhs) { 64 inline bool operator==(const Point& lhs, const Point& rhs) {
64 return lhs.x() == rhs.x() && lhs.y() == rhs.y(); 65 return lhs.x() == rhs.x() && lhs.y() == rhs.y();
65 } 66 }
66 67
67 inline bool operator!=(const Point& lhs, const Point& rhs) { 68 inline bool operator!=(const Point& lhs, const Point& rhs) {
68 return !(lhs == rhs); 69 return !(lhs == rhs);
69 } 70 }
70 71
71 inline Point operator+(Point lhs, Point rhs) { 72 inline Point operator+(Point lhs, Vector2d rhs) {
sky 2012/10/26 20:22:17 const& on both
72 return lhs.Add(rhs); 73 return lhs.Add(rhs);
73 } 74 }
74 75
75 inline Point operator-(Point lhs, Point rhs) { 76 inline Point operator-(Point lhs, Vector2d rhs) {
sky 2012/10/26 20:22:17 const& on both
76 return lhs.Subtract(rhs); 77 return lhs.Subtract(rhs);
77 } 78 }
78 79
80 inline Vector2d operator-(Point lhs, Point rhs) {
sky 2012/10/26 20:22:17 const& on both
81 return lhs.DistanceFrom(rhs);
82 }
83
84 inline Point PointAtDistanceFromOrigin(const Vector2d& distance_from_origin) {
85 return Point(distance_from_origin.x(), distance_from_origin.y());
86 }
87
79 #if !defined(COMPILER_MSVC) 88 #if !defined(COMPILER_MSVC)
80 extern template class PointBase<Point, int>; 89 extern template class PointBase<Point, int, Vector2d>;
81 #endif 90 #endif
82 91
83 } // namespace gfx 92 } // namespace gfx
84 93
85 #endif // UI_GFX_POINT_H_ 94 #endif // UI_GFX_POINT_H_
OLDNEW
« no previous file with comments | « ui/gfx/canvas.cc ('k') | ui/gfx/point.cc » ('j') | ui/gfx/point_f.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698