1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #include "startrek/common.h"
24 #include "startrek/sprite.h"
25
26 namespace StarTrek {
27
Sprite()28 Sprite::Sprite() :
29 pos(), drawPriority(0), drawPriority2(0), field8(""),
30 bitmap(nullptr), drawMode(0), textColor(0), bitmapChanged(false),
31 rect2Valid(false), isOnScreen(false), field16(false), lastDrawRect(),
32 drawRect(), rectangle2(), drawX(0), drawY(0)
33 {}
34
~Sprite()35 Sprite::~Sprite() {
36 delete bitmap;
37 bitmap = nullptr;
38 }
39
setBitmap(Bitmap * b)40 void Sprite::setBitmap(Bitmap *b) {
41 if (bitmap)
42 delete bitmap;
43 bitmap = b;
44 bitmapChanged = true;
45 }
46
setBitmap(Common::MemoryReadStreamEndian * stream)47 void Sprite::setBitmap(Common::MemoryReadStreamEndian *stream) {
48 setBitmap(new Bitmap(stream));
49 }
50
setXYAndPriority(int16 x,int16 y,int16 priority)51 void Sprite::setXYAndPriority(int16 x, int16 y, int16 priority) {
52 pos.x = x;
53 pos.y = y;
54 drawPriority = priority;
55 bitmapChanged = true;
56 }
57
dontDrawNextFrame()58 void Sprite::dontDrawNextFrame() {
59 field16 = true;
60 bitmapChanged = true;
61 }
62
getRect()63 Common::Rect Sprite::getRect() {
64 Common::Rect rect(bitmap->width, bitmap->height);
65 rect.translate(pos.x - bitmap->xoffset, pos.y - bitmap->yoffset);
66 return rect;
67 }
68
saveLoadWithSerializer(Common::Serializer & ser)69 void Sprite::saveLoadWithSerializer(Common::Serializer &ser) {
70 ser.syncAsSint16LE(pos.x);
71 ser.syncAsSint16LE(pos.y);
72 ser.syncAsUint16LE(drawPriority);
73 ser.syncAsUint16LE(drawPriority2);
74 ser.syncString(field8);
75 // Note: bitmap must be reloaded
76 ser.syncAsUint16LE(drawMode);
77 ser.syncAsUint16LE(textColor);
78 ser.syncAsUint16LE(bitmapChanged);
79 ser.syncAsUint16LE(rect2Valid);
80 ser.syncAsUint16LE(isOnScreen);
81 ser.syncAsUint16LE(field16);
82 serializeRect(lastDrawRect, ser);
83 serializeRect(drawRect, ser);
84 serializeRect(rectangle2, ser);
85 ser.syncAsSint16LE(drawX);
86 ser.syncAsSint16LE(drawY);
87 }
88
89 } // End of namespace StarTrek
90