blob: a70807e5381dcf70dcf001b6981d8a5d2ecacbaf [file] [log] [blame]
license.botf003cfe2008-08-24 09:55:55 +09001// 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.commit3f4a7322008-07-27 06:49:38 +09004
5#ifndef BASE_GFX_POINT_H__
6#define BASE_GFX_POINT_H__
7
avi@google.com82277242008-08-07 05:38:29 +09008#include "build/build_config.h"
9
initial.commit3f4a7322008-07-27 06:49:38 +090010#ifdef UNIT_TEST
11#include <iostream>
12#endif
13
avi@google.com82277242008-08-07 05:38:29 +090014#if defined(OS_WIN)
initial.commit3f4a7322008-07-27 06:49:38 +090015typedef struct tagPOINT POINT;
avi@google.com82277242008-08-07 05:38:29 +090016#elif defined(OS_MACOSX)
17#include <ApplicationServices/ApplicationServices.h>
18#endif
initial.commit3f4a7322008-07-27 06:49:38 +090019
20namespace gfx {
21
22//
23// A point has an x and y coordinate.
24//
25class Point {
26 public:
27 Point();
28 Point(int x, int y);
avi@google.com82277242008-08-07 05:38:29 +090029#if defined(OS_WIN)
initial.commit3f4a7322008-07-27 06:49:38 +090030 explicit Point(const POINT& point);
avi@google.com82277242008-08-07 05:38:29 +090031#elif defined(OS_MACOSX)
32 explicit Point(const CGPoint& point);
33#endif
initial.commit3f4a7322008-07-27 06:49:38 +090034
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.com82277242008-08-07 05:38:29 +090056#if defined(OS_WIN)
initial.commit3f4a7322008-07-27 06:49:38 +090057 POINT ToPOINT() const;
avi@google.com82277242008-08-07 05:38:29 +090058#elif defined(OS_MACOSX)
59 CGPoint ToCGPoint() const;
60#endif
initial.commit3f4a7322008-07-27 06:49:38 +090061
62 private:
63 int x_;
64 int y_;
65};
66
67} // namespace gfx
68
69#ifdef UNIT_TEST
70
71inline 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.botf003cfe2008-08-24 09:55:55 +090078