2009-05-26 14:13:08 +00:00
|
|
|
/* Residual - A 3D game interpreter
|
2008-06-13 14:57:47 +00:00
|
|
|
*
|
|
|
|
* Residual is the legal property of its developers, whose names
|
2011-04-16 14:12:44 +02:00
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
2008-06-13 14:57:47 +00:00
|
|
|
* file distributed with this source distribution.
|
2006-04-02 14:20:45 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*
|
|
|
|
*/
|
2005-04-07 19:29:06 +00: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-04-10 11:24:03 +02:00
|
|
|
#include "engines/grim/colormap.h"
|
2011-05-01 18:51:26 +02:00
|
|
|
#include "engines/grim/grim.h"
|
2011-05-13 17:55:14 -07:00
|
|
|
#include "engines/grim/bitmap.h"
|
2005-04-07 19:29:06 +00:00
|
|
|
|
2009-05-25 06:49:57 +00:00
|
|
|
namespace Grim {
|
|
|
|
|
2011-03-21 05:16:27 +08:00
|
|
|
PrimitiveObject::PrimitiveObject() :
|
2011-09-12 10:11:02 +08:00
|
|
|
PoolObject<PrimitiveObject, MKTAG('P', 'R', 'I', 'M')>() {
|
2005-04-07 19:29:06 +00:00
|
|
|
_filled = false;
|
|
|
|
_type = 0;
|
2005-04-08 11:16:57 +00:00
|
|
|
_bitmap = NULL;
|
2011-05-01 18:51:26 +02:00
|
|
|
_color = NULL;
|
2005-04-07 19:29:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PrimitiveObject::~PrimitiveObject() {
|
2011-03-21 05:16:27 +08:00
|
|
|
if (_bitmap && _type == 2)
|
2011-05-13 17:55:14 -07:00
|
|
|
delete _bitmap;
|
2005-04-07 19:29:06 +00:00
|
|
|
}
|
|
|
|
|
2011-03-21 05:16:27 +08:00
|
|
|
void PrimitiveObject::saveState(SaveGame *savedState) const {
|
2009-06-23 07:14:53 +00:00
|
|
|
savedState->writeLESint32(_type);
|
2011-03-21 05:16:27 +08:00
|
|
|
|
2011-05-02 03:50:09 +08:00
|
|
|
savedState->writeLEUint32(_color->getId());
|
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
|
|
|
|
2011-05-01 18:51:26 +02:00
|
|
|
if (_bitmap) {
|
2011-05-08 18:39:28 +02:00
|
|
|
savedState->writeLEUint32(_bitmap->getId());
|
2011-05-01 18:51:26 +02:00
|
|
|
} else {
|
|
|
|
savedState->writeLEUint32(0);
|
|
|
|
}
|
2011-03-21 05:16:27 +08:00
|
|
|
|
2009-06-23 07:14:53 +00:00
|
|
|
savedState->writeLEUint32(_p1.x);
|
|
|
|
savedState->writeLEUint32(_p1.y);
|
|
|
|
savedState->writeLEUint32(_p2.x);
|
|
|
|
savedState->writeLEUint32(_p2.y);
|
|
|
|
savedState->writeLEUint32(_p3.x);
|
|
|
|
savedState->writeLEUint32(_p3.y);
|
|
|
|
savedState->writeLEUint32(_p4.x);
|
|
|
|
savedState->writeLEUint32(_p4.y);
|
|
|
|
}
|
|
|
|
|
2011-03-21 05:16:27 +08:00
|
|
|
bool PrimitiveObject::restoreState(SaveGame *savedState) {
|
|
|
|
_type = savedState->readLESint32();
|
|
|
|
|
2011-11-21 22:07:12 +01:00
|
|
|
_color = PoolColor::getPool().getObject(savedState->readLEUint32());
|
2011-03-21 05:16:27 +08:00
|
|
|
|
|
|
|
_filled = savedState->readLEUint32();
|
|
|
|
|
2011-11-21 22:07:12 +01:00
|
|
|
_bitmap = Bitmap::getPool().getObject(savedState->readLEUint32());
|
2011-03-21 05:16:27 +08:00
|
|
|
|
|
|
|
_p1.x = savedState->readLEUint32();
|
|
|
|
_p1.y = savedState->readLEUint32();
|
|
|
|
_p2.x = savedState->readLEUint32();
|
|
|
|
_p2.y = savedState->readLEUint32();
|
|
|
|
_p3.x = savedState->readLEUint32();
|
|
|
|
_p3.y = savedState->readLEUint32();
|
|
|
|
_p4.x = savedState->readLEUint32();
|
|
|
|
_p4.y = savedState->readLEUint32();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-09-07 23:08:59 +02:00
|
|
|
void PrimitiveObject::createRectangle(Common::Point p1, Common::Point p2, PoolColor *color, bool filled) {
|
2009-05-24 06:09:42 +00:00
|
|
|
_type = RECTANGLE;
|
2009-05-10 10:11:55 +00:00
|
|
|
_p1 = p1;
|
|
|
|
_p2 = p2;
|
2005-04-07 19:29:06 +00:00
|
|
|
_color = color;
|
|
|
|
_filled = filled;
|
|
|
|
}
|
|
|
|
|
2009-05-10 10:11:55 +00:00
|
|
|
void PrimitiveObject::createBitmap(Bitmap *bitmap, Common::Point p, bool /*transparent*/) {
|
2009-05-24 06:09:42 +00:00
|
|
|
_type = BITMAP;
|
2005-04-08 11:16:57 +00:00
|
|
|
_bitmap = bitmap;
|
2009-05-10 10:11:55 +00:00
|
|
|
_bitmap->setX(p.x);
|
|
|
|
_bitmap->setY(p.y);
|
2005-04-08 11:16:57 +00:00
|
|
|
// transparent: what to do ?
|
|
|
|
}
|
|
|
|
|
2011-09-07 23:08:59 +02:00
|
|
|
void PrimitiveObject::createLine(Common::Point p1, Common::Point p2, PoolColor *color) {
|
2009-05-24 06:09:42 +00:00
|
|
|
_type = LINE;
|
2009-05-10 10:11:55 +00:00
|
|
|
_p1 = p1;
|
|
|
|
_p2 = p2;
|
2005-05-05 21:23:17 +00:00
|
|
|
_color = color;
|
|
|
|
}
|
|
|
|
|
2011-09-07 23:08:59 +02:00
|
|
|
void PrimitiveObject::createPolygon(Common::Point p1, Common::Point p2, Common::Point p3, Common::Point p4, PoolColor *color) {
|
2009-05-24 14:19:30 +00:00
|
|
|
_type = POLYGON;
|
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;
|
|
|
|
}
|
|
|
|
|
2005-04-07 19:29:06 +00:00
|
|
|
void PrimitiveObject::draw() {
|
|
|
|
assert(_type);
|
|
|
|
|
2009-05-24 06:09:42 +00:00
|
|
|
if (_type == RECTANGLE)
|
2005-04-07 19:29:06 +00:00
|
|
|
g_driver->drawRectangle(this);
|
2009-05-24 06:09:42 +00:00
|
|
|
else if (_type == BITMAP)
|
2011-05-13 17:55:14 -07:00
|
|
|
g_driver->drawBitmap(_bitmap);
|
2009-05-24 06:09:42 +00:00
|
|
|
else if (_type == LINE)
|
2005-05-05 21:23:17 +00:00
|
|
|
g_driver->drawLine(this);
|
2009-05-24 06:09:42 +00:00
|
|
|
else if (_type == POLYGON)
|
2007-01-30 12:38:26 +00:00
|
|
|
g_driver->drawPolygon(this);
|
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;
|
|
|
|
if (_type == RECTANGLE || _type == LINE || _type == POLYGON)
|
|
|
|
_p2.x += dx;
|
|
|
|
if (_type == POLYGON) {
|
|
|
|
_p3.x += dx;
|
|
|
|
_p4.x += dx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (y != -1) {
|
|
|
|
int dy = y - _p1.y;
|
|
|
|
_p1.y += dy;
|
|
|
|
if (_type == RECTANGLE || _type == LINE || _type == POLYGON)
|
|
|
|
_p2.y += dy;
|
|
|
|
if (_type == POLYGON) {
|
|
|
|
_p3.y += dy;
|
|
|
|
_p4.y += dy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-05-25 06:49:57 +00:00
|
|
|
|
|
|
|
} // end of namespace Grim
|