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

Side by Side Diff: gfx/point.h

Issue 6246027: Move src/gfx/ to src/ui/gfx... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 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
« no previous file with comments | « gfx/platform_font_win.cc ('k') | gfx/point.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 GFX_POINT_H_ 5 #ifndef GFX_POINT_H_
6 #define GFX_POINT_H_ 6 #define GFX_POINT_H_
7 #pragma once 7 #pragma once
8 8
9 #include "build/build_config.h" 9 #include "ui/gfx/point.h"
10 10 // TODO(sail): remove this file once all includes have been updated.
11 #include <iosfwd>
12
13 #if defined(OS_WIN)
14 typedef unsigned long DWORD;
15 typedef struct tagPOINT POINT;
16 #elif defined(OS_MACOSX)
17 #include <ApplicationServices/ApplicationServices.h>
18 #endif
19
20 namespace gfx {
21
22 // A point has an x and y coordinate.
23 class Point {
24 public:
25 Point();
26 Point(int x, int y);
27 #if defined(OS_WIN)
28 // |point| is a DWORD value that contains a coordinate. The x-coordinate is
29 // the low-order short and the y-coordinate is the high-order short. This
30 // value is commonly acquired from GetMessagePos/GetCursorPos.
31 explicit Point(DWORD point);
32 explicit Point(const POINT& point);
33 Point& operator=(const POINT& point);
34 #elif defined(OS_MACOSX)
35 explicit Point(const CGPoint& point);
36 #endif
37
38 ~Point() {}
39
40 int x() const { return x_; }
41 int y() const { return y_; }
42
43 void SetPoint(int x, int y) {
44 x_ = x;
45 y_ = y;
46 }
47
48 void set_x(int x) { x_ = x; }
49 void set_y(int y) { y_ = y; }
50
51 void Offset(int delta_x, int delta_y) {
52 x_ += delta_x;
53 y_ += delta_y;
54 }
55
56 Point Add(const Point& other) const{
57 Point copy = *this;
58 copy.Offset(other.x_, other.y_);
59 return copy;
60 }
61
62 Point Subtract(const Point& other) const {
63 Point copy = *this;
64 copy.Offset(-other.x_, -other.y_);
65 return copy;
66 }
67
68 bool operator==(const Point& rhs) const {
69 return x_ == rhs.x_ && y_ == rhs.y_;
70 }
71
72 bool operator!=(const Point& rhs) const {
73 return !(*this == rhs);
74 }
75
76 // A point is less than another point if its y-value is closer
77 // to the origin. If the y-values are the same, then point with
78 // the x-value closer to the origin is considered less than the
79 // other.
80 // This comparison is required to use Points in sets, or sorted
81 // vectors.
82 bool operator<(const Point& rhs) const {
83 return (y_ == rhs.y_) ? (x_ < rhs.x_) : (y_ < rhs.y_);
84 }
85
86 #if defined(OS_WIN)
87 POINT ToPOINT() const;
88 #elif defined(OS_MACOSX)
89 CGPoint ToCGPoint() const;
90 #endif
91
92 private:
93 int x_;
94 int y_;
95 };
96
97 std::ostream& operator<<(std::ostream& out, const gfx::Point& p);
98
99 } // namespace gfx
100 11
101 #endif // GFX_POINT_H_ 12 #endif // GFX_POINT_H_
OLDNEW
« no previous file with comments | « gfx/platform_font_win.cc ('k') | gfx/point.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698