Debian Codegraph @

src/tools/dlgedit/dlg_point.h

raw
1 /*
2 Copyright (C) 2002 Kai Sterker <[email protected]>
3 Part of the Adonthell Project <http://adonthell.nongnu.org>
4
5 Dlgedit is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 Dlgedit is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with Dlgedit. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 /**
20 * @file dlg_point.h
21 *
22 * @author Kai Sterker
23 * @brief A wrapper around GdkPoint.
24 */
25
26 #ifndef DLG_POINT_H
27 #define DLG_POINT_H
28
29 #include <gdk/gdk.h>
30
31 /**
32 * The representation of a point, defined by its x and y coordinate.
33 *
34 * This class provides some abstraction from the GdkPoint type
35 * defined in GTK+, to remain as independent from the actual GUI
36 * toolkit as possible.
37 */
38 class DlgPoint
39 {
40 public:
41 DlgPoint () : x_(0), y_(0) { }
42 DlgPoint (int x, int y) : x_(x), y_(y) { }
43 DlgPoint (GdkPoint &point) : x_(point.x), y_(point.y) { }
44
45 int x () const { return x_; }
46 int y () const { return y_; }
47
48 /**
49 * Creates a new point, which is moved by the values of the given point.
50 * @param p the distance to offset this point
51 * @return this point, offset by the point p
52 */
53 DlgPoint offset (DlgPoint &p) const;
54 /**
55 * Creates a new point, which is moved by the given values.
56 * @param x the offset in x direction
57 * @param y the offset in y direction
58 * @return this point, offset by the given values.
59 */
60 DlgPoint offset (int x, int y) { return DlgPoint (x_ + x, y_ + y); }
61 /**
62 * Offset this point by the given values.
63 * @param x the offset in x direction
64 * @param y the offset in y direction
65 */
66 void move (DlgPoint &p) { x_ += p.x (); y_ += p.y (); }
67 /**
68 * Offsets this point by the given values.
69 * @param x the offset in x direction
70 * @param y the offset in y direction
71 */
72 void move (int x, int y) { x_ += x; y_ += y; }
73
74 /**
75 * Convert a DlgPoint into a GdkPoint.
76 */
77 operator GdkPoint();
78
79 /**
80 * Assign another point to this one
81 */
82 DlgPoint &operator= (const DlgPoint &p)
83 {
84 x_ = p.x ();
85 y_ = p.y ();
86 return *this;
87 }
88
89 /**
90 * Equal operator
91 */
92 bool operator== (const DlgPoint &p)
93 {
94 return x_ == p.x() && y_ == p.y();
95 }
96
97 /**
98 * Less Than operator
99 */
100 bool operator< (const DlgPoint &p)
101 {
102 if (x_ == p.x ()) return y_ < p.y ();
103 else return x_ < p.x ();
104 }
105
106 private:
107 int x_;
108 int y_;
109 };
110
111 #endif // DLG_POINT_H