summaryrefslogtreecommitdiff
path: root/lyt/textbox.cpp
diff options
context:
space:
mode:
authorTreeki <treeki@gmail.com>2010-10-07 15:56:13 +0200
committerTreeki <treeki@gmail.com>2010-10-07 15:56:13 +0200
commit5f6dad55d75cbe146ff7fefc899a02ccd39078ba (patch)
tree0822df14cc6d2c0329810c9ae7b4a4a638fe82b1 /lyt/textbox.cpp
downloadLayoutStudio-5f6dad55d75cbe146ff7fefc899a02ccd39078ba.tar.gz
LayoutStudio-5f6dad55d75cbe146ff7fefc899a02ccd39078ba.zip
initial commit -- everything compiles except for material.cpp. the material system still needs quite a bit of work; this will come in due time
Diffstat (limited to 'lyt/textbox.cpp')
-rw-r--r--lyt/textbox.cpp115
1 files changed, 115 insertions, 0 deletions
diff --git a/lyt/textbox.cpp b/lyt/textbox.cpp
new file mode 100644
index 0000000..06aed4e
--- /dev/null
+++ b/lyt/textbox.cpp
@@ -0,0 +1,115 @@
+#include "textbox.h"
+#include "layout.h"
+#include "common.h"
+
+
+LYTTextBox::LYTTextBox(LYTLayout &layout) : LYTPane(layout) {
+}
+
+
+void LYTTextBox::dumpToDebug(bool showHeading) {
+ if (showHeading)
+ qDebug() << "LYTTextBox" << name << "@" << (void*)this;
+
+ LYTPane::dumpToDebug(false);
+
+ qDebug() << "- Text:" << text;
+ qDebug() << "- Buffer Length:" << bufferLength;
+ qDebug() << "- Material:" << materialName << "- Font:" << fontName;
+ qDebug() << "- Alignment:" << alignment << "- Alignment Override:" << alignmentOverride;
+ qDebug() << "- Colours:" << colour1 << "--" << colour2;
+ qDebug() << "- Font Size:" << fontSizeX << "x" << fontSizeY;
+ qDebug() << "- Char Space:" << charSpace << "- Line Space:" << lineSpace;
+}
+
+
+
+void LYTTextBox::writeToDataStream(QDataStream &out) {
+ LYTPane::writeToDataStream(out);
+
+ // lengths are stored in bytes (including zero terminator) not characters
+ out << (quint16)((bufferLength + 1) * 2);
+ out << (quint16)((text.length() + 1) * 2);
+
+ // calculate the material and font numbers
+ int materialNum = m_layout.materials.keys().indexOf(materialName);
+ int fontNum = m_layout.m_fontRefs.indexOf(fontName);
+
+ out << (quint16)materialNum;
+ out << (quint16)fontNum;
+
+ out << (quint8)alignment;
+ out << (quint8)alignmentOverride;
+
+ out.skipRawData(2); // padding
+
+ out << (quint32)0x74; // fixed offset to textbox contents
+
+ WriteRGBA8Color(colour1, out);
+ WriteRGBA8Color(colour2, out);
+
+ out << (float)fontSizeX;
+ out << (float)fontSizeY;
+ out << (float)charSpace;
+ out << (float)lineSpace;
+
+ // write the textbox contents
+ const ushort *convertedText = text.utf16();
+ for (int i = 0; i < text.length(); i++)
+ out << (quint16)convertedText[i];
+}
+
+
+void LYTTextBox::readFromDataStream(QDataStream &in) {
+ qint64 saveStartPos = in.device()->pos();
+
+ LYTPane::readFromDataStream(in);
+
+ // the lengths are stored in bytes (not characters) and count the
+ // zero terminator, and strings are UTF-16 (I think) so we need
+ // to take it off here
+ in >> (quint16&)bufferLength;
+ bufferLength >>= 1;
+ bufferLength--;
+
+ quint16 stringLength;
+ in >> (quint16&)stringLength;
+ stringLength >>= 1;
+ stringLength--;
+
+ // read the material and font names
+ quint16 materialNum, fontNum;
+ in >> (quint16&)materialNum;
+ in >> (quint16&)fontNum;
+
+ materialName = m_layout.materials.keys().at(materialNum);
+ fontName = m_layout.m_fontRefs.at(fontNum);
+
+ in >> (quint8&)alignment;
+ in >> (quint8&)alignmentOverride;
+
+ in.skipRawData(2); // padding
+
+ quint32 stringOffset;
+ in >> (quint32&)stringOffset;
+
+ ReadRGBA8Color(colour1, in);
+ ReadRGBA8Color(colour2, in);
+
+ in >> (float&)fontSizeX;
+ in >> (float&)fontSizeY;
+ in >> (float&)charSpace;
+ in >> (float&)lineSpace;
+
+ // read the textbox contents
+ // subtract 8 to account for BinaryBlockHeader or whatever it's called
+ in.device()->seek(saveStartPos + stringOffset - 8);
+
+ ushort *rawText = new ushort[stringLength];
+
+ for (int i = 0; i < stringLength; i++)
+ in >> (quint16&)rawText[i];
+
+ text.setUtf16(rawText, stringLength);
+ delete[] rawText;
+}