ScummVM API documentation
polygon.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#ifndef COMMON_POLYGON_H
23#define COMMON_POLYGON_H
24
25#include "common/scummsys.h"
26
27#ifdef ENABLE_VKEYBD
28
29#include "common/array.h"
30#include "common/rect.h"
31
32namespace Common {
33
34struct Polygon {
35
36 Polygon() {}
37 Polygon(Array<Point> p) : _points(p) {
38 for (uint i = 0; i < p.size(); i++) {
39 _bound.extend(Rect(p[i].x, p[i].y, p[i].x, p[i].y));
40 }
41 }
42 Polygon(Point *p, int n) {
43 for (int i = 0; i < n; i++) {
44 addPoint(p[i]);
45 }
46 }
47
48 void addPoint(const Point &p) {
49 _points.push_back(p);
50 _bound.extend(Rect(p.x, p.y, p.x, p.y));
51 }
52
53 void addPoint(int16 x, int16 y) {
54 addPoint(Point(x, y));
55 }
56
57 uint getPointCount() {
58 return _points.size();
59 }
60
68 bool contains(int16 x, int16 y) const;
69
76 bool contains(const Point &p) const {
77 return contains(p.x, p.y);
78 }
79
80 void moveTo(int16 x, int16 y) {
81 int16 dx = x - ((_bound.right + _bound.left) / 2);
82 int16 dy = y - ((_bound.bottom + _bound.top) / 2);
83 translate(dx, dy);
84 }
85
86 void moveTo(const Point &p) {
87 moveTo(p.x, p.y);
88 }
89
90 void translate(int16 dx, int16 dy) {
92 for (it = _points.begin(); it != _points.end(); it++) {
93 it->x += dx;
94 it->y += dy;
95 }
96 }
97
98 Rect getBoundingRect() const {
99 return _bound;
100 }
101
102private:
103 Array<Point> _points;
104 Rect _bound;
105};
106
107} // End of namespace Common
108
109#endif // #ifdef ENABLE_VKEYBD
110
111#endif // #ifndef COMMON_POLYGON_H
Point * iterator
Definition: array.h:54
Definition: algorithm.h:29
T x
Definition: rect.h:48
Definition: display_client.h:58