license.bot | f003cfe | 2008-08-24 09:55:55 +0900 | [diff] [blame^] | 1 | // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 4 | |
| 5 | #ifndef BASE_GFX_POINT_H__ |
| 6 | #define BASE_GFX_POINT_H__ |
| 7 | |
avi@google.com | 8227724 | 2008-08-07 05:38:29 +0900 | [diff] [blame] | 8 | #include "build/build_config.h" |
| 9 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 10 | #ifdef UNIT_TEST |
| 11 | #include <iostream> |
| 12 | #endif |
| 13 | |
avi@google.com | 8227724 | 2008-08-07 05:38:29 +0900 | [diff] [blame] | 14 | #if defined(OS_WIN) |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 15 | typedef struct tagPOINT POINT; |
avi@google.com | 8227724 | 2008-08-07 05:38:29 +0900 | [diff] [blame] | 16 | #elif defined(OS_MACOSX) |
| 17 | #include <ApplicationServices/ApplicationServices.h> |
| 18 | #endif |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 19 | |
| 20 | namespace gfx { |
| 21 | |
| 22 | // |
| 23 | // A point has an x and y coordinate. |
| 24 | // |
| 25 | class Point { |
| 26 | public: |
| 27 | Point(); |
| 28 | Point(int x, int y); |
avi@google.com | 8227724 | 2008-08-07 05:38:29 +0900 | [diff] [blame] | 29 | #if defined(OS_WIN) |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 30 | explicit Point(const POINT& point); |
avi@google.com | 8227724 | 2008-08-07 05:38:29 +0900 | [diff] [blame] | 31 | #elif defined(OS_MACOSX) |
| 32 | explicit Point(const CGPoint& point); |
| 33 | #endif |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 34 | |
| 35 | ~Point() {} |
| 36 | |
| 37 | int x() const { return x_; } |
| 38 | int y() const { return y_; } |
| 39 | |
| 40 | void SetPoint(int x, int y) { |
| 41 | x_ = x; |
| 42 | y_ = y; |
| 43 | } |
| 44 | |
| 45 | void set_x(int x) { x_ = x; } |
| 46 | void set_y(int y) { y_ = y; } |
| 47 | |
| 48 | bool operator==(const Point& rhs) const { |
| 49 | return x_ == rhs.x_ && y_ == rhs.y_; |
| 50 | } |
| 51 | |
| 52 | bool operator!=(const Point& rhs) const { |
| 53 | return !(*this == rhs); |
| 54 | } |
| 55 | |
avi@google.com | 8227724 | 2008-08-07 05:38:29 +0900 | [diff] [blame] | 56 | #if defined(OS_WIN) |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 57 | POINT ToPOINT() const; |
avi@google.com | 8227724 | 2008-08-07 05:38:29 +0900 | [diff] [blame] | 58 | #elif defined(OS_MACOSX) |
| 59 | CGPoint ToCGPoint() const; |
| 60 | #endif |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 61 | |
| 62 | private: |
| 63 | int x_; |
| 64 | int y_; |
| 65 | }; |
| 66 | |
| 67 | } // namespace gfx |
| 68 | |
| 69 | #ifdef UNIT_TEST |
| 70 | |
| 71 | inline std::ostream& operator<<(std::ostream& out, const gfx::Point& p) { |
| 72 | return out << p.x() << "," << p.y(); |
| 73 | } |
| 74 | |
| 75 | #endif // #ifdef UNIT_TEST |
| 76 | |
| 77 | #endif // BASE_GFX_POINT_H__ |
license.bot | f003cfe | 2008-08-24 09:55:55 +0900 | [diff] [blame^] | 78 | |