File: te_sprite_layout.cpp

package info (click to toggle)
scummvm 2.7.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 363,784 kB
  • sloc: cpp: 3,622,060; asm: 27,410; python: 10,528; sh: 10,241; xml: 6,752; java: 5,579; perl: 2,570; yacc: 1,635; javascript: 1,016; lex: 539; makefile: 398; ansic: 378; awk: 275; objc: 82; sed: 11; php: 1
file content (207 lines) | stat: -rw-r--r-- 5,501 bytes parent folder | download
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
/* 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 3 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, see <http://www.gnu.org/licenses/>.
 *
 */

#include "tetraedge/tetraedge.h"
#include "tetraedge/te/te_matrix4x4.h"
#include "tetraedge/te/te_renderer.h"
#include "tetraedge/te/te_sprite_layout.h"

namespace Tetraedge {

TeSpriteLayout::TeSpriteLayout() : _tiledSurfacePtr(new TeTiledSurface()), _sizeSet(false) {
	_tiledSurfacePtr->setColor(TeColor(255, 255, 255, 255));
	//_tiledSurfacePtr->_shouldDraw = true // should already be true..

	updateMesh();
}

int TeSpriteLayout::bufferSize() {
	return _tiledSurfacePtr->bufferSize();
}

void TeSpriteLayout::cont() {
	_tiledSurfacePtr->cont();
}

void TeSpriteLayout::draw() {
	if (!worldVisible())
		return;

	/*
	if (name() == "DEPLIANT")
		debug("Draw SpriteLayout %p (%s, surf %s, size %.01fx%.01f, surf %.01fx%.01f, %s)", this,
			  name().empty() ? "no name" : name().c_str(), _tiledSurfacePtr->getAccessName().toString().c_str(),
			  size().x(), size().y(),
			  _tiledSurfacePtr->size().x(), _tiledSurfacePtr->size().y(), color().dump().c_str());*/
	TeMatrix4x4 matrix = worldTransformationMatrix();

	if (sizeType() == ABSOLUTE) {
		matrix(0, 3) = (int)matrix(0, 3);
		matrix(1, 3) = (int)matrix(1, 3);
	}

	TeRenderer *renderer = g_engine->getRenderer();
	renderer->pushMatrix();
	renderer->loadMatrix(matrix);
	_tiledSurfacePtr->draw();
	renderer->popMatrix();
	TeLayout::draw();
}

bool TeSpriteLayout::onParentWorldColorChanged() {
	Te3DObject2::onParentWorldColorChanged();
	setColor(color());
	return false;
}

bool TeSpriteLayout::load(const Common::Path &path) {
	if (path.empty()) {
		_tiledSurfacePtr = new TeTiledSurface();
		return true;
	}

	stop();
	unload();

	if (_tiledSurfacePtr->load(path)) {
		const TeVector2s32 texSize = _tiledSurfacePtr->tiledTexture()->totalSize();
		if (texSize._y <= 0) {
			setRatio(1.0);
		} else {
			setRatio(texSize._x / texSize._y);
		}
		if (sizeType() == CoordinatesType::ABSOLUTE && !_sizeSet) {
			setSize(TeVector3f32(texSize._x, texSize._y, 1.0));
		}
		updateMesh();
	} else {
		debug("Failed to load TeSpriteLayout %s", path.toString().c_str());
	}
	return true;
}

bool TeSpriteLayout::load(TeIntrusivePtr<Te3DTexture> &texture) {
	unload();

	if (_tiledSurfacePtr->load(texture)) {
		const TeVector2s32 tiledTexSize = _tiledSurfacePtr->tiledTexture()->totalSize();
		if (tiledTexSize._y <= 0) {
			setRatio(1.0);
		} else {
			setRatio((float)tiledTexSize._x / tiledTexSize._y);
		}

		if (sizeType() == CoordinatesType::ABSOLUTE && !_sizeSet) {
			setSize(TeVector3f32(tiledTexSize._x, tiledTexSize._y, 1.0));
		}
		updateMesh();
		return true;
	} else {
		debug("Failed to load TeSpriteLayout from texture %s", texture->getAccessName().toString().c_str());
	}
	return false;
}

bool TeSpriteLayout::load(TeImage &img) {
	unload();

	if (_tiledSurfacePtr->load(img)) {
		const TeVector2s32 tiledTexSize = _tiledSurfacePtr->tiledTexture()->totalSize();
		if (tiledTexSize._y <= 0) {
			setRatio(1.0);
		} else {
			setRatio((float)tiledTexSize._x / tiledTexSize._y);
		}

		if (sizeType() == CoordinatesType::ABSOLUTE && !_sizeSet) {
			setSize(TeVector3f32(tiledTexSize._x, tiledTexSize._y, 1.0));
		}
		updateMesh();
		return true;
	} else {
		debug("Failed to load TeSpriteLayout from texture %s", img.getAccessName().toString().c_str());
	}
	return false;
}

void TeSpriteLayout::play() {
	_tiledSurfacePtr->play();
}

void TeSpriteLayout::unload() {
	_tiledSurfacePtr->unload();
}

void TeSpriteLayout::pause() {
	_tiledSurfacePtr->pause();
}

void TeSpriteLayout::setBufferSize(long bufsize) {
	_tiledSurfacePtr->setBufferSize(bufsize);
}

void TeSpriteLayout::setColor(const TeColor &col) {
	Te3DObject2::setColor(col);
	_tiledSurfacePtr->setColor(color());
}

void TeSpriteLayout::setColorKey(const TeColor &col) {
	_tiledSurfacePtr->setColorKey(col);
}

void TeSpriteLayout::setColorKeyActivated(bool activated) {
	_tiledSurfacePtr->setColorKeyActivated(activated);
}

void TeSpriteLayout::setColorKeyTolerence(float val) {
	_tiledSurfacePtr->setColorKeyTolerence(val);
}

bool TeSpriteLayout::setName(const Common::String &newName) {
	TeLayout::setName(newName);
	_tiledSurfacePtr->setName(newName);
	return true;
}

void TeSpriteLayout::setSize(const TeVector3f32 &newSize) {
	TeLayout::setSize(newSize);
	_sizeSet = true;
}

void TeSpriteLayout::stop() {
	_tiledSurfacePtr->stop();
}

void TeSpriteLayout::updateMesh() {
	TeLayout::updateMesh();
	// Surface always renders to a 1x1 mesh.
	const TeVector3f32 surfaceScale(xSize(), -ySize(), 1.0);
	_tiledSurfacePtr->setScale(surfaceScale);
}

void TeSpriteLayout::updateSize() {
	//if (!name().empty()) {
		TeLayout::updateSize();
		updatePosition();
	//}
}

} // end namespace Tetraedge