2012-01-06 23:29:45 +01:00
|
|
|
/* ResidualVM - A 3D game interpreter
|
2008-06-13 14:57:47 +00:00
|
|
|
*
|
2012-01-06 23:29:45 +01:00
|
|
|
* ResidualVM is the legal property of its developers, whose names
|
2012-12-19 23:15:43 +01:00
|
|
|
* are too numerous to list here. Please refer to the AUTHORS
|
2008-06-13 14:57:47 +00:00
|
|
|
* file distributed with this source distribution.
|
2006-04-02 14:20:45 +00:00
|
|
|
*
|
2012-12-19 23:15:43 +01:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2014-04-05 18:18:42 +02:00
|
|
|
*
|
2012-12-19 23:15:43 +01:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2006-04-02 14:20:45 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-12-19 23:15:43 +01:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2014-04-05 18:18:42 +02:00
|
|
|
*
|
2012-12-19 23:15:43 +01:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2006-04-02 14:20:45 +00:00
|
|
|
*
|
|
|
|
*/
|
2005-04-07 19:29:06 +00:00
|
|
|
|
2012-12-19 23:15:43 +01:00
|
|
|
|
2009-05-24 19:13:58 +00:00
|
|
|
#include "engines/grim/gfx_base.h"
|
|
|
|
#include "engines/grim/primitives.h"
|
2009-06-23 07:14:53 +00:00
|
|
|
#include "engines/grim/savegame.h"
|
2011-05-01 18:51:26 +02:00
|
|
|
#include "engines/grim/grim.h"
|
2011-12-17 15:34:37 -08:00
|
|
|
#include "engines/grim/color.h"
|
2005-04-07 19:29:06 +00:00
|
|
|
|
2009-05-25 06:49:57 +00:00
|
|
|
namespace Grim {
|
|
|
|
|
2013-10-26 13:57:55 -07:00
|
|
|
PrimitiveObject::PrimitiveObject() :
|
|
|
|
_filled(false), _type(InvalidType) {
|
2005-04-07 19:29:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PrimitiveObject::~PrimitiveObject() {
|
|
|
|
}
|
|
|
|
|
2011-03-21 05:16:27 +08:00
|
|
|
void PrimitiveObject::saveState(SaveGame *savedState) const {
|
2013-10-26 13:51:54 -07:00
|
|
|
savedState->writeLESint32((int32)_type);
|
2011-03-21 05:16:27 +08:00
|
|
|
|
2012-01-27 11:47:28 -08:00
|
|
|
savedState->writeColor(_color);
|
2011-03-21 05:16:27 +08:00
|
|
|
|
2009-06-23 07:14:53 +00:00
|
|
|
savedState->writeLEUint32(_filled);
|
2011-03-21 05:16:27 +08:00
|
|
|
|
2012-01-27 15:09:13 -08:00
|
|
|
savedState->writeLEUint16(_p1.x);
|
|
|
|
savedState->writeLEUint16(_p1.y);
|
|
|
|
savedState->writeLEUint16(_p2.x);
|
|
|
|
savedState->writeLEUint16(_p2.y);
|
|
|
|
savedState->writeLEUint16(_p3.x);
|
|
|
|
savedState->writeLEUint16(_p3.y);
|
|
|
|
savedState->writeLEUint16(_p4.x);
|
|
|
|
savedState->writeLEUint16(_p4.y);
|
2009-06-23 07:14:53 +00:00
|
|
|
}
|
|
|
|
|
2011-03-21 05:16:27 +08:00
|
|
|
bool PrimitiveObject::restoreState(SaveGame *savedState) {
|
2013-10-26 13:51:54 -07:00
|
|
|
_type = (PrimType)savedState->readLESint32();
|
2011-03-21 05:16:27 +08:00
|
|
|
|
2012-01-28 12:31:09 +01:00
|
|
|
_color = savedState->readColor();
|
2011-03-21 05:16:27 +08:00
|
|
|
|
|
|
|
_filled = savedState->readLEUint32();
|
|
|
|
|
2012-01-27 15:09:13 -08:00
|
|
|
_p1.x = savedState->readLEUint16();
|
|
|
|
_p1.y = savedState->readLEUint16();
|
|
|
|
_p2.x = savedState->readLEUint16();
|
|
|
|
_p2.y = savedState->readLEUint16();
|
|
|
|
_p3.x = savedState->readLEUint16();
|
|
|
|
_p3.y = savedState->readLEUint16();
|
|
|
|
_p4.x = savedState->readLEUint16();
|
|
|
|
_p4.y = savedState->readLEUint16();
|
2011-03-21 05:16:27 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-05-05 18:03:04 -07:00
|
|
|
void PrimitiveObject::createRectangle(const Common::Point &p1, const Common::Point &p2, const Color &color, bool filled) {
|
2013-10-26 13:51:54 -07:00
|
|
|
_type = RectangleType;
|
2009-05-10 10:11:55 +00:00
|
|
|
_p1 = p1;
|
|
|
|
_p2 = p2;
|
2005-04-07 19:29:06 +00:00
|
|
|
_color = color;
|
|
|
|
_filled = filled;
|
|
|
|
}
|
|
|
|
|
2012-05-05 18:03:04 -07:00
|
|
|
void PrimitiveObject::createLine(const Common::Point &p1, const Common::Point &p2, const Color &color) {
|
2013-10-26 13:51:54 -07:00
|
|
|
_type = LineType;
|
2009-05-10 10:11:55 +00:00
|
|
|
_p1 = p1;
|
|
|
|
_p2 = p2;
|
2005-05-05 21:23:17 +00:00
|
|
|
_color = color;
|
|
|
|
}
|
|
|
|
|
2012-05-05 18:03:04 -07:00
|
|
|
void PrimitiveObject::createPolygon(const Common::Point &p1, const Common::Point &p2, const Common::Point &p3, const Common::Point &p4, const Color &color) {
|
2013-10-26 13:51:54 -07:00
|
|
|
_type = PolygonType;
|
2009-05-10 10:11:55 +00:00
|
|
|
_p1 = p1;
|
|
|
|
_p2 = p2;
|
|
|
|
_p3 = p3;
|
|
|
|
_p4 = p4;
|
2007-01-30 12:38:26 +00:00
|
|
|
_color = color;
|
|
|
|
}
|
|
|
|
|
2012-05-05 18:03:04 -07:00
|
|
|
void PrimitiveObject::draw() const {
|
2013-10-26 13:51:54 -07:00
|
|
|
assert(_type != InvalidType);
|
2005-04-07 19:29:06 +00:00
|
|
|
|
2013-10-26 13:51:54 -07:00
|
|
|
if (_type == RectangleType) {
|
2005-04-07 19:29:06 +00:00
|
|
|
g_driver->drawRectangle(this);
|
2013-10-26 13:51:54 -07:00
|
|
|
} else if (_type == LineType) {
|
2005-05-05 21:23:17 +00:00
|
|
|
g_driver->drawLine(this);
|
2013-10-26 13:51:54 -07:00
|
|
|
} else if (_type == PolygonType) {
|
2007-01-30 12:38:26 +00:00
|
|
|
g_driver->drawPolygon(this);
|
2013-10-26 13:51:54 -07:00
|
|
|
}
|
2005-04-07 19:29:06 +00:00
|
|
|
}
|
2009-05-24 06:09:42 +00:00
|
|
|
|
|
|
|
void PrimitiveObject::setPos(int x, int y) {
|
|
|
|
if (x != -1) {
|
|
|
|
int dx = x - _p1.x;
|
|
|
|
_p1.x += dx;
|
2013-10-26 13:51:54 -07:00
|
|
|
if (_type == RectangleType || _type == LineType || _type == PolygonType) {
|
2009-05-24 06:09:42 +00:00
|
|
|
_p2.x += dx;
|
2013-10-26 13:51:54 -07:00
|
|
|
}
|
|
|
|
if (_type == PolygonType) {
|
2009-05-24 06:09:42 +00:00
|
|
|
_p3.x += dx;
|
|
|
|
_p4.x += dx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (y != -1) {
|
|
|
|
int dy = y - _p1.y;
|
|
|
|
_p1.y += dy;
|
2013-10-26 13:51:54 -07:00
|
|
|
if (_type == RectangleType || _type == LineType || _type == PolygonType)
|
2009-05-24 06:09:42 +00:00
|
|
|
_p2.y += dy;
|
2013-10-26 13:51:54 -07:00
|
|
|
if (_type == PolygonType) {
|
2009-05-24 06:09:42 +00:00
|
|
|
_p3.y += dy;
|
|
|
|
_p4.y += dy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-05-25 06:49:57 +00:00
|
|
|
|
2014-06-05 07:48:40 -07:00
|
|
|
void PrimitiveObject::setEndpoint(int x, int y) {
|
|
|
|
assert(_type == LineType);
|
|
|
|
|
|
|
|
_p2.x = x;
|
|
|
|
_p2.y = y;
|
|
|
|
}
|
|
|
|
|
2009-05-25 06:49:57 +00:00
|
|
|
} // end of namespace Grim
|