blob: 8cd5f1f1a56b21cb6c33f173ce5a4ac0587c00e1 (
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
|
/*******************************************************************************
This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio)
Copyright (c) 2010 Treeki (treeki@gmail.com)
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, version 2.0.
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 2.0 for more details.
You should have received a copy of the GNU General Public License 2.0
along with this program. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
#include "picture.h"
#include "layout.h"
#include "common.h"
LYTPicture::LYTPicture(LYTLayout &layout) : LYTPane(layout) {
}
Magic LYTPicture::magic() const {
return Magic('pic1');
}
void LYTPicture::dumpToDebug(bool showHeading) const {
if (showHeading)
qDebug() << "LYTPicture" << name << "@" << (void*)this;
LYTPane::dumpToDebug(false);
qDebug() << "- Vertex Colours:" << vtxColours[0] << "-" << vtxColours[1];
qDebug() << " " << vtxColours[2] << "-" << vtxColours[3];
qDebug() << "- Material:" << materialName;
qDebug() << "- Tex Coords:" << texCoords.count();
foreach (LYTTexCoords texCoord, texCoords) {
qDebug() << "----" << texCoord.coord[0] << "-" << texCoord.coord[1] << "-" << texCoord.coord[2] << "-" << texCoord.coord[3];
}
}
void LYTPicture::writeToDataStream(QDataStream &out) const {
LYTPane::writeToDataStream(out);
for (int i = 0; i < 4; i++)
WriteRGBA8Color(vtxColours[i], out);
// calculate the material number
int materialNum = m_layout.materials.getIndexOfName(materialName);
out << (quint16)materialNum;
// write texcoords
out << (quint8)texCoords.count();
WritePadding(1, out);
foreach (LYTTexCoords texCoord, texCoords) {
for (int i = 0; i < 4; i++)
WritePointF(out, texCoord.coord[i]);
}
}
void LYTPicture::readFromDataStream(QDataStream &in) {
LYTPane::readFromDataStream(in);
for (int i = 0; i < 4; i++)
ReadRGBA8Color(vtxColours[i], in);
// read the material name
quint16 materialNum;
in >> (quint16&)materialNum;
materialName = m_layout.materials.getNameOfIndex(materialNum);
// read texcoords
quint8 texCoordNum;
in >> (quint8&)texCoordNum;
in.skipRawData(1); // padding
texCoords.resize(texCoordNum);
for (int i = 0; i < texCoordNum; i++) {
for (int j = 0; j < 4; j++)
ReadPointF(in, texCoords[i].coord[j]);
}
}
|