aboutsummaryrefslogtreecommitdiff
path: root/engines/director/cast.cpp
blob: 4522eaeeb662bced0dd29ac647c358bd4d4cd21d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * 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.
 *
 * This program 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 General Public License for more details.
 *
 * 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.
 *
 */

#include "director/director.h"
#include "director/cast.h"
#include "director/score.h"

namespace Director {

BitmapCast::BitmapCast(Common::ReadStreamEndian &stream, uint16 version) {
	if (version < 4) {
		flags = stream.readByte();
		someFlaggyThing = stream.readUint16();
		initialRect = Score::readRect(stream);
		boundingRect = Score::readRect(stream);
		regY = stream.readUint16();
		regX = stream.readUint16();
		unk1 = unk2 = 0;

		if (someFlaggyThing & 0x8000) {
			unk1 = stream.readUint16();
			unk2 = stream.readUint16();
		}
	} else {
		stream.readByte();
		stream.readByte();

		flags = 0;
		someFlaggyThing = 0;
		unk1 = unk2 = 0;

		initialRect = Score::readRect(stream);
		boundingRect = Score::readRect(stream);
		regX = stream.readUint16();
		regY = stream.readUint16();

		bitsPerPixel = stream.readUint16();
		if (bitsPerPixel == 0)
			bitsPerPixel = 1;

		int tail = 0;

		while (!stream.eos()) {
			stream.readByte();
			tail++;
		}

		warning("BitmapCast: %d bytes left", tail);
	}
	modified = 0;
}

TextCast::TextCast(Common::ReadStreamEndian &stream, uint16 version) {
	borderSize = kSizeNone;
	gutterSize = kSizeNone;
	boxShadow = kSizeNone;

	flags1 = 0;
	fontId = 0;
	fontSize = 12;
	textType = kTextTypeFixed;
	textAlign = kTextAlignLeft;
	textShadow = kSizeNone;
	textSlant = 0;
	palinfo1 = palinfo2 = palinfo3 = 0;

	if (version < 4) {
		flags1 = stream.readByte();
		borderSize = static_cast<SizeType>(stream.readByte());
		gutterSize = static_cast<SizeType>(stream.readByte());
		boxShadow = static_cast<SizeType>(stream.readByte());
		textType = static_cast<TextType>(stream.readByte());
		textAlign = static_cast<TextAlignType>(stream.readUint16());
		palinfo1 = stream.readUint16();
		palinfo2 = stream.readUint16();
		palinfo3 = stream.readUint16();

		int t = stream.readUint32();
		assert(t == 0); // So far we saw only 0 here

		initialRect = Score::readRect(stream);
		textShadow = static_cast<SizeType>(stream.readByte());
		byte flags = stream.readByte();
		if (flags & 0x1)
			textFlags.push_back(kTextFlagEditable);
		if (flags & 0x2)
			textFlags.push_back(kTextFlagAutoTab);
		if (flags & 0x4)
			textFlags.push_back(kTextFlagDoNotWrap);
		if (flags & 0xf8)
			warning("Unprocessed text cast flags: %x", flags & 0xf8);

		// TODO: FIXME: guesswork
		fontId = stream.readByte();
		fontSize = stream.readByte();
		textSlant = 0;
	} else if (version < 5) {
		borderSize = static_cast<SizeType>(stream.readByte());
		gutterSize = static_cast<SizeType>(stream.readByte());
		boxShadow = static_cast<SizeType>(stream.readByte());
		textType = static_cast<TextType>(stream.readByte());
		textAlign = static_cast<TextAlignType>(stream.readSint16()); //this is because 'right' is -1? or should that be 255?
		stream.readUint16();
		stream.readUint16();
		stream.readUint16();
		stream.readUint16();

		fontId = 1; //this is in STXT

		initialRect = Score::readRect(stream);
		stream.readUint16();
		textShadow = static_cast<SizeType>(stream.readByte());
		byte flags = stream.readByte();

		if (flags)
			warning("Unproxessed text cast flags: %x", flags);

		fontSize = stream.readUint16();
		textSlant = 0;
	} else {
		initialRect = Score::readRect(stream);
		boundingRect = Score::readRect(stream);
	}

	modified = 0;
}

ShapeCast::ShapeCast(Common::ReadStreamEndian &stream, uint16 version) {
	if (version < 4) {
		/*byte flags = */ stream.readByte();
		/*unk1 = */ stream.readByte();
		shapeType = static_cast<ShapeType>(stream.readByte());
		initialRect = Score::readRect(stream);
		pattern = stream.readUint16BE();
		fgCol = stream.readByte();
		bgCol = stream.readByte();
		fillType = stream.readByte();
		lineThickness = stream.readByte();
		lineDirection = stream.readByte();
	} else {
		stream.readByte();
		stream.readByte();

		initialRect = Score::readRect(stream);
		boundingRect = Score::readRect(stream);

		shapeType = kShapeRectangle;
		pattern = 0;
		fgCol = bgCol = 0;
		fillType = 0;
		lineThickness = 1;
		lineDirection = 0;
	}
	modified = 0;
}

ButtonCast::ButtonCast(Common::ReadStreamEndian &stream, uint16 version) : TextCast(stream, version) {
	if (version < 4) {
		buttonType = static_cast<ButtonType>(stream.readUint16BE());
	} else {
		stream.readByte();
		stream.readByte();

		initialRect = Score::readRect(stream);
		boundingRect = Score::readRect(stream);

		buttonType = static_cast<ButtonType>(stream.readUint16BE());
	}
	modified = 0;
}

ScriptCast::ScriptCast(Common::ReadStreamEndian &stream, uint16 version) {
	if (version < 4) {
		error("Unhandled Script cast");
	} else {
		stream.readByte();
		stream.readByte();

		initialRect = Score::readRect(stream);
		boundingRect = Score::readRect(stream);

		id = stream.readUint32();

		debugC(4, kDebugLoading, "CASt: Script id: %d", id);

		stream.readByte(); // There should be no more data
		assert(stream.eos());
	}
	modified = 0;
}

} // End of namespace Director