ScummVM API documentation
gr_screen_region.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 
23 #ifndef QDENGINE_SYSTEM_GRAPHICS_GR_SCREEN_REGION_H
24 #define QDENGINE_SYSTEM_GRAPHICS_GR_SCREEN_REGION_H
25 
26 namespace QDEngine {
27 
28 #define grScreenRegion_EMPTY grScreenRegion(0, 0, 0, 0)
29 
32 public:
33  grScreenRegion() : _x(0), _y(0), _size_x(0), _size_y(0) {}
34  grScreenRegion(int x, int y, int sx, int sy) : _x(x), _y(y), _size_x(sx), _size_y(sy) {}
35 
36  bool operator == (const grScreenRegion &reg) const {
37  if (_x == reg._x && _y == reg._y && _size_x == reg._size_x && _size_y == reg._size_y)
38  return true;
39 
40  if (is_empty() && reg.is_empty())
41  return true;
42 
43  return false;
44  }
45 
46  bool operator != (const grScreenRegion &reg) const {
47  if (is_empty() && reg.is_empty())
48  return false;
49 
50  if (_x != reg._x || _y != reg._y || _size_x != reg._size_x || _size_y != reg._size_y)
51  return true;
52 
53  return false;
54  }
55 
56  grScreenRegion &operator += (const grScreenRegion &reg) {
57  if (reg.is_empty()) return *this;
58 
59  if (is_empty()) {
60  *this = reg;
61  return *this;
62  }
63 
64  int x0 = (min_x() < reg.min_x()) ? min_x() : reg.min_x();
65  int x1 = (max_x() > reg.max_x()) ? max_x() : reg.max_x();
66 
67  int y0 = (min_y() < reg.min_y()) ? min_y() : reg.min_y();
68  int y1 = (max_y() > reg.max_y()) ? max_y() : reg.max_y();
69 
70  _x = (x0 + x1) / 2;
71  _y = (y0 + y1) / 2;
72 
73  _size_x = x1 - x0;
74  _size_y = y1 - y0;
75 
76  return *this;
77  }
78 
79  int x() const {
80  return _x;
81  }
82  int y() const {
83  return _y;
84  }
85 
86  int size_x() const {
87  return _size_x;
88  }
89  int size_y() const {
90  return _size_y;
91  }
92 
93  int min_x() const {
94  return _x - _size_x / 2;
95  }
96  int max_x() const {
97  return _x + _size_x / 2;
98  }
99 
100  int min_y() const {
101  return _y - _size_y / 2;
102  }
103  int max_y() const {
104  return _y + _size_y / 2;
105  }
106 
107  void move(int dx, int dy) {
108  _x += dx;
109  _y += dy;
110  }
111 
112  bool is_empty() const {
113  return (!_size_x || !_size_y);
114  }
115 
116  bool is_inside(int x, int y) const {
117  if (x >= min_x() && x < max_x() && y >= min_y() && y < max_y()) return true;
118  return false;
119  }
120 
121  void clear() {
122  _size_x = 0;
123  }
124 
125  static const grScreenRegion EMPTY;
126 
127 private:
128 
130  int _x;
131  int _y;
132 
133  int _size_x;
134  int _size_y;
135 };
136 
137 } // namespace QDEngine
138 
139 #endif // QDENGINE_SYSTEM_GRAPHICS_GR_SCREEN_REGION_H
Базовый класс для игровых ресурсов.
Definition: console.h:28
Прямоугольная область на экране.
Definition: gr_screen_region.h:31