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

engines/grim/primitives.cpp

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the AUTHORS
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 
00024 #include "engines/grim/gfx_base.h"
00025 #include "engines/grim/primitives.h"
00026 #include "engines/grim/savegame.h"
00027 #include "engines/grim/grim.h"
00028 #include "engines/grim/color.h"
00029 
00030 namespace Grim {
00031 
00032 PrimitiveObject::PrimitiveObject() :
00033         _filled(false), _type(InvalidType) {
00034 }
00035 
00036 PrimitiveObject::~PrimitiveObject() {
00037 }
00038 
00039 void PrimitiveObject::saveState(SaveGame *savedState) const {
00040     savedState->writeLESint32((int32)_type);
00041 
00042     savedState->writeColor(_color);
00043 
00044     savedState->writeLEUint32(_filled);
00045 
00046     savedState->writeLEUint16(_p1.x);
00047     savedState->writeLEUint16(_p1.y);
00048     savedState->writeLEUint16(_p2.x);
00049     savedState->writeLEUint16(_p2.y);
00050     savedState->writeLEUint16(_p3.x);
00051     savedState->writeLEUint16(_p3.y);
00052     savedState->writeLEUint16(_p4.x);
00053     savedState->writeLEUint16(_p4.y);
00054 }
00055 
00056 bool PrimitiveObject::restoreState(SaveGame *savedState) {
00057     _type = (PrimType)savedState->readLESint32();
00058 
00059     _color = savedState->readColor();
00060 
00061     _filled = savedState->readLEUint32();
00062 
00063     _p1.x = savedState->readLEUint16();
00064     _p1.y = savedState->readLEUint16();
00065     _p2.x = savedState->readLEUint16();
00066     _p2.y = savedState->readLEUint16();
00067     _p3.x = savedState->readLEUint16();
00068     _p3.y = savedState->readLEUint16();
00069     _p4.x = savedState->readLEUint16();
00070     _p4.y = savedState->readLEUint16();
00071 
00072     return true;
00073 }
00074 
00075 void PrimitiveObject::createRectangle(const Common::Point &p1, const Common::Point &p2, const Color &color, bool filled) {
00076     _type = RectangleType;
00077     _p1 = p1;
00078     _p2 = p2;
00079     _color = color;
00080     _filled = filled;
00081 }
00082 
00083 void PrimitiveObject::createLine(const Common::Point &p1, const Common::Point &p2, const Color &color) {
00084     _type = LineType;
00085     _p1 = p1;
00086     _p2 = p2;
00087     _color = color;
00088 }
00089 
00090 void PrimitiveObject::createPolygon(const Common::Point &p1, const Common::Point &p2, const Common::Point &p3, const Common::Point &p4, const Color &color) {
00091     _type = PolygonType;
00092     _p1 = p1;
00093     _p2 = p2;
00094     _p3 = p3;
00095     _p4 = p4;
00096     _color = color;
00097 }
00098 
00099 void PrimitiveObject::draw() const {
00100     assert(_type != InvalidType);
00101 
00102     if (_type == RectangleType) {
00103         g_driver->drawRectangle(this);
00104     } else if (_type == LineType) {
00105         g_driver->drawLine(this);
00106     } else if (_type == PolygonType) {
00107         g_driver->drawPolygon(this);
00108     }
00109 }
00110 
00111 void PrimitiveObject::setPos(int x, int y) {
00112     if (x != -1) {
00113         int dx = x - _p1.x;
00114         _p1.x += dx;
00115         if (_type == RectangleType || _type == LineType || _type == PolygonType) {
00116             _p2.x += dx;
00117         }
00118         if (_type == PolygonType) {
00119             _p3.x += dx;
00120             _p4.x += dx;
00121         }
00122     }
00123     if (y != -1) {
00124         int dy = y - _p1.y;
00125         _p1.y += dy;
00126         if (_type == RectangleType || _type == LineType || _type == PolygonType)
00127             _p2.y += dy;
00128         if (_type == PolygonType) {
00129             _p3.y += dy;
00130             _p4.y += dy;
00131         }
00132     }
00133 }
00134 
00135 void PrimitiveObject::setEndpoint(int x, int y) {
00136     assert(_type == LineType);
00137 
00138     _p2.x = x;
00139     _p2.y = y;
00140 }
00141 
00142 } // end of namespace Grim


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