MyGUI
3.2.0
Main Page
Related Pages
Namespaces
Data Structures
Files
Examples
File List
Globals
MyGUIEngine
include
MyGUI_TPoint.h
Go to the documentation of this file.
1
6
/*
7
This file is part of MyGUI.
8
9
MyGUI is free software: you can redistribute it and/or modify
10
it under the terms of the GNU Lesser General Public License as published by
11
the Free Software Foundation, either version 3 of the License, or
12
(at your option) any later version.
13
14
MyGUI is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU Lesser General Public License for more details.
18
19
You should have received a copy of the GNU Lesser General Public License
20
along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
21
*/
22
#ifndef __MYGUI_TPONT_H__
23
#define __MYGUI_TPONT_H__
24
25
#include "
MyGUI_Prerequest.h
"
26
27
namespace
MyGUI
28
{
29
namespace
types
30
{
31
32
template
<
typename
T>
33
struct
TPoint
34
{
35
T
left
;
36
T
top
;
37
38
TPoint
() :
39
left
(0),
40
top
(0)
41
{
42
}
43
44
TPoint
(T
const
& _left, T
const
& _top) :
45
left
(_left),
46
top
(_top)
47
{
48
}
49
50
TPoint
(
TPoint
const
& _obj) :
51
left
(_obj.
left
),
52
top
(_obj.
top
)
53
{
54
}
55
56
TPoint
&
operator -=
(
TPoint
const
& _obj)
57
{
58
left
-= _obj.
left
;
59
top
-= _obj.
top
;
60
return
*
this
;
61
}
62
63
TPoint
&
operator +=
(
TPoint
const
& _obj)
64
{
65
left
+= _obj.
left
;
66
top
+= _obj.
top
;
67
return
*
this
;
68
}
69
70
TPoint
operator -
(
TPoint
const
& _obj)
const
71
{
72
return
TPoint
(
left
- _obj.
left
,
top
- _obj.
top
);
73
}
74
75
TPoint
operator +
(
TPoint
const
& _obj)
const
76
{
77
return
TPoint
(
left
+ _obj.
left
,
top
+ _obj.
top
);
78
}
79
80
TPoint
&
operator =
(
TPoint
const
& _obj)
81
{
82
left
= _obj.
left
;
83
top
= _obj.
top
;
84
return
*
this
;
85
}
86
87
template
<
typename
U>
88
TPoint
&
operator =
(
TPoint<U>
const
& _obj)
89
{
90
left
= _obj.
left
;
91
top
= _obj.
top
;
92
return
*
this
;
93
}
94
95
bool
operator ==
(
TPoint
const
& _obj)
const
96
{
97
return
((
left
== _obj.
left
) && (
top
== _obj.
top
));
98
}
99
100
bool
operator !=
(
TPoint
const
& _obj)
const
101
{
102
return
! ((
left
== _obj.
left
) && (
top
== _obj.
top
));
103
}
104
105
void
clear
()
106
{
107
left
=
top
= 0;
108
}
109
110
void
set
(T
const
& _left, T
const
& _top)
111
{
112
left
= _left;
113
top
= _top;
114
}
115
116
void
swap
(
TPoint
& _value)
117
{
118
TPoint
tmp = _value;
119
_value = *
this
;
120
*
this
= tmp;
121
}
122
123
bool
empty
()
const
124
{
125
return
((
left
== 0) && (
top
== 0));
126
}
127
128
std::string
print
()
const
129
{
130
std::ostringstream stream;
131
stream << *
this
;
132
return
stream.str();
133
}
134
135
static
TPoint<T>
parse
(
const
std::string& _value)
136
{
137
TPoint<T>
result;
138
std::istringstream stream(_value);
139
stream >> result.
left
>> result.
top
;
140
if
(stream.fail())
141
{
142
return
TPoint<T>
();
143
}
144
else
145
{
146
int
item = stream.get();
147
while
(item != -1)
148
{
149
if
(item !=
' '
&& item !=
'\t'
)
150
return
TPoint<T>
();
151
item = stream.get();
152
}
153
}
154
return
result;
155
}
156
157
friend
std::ostream& operator << (std::ostream& _stream, const TPoint<T>& _value)
158
{
159
_stream << _value.
left
<<
" "
<< _value.top;
160
return
_stream;
161
}
162
163
friend
std::istream&
operator >>
(std::istream& _stream,
TPoint<T>
& _value)
164
{
165
_stream >> _value.
left
>> _value.
top
;
166
if
(_stream.fail())
167
_value.
clear
();
168
return
_stream;
169
}
170
};
171
172
}
// namespace types
173
174
}
// namespace MyGUI
175
176
#endif // __MYGUI_TPONT_H__
Generated by
1.8.4