ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

polygon.h

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef COMMON_POLYGON_H
00024 #define COMMON_POLYGON_H
00025 
00026 #include "common/scummsys.h"
00027 
00028 #ifdef ENABLE_VKEYBD
00029 
00030 #include "common/array.h"
00031 #include "common/rect.h"
00032 
00033 namespace Common {
00034 
00035 struct Polygon {
00036 
00037     Polygon() {}
00038     Polygon(Array<Point> p) : _points(p) {
00039         for (uint i = 0; i < p.size(); i++) {
00040             _bound.extend(Rect(p[i].x, p[i].y, p[i].x, p[i].y));
00041         }
00042     }
00043     Polygon(Point *p, int n) {
00044         for (int i = 0; i < n; i++) {
00045             addPoint(p[i]);
00046         }
00047     }
00048 
00049     void addPoint(const Point &p) {
00050         _points.push_back(p);
00051         _bound.extend(Rect(p.x, p.y, p.x, p.y));
00052     }
00053 
00054     void addPoint(int16 x, int16 y) {
00055         addPoint(Point(x, y));
00056     }
00057 
00058     uint getPointCount() {
00059         return _points.size();
00060     }
00061 
00069     bool contains(int16 x, int16 y) const;
00070 
00077     bool contains(const Point &p) const {
00078         return contains(p.x, p.y);
00079     }
00080 
00081     void moveTo(int16 x, int16 y) {
00082         int16 dx = x - ((_bound.right + _bound.left) / 2);
00083         int16 dy = y - ((_bound.bottom + _bound.top) / 2);
00084         translate(dx, dy);
00085     }
00086 
00087     void moveTo(const Point &p) {
00088         moveTo(p.x, p.y);
00089     }
00090 
00091     void translate(int16 dx, int16 dy) {
00092         Array<Point>::iterator it;
00093         for (it = _points.begin(); it != _points.end(); it++) {
00094             it->x += dx;
00095             it->y += dy;
00096         }
00097     }
00098 
00099     Rect getBoundingRect() const {
00100         return _bound;
00101     }
00102 
00103 private:
00104     Array<Point> _points;
00105     Rect _bound;
00106 };
00107 
00108 } // End of namespace Common
00109 
00110 #endif // #ifdef ENABLE_VKEYBD
00111 
00112 #endif // #ifndef COMMON_POLYGON_H


Generated on Sat Mar 16 2019 05:01:50 for ResidualVM by doxygen 1.7.1
curved edge   curved edge