scummvm/engines/grim/primitives.cpp

158 lines
4.0 KiB
C++
Raw Normal View History

2009-05-26 14:13:08 +00:00
/* Residual - A 3D game interpreter
*
* 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
* 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
#include "engines/grim/gfx_base.h"
#include "engines/grim/primitives.h"
#include "engines/grim/savegame.h"
2011-04-10 11:24:03 +02:00
#include "engines/grim/colormap.h"
#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 {
PrimitiveObject::PrimitiveObject() :
PoolObject<PrimitiveObject, MKTAG('P', 'R', 'I', 'M')>() {
2005-04-07 19:29:06 +00:00
_filled = false;
_type = 0;
_bitmap = NULL;
_color = NULL;
2005-04-07 19:29:06 +00:00
}
PrimitiveObject::~PrimitiveObject() {
if (_bitmap && _type == 2)
2011-05-13 17:55:14 -07:00
delete _bitmap;
2005-04-07 19:29:06 +00:00
}
void PrimitiveObject::saveState(SaveGame *savedState) const {
savedState->writeLESint32(_type);
2011-05-02 03:50:09 +08:00
savedState->writeLEUint32(_color->getId());
savedState->writeLEUint32(_filled);
if (_bitmap) {
savedState->writeLEUint32(_bitmap->getId());
} else {
savedState->writeLEUint32(0);
}
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);
}
bool PrimitiveObject::restoreState(SaveGame *savedState) {
_type = savedState->readLESint32();
_color = PoolColor::getPool().getObject(savedState->readLEUint32());
_filled = savedState->readLEUint32();
_bitmap = Bitmap::getPool().getObject(savedState->readLEUint32());
_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;
}
void PrimitiveObject::createRectangle(Common::Point p1, Common::Point p2, PoolColor *color, bool filled) {
_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*/) {
_type = BITMAP;
_bitmap = bitmap;
2009-05-10 10:11:55 +00:00
_bitmap->setX(p.x);
_bitmap->setY(p.y);
// transparent: what to do ?
}
void PrimitiveObject::createLine(Common::Point p1, Common::Point p2, PoolColor *color) {
_type = LINE;
2009-05-10 10:11:55 +00:00
_p1 = p1;
_p2 = p2;
_color = color;
}
void PrimitiveObject::createPolygon(Common::Point p1, Common::Point p2, Common::Point p3, Common::Point p4, PoolColor *color) {
_type = POLYGON;
2009-05-10 10:11:55 +00:00
_p1 = p1;
_p2 = p2;
_p3 = p3;
_p4 = p4;
_color = color;
}
2005-04-07 19:29:06 +00:00
void PrimitiveObject::draw() {
assert(_type);
if (_type == RECTANGLE)
2005-04-07 19:29:06 +00:00
g_driver->drawRectangle(this);
else if (_type == BITMAP)
2011-05-13 17:55:14 -07:00
g_driver->drawBitmap(_bitmap);
else if (_type == LINE)
g_driver->drawLine(this);
else if (_type == POLYGON)
g_driver->drawPolygon(this);
2005-04-07 19:29:06 +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