The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
point.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2016 by Mark de Wever <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program 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  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #ifndef GUI_LIB_TYPES_POINT_HPP_INCLUDED
16 #define GUI_LIB_TYPES_POINT_HPP_INCLUDED
17 
18 #include <iosfwd>
19 
20 namespace gui2
21 {
22 
23 /** Holds a 2D point. */
24 struct tpoint
25 {
26  tpoint(const int x_, const int y_) : x(x_), y(y_)
27  {
28  }
29 
30  /** x coordinate. */
31  int x;
32 
33  /** y coordinate. */
34  int y;
35 
36  bool operator==(const tpoint& point) const
37  {
38  return x == point.x && y == point.y;
39  }
40  bool operator!=(const tpoint& point) const
41  {
42  return x != point.x || y != point.y;
43  }
44  bool operator<(const tpoint& point) const
45  {
46  return x < point.x || (x == point.x && y < point.y);
47  }
48 
49  bool operator<=(const tpoint& point) const
50  {
51  return x < point.x || (x == point.x && y <= point.y);
52  }
53 
54  tpoint operator+(const tpoint& point) const
55  {
56  return tpoint(x + point.x, y + point.y);
57  }
58 
59  tpoint& operator+=(const tpoint& point);
60 
61  tpoint operator-(const tpoint& point) const
62  {
63  return tpoint(x - point.x, y - point.y);
64  }
65 
66  tpoint& operator-=(const tpoint& point);
67 };
68 
69 std::ostream& operator<<(std::ostream& stream, const tpoint& point);
70 
71 
72 } // namespace gui2
73 
74 #endif
tformula< unsigned > x_
The x coordinate of the rectangle.
Definition: canvas.cpp:682
tpoint operator+(const tpoint &point) const
Definition: point.hpp:54
tpoint & operator-=(const tpoint &point)
Definition: point.cpp:31
bool operator<=(const tpoint &point) const
Definition: point.hpp:49
bool operator==(const tpoint &point) const
Definition: point.hpp:36
bool operator<(const tpoint &point) const
Definition: point.hpp:44
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1220
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
GLuint GLuint stream
Definition: glew.h:5239
bool operator!=(const tpoint &point) const
Definition: point.hpp:40
int y
y coordinate.
Definition: point.hpp:34
std::ostream & operator<<(std::ostream &stream, const tpoint &point)
Definition: point.cpp:38
tpoint(const int x_, const int y_)
Definition: point.hpp:26
int x
x coordinate.
Definition: point.hpp:31
Holds a 2D point.
Definition: point.hpp:24
GLint GLint GLint GLint GLint x
Definition: glew.h:1220
tformula< unsigned > y_
The y coordinate of the rectangle.
Definition: canvas.cpp:682
tpoint operator-(const tpoint &point) const
Definition: point.hpp:61
tpoint & operator+=(const tpoint &point)
Definition: point.cpp:24