├── LICENSE.txt ├── LayoutStudio.pro ├── README.markdown ├── icons ├── bounding.png ├── pane.png ├── picture.png ├── textbox.png └── window.png ├── layoutgl ├── texturemanager.cpp ├── texturemanager.h ├── widget.cpp └── widget.h ├── lscolorpicker.cpp ├── lscolorpicker.h ├── lsglobals.cpp ├── lsglobals.h ├── lslayoutwindow.cpp ├── lslayoutwindow.h ├── lsmainwindow.cpp ├── lsmainwindow.h ├── lsmaterialeditor.cpp ├── lsmaterialeditor.h ├── lsmaterialeditors.h ├── lsmaterialmodel.cpp ├── lsmaterialmodel.h ├── lspackagemodel.cpp ├── lspackagemodel.h ├── lspaneeditor.cpp ├── lspaneeditor.h ├── lsscenemodel.cpp ├── lsscenemodel.h ├── lsseteditor.cpp ├── lsseteditor.h ├── lstexcoordseteditor.cpp ├── lstexcoordseteditor.h ├── lyt ├── archivepackage.cpp ├── archivepackage.h ├── binaryfile.cpp ├── binaryfile.h ├── binaryfilesection.cpp ├── binaryfilesection.h ├── bounding.cpp ├── bounding.h ├── common.h ├── directorypackage.cpp ├── directorypackage.h ├── group.cpp ├── group.h ├── layout.cpp ├── layout.h ├── materials │ ├── alphacompare.cpp │ ├── alphacompare.h │ ├── blendmode.cpp │ ├── blendmode.h │ ├── chanctrl.cpp │ ├── chanctrl.h │ ├── indirectstage.cpp │ ├── indirectstage.h │ ├── material.cpp │ ├── material.h │ ├── materialcontainer.h │ ├── tevstage.cpp │ ├── tevstage.h │ ├── tevswaptable.cpp │ ├── tevswaptable.h │ ├── texcoordgen.cpp │ ├── texcoordgen.h │ ├── texmap.cpp │ ├── texmap.h │ ├── texsrt.cpp │ └── texsrt.h ├── packagebase.cpp ├── packagebase.h ├── pane.cpp ├── pane.h ├── picture.cpp ├── picture.h ├── textbox.cpp ├── textbox.h ├── window.cpp └── window.h ├── main.cpp ├── resources.qrc └── wii ├── archiveu8.cpp ├── archiveu8.h ├── common.cpp ├── common.h ├── filesystem.cpp ├── filesystem.h ├── gx.h ├── stringtablebuilder.cpp ├── stringtablebuilder.h ├── texpalette.cpp └── texpalette.h /LayoutStudio.pro: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------- 2 | # Project created by QtCreator 2010-10-03T04:03:27 3 | # ------------------------------------------------- 4 | QT += opengl 5 | TARGET = LayoutStudio 6 | TEMPLATE = app 7 | SOURCES += main.cpp \ 8 | lsmainwindow.cpp \ 9 | lsglobals.cpp \ 10 | lyt/packagebase.cpp \ 11 | lyt/directorypackage.cpp \ 12 | lyt/layout.cpp \ 13 | lyt/binaryfile.cpp \ 14 | lyt/binaryfilesection.cpp \ 15 | lyt/materials/material.cpp \ 16 | lyt/pane.cpp \ 17 | lyt/textbox.cpp \ 18 | lyt/picture.cpp \ 19 | lyt/window.cpp \ 20 | lyt/bounding.cpp \ 21 | lyt/group.cpp \ 22 | lyt/materials/texmap.cpp \ 23 | lyt/materials/texsrt.cpp \ 24 | lyt/materials/texcoordgen.cpp \ 25 | lyt/materials/chanctrl.cpp \ 26 | lyt/materials/tevswaptable.cpp \ 27 | lyt/materials/indirectstage.cpp \ 28 | lyt/materials/tevstage.cpp \ 29 | lyt/materials/alphacompare.cpp \ 30 | lyt/materials/blendmode.cpp \ 31 | wii/common.cpp \ 32 | wii/archiveu8.cpp \ 33 | wii/filesystem.cpp \ 34 | lyt/archivepackage.cpp \ 35 | wii/stringtablebuilder.cpp \ 36 | layoutgl/texturemanager.cpp \ 37 | layoutgl/widget.cpp \ 38 | wii/texpalette.cpp \ 39 | lspackagemodel.cpp \ 40 | lslayoutwindow.cpp \ 41 | lsscenemodel.cpp \ 42 | lspaneeditor.cpp \ 43 | lstexcoordseteditor.cpp \ 44 | lsmaterialeditor.cpp \ 45 | lscolorpicker.cpp \ 46 | lsmaterialmodel.cpp \ 47 | lsseteditor.cpp 48 | HEADERS += lsmainwindow.h \ 49 | lsglobals.h \ 50 | lyt/packagebase.h \ 51 | lyt/directorypackage.h \ 52 | lyt/layout.h \ 53 | lyt/binaryfile.h \ 54 | lyt/binaryfilesection.h \ 55 | lyt/materials/material.h \ 56 | lyt/pane.h \ 57 | lyt/common.h \ 58 | lyt/textbox.h \ 59 | lyt/picture.h \ 60 | lyt/window.h \ 61 | lyt/bounding.h \ 62 | lyt/group.h \ 63 | lyt/materials/texmap.h \ 64 | lyt/materials/texsrt.h \ 65 | lyt/materials/texcoordgen.h \ 66 | lyt/materials/chanctrl.h \ 67 | lyt/materials/tevswaptable.h \ 68 | lyt/materials/indirectstage.h \ 69 | lyt/materials/tevstage.h \ 70 | lyt/materials/alphacompare.h \ 71 | lyt/materials/blendmode.h \ 72 | wii/archiveu8.h \ 73 | wii/common.h \ 74 | wii/filesystem.h \ 75 | lyt/archivepackage.h \ 76 | wii/stringtablebuilder.h \ 77 | lyt/materials/materialcontainer.h \ 78 | layoutgl/texturemanager.h \ 79 | layoutgl/widget.h \ 80 | wii/texpalette.h \ 81 | wii/gx.h \ 82 | lspackagemodel.h \ 83 | lslayoutwindow.h \ 84 | lsscenemodel.h \ 85 | lspaneeditor.h \ 86 | lstexcoordseteditor.h \ 87 | lsmaterialeditor.h \ 88 | lscolorpicker.h \ 89 | lsmaterialmodel.h \ 90 | lsseteditor.h \ 91 | lsmaterialeditors.h 92 | FORMS += 93 | RESOURCES += resources.qrc 94 | 95 | OTHER_FILES += \ 96 | icons/window.png \ 97 | icons/textbox.png \ 98 | icons/picture.png \ 99 | icons/pane.png \ 100 | icons/bounding.png \ 101 | README.markdown \ 102 | LICENSE.txt 103 | -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | LayoutStudio Readme 2 | =================== 3 | 4 | LayoutStudio is a work-in-progress application written by Treeki which plans to 5 | offer graphical editing of Wii NW4R layouts/banners (.brlyt/.brlan files) with 6 | functional, real-time previews. 7 | 8 | The application is written in C++ (with heavy usage of Nokia's Qt toolkit). 9 | 10 | I originally started this project in 2010, and wrote all the code required to 11 | read and write layout files, but then lost interest because I didn't know where 12 | to start with the rendering code. 13 | 14 | In July 2012, I've taken it back up and changed my focus. Instead of trying to 15 | render layouts exactly the same way as they appear on the Wii, I'm going to 16 | forget about all the fancy TEV stuff and just create something that's usable for 17 | designing and editing layouts. I've been informed that this is actually how 18 | Nintendo's official tool works. 19 | 20 | Of course, I'd still love to add accurate rendering to this some day, but it's 21 | not going to be my #1 goal any more. Having a working editor is more important. 22 | 23 | 24 | ### Implemented Features ### 25 | - BRLYT reading, writing (writing is not fully tested yet) 26 | - Simple API for manipulating layout files from other code 27 | - Wii filesystem API (currently only supports U8 archives) 28 | 29 | 30 | ### Planned Features ### 31 | - BRLAN reading/writing 32 | - Graphical interface for editing layouts and animations 33 | - Rendering of layouts using OpenGL 34 | - BRFNT support 35 | 36 | 37 | ### Current (Short-Term) TODO ### 38 | - Disassemble code that sets up indirect textures for materials 39 | - Add usd1 handling 40 | - Add TPL file support 41 | 42 | 43 | Other Stuff 44 | ----------- 45 | 46 | Special thanks to megazig, trap15 and everyone else who worked on benzin. 47 | Greets to #HACKERCHANNEL and the Newer team :p 48 | 49 | Icons used in the GUI are from the Fugue set by [Yusuke Kamiyamane][yk]. 50 | 51 | The project is licensed under the GNU General Public License v2. 52 | 53 | [yk]: http://p.yusukekamiyamane.com/ 54 | -------------------------------------------------------------------------------- /icons/bounding.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Treeki/LayoutStudio/be8b56a7f0a8f6ba5456a099b61d032fd8aa2f61/icons/bounding.png -------------------------------------------------------------------------------- /icons/pane.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Treeki/LayoutStudio/be8b56a7f0a8f6ba5456a099b61d032fd8aa2f61/icons/pane.png -------------------------------------------------------------------------------- /icons/picture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Treeki/LayoutStudio/be8b56a7f0a8f6ba5456a099b61d032fd8aa2f61/icons/picture.png -------------------------------------------------------------------------------- /icons/textbox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Treeki/LayoutStudio/be8b56a7f0a8f6ba5456a099b61d032fd8aa2f61/icons/textbox.png -------------------------------------------------------------------------------- /icons/window.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Treeki/LayoutStudio/be8b56a7f0a8f6ba5456a099b61d032fd8aa2f61/icons/window.png -------------------------------------------------------------------------------- /layoutgl/texturemanager.cpp: -------------------------------------------------------------------------------- 1 | #include "texturemanager.h" 2 | 3 | LGLTextureManager::LGLTextureManager() { 4 | } 5 | 6 | void LGLTextureManager::setup(QGLWidget *gl, const LYTLayout *layout) { 7 | // TODO: code to cleanup previous stuff 8 | 9 | //m_gl = gl; 10 | m_layout = layout; 11 | m_package = &layout->package(); 12 | 13 | QStringList textures = layout->generateTextureRefs(); 14 | 15 | foreach (const QString &texName, textures) { 16 | qDebug() << texName; 17 | 18 | QByteArray tplData = m_package->getTexture(texName); 19 | 20 | QDataStream tplStream(tplData); 21 | WiiTexPalette tpl(tplStream); 22 | 23 | const QImage &image = tpl.textures.first().image; 24 | image.save(QString("tpl/%2__%1.png").arg(texName).arg((int)tpl.textures.first().format)); 25 | // dirty, dirty hack, TODO: FIXME 26 | GLuint tex = gl->bindTexture(image, GL_TEXTURE_2D); 27 | 28 | m_textures.insert(texName, tex); 29 | m_images.insert(texName, image); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /layoutgl/texturemanager.h: -------------------------------------------------------------------------------- 1 | #ifndef TEXTUREMANAGER_H 2 | #define TEXTUREMANAGER_H 3 | 4 | #include "wii/texpalette.h" 5 | #include "lyt/layout.h" 6 | #include 7 | #include 8 | 9 | class LGLTextureManager { 10 | public: 11 | LGLTextureManager(); 12 | 13 | void setup(QGLWidget *gl, const LYTLayout *layout); 14 | 15 | private: 16 | const QGLContext *m_gl; 17 | const LYTLayout *m_layout; 18 | const LYTPackageBase *m_package; 19 | 20 | QHash m_textures; 21 | QHash m_images; 22 | 23 | public: 24 | GLuint glTextureForName(const QString name) const { 25 | return m_textures.value(name); 26 | } 27 | 28 | QImage imageForName(const QString name) const { 29 | return m_images.value(name); 30 | } 31 | }; 32 | 33 | #endif // TEXTUREMANAGER_H 34 | -------------------------------------------------------------------------------- /layoutgl/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | 6 | #include "lyt/layout.h" 7 | #include "layoutgl/texturemanager.h" 8 | 9 | class LGLWidget : public QGLWidget 10 | { 11 | Q_OBJECT 12 | public: 13 | explicit LGLWidget(QWidget *parent = 0); 14 | 15 | void setLayout(LYTLayout *layout); 16 | 17 | protected: 18 | void initializeGL(); 19 | void resizeGL(int w, int h); 20 | void paintGL(); 21 | 22 | LYTLayout *m_layout; 23 | 24 | void renderPane(const LYTPane *pane, quint8 parentAlpha); 25 | 26 | void drawPicture(const LYTPicture *pic, quint8 effectiveAlpha); 27 | void drawWindow(const LYTWindow *wnd, quint8 effectiveAlpha); 28 | 29 | const LYTMaterial &getMaterial(const QString &materialName) { 30 | return *m_layout->materials.getMaterialByName(materialName); 31 | } 32 | 33 | void useMaterial(const QString &materialName); 34 | void useMaterial(const LYTMaterial &material); 35 | 36 | void drawQuad(float x, float y, float w, float h, const QVector &texCoords, const QColor *colours, uchar alpha); 37 | void drawQuad(float x, float y, float w, float h, int texCoordCount, const LYTTexCoords *texCoords, const QColor *colours, uchar alpha); 38 | 39 | void getTextureSize(const QString &materialName, float *w, float *h); 40 | 41 | void dealWithWindowFrame(LYTTexCoords &coords, const QString &materialName, int flipType, 42 | float pieceWidth, float pieceHeight, 43 | int rep1, int rep2, int rep3, int rep4); 44 | 45 | LGLTextureManager m_texMgr; 46 | 47 | signals: 48 | 49 | public slots: 50 | 51 | }; 52 | 53 | #endif // WIDGET_H 54 | -------------------------------------------------------------------------------- /lscolorpicker.cpp: -------------------------------------------------------------------------------- 1 | #include "lscolorpicker.h" 2 | #include 3 | 4 | LSColorPicker::LSColorPicker(QWidget *parent) : 5 | QToolButton(parent) { 6 | 7 | connect(this, SIGNAL(clicked()), SLOT(tryAndChoose())); 8 | setColor(QColor::fromRgb(255,255,255,255)); 9 | } 10 | 11 | void LSColorPicker::setColor(QColor newCol) { 12 | m_color = newCol; 13 | refreshButton(); 14 | } 15 | 16 | void LSColorPicker::tryAndChoose() { 17 | QColor newCol = QColorDialog::getColor( 18 | m_color, this, 19 | "Pick a Colour", 20 | QColorDialog::ShowAlphaChannel); 21 | 22 | if (newCol.isValid() && newCol != m_color) { 23 | QColor oldCol = m_color; 24 | m_color = newCol; 25 | refreshButton(); 26 | emit colorPicked(newCol, oldCol); 27 | } 28 | } 29 | 30 | 31 | void LSColorPicker::refreshButton() { 32 | setStyleSheet(QString("QToolButton { background-color: rgba(%1,%2,%3,%4); }") 33 | .arg(m_color.red()) 34 | .arg(m_color.green()) 35 | .arg(m_color.blue()) 36 | .arg(m_color.alpha())); 37 | 38 | setText(QString("RGBA (#%5%6%7%8)\n%1,%2,%3,%4") 39 | .arg(m_color.red()) 40 | .arg(m_color.green()) 41 | .arg(m_color.blue()) 42 | .arg(m_color.alpha()) 43 | .arg(m_color.red(), 2, 16, (QChar)'0') 44 | .arg(m_color.green(), 2, 16, (QChar)'0') 45 | .arg(m_color.blue(), 2, 16, (QChar)'0') 46 | .arg(m_color.alpha(), 2, 16, (QChar)'0')); 47 | } 48 | -------------------------------------------------------------------------------- /lscolorpicker.h: -------------------------------------------------------------------------------- 1 | #ifndef LSCOLORPICKER_H 2 | #define LSCOLORPICKER_H 3 | 4 | #include 5 | 6 | class LSColorPicker : public QToolButton 7 | { 8 | Q_OBJECT 9 | public: 10 | explicit LSColorPicker(QWidget *parent = 0); 11 | 12 | QColor color() const { return m_color; } 13 | void setColor(QColor newCol); 14 | 15 | private: 16 | QColor m_color; 17 | 18 | private slots: 19 | void tryAndChoose(); 20 | void refreshButton(); 21 | 22 | signals: 23 | void colorPicked(QColor newCol, QColor oldCol); 24 | 25 | }; 26 | 27 | #endif // LSCOLORPICKER_H 28 | -------------------------------------------------------------------------------- /lsglobals.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #include "lsglobals.h" 19 | 20 | bool LSGlobals::m_loaded = false; 21 | QHash LSGlobals::m_icons; 22 | 23 | 24 | bool LSGlobals::setup() { 25 | if (m_loaded) 26 | return false; 27 | 28 | 29 | 30 | // Load icons 31 | loadIcon("pane"); 32 | loadIcon("picture"); 33 | loadIcon("textbox"); 34 | loadIcon("bounding"); 35 | loadIcon("window"); 36 | 37 | 38 | 39 | m_loaded = true; 40 | return true; 41 | } 42 | 43 | 44 | bool LSGlobals::loadIcon(QString name) { 45 | m_icons[name] = QIcon(QString(":icons/%1").arg(name)); 46 | return true; 47 | } 48 | 49 | 50 | QIcon LSGlobals::getIcon(QString name) { 51 | return m_icons.value(name); 52 | } 53 | -------------------------------------------------------------------------------- /lsglobals.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #ifndef LSGLOBALS_H 19 | #define LSGLOBALS_H 20 | 21 | #include 22 | #include 23 | 24 | class LSGlobals { 25 | public: 26 | static bool setup(); 27 | 28 | static QIcon getIcon(QString name); 29 | 30 | private: 31 | static bool m_loaded; 32 | 33 | static QHash m_icons; 34 | 35 | static bool loadIcon(QString name); 36 | }; 37 | 38 | #endif // LSGLOBALS_H 39 | -------------------------------------------------------------------------------- /lslayoutwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "lslayoutwindow.h" 2 | #include "lsscenemodel.h" 3 | #include "lsmaterialmodel.h" 4 | #include "lspaneeditor.h" 5 | #include "lsmaterialeditor.h" 6 | #include "layoutgl/widget.h" 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | LSLayoutWindow::LSLayoutWindow(LYTPackageBase *pkg, const QString &layoutName, QWidget *parent) : 13 | QMainWindow(parent) { 14 | 15 | m_layoutName = layoutName; 16 | m_package = pkg; 17 | m_loadingSettings = true; 18 | 19 | m_tabWidget = new QTabWidget(this); 20 | setCentralWidget(m_tabWidget); 21 | 22 | QWidget *w; 23 | 24 | // prepare the Settings tab 25 | w = new QWidget(this); 26 | QGridLayout *sgrid = new QGridLayout(w); 27 | 28 | QGroupBox *sizeGroup = new QGroupBox("Layout Size", this); 29 | sgrid->addWidget(sizeGroup, 0, 0, 1, 2); 30 | 31 | QFormLayout *sizeForm = new QFormLayout(sizeGroup); 32 | 33 | m_widthBox = new QDoubleSpinBox(this); 34 | m_widthBox->setRange(0.0, 1000.0); 35 | m_heightBox = new QDoubleSpinBox(this); 36 | m_heightBox->setRange(0.0, 1000.0); 37 | 38 | sizeForm->addRow("Width", m_widthBox); 39 | sizeForm->addRow("Height", m_heightBox); 40 | 41 | connect(m_widthBox, SIGNAL(valueChanged(double)), SLOT(handleWidthChanged(double))); 42 | connect(m_heightBox, SIGNAL(valueChanged(double)), SLOT(handleHeightChanged(double))); 43 | 44 | 45 | QGroupBox *grpGroup = new QGroupBox("Groups", this); 46 | 47 | sgrid->addWidget(grpGroup, 1, 0, 1, 2); 48 | sgrid->setRowStretch(1, 1); 49 | 50 | m_tabWidget->addTab(w, "Layout"); 51 | 52 | // prepare the Scene Graph tab 53 | m_sceneSplitter = new QSplitter(this); 54 | 55 | w = new QWidget(this); 56 | QGridLayout *ggrid = new QGridLayout(w); 57 | 58 | m_searchBox = new QLineEdit(this); 59 | m_searchBox->setPlaceholderText("Search panes..."); 60 | 61 | m_clearSearchButton = new QPushButton("Clear", this); 62 | 63 | m_sceneGraph = new QTreeView(this); 64 | m_sceneGraph->setHeaderHidden(true); 65 | m_sceneSearchList = new QListView(this); 66 | m_sceneListSwitcher = new QStackedLayout; 67 | m_sceneListSwitcher->addWidget(m_sceneGraph); 68 | m_sceneListSwitcher->addWidget(m_sceneSearchList); 69 | 70 | ggrid->addWidget(m_searchBox, 0, 0, 1, 1); 71 | ggrid->addWidget(m_clearSearchButton, 0, 1, 1, 1); 72 | ggrid->addLayout(m_sceneListSwitcher, 1, 0, 1, 2); 73 | 74 | QWidget *switcherWidget = new QWidget(this); 75 | m_paneEditorSwitcher = new QStackedLayout(switcherWidget); 76 | 77 | m_paneEditor = new LSPaneEditor(switcherWidget); 78 | 79 | m_paneEditorSwitcher->addWidget(new QLabel("Choose a pane to edit from the left.", switcherWidget)); 80 | m_paneEditorSwitcher->addWidget(m_paneEditor); 81 | 82 | m_sceneSplitter->addWidget(w); 83 | m_sceneSplitter->addWidget(switcherWidget); 84 | m_sceneSplitter->setCollapsible(1, false); 85 | 86 | m_tabWidget->addTab(m_sceneSplitter, "Scene Graph"); 87 | 88 | 89 | // prepare the materials tab 90 | m_materialSplitter = new QSplitter(this); 91 | 92 | w = new QWidget(this); 93 | QGridLayout *mgrid = new QGridLayout(w); 94 | 95 | m_addMaterialButton = new QPushButton("Add", w); 96 | m_removeMaterialButton = new QPushButton("Remove", w); 97 | m_materialList = new QListView(w); 98 | 99 | mgrid->addWidget(m_materialList, 0, 0, 1, 2); 100 | mgrid->addWidget(m_addMaterialButton, 1, 0, 1, 1); 101 | mgrid->addWidget(m_removeMaterialButton, 1, 1, 1, 1); 102 | 103 | QScrollArea *matScroller = new QScrollArea(m_materialSplitter); 104 | m_materialEditor = new LSMaterialEditor(matScroller); 105 | 106 | m_materialSplitter->addWidget(w); 107 | m_materialSplitter->addWidget(matScroller); 108 | m_materialSplitter->setCollapsible(1, false); 109 | 110 | matScroller->setWidget(m_materialEditor); 111 | 112 | m_tabWidget->addTab(m_materialSplitter, "Materials"); 113 | 114 | 115 | // get the resource 116 | m_layout = new LYTLayout(*m_package, m_layoutName); 117 | 118 | m_widthBox->setValue(m_layout->width); 119 | m_heightBox->setValue(m_layout->height); 120 | 121 | LSSceneModel *scnModel = new LSSceneModel(m_layout, true, this); 122 | 123 | m_sceneGraph->setSelectionMode(QAbstractItemView::ExtendedSelection); 124 | m_sceneGraph->setDragEnabled(true); 125 | m_sceneGraph->setAcceptDrops(true); 126 | m_sceneGraph->setDropIndicatorShown(true); 127 | m_sceneGraph->setModel(scnModel); 128 | m_sceneGraph->expandAll(); 129 | connect(m_sceneGraph->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), SLOT(selectedPaneChanged(QModelIndex,QModelIndex))); 130 | 131 | LSMaterialModel *matModel = new LSMaterialModel(&m_layout->materials, this); 132 | 133 | m_materialList->setSelectionMode(QAbstractItemView::SingleSelection); 134 | m_materialList->setModel(matModel); 135 | connect(m_materialList->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), SLOT(selectedMaterialChanged(QModelIndex,QModelIndex))); 136 | 137 | setWindowTitle(m_layoutName); 138 | 139 | 140 | // finally make the widget 141 | m_renderer = new LGLWidget(); 142 | m_renderer->setLayout(m_layout); 143 | m_renderer->setWindowTitle(QString("Preview: %1").arg(m_layoutName)); 144 | m_renderer->setWindowFlags( 145 | Qt::CustomizeWindowHint | 146 | Qt::WindowTitleHint | 147 | Qt::WindowMinimizeButtonHint); 148 | m_renderer->show(); 149 | 150 | connect(m_paneEditor, SIGNAL(mustRedrawLayout()), m_renderer, SLOT(updateGL())); 151 | connect(scnModel, SIGNAL(paneVisibilityChanged()), m_renderer, SLOT(updateGL())); 152 | 153 | // clean up here 154 | setAttribute(Qt::WA_DeleteOnClose); 155 | 156 | m_loadingSettings = false; 157 | } 158 | 159 | LSLayoutWindow::~LSLayoutWindow() { 160 | m_renderer->close(); 161 | delete m_renderer; 162 | delete m_layout; 163 | } 164 | 165 | 166 | void LSLayoutWindow::selectedPaneChanged(const QModelIndex ¤t, const QModelIndex &previous) { 167 | (void)previous; 168 | LYTPane *pane = (LYTPane*)current.internalPointer(); 169 | 170 | m_paneEditor->setPane(pane); 171 | m_paneEditorSwitcher->setCurrentIndex(1); 172 | } 173 | 174 | void LSLayoutWindow::selectedMaterialChanged(const QModelIndex ¤t, const QModelIndex &previous) { 175 | (void)previous; 176 | LYTMaterial *mat = m_layout->materials.getMaterialByIndex(current.row()); 177 | 178 | m_materialEditor->setMaterial(mat); 179 | } 180 | 181 | 182 | void LSLayoutWindow::handleWidthChanged(double v) { 183 | m_layout->width = v; 184 | if (!m_loadingSettings) 185 | m_renderer->updateGL(); 186 | } 187 | 188 | void LSLayoutWindow::handleHeightChanged(double v) { 189 | m_layout->height = v; 190 | if (!m_loadingSettings) 191 | m_renderer->updateGL(); 192 | } 193 | 194 | -------------------------------------------------------------------------------- /lslayoutwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef LSLAYOUTWINDOW_H 2 | #define LSLAYOUTWINDOW_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "lyt/packagebase.h" 14 | #include "lyt/layout.h" 15 | class LSPaneEditor; 16 | class LSMaterialEditor; 17 | class LGLWidget; 18 | 19 | class LSLayoutWindow : public QMainWindow { 20 | Q_OBJECT 21 | public: 22 | explicit LSLayoutWindow(LYTPackageBase *pkg, const QString &layoutName, QWidget *parent = 0); 23 | ~LSLayoutWindow(); 24 | 25 | QString layoutName() const { return m_layoutName; } 26 | // TODO: set layoutname method 27 | 28 | LYTLayout *editedLayout() const { return m_layout; } 29 | 30 | private: 31 | QString m_layoutName; 32 | LYTPackageBase *m_package; 33 | LYTLayout *m_layout; 34 | 35 | LGLWidget *m_renderer; 36 | 37 | QTabWidget *m_tabWidget; 38 | 39 | // settings 40 | QDoubleSpinBox *m_widthBox, *m_heightBox; 41 | 42 | // scene graph 43 | QSplitter *m_sceneSplitter; 44 | 45 | QStackedLayout *m_sceneListSwitcher; 46 | QLineEdit *m_searchBox; 47 | QPushButton *m_clearSearchButton; 48 | QTreeView *m_sceneGraph; 49 | QListView *m_sceneSearchList; 50 | 51 | QStackedLayout *m_paneEditorSwitcher; 52 | LSPaneEditor *m_paneEditor; 53 | 54 | bool m_loadingSettings; 55 | 56 | // material things 57 | QSplitter *m_materialSplitter; 58 | 59 | QListView *m_materialList; 60 | QPushButton *m_addMaterialButton; 61 | QPushButton *m_removeMaterialButton; 62 | 63 | LSMaterialEditor *m_materialEditor; 64 | 65 | private slots: 66 | void handleWidthChanged(double v); 67 | void handleHeightChanged(double v); 68 | void selectedPaneChanged(const QModelIndex ¤t, const QModelIndex &previous); 69 | void selectedMaterialChanged(const QModelIndex ¤t, const QModelIndex &previous); 70 | 71 | signals: 72 | 73 | public slots: 74 | 75 | }; 76 | 77 | #endif // LSLAYOUTWINDOW_H 78 | -------------------------------------------------------------------------------- /lsmainwindow.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #include "lsmainwindow.h" 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "lyt/archivepackage.h" 25 | #include "lslayoutwindow.h" 26 | 27 | LSMainWindow::LSMainWindow(QWidget *parent) : QMainWindow(parent) { 28 | m_package = 0; 29 | m_dirty = false; 30 | m_isSaved = false; 31 | 32 | createActions(); 33 | 34 | m_view = new QTreeView(this); 35 | m_view->setHeaderHidden(true); 36 | setCentralWidget(m_view); 37 | 38 | connect(m_view, SIGNAL(activated(QModelIndex)), SLOT(handleItemActivated(QModelIndex))); 39 | 40 | newArchive(); 41 | } 42 | 43 | LSMainWindow::~LSMainWindow() { 44 | if (m_package) 45 | delete m_package; 46 | } 47 | 48 | 49 | void LSMainWindow::createActions() { 50 | m_newArchiveAction = new QAction("&New Archive", this); 51 | m_openArchiveAction = new QAction("&Open Archive...", this); 52 | m_saveAction = new QAction("&Save", this); 53 | m_saveArchiveAsAction = new QAction("Save Archive &As...", this); 54 | 55 | m_newArchiveAction->setShortcuts(QKeySequence::New); 56 | m_openArchiveAction->setShortcuts(QKeySequence::Open); 57 | m_saveAction->setShortcuts(QKeySequence::Save); 58 | m_saveArchiveAsAction->setShortcuts(QKeySequence::SaveAs); 59 | 60 | connect(m_newArchiveAction, SIGNAL(triggered()), SLOT(newArchive())); 61 | connect(m_openArchiveAction, SIGNAL(triggered()), SLOT(openArchive())); 62 | connect(m_saveAction, SIGNAL(triggered()), SLOT(save())); 63 | connect(m_saveArchiveAsAction, SIGNAL(triggered()), SLOT(saveArchiveAs())); 64 | 65 | m_addLayoutAction = new QAction("New &Layout...", this); 66 | m_addAnimationAction = new QAction("New &Animation...", this); 67 | m_addTextureAction = new QAction("New &Texture...", this); 68 | m_importNewAction = new QAction("&New Item...", this); 69 | m_importAction = new QAction("&Replace This Item...", this); 70 | m_exportAction = new QAction("&Export to File...", this); 71 | m_renameAction = new QAction("Re&name Item...", this); 72 | m_removeAction = new QAction("&Remove Item...", this); 73 | 74 | m_addActionMapper = new QSignalMapper(this); 75 | m_addActionMapper->setMapping(m_addLayoutAction, (int)LYTPackageBase::Layout); 76 | m_addActionMapper->setMapping(m_addAnimationAction, (int)LYTPackageBase::Animation); 77 | m_addActionMapper->setMapping(m_addTextureAction, (int)LYTPackageBase::Texture); 78 | 79 | connect(m_addLayoutAction, SIGNAL(triggered()), m_addActionMapper, SLOT(map())); 80 | connect(m_addAnimationAction, SIGNAL(triggered()), m_addActionMapper, SLOT(map())); 81 | connect(m_addTextureAction, SIGNAL(triggered()), m_addActionMapper, SLOT(map())); 82 | connect(m_addActionMapper, SIGNAL(mapped(int)), SLOT(handleAddSomething(int))); 83 | 84 | connect(m_renameAction, SIGNAL(triggered()), SLOT(handleRenameItem())); 85 | connect(m_removeAction, SIGNAL(triggered()), SLOT(handleRemoveItem())); 86 | 87 | QMenuBar *bar = menuBar(); 88 | QMenu *m; 89 | 90 | m = bar->addMenu("&File"); 91 | m->addAction(m_newArchiveAction); 92 | m->addAction(m_openArchiveAction); 93 | m->addAction(m_saveAction); 94 | m->addAction(m_saveArchiveAsAction); 95 | 96 | m = bar->addMenu("&Edit"); 97 | m->addAction(m_addLayoutAction); 98 | m->addAction(m_addAnimationAction); 99 | m->addAction(m_addTextureAction); 100 | m->addSeparator(); 101 | QMenu *importMenu = m->addMenu("&Import from File"); 102 | importMenu->addAction(m_importNewAction); 103 | importMenu->addAction(m_importAction); 104 | m->addAction(m_exportAction); 105 | m->addSeparator(); 106 | m->addAction(m_renameAction); 107 | m->addAction(m_removeAction); 108 | } 109 | 110 | 111 | void LSMainWindow::handleAddSomething(int whatToAdd) { 112 | LYTPackageBase::ItemType what = (LYTPackageBase::ItemType)whatToAdd; 113 | 114 | const char *typeName; 115 | QString extension; 116 | switch (what) { 117 | case LYTPackageBase::Layout: 118 | typeName = "layout"; 119 | extension = ".brlyt"; 120 | break; 121 | case LYTPackageBase::Animation: 122 | typeName = "animation"; 123 | extension = ".brlan"; 124 | break; 125 | case LYTPackageBase::Texture: 126 | typeName = "texture"; 127 | extension = ".tpl"; 128 | break; 129 | default: return; 130 | } 131 | 132 | QString name = QInputDialog::getText(this, 133 | "Add Item", 134 | QString("Name this %1:").arg(typeName)); 135 | 136 | if (!name.isEmpty()) { 137 | QByteArray data = LYTPackageBase::createSkeletonItem(what); 138 | if (!name.endsWith(extension)) 139 | name.append(extension); 140 | 141 | m_package->write(what, name, data); 142 | } 143 | } 144 | 145 | 146 | void LSMainWindow::handleRemoveItem() { 147 | QString what = selectedItem(); 148 | LYTPackageBase::ItemType whatType = selectedItemType(); 149 | 150 | if (!what.isEmpty()) { 151 | QString confirmText = QString("Are you sure you want to delete '%1'? You'll lose it forever...!").arg(what); 152 | 153 | int confirm = QMessageBox::question(this, 154 | "Confirm Removal", 155 | confirmText, 156 | QMessageBox::Yes, 157 | QMessageBox::No); 158 | 159 | if (confirm == QMessageBox::Yes) { 160 | m_package->remove(whatType, what); 161 | } 162 | } 163 | } 164 | 165 | 166 | void LSMainWindow::handleRenameItem() { 167 | QString what = selectedItem(); 168 | LYTPackageBase::ItemType whatType = selectedItemType(); 169 | 170 | if (!what.isEmpty()) { 171 | QString newName = QInputDialog::getText(this, 172 | "Rename Item", 173 | QString("Enter a new name:"), 174 | QLineEdit::NoEcho, 175 | what); 176 | 177 | if (!newName.isEmpty()) { 178 | m_package->rename(whatType, what, newName); 179 | } 180 | } 181 | } 182 | 183 | 184 | QString LSMainWindow::selectedItem() const { 185 | QModelIndex idx = m_view->currentIndex(); 186 | return m_model->itemNameForIndex(idx); 187 | } 188 | 189 | LYTPackageBase::ItemType LSMainWindow::selectedItemType() const { 190 | QModelIndex idx = m_view->currentIndex(); 191 | return m_model->itemTypeForIndex(idx); 192 | } 193 | 194 | 195 | void LSMainWindow::handleItemActivated(const QModelIndex &index) { 196 | QString what = selectedItem(); 197 | LYTPackageBase::ItemType whatType = selectedItemType(); 198 | 199 | if (what.isEmpty()) 200 | return; 201 | 202 | switch (whatType) { 203 | case LYTPackageBase::Layout: 204 | LSLayoutWindow *w = new LSLayoutWindow(m_package, what); 205 | w->show(); 206 | break; 207 | } 208 | } 209 | 210 | 211 | bool LSMainWindow::ensureSaved() { 212 | // TODO 213 | return false; 214 | } 215 | 216 | void LSMainWindow::updateTitleBar() { 217 | QString title; 218 | if (m_isSaved) 219 | title = m_package->description(); 220 | else 221 | title = "[Unsaved]"; 222 | 223 | if (m_dirty) 224 | title.append('*'); 225 | title.append(" - LayoutStudio"); 226 | 227 | setWindowTitle(title); 228 | setWindowModified(m_dirty); 229 | } 230 | 231 | void LSMainWindow::newArchive() { 232 | if (ensureSaved()) 233 | return; 234 | 235 | LYTArchivePackage *pkg = new LYTArchivePackage; 236 | setCurrentPackage(pkg); 237 | 238 | m_dirty = false; 239 | m_isSaved = false; 240 | updateTitleBar(); 241 | } 242 | 243 | void LSMainWindow::openArchive() { 244 | if (ensureSaved()) 245 | return; 246 | 247 | QString path = QFileDialog::getOpenFileName(this, 248 | "Open a Layout Archive", 249 | QString(), 250 | "Wii Archives (*.arc)" 251 | ); 252 | 253 | if (path.isEmpty()) 254 | return; 255 | 256 | LYTArchivePackage *pkg = new LYTArchivePackage(path); 257 | setCurrentPackage(pkg); 258 | 259 | m_dirty = false; 260 | m_isSaved = true; 261 | updateTitleBar(); 262 | } 263 | 264 | void LSMainWindow::save() { 265 | // TODO: check that m_package is an arc 266 | if (m_isSaved) { 267 | m_dirty = false; 268 | m_package->savePackage(); 269 | updateTitleBar(); 270 | } else { 271 | saveArchiveAs(); 272 | } 273 | } 274 | 275 | void LSMainWindow::saveArchiveAs() { 276 | // TODO: check that m_package is an arc 277 | QString newPath = QFileDialog::getSaveFileName(this, 278 | "Save Layout Archive", 279 | QString(), 280 | "Wii Archives (*.arc)" 281 | ); 282 | 283 | if (newPath.isEmpty()) 284 | return; 285 | 286 | LYTArchivePackage *pkg = (LYTArchivePackage*)m_package; 287 | pkg->setFilename(newPath); 288 | pkg->savePackage(); 289 | 290 | m_dirty = false; 291 | m_isSaved = true; 292 | updateTitleBar(); 293 | } 294 | 295 | 296 | void LSMainWindow::setCurrentPackage(LYTPackageBase *pkg) { 297 | m_package = pkg; 298 | 299 | QItemSelectionModel *oldSel = m_view->selectionModel(); 300 | QAbstractItemModel *model = m_view->model(); 301 | 302 | m_model = new LSPackageModel(pkg, this); 303 | m_view->setModel(m_model); 304 | 305 | if (model) 306 | delete model; 307 | if (oldSel) 308 | delete oldSel; 309 | } 310 | -------------------------------------------------------------------------------- /lsmainwindow.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #ifndef LSMAINWINDOW_H 19 | #define LSMAINWINDOW_H 20 | 21 | #include "lyt/packagebase.h" 22 | #include "lspackagemodel.h" 23 | #include 24 | #include 25 | #include 26 | 27 | class LSMainWindow : public QMainWindow { 28 | Q_OBJECT 29 | public: 30 | LSMainWindow(QWidget *parent = 0); 31 | ~LSMainWindow(); 32 | 33 | protected: 34 | bool ensureSaved(); 35 | 36 | public: 37 | void updateTitleBar(); 38 | 39 | public slots: 40 | void newArchive(); 41 | void openArchive(); 42 | void save(); 43 | void saveArchiveAs(); 44 | 45 | private slots: 46 | void handleAddSomething(int whatToAdd); 47 | void handleRenameItem(); 48 | void handleRemoveItem(); 49 | void handleItemActivated(const QModelIndex &index); 50 | 51 | private: 52 | LYTPackageBase *m_package; 53 | void setCurrentPackage(LYTPackageBase *pkg); 54 | 55 | void createActions(); 56 | QAction *m_newArchiveAction, *m_openArchiveAction, *m_saveArchiveAsAction; 57 | QAction *m_saveAction; 58 | 59 | QAction *m_addLayoutAction, *m_addAnimationAction; 60 | QAction *m_addTextureAction; 61 | QSignalMapper *m_addActionMapper; 62 | QAction *m_importNewAction, *m_importAction; 63 | QAction *m_renameAction, *m_removeAction, *m_exportAction; 64 | 65 | LSPackageModel *m_model; 66 | QTreeView *m_view; 67 | 68 | bool m_dirty; 69 | bool m_isSaved; 70 | 71 | protected: 72 | QString selectedItem() const; 73 | LYTPackageBase::ItemType selectedItemType() const; 74 | }; 75 | 76 | #endif // LSMAINWINDOW_H 77 | -------------------------------------------------------------------------------- /lsmaterialeditor.cpp: -------------------------------------------------------------------------------- 1 | #include "lsmaterialeditor.h" 2 | #include "lsmaterialeditors.h" 3 | #include 4 | 5 | LSMaterialEditor::LSMaterialEditor(QWidget *parent) : 6 | QWidget(parent) { 7 | 8 | QGridLayout *grid = new QGridLayout(this); 9 | int gridRow = 0; 10 | 11 | m_nameEntry = new QLineEdit(this); 12 | 13 | grid->addWidget(new QLabel("Name:", this), gridRow, 0, 1, 1); 14 | grid->addWidget(m_nameEntry, gridRow, 1, 1, 1); 15 | gridRow++; 16 | 17 | // TEV colour box 18 | QGroupBox *tevCBox = new QGroupBox("TEV Colours", this); 19 | QGridLayout *tevCLayout = new QGridLayout(tevCBox); 20 | 21 | tevCLayout->addWidget(new QLabel("Initial Registers:", tevCBox), 0, 0, 1, 4); 22 | tevCLayout->addWidget(new QLabel("Constant:", tevCBox), 2, 0, 1, 4); 23 | 24 | for (int i = 0; i < 7; i++) { 25 | m_colourPickers[i] = new LSColorPicker(tevCBox); 26 | bool isKonst = (i >= 3); 27 | tevCLayout->addWidget(m_colourPickers[i], isKonst?3:1, isKonst?(i-3):i, 1, 1); 28 | } 29 | 30 | grid->addWidget(tevCBox, gridRow, 0, 1, 2); 31 | gridRow++; 32 | 33 | // TEV stages 34 | QGroupBox *stageBox = new QGroupBox("TEV Stages", this); 35 | QVBoxLayout *stageLayout = new QVBoxLayout(stageBox); 36 | 37 | m_tevStageSetEditor = new LSSetEditor(16, stageBox); 38 | stageLayout->addWidget(m_tevStageSetEditor); 39 | 40 | grid->addWidget(stageBox, gridRow, 0, 1, 2); 41 | gridRow++; 42 | 43 | // finish it all up 44 | grid->setRowStretch(gridRow, 1); 45 | 46 | 47 | m_currentlyLoadingMaterial = false; 48 | m_material = 0; 49 | } 50 | 51 | void LSMaterialEditor::setMaterial(LYTMaterial *mat) { 52 | m_currentlyLoadingMaterial = true; 53 | m_material = mat; 54 | 55 | m_nameEntry->setText(mat->name); 56 | 57 | for (int i = 0; i < 3; i++) 58 | m_colourPickers[i]->setColor(mat->colours[i]); 59 | for (int i = 0; i < 4; i++) 60 | m_colourPickers[i+3]->setColor(mat->tevKColour[i]); 61 | 62 | m_tevStageSetEditor->setData(&mat->tevStages); 63 | 64 | m_currentlyLoadingMaterial = false; 65 | } 66 | 67 | 68 | void LSMaterialEditor::handleNameChanged(QString value) { 69 | 70 | } 71 | 72 | void LSMaterialEditor::handleSaveChangedName() { 73 | 74 | } 75 | 76 | void LSMaterialEditor::handleColourPicked(QColor value) { 77 | 78 | } 79 | -------------------------------------------------------------------------------- /lsmaterialeditor.h: -------------------------------------------------------------------------------- 1 | #ifndef LSMATERIALEDITOR_H 2 | #define LSMATERIALEDITOR_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "lyt/materials/materialcontainer.h" 9 | #include "lscolorpicker.h" 10 | #include "lsseteditor.h" 11 | 12 | class LSTexMapEditor; 13 | class LSTexSRTEditor; 14 | class LSTexCoordGenEditor; 15 | class LSIndTexSRTEditor; 16 | class LSIndTexStageEditor; 17 | class LSTevStageEditor; 18 | 19 | class LSMaterialEditor : public QWidget { 20 | Q_OBJECT 21 | public: 22 | explicit LSMaterialEditor(QWidget *parent = 0); 23 | 24 | private: 25 | QLineEdit *m_nameEntry; 26 | 27 | LSColorPicker *m_colourPickers[7]; 28 | 29 | bool m_currentlyLoadingMaterial; 30 | LYTMaterial *m_material; 31 | 32 | LSSetEditor *m_tevStageSetEditor; 33 | 34 | private slots: 35 | void handleNameChanged(QString value); 36 | void handleSaveChangedName(); 37 | 38 | void handleColourPicked(QColor value); 39 | 40 | signals: 41 | void mustRedrawLayout(); 42 | 43 | public slots: 44 | void setMaterial(LYTMaterial *mat); 45 | 46 | }; 47 | 48 | #endif // LSMATERIALEDITOR_H 49 | -------------------------------------------------------------------------------- /lsmaterialmodel.cpp: -------------------------------------------------------------------------------- 1 | #include "lsmaterialmodel.h" 2 | 3 | LSMaterialModel::LSMaterialModel(LYTMaterialContainer *container, QObject *parent) : 4 | QAbstractListModel(parent) 5 | { 6 | m_container = container; 7 | } 8 | 9 | 10 | int LSMaterialModel::rowCount(const QModelIndex &parent) const { 11 | return m_container->count(); 12 | } 13 | 14 | QVariant LSMaterialModel::data(const QModelIndex &index, int role) const { 15 | if (index.isValid()) { 16 | switch (role) { 17 | case Qt::DisplayRole: 18 | return m_container->getNameOfIndex(index.row()); 19 | } 20 | } 21 | 22 | return QVariant(); 23 | } 24 | -------------------------------------------------------------------------------- /lsmaterialmodel.h: -------------------------------------------------------------------------------- 1 | #ifndef LSMATERIALMODEL_H 2 | #define LSMATERIALMODEL_H 3 | 4 | #include 5 | #include "lyt/materials/materialcontainer.h" 6 | 7 | class LSMaterialModel : public QAbstractListModel 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit LSMaterialModel(LYTMaterialContainer *container, QObject *parent = 0); 12 | 13 | int rowCount(const QModelIndex &parent) const; 14 | QVariant data(const QModelIndex &index, int role) const; 15 | 16 | private: 17 | LYTMaterialContainer *m_container; 18 | 19 | signals: 20 | 21 | public slots: 22 | 23 | }; 24 | 25 | #endif // LSMATERIALMODEL_H 26 | -------------------------------------------------------------------------------- /lspackagemodel.cpp: -------------------------------------------------------------------------------- 1 | #include "lspackagemodel.h" 2 | 3 | struct ContentKind { 4 | LYTPackageBase::ItemType type; 5 | QString name; 6 | }; 7 | 8 | static const ContentKind ContentKinds[4] = { 9 | {LYTPackageBase::Layout, "Layouts"}, 10 | {LYTPackageBase::Animation, "Animations"}, 11 | {LYTPackageBase::Texture, "Textures"}, 12 | {LYTPackageBase::Font, "Fonts"}, 13 | }; 14 | const int ContentKindCount = 4; 15 | 16 | static int ContentKindForType(LYTPackageBase::ItemType type) { 17 | switch (type) { 18 | case LYTPackageBase::Layout: return 0; 19 | case LYTPackageBase::Animation: return 1; 20 | case LYTPackageBase::Texture: return 2; 21 | case LYTPackageBase::Font: return 3; 22 | } 23 | return -1; 24 | } 25 | 26 | LSPackageModel::LSPackageModel(LYTPackageBase *pkg, QObject *parent) : 27 | QAbstractItemModel(parent) 28 | { 29 | m_package = pkg; 30 | 31 | m_caches = new QStringList[ContentKindCount]; 32 | for (int i = 0; i < ContentKindCount; i++) { 33 | m_caches[i] = pkg->list(ContentKinds[i].type); 34 | m_caches[i].sort(); 35 | } 36 | 37 | connect(pkg, SIGNAL(fileWasAdded(LYTPackageBase::ItemType,QString)), SLOT(handleFileWasAdded(LYTPackageBase::ItemType,QString))); 38 | //connect(pkg, SIGNAL(fileWasModified(LYTPackageBase::ItemType,QString)), SLOT(handleFileWasModified(LYTPackageBase::ItemType,QString))); 39 | connect(pkg, SIGNAL(fileWasRemoved(LYTPackageBase::ItemType,QString)), SLOT(handleFileWasRemoved(LYTPackageBase::ItemType,QString))); 40 | connect(pkg, SIGNAL(fileWasRenamed(LYTPackageBase::ItemType,QString,QString)), SLOT(handleFileWasRenamed(LYTPackageBase::ItemType,QString,QString))); 41 | } 42 | 43 | LSPackageModel::~LSPackageModel() { 44 | delete[] m_caches; 45 | } 46 | 47 | 48 | QModelIndex LSPackageModel::index(int row, int column, const QModelIndex &parent) const { 49 | if (!hasIndex(row, column, parent)) 50 | return QModelIndex(); 51 | 52 | if (!parent.isValid()) 53 | return createIndex(row, column, 0); 54 | 55 | return createIndex(row, column, parent.row() + 1); 56 | } 57 | 58 | QModelIndex LSPackageModel::parent(const QModelIndex &child) const { 59 | if (!child.isValid()) 60 | return QModelIndex(); 61 | 62 | if (child.internalId() > 0) 63 | return createIndex(child.internalId() - 1, 0, 0); 64 | else 65 | return QModelIndex(); 66 | } 67 | 68 | int LSPackageModel::rowCount(const QModelIndex &parent) const { 69 | if (!parent.isValid()) 70 | return ContentKindCount; 71 | else if (parent.internalId() > 0) 72 | return 0; // an actual item 73 | else 74 | return m_caches[parent.row()].count(); 75 | } 76 | 77 | int LSPackageModel::columnCount(const QModelIndex &parent) const { 78 | return 1; 79 | } 80 | 81 | QVariant LSPackageModel::data(const QModelIndex &index, int role) const { 82 | if (!index.isValid()) 83 | return QVariant(); 84 | if (role != Qt::DisplayRole) 85 | return QVariant(); 86 | 87 | int whatIs = index.internalId(); 88 | if (whatIs == 0) 89 | return ContentKinds[index.row()].name; 90 | else 91 | return m_caches[whatIs - 1].at(index.row()); 92 | } 93 | 94 | 95 | void LSPackageModel::handleFileWasAdded(LYTPackageBase::ItemType type, QString name) { 96 | int kind = ContentKindForType(type); 97 | 98 | QStringList newCache = m_caches[kind]; 99 | newCache.append(name); 100 | newCache.sort(); 101 | 102 | // where was this added? 103 | int idx = newCache.indexOf(name); 104 | beginInsertRows(createIndex(kind, 0, 0), idx, idx); 105 | m_caches[kind] = newCache; 106 | endInsertRows(); 107 | } 108 | 109 | void LSPackageModel::handleFileWasRemoved(LYTPackageBase::ItemType type, QString name) { 110 | int kind = ContentKindForType(type); 111 | 112 | int idx = m_caches[kind].indexOf(name); 113 | beginRemoveRows(createIndex(kind, 0, 0), idx, idx); 114 | m_caches[kind].removeAt(idx); 115 | endRemoveRows(); 116 | } 117 | 118 | void LSPackageModel::handleFileWasRenamed(LYTPackageBase::ItemType type, QString from, QString to) { 119 | int kind = ContentKindForType(type); 120 | 121 | QStringList newCache = m_caches[kind]; 122 | int fromIdx = newCache.indexOf(from); 123 | 124 | // this is really a mess, but I cannot think of a better way to do it 125 | // first, make a new cache, but don't store it to m_caches yet... 126 | newCache[fromIdx] = to; 127 | newCache.sort(); 128 | 129 | // and now, get the to Index... 130 | int toIdx = newCache.indexOf(to); 131 | // if the new index is less than the old one, then leave it that way 132 | // if the new index is the same as the old one, that's fine, do nothing 133 | // if the new index is more than the old one... add 1 to it to take into 134 | // account that the old one is no longer around when it was computed BUT Qt 135 | // expects it to be 136 | // did that make sense? probably not, oh well 137 | if (toIdx > fromIdx) 138 | toIdx++; 139 | 140 | QModelIndex whatChanged = createIndex(fromIdx, 0, kind + 1); 141 | emit dataChanged(whatChanged, whatChanged); 142 | 143 | QModelIndex parent = createIndex(kind, 0, 0); 144 | 145 | if (toIdx != fromIdx) 146 | beginMoveRows(parent, fromIdx, fromIdx, parent, toIdx); 147 | m_caches[kind] = newCache; 148 | if (toIdx != fromIdx) 149 | endMoveRows(); 150 | } 151 | 152 | 153 | QString LSPackageModel::itemNameForIndex(const QModelIndex &index) const { 154 | if (index.internalId() > 0) 155 | return m_caches[index.internalId() - 1].at(index.row()); 156 | return QString(); 157 | } 158 | 159 | LYTPackageBase::ItemType LSPackageModel::itemTypeForIndex(const QModelIndex &index) const { 160 | if (index.internalId() > 0) 161 | return ContentKinds[index.internalId() - 1].type; 162 | return (LYTPackageBase::ItemType)-1; 163 | } 164 | -------------------------------------------------------------------------------- /lspackagemodel.h: -------------------------------------------------------------------------------- 1 | #ifndef LSPACKAGEMODEL_H 2 | #define LSPACKAGEMODEL_H 3 | 4 | #include 5 | #include "lyt/packagebase.h" 6 | 7 | class LSPackageModel : public QAbstractItemModel { 8 | Q_OBJECT 9 | public: 10 | explicit LSPackageModel(LYTPackageBase *pkg, QObject *parent = 0); 11 | ~LSPackageModel(); 12 | 13 | LYTPackageBase *package() const { return m_package; } 14 | 15 | QModelIndex index(int row, int column, const QModelIndex &parent) const; 16 | QModelIndex parent(const QModelIndex &child) const; 17 | int rowCount(const QModelIndex &parent) const; 18 | int columnCount(const QModelIndex &parent) const; 19 | QVariant data(const QModelIndex &index, int role) const; 20 | 21 | QString itemNameForIndex(const QModelIndex &index) const; 22 | LYTPackageBase::ItemType itemTypeForIndex(const QModelIndex &index) const; 23 | 24 | signals: 25 | 26 | private slots: 27 | //void handleAboutToAddFile(LYTPackageBase::ItemType type, QString name); 28 | //void handleAboutToRemoveFile(LYTPackageBase::ItemType type, QString name); 29 | //void handleAboutToRenameFile(LYTPackageBase::ItemType type, QString from, QString to); 30 | //void handleAboutToModifyFile(LYTPackageBase::ItemType type, QString name); 31 | 32 | void handleFileWasAdded(LYTPackageBase::ItemType type, QString name); 33 | void handleFileWasRemoved(LYTPackageBase::ItemType type, QString name); 34 | void handleFileWasRenamed(LYTPackageBase::ItemType type, QString from, QString to); 35 | //void handleFileWasModified(LYTPackageBase::ItemType type, QString name); 36 | 37 | public slots: 38 | 39 | protected: 40 | LYTPackageBase *m_package; 41 | 42 | QStringList *m_caches; 43 | }; 44 | 45 | #endif // LSPACKAGEMODEL_H 46 | -------------------------------------------------------------------------------- /lspaneeditor.h: -------------------------------------------------------------------------------- 1 | #ifndef LSPANEEDITOR_H 2 | #define LSPANEEDITOR_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include "lyt/pane.h" 15 | #include "lscolorpicker.h" 16 | class LSTexCoordSetEditor; 17 | 18 | class LYTPicture; 19 | 20 | class LSPaneEditor : public QWidget { 21 | Q_OBJECT 22 | public: 23 | explicit LSPaneEditor(QWidget *parent = 0); 24 | 25 | private: 26 | QLabel *m_headingLabel; 27 | QTabWidget *m_tabs; 28 | 29 | QToolButton *m_addChildButton; 30 | QMenu *m_addChildMenu; 31 | QToolButton *m_removeButton; 32 | 33 | 34 | // Main pane tab 35 | QWidget *m_paneTab; 36 | 37 | QLineEdit *m_nameEntry, *m_userDataEntry; 38 | QSpinBox *m_alpha; 39 | QCheckBox *m_influencedAlpha; 40 | 41 | QDoubleSpinBox *m_width, *m_height; 42 | QComboBox *m_horzOrigin, *m_vertOrigin; 43 | QCheckBox *m_widescreen; //, *m_visible; 44 | 45 | union { 46 | QDoubleSpinBox *m_srtSpinBoxes[8]; 47 | struct { 48 | QDoubleSpinBox *m_transSpinBoxes[3]; 49 | QDoubleSpinBox *m_rotSpinBoxes[3]; 50 | QDoubleSpinBox *m_scaleSpinBoxes[2]; 51 | }; 52 | struct { 53 | QDoubleSpinBox *m_transX, *m_transY, *m_transZ; 54 | QDoubleSpinBox *m_rotX, *m_rotY, *m_rotZ; 55 | QDoubleSpinBox *m_scaleX, *m_scaleY; 56 | }; 57 | }; 58 | 59 | // Picture tab 60 | QWidget *m_pictureTab; 61 | 62 | LSTexCoordSetEditor *m_picTexCoordEditor; 63 | LSColorPicker *m_picColourButtons[4]; 64 | 65 | 66 | void createPaneTab(); 67 | void createPictureTab(); 68 | 69 | 70 | bool m_currentlyLoadingPane; 71 | union { 72 | LYTPane *m_pane; 73 | LYTPicture *m_picture; 74 | }; 75 | 76 | private slots: 77 | void handleNameChanged(QString value); 78 | void handleUserDataChanged(QString value); 79 | void handleAlphaChanged(int value); 80 | void handleInfluencedAlphaChanged(bool value); 81 | void handleWidthChanged(double value); 82 | void handleHeightChanged(double value); 83 | void handleHorzOriginChanged(int value); 84 | void handleVertOriginChanged(int value); 85 | void handleWidescreenChanged(bool value); 86 | //void handleVisibleChanged(bool value); 87 | void handleTransXChanged(double value); 88 | void handleTransYChanged(double value); 89 | void handleTransZChanged(double value); 90 | void handleRotXChanged(double value); 91 | void handleRotYChanged(double value); 92 | void handleRotZChanged(double value); 93 | void handleScaleXChanged(double value); 94 | void handleScaleYChanged(double value); 95 | 96 | void handlePicColourPicked(QColor value); 97 | 98 | signals: 99 | void mustRedrawLayout(); 100 | 101 | public slots: 102 | void setPane(LYTPane *pane); 103 | 104 | }; 105 | 106 | #endif // LSPANEEDITOR_H 107 | -------------------------------------------------------------------------------- /lsscenemodel.cpp: -------------------------------------------------------------------------------- 1 | #include "lsscenemodel.h" 2 | #include "lsglobals.h" 3 | 4 | LSSceneModel::LSSceneModel(LYTLayout *layout, bool exposeVisibility, QObject *parent) : 5 | QAbstractItemModel(parent), m_exposesVisibility(exposeVisibility) 6 | { 7 | m_layout = layout; 8 | 9 | m_paneIcons[LYTPane::PaneType] = LSGlobals::getIcon("pane"); 10 | m_paneIcons[LYTPane::PictureType] = LSGlobals::getIcon("picture"); 11 | m_paneIcons[LYTPane::TextBoxType] = LSGlobals::getIcon("textbox"); 12 | m_paneIcons[LYTPane::WindowType] = LSGlobals::getIcon("window"); 13 | m_paneIcons[LYTPane::BoundingType] = LSGlobals::getIcon("bounding"); 14 | 15 | m_movingPaneParent = 0; 16 | } 17 | 18 | LSSceneModel::~LSSceneModel() { 19 | if (m_movingPaneParent) 20 | delete m_movingPaneParent; 21 | } 22 | 23 | 24 | QModelIndex LSSceneModel::index(int row, int column, const QModelIndex &parent) const { 25 | if (!hasIndex(row, column, parent)) 26 | return QModelIndex(); 27 | 28 | if (!parent.isValid()) 29 | return createIndex(row, column, m_layout->rootPane); 30 | 31 | // what's the parent..? 32 | LYTPane *parentPane = (LYTPane*)parent.internalPointer(); 33 | LYTPane *pane = parentPane->children.at(row); 34 | return createIndex(row, column, pane); 35 | } 36 | 37 | QModelIndex LSSceneModel::parent(const QModelIndex &child) const { 38 | if (!child.isValid()) 39 | return QModelIndex(); 40 | 41 | LYTPane *childPane = (LYTPane*)child.internalPointer(); 42 | LYTPane *parentPane = childPane->parent; 43 | if (parentPane) { 44 | LYTPane *parentParentPane = parentPane->parent; 45 | int index = parentParentPane ? parentParentPane->children.indexOf(parentPane) : 0; 46 | return createIndex(index, 0, parentPane); 47 | } else { 48 | return QModelIndex(); 49 | } 50 | } 51 | 52 | int LSSceneModel::rowCount(const QModelIndex &parent) const { 53 | if (!parent.isValid()) { 54 | return 1; // the root pane 55 | } 56 | 57 | LYTPane *parentPane = (LYTPane*)parent.internalPointer(); 58 | return parentPane->children.count(); 59 | } 60 | 61 | int LSSceneModel::columnCount(const QModelIndex &parent) const { 62 | (void)parent; 63 | return 1; 64 | } 65 | 66 | QVariant LSSceneModel::data(const QModelIndex &index, int role) const { 67 | LYTPane *pane = (LYTPane*)index.internalPointer(); 68 | if (pane) { 69 | switch (role) { 70 | case Qt::DisplayRole: 71 | return pane->name; 72 | case Qt::DecorationRole: 73 | return m_paneIcons[pane->type()]; 74 | } 75 | 76 | if (m_exposesVisibility && role == Qt::CheckStateRole) { 77 | return pane->visible ? Qt::Checked : Qt::Unchecked; 78 | } 79 | } 80 | return QVariant(); 81 | } 82 | 83 | bool LSSceneModel::setData(const QModelIndex &index, const QVariant &value, int role) { 84 | if (m_exposesVisibility && role == Qt::CheckStateRole) { 85 | LYTPane *pane = (LYTPane*)index.internalPointer(); 86 | 87 | bool newVisible = value.toBool(); 88 | if (pane->visible != newVisible) { 89 | pane->visible = newVisible; 90 | emit dataChanged(index, index); 91 | emit paneVisibilityChanged(); 92 | } 93 | } 94 | 95 | return false; 96 | } 97 | 98 | 99 | Qt::ItemFlags LSSceneModel::flags(const QModelIndex &index) const { 100 | Qt::ItemFlags flag; 101 | flag = Qt::ItemIsEnabled | Qt::ItemIsSelectable | 102 | Qt::ItemIsDropEnabled; 103 | 104 | if (index.isValid() && index.parent().isValid()) 105 | flag |= Qt::ItemIsDragEnabled; 106 | 107 | if (m_exposesVisibility) 108 | flag |= Qt::ItemIsUserCheckable; 109 | 110 | return flag; 111 | } 112 | 113 | 114 | Qt::DropActions LSSceneModel::supportedDropActions() const { 115 | return Qt::MoveAction; 116 | } 117 | 118 | 119 | // I am doing a terrible, terrible, terrible thing here. 120 | // I hate drag-and-drop. 121 | 122 | // As far as I can see, insertRows and removeRows are ONLY called by Qt when 123 | // dragging something. So instead of doing a real insertion/removal... I'll 124 | // store the intended destination, and once I'm told what pane needs to be 125 | // removed (moved) I do the whole thing at once. 126 | 127 | bool LSSceneModel::insertRows(int row, int count, const QModelIndex &parent) { 128 | qDebug("LSSceneModel::insertRows(%d, %d, something)", row, count); 129 | 130 | if (m_movingPaneParent) { 131 | qWarning("huh, already moving something? dunno"); 132 | return false; 133 | } 134 | 135 | if (!parent.isValid()) { 136 | qWarning("can't move stuff to the top level"); 137 | return false; 138 | } 139 | 140 | m_movingPaneParent = new QPersistentModelIndex(parent); 141 | m_movingPaneRow = row; 142 | m_movingPaneCount = count; 143 | 144 | return true; 145 | } 146 | 147 | bool LSSceneModel::removeRows(int row, int count, const QModelIndex &parent) { 148 | qDebug("LSSceneModel::removeRows(%d, %d, something)", row, count); 149 | 150 | if (!m_movingPaneParent) { 151 | qWarning("huh, not moving anything / nothing left to move? dunno"); 152 | return false; 153 | } 154 | 155 | // detach all the existing panes 156 | LYTPane *parentPane = (LYTPane*)parent.internalPointer(); 157 | 158 | QVector removingPanes; 159 | removingPanes.reserve(count); 160 | 161 | beginRemoveRows(parent, row, row + count - 1); 162 | for (int i = 0; i < count; i++) { 163 | removingPanes.append(parentPane->children.at(row)); 164 | parentPane->children.removeAt(row); 165 | } 166 | endRemoveRows(); 167 | 168 | // now add them in their new homes! 169 | LYTPane *newParentPane = (LYTPane*)m_movingPaneParent->internalPointer(); 170 | 171 | // note: compensate for the offset: if we're moving the thing within the 172 | // same parent and the destination row is higher than the source row, then 173 | // removing the source row will have changed the index of the row the user 174 | // actually wanted to move the moved row to... what a terrible sentence :| 175 | if (*m_movingPaneParent == parent && m_movingPaneRow > row) 176 | m_movingPaneRow -= count; 177 | 178 | beginInsertRows(*m_movingPaneParent, m_movingPaneRow, m_movingPaneRow + count - 1); 179 | 180 | for (int i = 0; i < count; i++) { 181 | LYTPane *pane = removingPanes.at(i); 182 | 183 | pane->parent = newParentPane; 184 | newParentPane->children.insert(m_movingPaneRow, pane); 185 | 186 | m_movingPaneRow++; 187 | } 188 | 189 | endInsertRows(); 190 | 191 | // clean up if needed 192 | m_movingPaneCount -= count; 193 | 194 | if (m_movingPaneCount <= 0) { 195 | delete m_movingPaneParent; 196 | m_movingPaneParent = 0; 197 | } 198 | 199 | return true; 200 | } 201 | 202 | -------------------------------------------------------------------------------- /lsscenemodel.h: -------------------------------------------------------------------------------- 1 | #ifndef LSSCENEMODEL_H 2 | #define LSSCENEMODEL_H 3 | 4 | #include 5 | #include 6 | #include "lyt/layout.h" 7 | 8 | class LSSceneModel : public QAbstractItemModel { 9 | Q_OBJECT 10 | public: 11 | explicit LSSceneModel(LYTLayout *layout, bool exposeVisibility, QObject *parent = 0); 12 | ~LSSceneModel(); 13 | 14 | LYTLayout *layout() const { return m_layout; } 15 | 16 | QModelIndex index(int row, int column, const QModelIndex &parent) const; 17 | QModelIndex parent(const QModelIndex &child) const; 18 | int rowCount(const QModelIndex &parent) const; 19 | int columnCount(const QModelIndex &parent) const; 20 | QVariant data(const QModelIndex &index, int role) const; 21 | bool setData(const QModelIndex &index, const QVariant &value, int role); 22 | 23 | Qt::ItemFlags flags(const QModelIndex &index) const; 24 | Qt::DropActions supportedDropActions() const; 25 | 26 | bool insertRows(int row, int count, const QModelIndex &parent); 27 | bool removeRows(int row, int count, const QModelIndex &parent); 28 | 29 | private: 30 | LYTLayout *m_layout; 31 | 32 | QIcon m_paneIcons[LYTPane::PaneTypeCount]; 33 | 34 | QPersistentModelIndex *m_movingPaneParent; 35 | int m_movingPaneRow, m_movingPaneCount; 36 | 37 | bool m_exposesVisibility; 38 | 39 | signals: 40 | void paneVisibilityChanged(); 41 | 42 | public slots: 43 | 44 | }; 45 | 46 | #endif // LSSCENEMODEL_H 47 | -------------------------------------------------------------------------------- /lsseteditor.cpp: -------------------------------------------------------------------------------- 1 | #include "lsseteditor.h" 2 | #include 3 | #include 4 | 5 | _LSSetEditorBase::_LSSetEditorBase(int maxEntries, QWidget *parent) : 6 | QWidget(parent) { 7 | 8 | m_maxEntries = maxEntries; 9 | m_loadingThings = 0; 10 | } 11 | 12 | 13 | void _LSSetEditorBase::handleEntrySelected(int index) { 14 | if (!m_loadingThings) 15 | showEntry(index); 16 | } 17 | 18 | 19 | void _LSSetEditorBase::handleEntryCountChanged(int count) { 20 | if (!m_loadingThings) { 21 | int oldCount = m_chooser->count(); 22 | if (oldCount == count) 23 | return; 24 | 25 | changeEntryCountTo(count); 26 | resizeDataListTo(count); 27 | 28 | // moving from 0 to something...? 29 | if (oldCount == 0) { 30 | m_chooser->setCurrentIndex(0); 31 | showEntry(0); 32 | } 33 | 34 | emit dataEdited(); 35 | } 36 | } 37 | 38 | 39 | void _LSSetEditorBase::setup(QWidget *eWidget) { 40 | m_loadingThings++; 41 | 42 | m_entryCount = new QSpinBox(this); 43 | m_entryCount->setRange(0, m_maxEntries); 44 | connect(m_entryCount, SIGNAL(valueChanged(int)), SLOT(handleEntryCountChanged(int))); 45 | 46 | m_chooser = new QComboBox(this); 47 | connect(m_chooser, SIGNAL(currentIndexChanged(int)), SLOT(handleEntrySelected(int))); 48 | 49 | QGridLayout *layout = new QGridLayout(this); 50 | 51 | layout->addWidget(new QLabel("Count:", this), 0, 0, 1, 1); 52 | layout->addWidget(m_entryCount, 0, 1, 1, 1); 53 | layout->setColumnMinimumWidth(2, 10); 54 | layout->addWidget(m_chooser, 0, 3, 1, 1); 55 | layout->setColumnStretch(3, 1); 56 | 57 | layout->addWidget(eWidget, 1, 0, 1, 4); 58 | 59 | m_loadingThings--; 60 | } 61 | -------------------------------------------------------------------------------- /lsseteditor.h: -------------------------------------------------------------------------------- 1 | #ifndef LSSETEDITOR_H 2 | #define LSSETEDITOR_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | class _LSSetEntryEditorBaseBase : public QWidget { 9 | Q_OBJECT 10 | protected: 11 | explicit _LSSetEntryEditorBaseBase(QWidget *parent = 0) : 12 | QWidget(parent) { } 13 | 14 | signals: 15 | void dataEdited(); 16 | }; 17 | 18 | // class prototype 19 | template 20 | class LSSetEditor; 21 | 22 | template 23 | class LSSetEntryEditorBase : public _LSSetEntryEditorBaseBase { 24 | protected: 25 | explicit LSSetEntryEditorBase(QWidget *parent = 0) : 26 | _LSSetEntryEditorBaseBase(parent) { } 27 | 28 | public: 29 | void setCurrentEntry(TData &entry) { 30 | m_currentEntry = &entry; 31 | loadEntryFrom(entry); 32 | } 33 | 34 | private: 35 | TData *m_currentEntry; 36 | 37 | protected: 38 | virtual void loadEntryFrom(const TData &entry) = 0; 39 | TData *currentEntry() const { return m_currentEntry; } 40 | }; 41 | 42 | 43 | 44 | 45 | class _LSSetEditorBase : public QWidget { 46 | Q_OBJECT 47 | public: 48 | explicit _LSSetEditorBase(int maxEntries, QWidget *parent = 0); 49 | 50 | protected: 51 | int m_maxEntries; 52 | QSpinBox *m_entryCount; 53 | QComboBox *m_chooser; 54 | 55 | QWidget *m_setEditorWidget; 56 | 57 | int m_loadingThings; 58 | 59 | void setup(QWidget *eWidget); 60 | 61 | virtual void changeEntryCountTo(int count) = 0; 62 | virtual void showEntry(int index) = 0; 63 | virtual void resizeDataListTo(int count) = 0; 64 | 65 | private slots: 66 | void handleEntryCountChanged(int count); 67 | void handleEntrySelected(int index); 68 | 69 | signals: 70 | void dataEdited(); 71 | 72 | }; 73 | 74 | template 75 | class LSSetEditor : public _LSSetEditorBase { 76 | public: 77 | explicit LSSetEditor(int maxEntries, QWidget *parent = 0) : 78 | _LSSetEditorBase(maxEntries, parent) { 79 | 80 | TWidget *w = new TWidget(this); 81 | setup(w); 82 | 83 | m_setEditorWidget = w; 84 | m_typedSetEditorWidget = w; 85 | 86 | LSSetEntryEditorBase *checkMe = w; 87 | connect(checkMe, SIGNAL(dataEdited()), SIGNAL(dataEdited())); 88 | } 89 | 90 | void setData(QList *newData) { 91 | m_loadingThings++; 92 | 93 | m_data = newData; 94 | m_entryCount->setValue(newData->count()); 95 | changeEntryCountTo(newData->count()); 96 | 97 | m_chooser->setCurrentIndex(newData->count() ? 0 : -1); 98 | showEntry(newData->count() ? 0 : -1); 99 | 100 | m_loadingThings--; 101 | } 102 | 103 | protected: 104 | QList *m_data; 105 | TWidget *m_typedSetEditorWidget; 106 | 107 | void changeEntryCountTo(int count) { 108 | m_loadingThings++; 109 | 110 | int existingCount = m_chooser->count(); 111 | 112 | if (existingCount > count) { 113 | // remove something 114 | int nowSelected = m_chooser->currentIndex(); 115 | 116 | if (nowSelected >= count) { 117 | // oops, we'll need to select something else 118 | showEntry(count - 1); 119 | m_chooser->setCurrentIndex(count - 1); 120 | } 121 | 122 | for (int i = (existingCount - 1); i >= count; i--) 123 | m_chooser->removeItem(i); 124 | 125 | } else if (count > existingCount) { 126 | // add something 127 | 128 | for (int i = existingCount; i < count; i++) 129 | m_chooser->addItem(QString("Set %1").arg(i + 1)); 130 | } 131 | 132 | m_loadingThings--; 133 | } 134 | 135 | void resizeDataListTo(int count) { 136 | m_data->reserve(count); 137 | 138 | while (m_data->count() < count) 139 | m_data->append(TData()); 140 | while (m_data->count() > count) 141 | m_data->removeLast(); 142 | } 143 | 144 | void showEntry(int index) { 145 | m_loadingThings++; 146 | 147 | if (index == -1) { 148 | m_setEditorWidget->setEnabled(false); 149 | } else { 150 | m_setEditorWidget->setEnabled(true); 151 | TData &entry = (*m_data)[index]; 152 | m_typedSetEditorWidget->setCurrentEntry(entry); 153 | } 154 | } 155 | }; 156 | 157 | 158 | 159 | 160 | #endif // LSSETEDITOR_H 161 | -------------------------------------------------------------------------------- /lstexcoordseteditor.cpp: -------------------------------------------------------------------------------- 1 | #include "lstexcoordseteditor.h" 2 | #include 3 | #include 4 | #include 5 | 6 | LSTexCoordSetEditor::LSTexCoordSetEditor(QWidget *parent) : 7 | QWidget(parent) { 8 | 9 | m_loadingThings = 1; 10 | 11 | m_coordCount = new QSpinBox(this); 12 | m_coordCount->setRange(0, 8); 13 | connect(m_coordCount, SIGNAL(valueChanged(int)), SLOT(handleCoordCountChanged(int))); 14 | 15 | m_chooser = new QComboBox(this); 16 | connect(m_chooser, SIGNAL(currentIndexChanged(int)), SLOT(handleSetSelected(int))); 17 | 18 | for (int i = 0; i < 8; i++) { 19 | m_coordEntry[i] = new QDoubleSpinBox(this); 20 | m_coordEntry[i]->setRange(-10000000.0, 10000000.0); 21 | connect(m_coordEntry[i], SIGNAL(valueChanged(double)), SLOT(handleCoordChanged(double))); 22 | } 23 | 24 | 25 | QHBoxLayout *topLayout = new QHBoxLayout; 26 | topLayout->addWidget(new QLabel("Count:", this)); 27 | topLayout->addWidget(m_coordCount); 28 | topLayout->addSpacing(10); 29 | topLayout->addWidget(m_chooser, 1); 30 | 31 | // Layout: 32 | // 0 1 2 3 4 33 | // 0 34 | // 1 x y x y 35 | // 2 36 | // 3 x y x y 37 | 38 | QGridLayout *layout = new QGridLayout(this); 39 | layout->addLayout(topLayout, 0, 0, 1, 5); 40 | 41 | layout->addWidget(m_coordEntry[0], 1, 0, 1, 1); 42 | layout->addWidget(m_coordEntry[1], 1, 1, 1, 1); 43 | 44 | layout->addWidget(m_coordEntry[2], 1, 3, 1, 1); 45 | layout->addWidget(m_coordEntry[3], 1, 4, 1, 1); 46 | 47 | layout->addWidget(m_coordEntry[4], 3, 0, 1, 1); 48 | layout->addWidget(m_coordEntry[5], 3, 1, 1, 1); 49 | 50 | layout->addWidget(m_coordEntry[6], 3, 3, 1, 1); 51 | layout->addWidget(m_coordEntry[7], 3, 4, 1, 1); 52 | 53 | layout->setColumnMinimumWidth(2, 25); 54 | layout->setRowMinimumHeight(2, 10); 55 | 56 | m_loadingThings--; 57 | } 58 | 59 | 60 | void LSTexCoordSetEditor::setCoordPtr(QVector *coords) { 61 | m_loadingThings++; 62 | 63 | m_targetCoords = coords; 64 | 65 | m_coordCount->setValue(coords->count()); 66 | 67 | changeChooserCountTo(coords->count()); 68 | 69 | m_chooser->setCurrentIndex(coords->count() ? 0 : -1); 70 | showCoordSet(coords->count() ? 0 : -1); 71 | 72 | m_loadingThings--; 73 | } 74 | 75 | void LSTexCoordSetEditor::changeChooserCountTo(int count) { 76 | m_loadingThings++; 77 | 78 | int existingCount = m_chooser->count(); 79 | 80 | if (existingCount > count) { 81 | // remove something 82 | int nowSelected = m_chooser->currentIndex(); 83 | 84 | if (nowSelected >= count) { 85 | // oops, we'll need to select something else 86 | showCoordSet(count - 1); 87 | m_chooser->setCurrentIndex(count - 1); 88 | } 89 | 90 | for (int i = (existingCount - 1); i >= count; i--) 91 | m_chooser->removeItem(i); 92 | 93 | } else if (count > existingCount) { 94 | // add something 95 | 96 | for (int i = existingCount; i < count; i++) 97 | m_chooser->addItem(QString("Set %1").arg(i + 1)); 98 | } 99 | 100 | m_loadingThings--; 101 | } 102 | 103 | void LSTexCoordSetEditor::showCoordSet(int index) { 104 | m_loadingThings++; 105 | 106 | bool doesExist = (index != -1); 107 | 108 | for (int i = 0; i < 8; i++) 109 | m_coordEntry[i]->setEnabled(doesExist); 110 | 111 | if (doesExist) { 112 | const LYTTexCoords &set = m_targetCoords->at(index); 113 | 114 | for (int i = 0; i < 4; i++) { 115 | m_coordEntry[i*2]->setValue(set.coord[i].x()); 116 | m_coordEntry[i*2+1]->setValue(set.coord[i].y()); 117 | } 118 | } 119 | 120 | m_loadingThings--; 121 | } 122 | 123 | 124 | void LSTexCoordSetEditor::handleSetSelected(int index) { 125 | if (!m_loadingThings) 126 | showCoordSet(index); 127 | } 128 | 129 | void LSTexCoordSetEditor::handleCoordCountChanged(int count) { 130 | if (!m_loadingThings) { 131 | int oldCount = m_targetCoords->count(); 132 | if (oldCount == count) 133 | return; 134 | 135 | changeChooserCountTo(count); 136 | m_targetCoords->resize(count); 137 | 138 | // moving from 0 to something...? 139 | if (oldCount == 0) { 140 | m_chooser->setCurrentIndex(0); 141 | showCoordSet(0); 142 | } 143 | 144 | emit coordsEdited(); 145 | } 146 | } 147 | 148 | void LSTexCoordSetEditor::handleCoordChanged(double value) { 149 | if (!m_loadingThings) { 150 | // this code is.. kind of hacky. 151 | 152 | int whatID = -1; 153 | for (int i = 0; i < 8; i++) 154 | if (m_coordEntry[i] == sender()) { 155 | whatID = i; 156 | break; 157 | } 158 | 159 | if (whatID >= 0) { 160 | int coordIdx = m_chooser->currentIndex(); 161 | if (coordIdx == -1) 162 | return; 163 | 164 | LYTTexCoords &coord = (*m_targetCoords)[coordIdx]; 165 | 166 | if ((whatID % 2) == 1) 167 | coord.coord[whatID / 2].setY(value); 168 | else 169 | coord.coord[whatID / 2].setX(value); 170 | 171 | emit coordsEdited(); 172 | } 173 | } 174 | } 175 | -------------------------------------------------------------------------------- /lstexcoordseteditor.h: -------------------------------------------------------------------------------- 1 | #ifndef LSTEXCOORDSETEDITOR_H 2 | #define LSTEXCOORDSETEDITOR_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include "lyt/common.h" 8 | 9 | class LSTexCoordSetEditor : public QWidget 10 | { 11 | Q_OBJECT 12 | public: 13 | explicit LSTexCoordSetEditor(QWidget *parent = 0); 14 | 15 | void setCoordPtr(QVector *coords); 16 | 17 | private: 18 | QVector *m_targetCoords; 19 | QSpinBox *m_coordCount; 20 | QComboBox *m_chooser; 21 | QDoubleSpinBox *m_coordEntry[8]; 22 | 23 | int m_loadingThings; 24 | 25 | void changeChooserCountTo(int count); 26 | void showCoordSet(int index); 27 | 28 | private slots: 29 | void handleCoordCountChanged(int count); 30 | void handleSetSelected(int index); 31 | void handleCoordChanged(double value); 32 | 33 | signals: 34 | void coordsEdited(); 35 | 36 | public slots: 37 | 38 | }; 39 | 40 | #endif // LSTEXCOORDSETEDITOR_H 41 | -------------------------------------------------------------------------------- /lyt/archivepackage.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #include "archivepackage.h" 19 | 20 | #include 21 | 22 | LYTArchivePackage::LYTArchivePackage(QObject *parent) : LYTPackageBase(parent) { 23 | m_archive = new WiiArchiveU8; 24 | } 25 | 26 | LYTArchivePackage::LYTArchivePackage(QString filename, QObject *parent) : LYTPackageBase(parent) { 27 | m_filename = filename; 28 | 29 | QFile file(filename); 30 | file.open(QFile::ReadOnly); 31 | QByteArray data = file.readAll(); 32 | 33 | QDataStream stream(data); 34 | m_archive = new WiiArchiveU8(stream); 35 | } 36 | 37 | LYTArchivePackage::~LYTArchivePackage() { 38 | delete m_archive; 39 | } 40 | 41 | 42 | 43 | WiiArchiveU8 *LYTArchivePackage::archive() const { 44 | return m_archive; 45 | } 46 | 47 | QString LYTArchivePackage::filename() const { 48 | return m_filename; 49 | } 50 | void LYTArchivePackage::setFilename(QString path) { 51 | m_filename = path; 52 | } 53 | 54 | 55 | 56 | QStringList LYTArchivePackage::list(ItemType type) const { 57 | WiiFSObject *obj = this->m_archive->root.resolvePath(defaultPathForItemType(type, true)); 58 | 59 | if (obj && obj->isDirectory()) { 60 | QStringList output; 61 | 62 | foreach (WiiFSObject *ptr, ((WiiDirectory*)obj)->children) { 63 | output.append(ptr->name); 64 | } 65 | 66 | return output; 67 | } 68 | 69 | return QStringList(); 70 | } 71 | 72 | QByteArray LYTArchivePackage::get(ItemType type, const QString &name) const { 73 | QString dirName = defaultPathForItemType(type, true); 74 | WiiFSObject *obj = this->m_archive->root.resolvePath(QString("%1/%2").arg(dirName, name)); 75 | 76 | if (obj && obj->isFile()) { 77 | return ((WiiFile*)obj)->data; 78 | } 79 | 80 | return QByteArray(); 81 | } 82 | 83 | bool LYTArchivePackage::write(ItemType type, const QString &name, const QByteArray &data) { 84 | if (name.isEmpty()) 85 | return false; 86 | 87 | WiiFSObject *rootDir = this->m_archive->root.findByName("arc", false); 88 | if (!rootDir) { 89 | rootDir = new WiiDirectory; 90 | rootDir->name = "arc"; 91 | m_archive->root.addChild(rootDir); 92 | } 93 | if (!rootDir->isDirectory()) 94 | return false; 95 | 96 | QString dirName = defaultPathForItemType(type, false); 97 | WiiFSObject *dir = ((WiiDirectory*)rootDir)->findByName(dirName, false); 98 | 99 | if (!dir) { 100 | dir = new WiiDirectory; 101 | dir->name = dirName; 102 | ((WiiDirectory*)rootDir)->addChild(dir); 103 | } 104 | if (!dir->isDirectory()) 105 | return false; 106 | 107 | WiiFSObject *obj = ((WiiDirectory*)dir)->findByName(name, false); 108 | 109 | if (obj && obj->isFile()) { 110 | emit aboutToModifyFile(type, name); 111 | 112 | ((WiiFile*)obj)->data = data; 113 | 114 | emit fileWasModified(type, name); 115 | 116 | return true; 117 | 118 | } else if (!obj) { 119 | emit aboutToAddFile(type, name); 120 | 121 | WiiFile *newFile = new WiiFile; 122 | newFile->name = name; 123 | newFile->data = data; 124 | ((WiiDirectory*)dir)->addChild(newFile); 125 | 126 | emit fileWasAdded(type, name); 127 | 128 | return true; 129 | } 130 | 131 | return false; 132 | } 133 | 134 | bool LYTArchivePackage::remove(ItemType type, const QString &name) { 135 | WiiFSObject *obj = this->m_archive->root.resolvePath(defaultPathForItemType(type, true)); 136 | 137 | if (obj && obj->isDirectory()) { 138 | WiiDirectory *dir = (WiiDirectory*)obj; 139 | 140 | WiiFSObject *what = dir->findByName(name, false); 141 | if (what && what->isFile()) { 142 | emit aboutToRemoveFile(type, name); 143 | dir->removeChild(what); 144 | emit fileWasRemoved(type, name); 145 | return true; 146 | } 147 | } 148 | 149 | return false; 150 | } 151 | 152 | bool LYTArchivePackage::rename(ItemType type, const QString &from, const QString &to) { 153 | if (to.isEmpty()) 154 | return false; 155 | 156 | WiiFSObject *obj = this->m_archive->root.resolvePath(defaultPathForItemType(type, true)); 157 | 158 | if (obj && obj->isDirectory()) { 159 | WiiDirectory *dir = (WiiDirectory*)obj; 160 | 161 | WiiFSObject *what = dir->findByName(from, false); 162 | if (what && what->isFile()) { 163 | WiiFSObject *conflict = dir->findByName(to, false); 164 | if (!conflict) { 165 | emit aboutToRenameFile(type, from, to); 166 | what->name = to; 167 | emit fileWasRenamed(type, from, to); 168 | return true; 169 | } 170 | } 171 | } 172 | 173 | return false; 174 | } 175 | 176 | 177 | 178 | bool LYTArchivePackage::savePackage() { 179 | QFile file(m_filename); 180 | 181 | if (file.open(QFile::WriteOnly)) { 182 | QByteArray data; 183 | QDataStream stream(&data, QIODevice::ReadWrite); 184 | 185 | m_archive->writeToDataStream(stream); 186 | file.write(data); 187 | 188 | return true; 189 | } 190 | 191 | return false; 192 | } 193 | 194 | 195 | QString LYTArchivePackage::description() const { 196 | return m_filename; 197 | } 198 | -------------------------------------------------------------------------------- /lyt/archivepackage.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #ifndef LYTARCHIVEPACKAGE_H 19 | #define LYTARCHIVEPACKAGE_H 20 | 21 | #include "packagebase.h" 22 | #include "wii/archiveu8.h" 23 | 24 | class LYTArchivePackage : public LYTPackageBase { 25 | Q_OBJECT 26 | public: 27 | LYTArchivePackage(QObject *parent = 0); 28 | LYTArchivePackage(QString filename, QObject *parent = 0); 29 | 30 | ~LYTArchivePackage(); 31 | 32 | QStringList list(ItemType type) const; 33 | QByteArray get(ItemType type, const QString &name) const; 34 | bool write(ItemType type, const QString &name, const QByteArray &data); 35 | bool rename(ItemType type, const QString &from, const QString &to); 36 | bool remove(ItemType type, const QString &name); 37 | 38 | bool needsExplicitSave() const { return true; } 39 | bool savePackage(); 40 | QString description() const; 41 | 42 | WiiArchiveU8 *archive() const; 43 | QString filename() const; 44 | void setFilename(QString path); 45 | 46 | 47 | protected: 48 | WiiArchiveU8 *m_archive; 49 | QString m_filename; 50 | }; 51 | 52 | #endif // LYTARCHIVEPACKAGE_H 53 | -------------------------------------------------------------------------------- /lyt/binaryfile.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #include "binaryfile.h" 19 | #include "binaryfilesection.h" 20 | 21 | #include 22 | 23 | LYTBinaryFile::LYTBinaryFile(Magic m, Version v) : magic(m), version(v) { 24 | } 25 | 26 | 27 | LYTBinaryFile::LYTBinaryFile(QByteArray data) : magic(0), version(0) { 28 | QDataStream reader(data); 29 | InitDataStream(reader); 30 | 31 | quint16 endian, firstSectionOffset, sectionCount; 32 | quint32 fileSize; 33 | 34 | reader >> this->magic.value; 35 | reader >> endian; 36 | reader >> this->version.value; 37 | reader >> fileSize; 38 | reader >> firstSectionOffset; 39 | reader >> sectionCount; 40 | 41 | LYTBinaryFileSection section; 42 | 43 | for (int i = 0; i < sectionCount; i++) { 44 | section.readFromDataStream(reader); 45 | this->sections.append(section); 46 | } 47 | } 48 | 49 | 50 | QByteArray LYTBinaryFile::pack() const { 51 | // first off, calculate filesize for the header 52 | quint32 fileSize = 16; 53 | 54 | foreach (LYTBinaryFileSection section, this->sections) { 55 | fileSize += section.writtenSize(); 56 | } 57 | 58 | // set up other fields 59 | quint16 endian, firstSectionOffset; 60 | endian = 0xFEFF; 61 | firstSectionOffset = 16; 62 | 63 | 64 | // write it 65 | QByteArray output; 66 | QDataStream writer(&output, QIODevice::WriteOnly); 67 | InitDataStream(writer); 68 | 69 | writer << this->magic.value; 70 | writer << endian; 71 | writer << this->version.value; 72 | writer << fileSize; 73 | writer << firstSectionOffset; 74 | writer << (quint16)this->sections.count(); 75 | 76 | foreach (LYTBinaryFileSection section, this->sections) { 77 | section.writeToDataStream(writer); 78 | } 79 | 80 | return output; 81 | } 82 | -------------------------------------------------------------------------------- /lyt/binaryfile.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #ifndef LYTBINARYFILE_H 19 | #define LYTBINARYFILE_H 20 | 21 | #include 22 | 23 | #include "common.h" 24 | #include "binaryfilesection.h" 25 | 26 | class LYTBinaryFile { 27 | public: 28 | LYTBinaryFile(Magic magic, Version version); 29 | LYTBinaryFile(QByteArray data); 30 | 31 | QByteArray pack() const; 32 | 33 | Magic magic; 34 | Version version; 35 | 36 | QList sections; 37 | }; 38 | 39 | #endif // LYTBINARYFILE_H 40 | -------------------------------------------------------------------------------- /lyt/binaryfilesection.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #include "binaryfilesection.h" 19 | 20 | LYTBinaryFileSection::LYTBinaryFileSection() : magic(0) { 21 | } 22 | 23 | LYTBinaryFileSection::LYTBinaryFileSection(Magic m) : magic(m) { 24 | } 25 | 26 | LYTBinaryFileSection::LYTBinaryFileSection(Magic m, QByteArray d) : magic(m), data(d) { 27 | } 28 | 29 | 30 | void LYTBinaryFileSection::writeToDataStream(QDataStream &out) const { 31 | out << (quint32)magic.value; 32 | out << (quint32)AlignUp(data.length() + 8, 4); 33 | out.writeRawData(data.constData(), data.length()); 34 | 35 | int align = AlignUp(data.length(), 4) - data.length(); 36 | WritePadding(align, out); 37 | } 38 | 39 | void LYTBinaryFileSection::readFromDataStream(QDataStream &in) { 40 | quint32 length; 41 | 42 | in >> (quint32&)magic.value; 43 | in >> (quint32&)length; 44 | 45 | char *raw = new char[length - 8]; 46 | in.readRawData(raw, length - 8); 47 | 48 | data = QByteArray(raw, length - 8); 49 | } 50 | 51 | 52 | int LYTBinaryFileSection::writtenSize() const { 53 | return 8 + AlignUp(this->data.length(), 4); 54 | } 55 | 56 | 57 | QDataStream *LYTBinaryFileSection::createReadStream() const { 58 | QDataStream *stream = new QDataStream(this->data); 59 | InitDataStream(*stream); 60 | return stream; 61 | } 62 | 63 | 64 | QDataStream *LYTBinaryFileSection::createWriteStream() { 65 | QDataStream *stream = new QDataStream(&this->data, QIODevice::ReadWrite); 66 | InitDataStream(*stream); 67 | return stream; 68 | } 69 | -------------------------------------------------------------------------------- /lyt/binaryfilesection.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #ifndef LYTBINARYFILESECTION_H 19 | #define LYTBINARYFILESECTION_H 20 | 21 | #include 22 | 23 | #include "common.h" 24 | 25 | class LYTBinaryFileSection { 26 | public: 27 | LYTBinaryFileSection(); 28 | LYTBinaryFileSection(Magic magic); 29 | LYTBinaryFileSection(Magic magic, QByteArray data); 30 | 31 | Magic magic; 32 | QByteArray data; 33 | 34 | QDataStream *createReadStream() const; 35 | QDataStream *createWriteStream(); 36 | 37 | void writeToDataStream(QDataStream &out) const; 38 | void readFromDataStream(QDataStream &in); 39 | 40 | int writtenSize() const; 41 | }; 42 | 43 | 44 | 45 | #endif // LYTBINARYFILESECTION_H 46 | -------------------------------------------------------------------------------- /lyt/bounding.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #include "bounding.h" 19 | #include "layout.h" 20 | #include "common.h" 21 | 22 | 23 | LYTBounding::LYTBounding(LYTLayout &layout) : LYTPane(layout) { 24 | m_type = BoundingType; 25 | } 26 | 27 | 28 | Magic LYTBounding::magic() const { 29 | return Magic('bnd1'); 30 | } 31 | 32 | 33 | void LYTBounding::dumpToDebug(bool showHeading) const { 34 | if (showHeading) 35 | qDebug() << "LYTBounding" << name << "@" << (void*)this; 36 | 37 | LYTPane::dumpToDebug(false); 38 | } 39 | 40 | 41 | 42 | void LYTBounding::writeToDataStream(QDataStream &out) const { 43 | LYTPane::writeToDataStream(out); 44 | } 45 | 46 | 47 | void LYTBounding::readFromDataStream(QDataStream &in) { 48 | LYTPane::readFromDataStream(in); 49 | } 50 | -------------------------------------------------------------------------------- /lyt/bounding.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #ifndef LYTBOUNDING_H 19 | #define LYTBOUNDING_H 20 | 21 | #include "common.h" 22 | #include "pane.h" 23 | 24 | // the most useful object in LYT 25 | // it's just a regular Pane ... with a different name. 26 | 27 | class LYTBounding : public LYTPane { 28 | public: 29 | LYTBounding(LYTLayout &layout); 30 | 31 | 32 | Magic magic() const; 33 | 34 | void writeToDataStream(QDataStream &out) const; 35 | void readFromDataStream(QDataStream &in); 36 | 37 | void dumpToDebug(bool showHeading=true) const; 38 | }; 39 | 40 | 41 | #endif // LYTBOUNDING_H 42 | -------------------------------------------------------------------------------- /lyt/common.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #ifndef LYTCOMMON_H 19 | #define LYTCOMMON_H 20 | 21 | #include 22 | 23 | #include "../wii/common.h" 24 | 25 | union Magic { 26 | char str[4]; 27 | quint32 value; 28 | 29 | Magic(quint32 v) : value(v) { } 30 | }; 31 | 32 | union Version { 33 | char str[2]; 34 | quint16 value; 35 | 36 | Version(quint16 v) : value(v) { } 37 | }; 38 | 39 | 40 | 41 | struct LYTTexCoords { 42 | QPointF coord[4]; 43 | 44 | LYTTexCoords() { 45 | // Sane defaults 46 | coord[0] = QPointF(0.0f, 0.0f); 47 | coord[1] = QPointF(1.0f, 0.0f); 48 | coord[2] = QPointF(0.0f, 1.0f); 49 | coord[3] = QPointF(1.0f, 1.0f); 50 | } 51 | }; 52 | 53 | 54 | #endif // LYTCOMMON_H 55 | -------------------------------------------------------------------------------- /lyt/directorypackage.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #include "directorypackage.h" 19 | 20 | #include 21 | 22 | LYTDirectoryPackage::LYTDirectoryPackage(QString path, QObject *parent) : LYTPackageBase(parent) { 23 | qWarning("LYTDirectoryPackage is currently unmaintained, you probably shouldn't use it"); 24 | 25 | QDir fix_path(path); 26 | this->m_path = fix_path.absolutePath(); 27 | } 28 | 29 | 30 | 31 | QStringList LYTDirectoryPackage::list(ItemType type) const { 32 | QDir search(m_path); 33 | 34 | if (search.cd(defaultPathForItemType(type))) { 35 | return search.entryList(); 36 | } 37 | 38 | return QStringList(); 39 | } 40 | 41 | QByteArray LYTDirectoryPackage::get(ItemType type, const QString &name) const { 42 | QDir search(m_path); 43 | 44 | if (search.cd(defaultPathForItemType(type))) { 45 | QFile file(search.absoluteFilePath(name)); 46 | 47 | if (file.open(QFile::ReadOnly)) { 48 | return file.readAll(); 49 | } 50 | } 51 | 52 | return QByteArray(); 53 | } 54 | 55 | bool LYTDirectoryPackage::write(ItemType type, const QString &name, const QByteArray &data) { 56 | QDir search(m_path); 57 | QString dirName = defaultPathForItemType(type); 58 | 59 | if (!search.cd(dirName)) { 60 | if (!search.mkdir(dirName)) 61 | return false; 62 | if (!search.cd(dirName)) 63 | return false; 64 | } 65 | 66 | QFile file(search.absoluteFilePath(name)); 67 | 68 | if (file.open(QFile::WriteOnly)) { 69 | if (file.write(data) != -1) { 70 | return true; 71 | } 72 | } 73 | 74 | return false; 75 | } 76 | 77 | bool LYTDirectoryPackage::remove(ItemType type, const QString &name) { 78 | QDir search(m_path); 79 | 80 | if (search.cd(defaultPathForItemType(type))) { 81 | QFile file(search.absoluteFilePath(name)); 82 | 83 | if (file.open(QFile::WriteOnly)) { 84 | return file.remove(); 85 | } 86 | } 87 | 88 | return false; 89 | } 90 | 91 | 92 | 93 | bool LYTDirectoryPackage::savePackage() { 94 | // No-op since this is a directory 95 | return true; 96 | } 97 | 98 | 99 | QString LYTDirectoryPackage::description() const { 100 | return m_path; 101 | } 102 | -------------------------------------------------------------------------------- /lyt/directorypackage.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | // Currently unmaintained. 19 | // What this needs to be fixed up: 20 | // -- Implement rename() 21 | // -- Make it emit signals 22 | // -- Add support to the LayoutStudio UI 23 | 24 | #ifndef LYTDIRECTORYPACKAGE_H 25 | #define LYTDIRECTORYPACKAGE_H 26 | 27 | #include "packagebase.h" 28 | 29 | class LYTDirectoryPackage : public LYTPackageBase { 30 | Q_OBJECT 31 | public: 32 | LYTDirectoryPackage(QString path, QObject *parent = 0); 33 | 34 | QStringList list(ItemType type) const; 35 | QByteArray get(ItemType type, const QString &name) const; 36 | bool write(ItemType type, const QString &name, const QByteArray &data); 37 | bool remove(ItemType type, const QString &name); 38 | 39 | bool needsExplicitSave() const { return false; } 40 | bool savePackage(); 41 | QString description() const; 42 | QString path() const; 43 | 44 | protected: 45 | QString m_path; 46 | }; 47 | 48 | #endif // LYTDIRECTORYPACKAGE_H 49 | -------------------------------------------------------------------------------- /lyt/group.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #include "group.h" 19 | 20 | LYTGroup::LYTGroup() { 21 | } 22 | 23 | 24 | 25 | 26 | void LYTGroup::writeToDataStream(QDataStream &out) const { 27 | WriteFixedLengthASCII(out, name, 0x10); 28 | 29 | // write the contents 30 | out << (quint16)panes.count(); 31 | WritePadding(2, out); 32 | 33 | foreach (LYTPane *pane, panes) { 34 | WriteFixedLengthASCII(out, pane->name, 0x10); 35 | } 36 | } 37 | 38 | 39 | void LYTGroup::readFromDataStream(QDataStream &in, LYTPane &linkedPane) { 40 | name = ReadFixedLengthASCII(in, 0x10); 41 | qDebug() << "reading group" << name; 42 | 43 | // read the contents 44 | quint16 paneCount; 45 | in >> (quint16&)paneCount; 46 | in.skipRawData(2); // padding 47 | 48 | for (int i = 0; i < paneCount; i++) { 49 | QString paneName = ReadFixedLengthASCII(in, 0x10); 50 | 51 | qDebug() << "found" << paneName << "in group" << this->name; 52 | 53 | this->panes.append(linkedPane.findPaneByName(paneName, true)); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /lyt/group.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #ifndef LYTGROUP_H 19 | #define LYTGROUP_H 20 | 21 | #include "common.h" 22 | #include "pane.h" 23 | 24 | #include 25 | 26 | class LYTGroup { 27 | public: 28 | LYTGroup(); 29 | 30 | 31 | void writeToDataStream(QDataStream &out) const; 32 | void readFromDataStream(QDataStream &in, LYTPane &linkedPane); 33 | 34 | QString name; 35 | 36 | QList panes; 37 | }; 38 | 39 | #endif // LYTGROUP_H 40 | -------------------------------------------------------------------------------- /lyt/layout.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #ifndef LYTLAYOUT_H 19 | #define LYTLAYOUT_H 20 | 21 | #include "packagebase.h" 22 | #include "materials/material.h" 23 | #include "materials/materialcontainer.h" 24 | #include "group.h" 25 | #include "pane.h" 26 | #include "textbox.h" 27 | #include "picture.h" 28 | #include "window.h" 29 | #include "bounding.h" 30 | #include "binaryfile.h" 31 | #include "binaryfilesection.h" 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | class LYTTexMap; // forward declaration so it can be a friend class 38 | 39 | class LYTLayout { 40 | public: 41 | LYTLayout(LYTPackageBase &package); 42 | LYTLayout(LYTPackageBase &package, QString name); 43 | ~LYTLayout(); 44 | 45 | void clear(); 46 | LYTPackageBase &package() const; 47 | 48 | QByteArray pack(); 49 | 50 | quint8 flags; 51 | 52 | float width; 53 | float height; 54 | 55 | LYTMaterialContainer materials; 56 | 57 | LYTPane *rootPane; 58 | QList groups; 59 | 60 | QStringList generateTextureRefs() const; 61 | 62 | 63 | protected: 64 | LYTPackageBase &m_package; 65 | 66 | // these are private because they are not intended for public use 67 | // they're only here so that LYTPane's subclasses and a few others can read 68 | // this info when reading/writing -- hence why they are friend classes 69 | QStringList m_fontRefs; 70 | QStringList m_textureRefs; 71 | 72 | bool loadLayoutFromPackage(QString name); 73 | 74 | void readLyt1(LYTBinaryFileSection §ion); 75 | void readTxl1(LYTBinaryFileSection §ion); 76 | void readFnl1(LYTBinaryFileSection §ion); 77 | void readMat1(LYTBinaryFileSection §ion); 78 | 79 | LYTPane *createPaneObj(LYTBinaryFileSection §ion); 80 | 81 | QStringList generateFontRefs() const; 82 | 83 | void writeMat1(LYTBinaryFileSection §ion) const; 84 | void writePane(LYTBinaryFile &file, LYTPane *pane) const; 85 | void writeGroups(LYTBinaryFile &file) const; 86 | 87 | friend class LYTPane; 88 | friend class LYTTextBox; 89 | friend class LYTPicture; 90 | friend class LYTWindow; 91 | friend class LYTBounding; 92 | friend class LYTTexMap; 93 | 94 | }; 95 | 96 | #endif // LYTLAYOUT_H 97 | -------------------------------------------------------------------------------- /lyt/materials/alphacompare.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #include "alphacompare.h" 19 | #include "../layout.h" 20 | 21 | LYTAlphaCompare::LYTAlphaCompare() { 22 | } 23 | 24 | void LYTAlphaCompare::dumpToDebug() const { 25 | qDebug() << "LYTAlphaCompare @" << (void*)this; 26 | qDebug() << "Comp0:" << comp0 << "- Ref0:" << ref0; 27 | qDebug() << "Comp1:" << comp1 << "- Ref1:" << ref1; 28 | qDebug() << "Op:" << op; 29 | } 30 | 31 | 32 | void LYTAlphaCompare::writeToDataStream(QDataStream &out) const { 33 | out << (quint8)(comp0 | (comp1 << 4)); 34 | out << (quint8)op; 35 | out << (quint8)ref0; 36 | out << (quint8)ref1; 37 | } 38 | 39 | 40 | void LYTAlphaCompare::readFromDataStream(QDataStream &in) { 41 | quint8 value; 42 | 43 | in >> (quint8&)value; 44 | comp0 = BitExtract(value, 4, 32 - 4); 45 | comp1 = BitExtract(value, 4, 32 - 8); 46 | 47 | in >> (quint8&)op; 48 | in >> (quint8&)ref0; 49 | in >> (quint8&)ref1; 50 | } 51 | 52 | 53 | -------------------------------------------------------------------------------- /lyt/materials/alphacompare.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #ifndef LYTALPHACOMPARE_H 19 | #define LYTALPHACOMPARE_H 20 | 21 | #include "../common.h" 22 | #include "QtCore/QDataStream" 23 | 24 | class LYTAlphaCompare { 25 | public: 26 | LYTAlphaCompare(); 27 | 28 | void writeToDataStream(QDataStream &out) const; 29 | void readFromDataStream(QDataStream &in); 30 | 31 | void dumpToDebug() const; 32 | 33 | quint8 comp0; 34 | quint8 ref0; 35 | quint8 op; 36 | quint8 comp1; 37 | quint8 ref1; 38 | }; 39 | 40 | #endif // LYTALPHACOMPARE_H 41 | -------------------------------------------------------------------------------- /lyt/materials/blendmode.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #include "blendmode.h" 19 | #include "../layout.h" 20 | 21 | LYTBlendMode::LYTBlendMode() { 22 | } 23 | 24 | void LYTBlendMode::dumpToDebug() const { 25 | qDebug() << "LYTBlendMode @" << (void*)this; 26 | qDebug() << "srcFactor:" << srcFactor << "- destFactor:" << destFactor; 27 | qDebug() << "op:" << op << "- type:" << type; 28 | } 29 | 30 | 31 | void LYTBlendMode::writeToDataStream(QDataStream &out) const { 32 | out << (quint8)type; 33 | out << (quint8)srcFactor; 34 | out << (quint8)destFactor; 35 | out << (quint8)op; 36 | } 37 | 38 | 39 | void LYTBlendMode::readFromDataStream(QDataStream &in) { 40 | in >> (quint8&)type; 41 | in >> (quint8&)srcFactor; 42 | in >> (quint8&)destFactor; 43 | in >> (quint8&)op; 44 | } 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /lyt/materials/blendmode.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #ifndef LYTBLENDMODE_H 19 | #define LYTBLENDMODE_H 20 | 21 | #include "../common.h" 22 | #include "QtCore/QDataStream" 23 | 24 | class LYTBlendMode { 25 | public: 26 | LYTBlendMode(); 27 | 28 | void writeToDataStream(QDataStream &out) const; 29 | void readFromDataStream(QDataStream &in); 30 | 31 | void dumpToDebug() const; 32 | 33 | quint8 type; 34 | quint8 srcFactor; 35 | quint8 destFactor; 36 | quint8 op; 37 | }; 38 | 39 | #endif // LYTBLENDMODE_H 40 | -------------------------------------------------------------------------------- /lyt/materials/chanctrl.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #include "chanctrl.h" 19 | #include "../layout.h" 20 | 21 | LYTChanCtrl::LYTChanCtrl() { 22 | } 23 | 24 | void LYTChanCtrl::dumpToDebug() const { 25 | qDebug() << "LYTChanCtrl @" << (void*)this; 26 | qDebug() << "ColourMatSrc:" << colourMatSrc << "- AlphaMatSrc:" << alphaMatSrc; 27 | } 28 | 29 | 30 | void LYTChanCtrl::writeToDataStream(QDataStream &out) const { 31 | out << (quint8)colourMatSrc; 32 | out << (quint8)alphaMatSrc; 33 | WritePadding(2, out); 34 | } 35 | 36 | 37 | void LYTChanCtrl::readFromDataStream(QDataStream &in) { 38 | in >> (quint8&)colourMatSrc; 39 | in >> (quint8&)alphaMatSrc; 40 | in.skipRawData(2); // padding 41 | } 42 | 43 | -------------------------------------------------------------------------------- /lyt/materials/chanctrl.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #ifndef LYTCHANCTRL_H 19 | #define LYTCHANCTRL_H 20 | 21 | #include "../common.h" 22 | #include "QtCore/QDataStream" 23 | 24 | class LYTChanCtrl { 25 | public: 26 | LYTChanCtrl(); 27 | 28 | void writeToDataStream(QDataStream &out) const; 29 | void readFromDataStream(QDataStream &in); 30 | 31 | void dumpToDebug() const; 32 | 33 | quint8 colourMatSrc; 34 | quint8 alphaMatSrc; 35 | }; 36 | 37 | #endif // LYTCHANCTRL_H 38 | -------------------------------------------------------------------------------- /lyt/materials/indirectstage.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #include "indirectstage.h" 19 | #include "../layout.h" 20 | 21 | LYTIndirectStage::LYTIndirectStage() { 22 | } 23 | 24 | void LYTIndirectStage::dumpToDebug() const { 25 | qDebug() << "LYTIndirectStage @" << (void*)this; 26 | qDebug() << "texCoord:" << this->texCoord << "- texMap:" << this->texMap; 27 | qDebug() << "wrap_s:" << this->wrap_s << "- wrap_t:" << this->wrap_t; 28 | } 29 | 30 | 31 | void LYTIndirectStage::writeToDataStream(QDataStream &out) const { 32 | out << (quint8)texCoord; 33 | out << (quint8)texMap; 34 | out << (quint8)wrap_s; 35 | out << (quint8)wrap_t; 36 | } 37 | 38 | 39 | void LYTIndirectStage::readFromDataStream(QDataStream &in) { 40 | in >> (quint8&)texCoord; 41 | in >> (quint8&)texMap; 42 | in >> (quint8&)wrap_s; 43 | in >> (quint8&)wrap_t; 44 | } 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /lyt/materials/indirectstage.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #ifndef LYTINDIRECTSTAGE_H 19 | #define LYTINDIRECTSTAGE_H 20 | 21 | #include "../common.h" 22 | #include 23 | 24 | class LYTIndirectStage { 25 | public: 26 | LYTIndirectStage(); 27 | 28 | void writeToDataStream(QDataStream &out) const; 29 | void readFromDataStream(QDataStream &in); 30 | 31 | void dumpToDebug() const; 32 | 33 | quint8 texCoord; 34 | quint8 texMap; 35 | quint8 wrap_s; 36 | quint8 wrap_t; 37 | }; 38 | 39 | 40 | #endif // LYTINDIRECTSTAGE_H 41 | -------------------------------------------------------------------------------- /lyt/materials/material.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #include "material.h" 19 | #include "../layout.h" 20 | 21 | LYTMaterial::LYTMaterial(LYTLayout &layout) : m_layout(layout) { 22 | } 23 | 24 | LYTMaterial::~LYTMaterial() { 25 | } 26 | 27 | LYTLayout &LYTMaterial::layout() const { 28 | return m_layout; 29 | } 30 | 31 | 32 | void LYTMaterial::dumpToDebug() const { 33 | qDebug() << "LYTMaterial" << name << "@" << (void*)this; 34 | 35 | for (int i = 0; i < 3; i++) 36 | qDebug() << "Colour" << i << ":" << colours[i]; 37 | 38 | for (int i = 0; i < 4; i++) 39 | qDebug() << "TEV Constant Colour" << i << ":" << tevKColour[i]; 40 | 41 | qDebug() << "TexMaps:" << texMaps.count(); 42 | foreach (LYTTexMap texMap, texMaps) 43 | texMap.dumpToDebug(); 44 | 45 | qDebug() << "TexSRTs:" << texSRTs.count(); 46 | foreach (LYTTexSRT texSRT, texSRTs) 47 | texSRT.dumpToDebug(); 48 | 49 | qDebug() << "TexCoordGens:" << texCoordGens.count(); 50 | foreach (LYTTexCoordGen texCoordGen, texCoordGens) 51 | texCoordGen.dumpToDebug(); 52 | 53 | if (hasChanCtrl) 54 | chanCtrl.dumpToDebug(); 55 | else 56 | qDebug() << "ChanCtrl: none"; 57 | 58 | if (hasMatCol) 59 | qDebug() << "MatCol:" << matCol; 60 | else 61 | qDebug() << "MatCol: none"; 62 | 63 | if (hasTevSwapTable) 64 | tevSwapTable.dumpToDebug(); 65 | else 66 | qDebug() << "TevSwapTable: none"; 67 | 68 | qDebug() << "IndTexSRTs:" << indTexSRTs.count(); 69 | foreach (LYTTexSRT indTexSRT, indTexSRTs) 70 | indTexSRT.dumpToDebug(); 71 | 72 | qDebug() << "IndirectStages:" << indTexStages.count(); 73 | foreach (LYTIndirectStage indTexStage, indTexStages) 74 | indTexStage.dumpToDebug(); 75 | 76 | qDebug() << "TevStages:" << tevStages.count(); 77 | foreach (LYTTevStage tevStage, tevStages) 78 | tevStage.dumpToDebug(); 79 | 80 | if (hasAlphaCompare) 81 | alphaCompare.dumpToDebug(); 82 | else 83 | qDebug() << "AlphaCompare: none"; 84 | 85 | if (hasBlendMode) 86 | blendMode.dumpToDebug(); 87 | else 88 | qDebug() << "BlendMode: none"; 89 | } 90 | 91 | 92 | 93 | void LYTMaterial::writeToDataStream(QDataStream &out) const { 94 | WriteFixedLengthASCII(out, name, 0x14); 95 | 96 | for (int i = 0; i < 3; i++) 97 | WriteS10Color(this->colours[i], out); 98 | 99 | for (int i = 0; i < 4; i++) 100 | WriteRGBA8Color(this->tevKColour[i], out); 101 | 102 | 103 | LYTMaterialResourceNum resourceNum; 104 | resourceNum.setTexMapNum(texMaps.count()); 105 | resourceNum.setTexSRTNum(texSRTs.count()); 106 | resourceNum.setTexCoordGenNum(texCoordGens.count()); 107 | resourceNum.setHasChanCtrl(hasChanCtrl); 108 | resourceNum.setHasMatCol(hasMatCol); 109 | resourceNum.setHasTevSwapTable(hasTevSwapTable); 110 | resourceNum.setIndTexSRTNum(indTexSRTs.count()); 111 | resourceNum.setIndTexStageNum(indTexStages.count()); 112 | resourceNum.setTevStageNum(tevStages.count()); 113 | resourceNum.setHasAlphaCompare(hasAlphaCompare); 114 | resourceNum.setHasBlendMode(hasBlendMode); 115 | out << (quint32)resourceNum.value(); 116 | 117 | 118 | // TexMap 119 | for (int i = 0; i < texMaps.count(); i++) { 120 | texMaps.at(i).writeToDataStream(out, this->m_layout); 121 | } 122 | 123 | // TexSRT 124 | for (int i = 0; i < texSRTs.count(); i++) { 125 | texSRTs.at(i).writeToDataStream(out); 126 | } 127 | 128 | // TexCoordGen 129 | for (int i = 0; i < texCoordGens.count(); i++) { 130 | texCoordGens.at(i).writeToDataStream(out); 131 | } 132 | 133 | // ChanCtrl 134 | if (hasChanCtrl) { 135 | chanCtrl.writeToDataStream(out); 136 | } 137 | 138 | // MatCol 139 | if (hasMatCol) { 140 | WriteRGBA8Color(this->matCol, out); 141 | } 142 | 143 | // TevSwapTable 144 | if (hasTevSwapTable) { 145 | tevSwapTable.writeToDataStream(out); 146 | } 147 | 148 | // IndTexSRT 149 | for (int i = 0; i < indTexSRTs.count(); i++) { 150 | indTexSRTs.at(i).writeToDataStream(out); 151 | } 152 | 153 | // IndTexStage 154 | for (int i = 0; i < indTexStages.count(); i++) { 155 | indTexStages.at(i).writeToDataStream(out); 156 | } 157 | 158 | // TevStage 159 | for (int i = 0; i < tevStages.count(); i++) { 160 | tevStages.at(i).writeToDataStream(out); 161 | } 162 | 163 | // AlphaCompare 164 | if (hasAlphaCompare) { 165 | alphaCompare.writeToDataStream(out); 166 | } 167 | 168 | // BlendMode 169 | if (hasBlendMode) { 170 | blendMode.writeToDataStream(out); 171 | } 172 | 173 | } 174 | 175 | void LYTMaterial::readFromDataStream(QDataStream &in) { 176 | name = ReadFixedLengthASCII(in, 0x14); 177 | 178 | for (int i = 0; i < 3; i++) 179 | ReadS10Color(this->colours[i], in); 180 | 181 | for (int i = 0; i < 4; i++) 182 | ReadRGBA8Color(this->tevKColour[i], in); 183 | 184 | 185 | quint32 resNumValue; 186 | in >> (quint32&)resNumValue; 187 | LYTMaterialResourceNum resourceNum(resNumValue); 188 | 189 | // this is really complicated -_- 190 | // first off: TexMap 191 | texMaps.clear(); 192 | 193 | for (int i = 0; i < resourceNum.getTexMapNum(); i++) { 194 | this->readTexMap(in); 195 | } 196 | 197 | // TexSRT 198 | texSRTs.clear(); 199 | 200 | for (int i = 0; i < resourceNum.getTexSRTNum(); i++) { 201 | this->readTexSRT(in); 202 | } 203 | 204 | // TexCoordGen 205 | texCoordGens.clear(); 206 | 207 | for (int i = 0; i < resourceNum.getTexCoordGenNum(); i++) { 208 | this->readTexCoordGen(in); 209 | } 210 | 211 | // ChanCtrl 212 | if (resourceNum.hasChanCtrl()) { 213 | this->hasChanCtrl = true; 214 | this->chanCtrl.readFromDataStream(in); 215 | } else { 216 | this->hasChanCtrl = false; 217 | } 218 | 219 | // MatCol 220 | if (resourceNum.hasMatCol()) { 221 | this->hasMatCol = true; 222 | ReadRGBA8Color(this->matCol, in); 223 | } else { 224 | this->hasMatCol = false; 225 | } 226 | 227 | // TevSwapTable 228 | if (resourceNum.hasTevSwapTable()) { 229 | this->hasTevSwapTable = true; 230 | this->tevSwapTable.readFromDataStream(in); 231 | } else { 232 | this->hasTevSwapTable = false; 233 | } 234 | 235 | // IndTexSRT 236 | indTexSRTs.clear(); 237 | 238 | for (int i = 0; i < resourceNum.getIndTexSRTNum(); i++) { 239 | this->readIndTexSRT(in); 240 | } 241 | 242 | // IndTexStage 243 | indTexStages.clear(); 244 | 245 | for (int i = 0; i < resourceNum.getIndTexStageNum(); i++) { 246 | this->readIndirectStage(in); 247 | } 248 | 249 | // TevStage 250 | tevStages.clear(); 251 | 252 | for (int i = 0; i < resourceNum.getTevStageNum(); i++) { 253 | this->readTevStage(in); 254 | } 255 | 256 | // AlphaCompare 257 | if (resourceNum.hasAlphaCompare()) { 258 | this->hasAlphaCompare = true; 259 | this->alphaCompare.readFromDataStream(in); 260 | } else { 261 | this->hasAlphaCompare = false; 262 | } 263 | 264 | // BlendMode 265 | if (resourceNum.hasBlendMode()) { 266 | this->hasBlendMode = true; 267 | this->blendMode.readFromDataStream(in); 268 | } else { 269 | this->hasBlendMode = false; 270 | } 271 | } 272 | 273 | 274 | 275 | void LYTMaterial::readTexMap(QDataStream &in) { 276 | this->texMaps.append(LYTTexMap()); 277 | this->texMaps.last().readFromDataStream(in, m_layout); 278 | } 279 | 280 | void LYTMaterial::readTexSRT(QDataStream &in) { 281 | this->texSRTs.append(LYTTexSRT()); 282 | this->texSRTs.last().readFromDataStream(in); 283 | } 284 | 285 | void LYTMaterial::readTexCoordGen(QDataStream &in) { 286 | this->texCoordGens.append(LYTTexCoordGen()); 287 | this->texCoordGens.last().readFromDataStream(in); 288 | } 289 | 290 | void LYTMaterial::readIndTexSRT(QDataStream &in) { 291 | this->indTexSRTs.append(LYTTexSRT()); 292 | this->indTexSRTs.last().readFromDataStream(in); 293 | } 294 | 295 | void LYTMaterial::readIndirectStage(QDataStream &in) { 296 | this->indTexStages.append(LYTIndirectStage()); 297 | this->indTexStages.last().readFromDataStream(in); 298 | } 299 | 300 | void LYTMaterial::readTevStage(QDataStream &in) { 301 | this->tevStages.append(LYTTevStage()); 302 | this->tevStages.last().readFromDataStream(in); 303 | } 304 | 305 | 306 | -------------------------------------------------------------------------------- /lyt/materials/material.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #ifndef LYTMATERIAL_H 19 | #define LYTMATERIAL_H 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include "../common.h" 27 | #include "texmap.h" 28 | #include "texsrt.h" 29 | #include "texcoordgen.h" 30 | #include "chanctrl.h" 31 | #include "tevswaptable.h" 32 | #include "indirectstage.h" 33 | #include "tevstage.h" 34 | #include "alphacompare.h" 35 | #include "blendmode.h" 36 | 37 | 38 | class LYTLayout; 39 | 40 | 41 | class LYTMaterialResourceNum { 42 | public: 43 | LYTMaterialResourceNum() : m_value(0) { } 44 | LYTMaterialResourceNum(int initValue) : m_value(initValue) { } 45 | 46 | quint32 value() const { return m_value; } 47 | 48 | int getTexMapNum() const { return BitExtract(m_value, 4, 28); } 49 | int getTexSRTNum() const { return BitExtract(m_value, 4, 24); } 50 | int getTexCoordGenNum() const { return BitExtract(m_value, 4, 20); } 51 | bool hasChanCtrl() const { return BitExtract(m_value, 1, 6); } 52 | bool hasMatCol() const { return BitExtract(m_value, 1, 4); } 53 | bool hasTevSwapTable() const { return BitExtract(m_value, 1, 19); } 54 | bool hasAlphaCompare() const { return BitExtract(m_value, 1, 8); } 55 | bool hasBlendMode() const { return BitExtract(m_value, 1, 7); } 56 | int getIndTexSRTNum() const { return BitExtract(m_value, 2, 17); } 57 | int getIndTexStageNum() const { return BitExtract(m_value, 3, 14); } 58 | int getTevStageNum() const { return BitExtract(m_value, 5, 9); } 59 | 60 | void setTexMapNum(int v) { m_value = BitInsert(m_value, v, 4, 28); } 61 | void setTexSRTNum(int v) { m_value = BitInsert(m_value, v, 4, 24); } 62 | void setTexCoordGenNum(int v) { m_value = BitInsert(m_value, v, 4, 20); } 63 | void setHasChanCtrl(bool v) { m_value = BitInsert(m_value, v, 1, 6); } 64 | void setHasMatCol(bool v) { m_value = BitInsert(m_value, v, 1, 4); } 65 | void setHasTevSwapTable(bool v) { m_value = BitInsert(m_value, v, 1, 19); } 66 | void setHasAlphaCompare(bool v) { m_value = BitInsert(m_value, v, 1, 8); } 67 | void setHasBlendMode(bool v) { m_value = BitInsert(m_value, v, 1, 7); } 68 | void setIndTexSRTNum(int v) { m_value = BitInsert(m_value, v, 2, 17); } 69 | void setIndTexStageNum(int v) { m_value = BitInsert(m_value, v, 3, 14); } 70 | void setTevStageNum(int v) { m_value = BitInsert(m_value, v, 5, 9); } 71 | 72 | private: 73 | quint32 m_value; 74 | }; 75 | 76 | 77 | 78 | 79 | 80 | class LYTMaterial { 81 | public: 82 | LYTMaterial(LYTLayout &layout); 83 | ~LYTMaterial(); 84 | 85 | 86 | void writeToDataStream(QDataStream &out) const; 87 | void readFromDataStream(QDataStream &in); 88 | 89 | void dumpToDebug() const; 90 | 91 | LYTLayout &layout() const; 92 | 93 | QString name; 94 | 95 | QColor colours[3]; 96 | QColor tevKColour[4]; 97 | 98 | QList texMaps; 99 | QList texSRTs; 100 | QList texCoordGens; 101 | 102 | bool hasChanCtrl; 103 | LYTChanCtrl chanCtrl; 104 | 105 | bool hasMatCol; 106 | QColor matCol; 107 | 108 | bool hasTevSwapTable; 109 | LYTTevSwapTable tevSwapTable; 110 | 111 | bool hasAlphaCompare; 112 | LYTAlphaCompare alphaCompare; 113 | 114 | bool hasBlendMode; 115 | LYTBlendMode blendMode; 116 | 117 | QList indTexStages; 118 | QList indTexSRTs; 119 | 120 | QList tevStages; 121 | 122 | 123 | 124 | protected: 125 | LYTLayout &m_layout; 126 | 127 | void readTexMap(QDataStream &in); 128 | void readTexSRT(QDataStream &in); 129 | void readTexCoordGen(QDataStream &in); 130 | void readIndirectStage(QDataStream &in); 131 | void readIndTexSRT(QDataStream &in); 132 | void readTevStage(QDataStream &in); 133 | }; 134 | 135 | #endif // LYTMATERIAL_H 136 | -------------------------------------------------------------------------------- /lyt/materials/materialcontainer.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #ifndef LYTMATERIALCONTAINER_H 19 | #define LYTMATERIALCONTAINER_H 20 | 21 | #include 22 | #include 23 | #include "material.h" 24 | 25 | typedef QPair LYTMaterialContainerEntry; 26 | 27 | class LYTMaterialContainer { 28 | public: 29 | LYTMaterialContainer() { }; 30 | 31 | QList list; 32 | 33 | 34 | void addMaterial(QString name, LYTMaterial *material) { 35 | LYTMaterialContainerEntry entry; 36 | entry.first = name; 37 | entry.second = material; 38 | this->list.append(entry); 39 | } 40 | 41 | void clear() { this->list.clear(); } 42 | int count() const { return this->list.count(); } 43 | 44 | 45 | LYTMaterial *getMaterialByName(QString name) const { 46 | foreach (LYTMaterialContainerEntry entry, this->list) { 47 | if (entry.first == name) 48 | return entry.second; 49 | } 50 | 51 | return 0; 52 | } 53 | 54 | LYTMaterial *getMaterialByIndex(int index) const { 55 | return this->list.at(index).second; 56 | } 57 | 58 | int getIndexOfName(QString name) const { 59 | int i = 0; 60 | 61 | foreach (LYTMaterialContainerEntry entry, this->list) { 62 | if (entry.first == name) 63 | return i; 64 | i += 1; 65 | } 66 | 67 | return -1; 68 | } 69 | 70 | 71 | QString getNameOfIndex(int index) const { 72 | return this->list.at(index).first; 73 | } 74 | }; 75 | 76 | #endif // LYTMATERIALCONTAINER_H 77 | -------------------------------------------------------------------------------- /lyt/materials/tevstage.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #include "tevstage.h" 19 | #include "../layout.h" 20 | 21 | LYTTevStage::LYTTevStage() { 22 | } 23 | 24 | void LYTTevStage::dumpToDebug() const { 25 | qDebug() << "LYTTevStage @" << (void*)this; 26 | qDebug() << "TEV order: texCoord" << texCoord << ", colour" << colour << ", texMap" << texMap; 27 | qDebug() << "SwapMode: ras" << rasSwapMode << ", tex" << texSwapMode; 28 | 29 | qDebug() << "Colour In:" << colourInA << colourInB << colourInC << colourInD; 30 | qDebug() << "Op:" << colourOp << ", Bias:" << colourBias << ", Scale:" << colourScale; 31 | qDebug() << "Clamp:" << colourClamp << ", OutReg:" << colourOutReg; 32 | 33 | qDebug() << "Alpha In:" << alphaInA << alphaInB << alphaInC << alphaInD; 34 | qDebug() << "Op:" << alphaOp << ", Bias:" << alphaBias << ", Scale:" << alphaScale; 35 | qDebug() << "Clamp:" << alphaClamp << ", OutReg:" << alphaOutReg; 36 | 37 | qDebug() << "Colour Const:" << colourConst << ", Alpha Const:" << alphaConst; 38 | 39 | qDebug() << "Indirect Stage:" << indStage << ", Format:" << indFormat; 40 | qDebug() << "Bias:" << indBias << ", Matrix:" << indMatrix; 41 | qDebug() << "WrapS:" << indWrapS << ", WrapT:" << indWrapT << ", AddPrev:" << indAddPrev; 42 | qDebug() << "UtcLod:" << indUtcLod << ", AlphaSel:" << indAlphaSel; 43 | } 44 | 45 | 46 | void LYTTevStage::writeToDataStream(QDataStream &out) const { 47 | char data[0x10]; 48 | qMemSet(data, 0, 0x10); 49 | 50 | // TEV order: 51 | data[0] = texCoord; 52 | data[1] = colour; 53 | data[2] = texMap & 0xFF; 54 | data[3] = BitInsert(data[3], texMap >> 8, 1, 32 - 1); 55 | 56 | // SwapMode: 57 | data[3] = BitInsert(data[3], rasSwapMode, 2, 32 - 3); 58 | data[3] = BitInsert(data[3], texSwapMode, 2, 32 - 5); 59 | 60 | // Colour In: 61 | data[4] = BitInsert(data[4], colourInA, 4, 32 - 4); 62 | data[4] = BitInsert(data[4], colourInB, 4, 32 - 8); 63 | data[5] = BitInsert(data[5], colourInC, 4, 32 - 4); 64 | data[5] = BitInsert(data[5], colourInD, 4, 32 - 8); 65 | 66 | // Colour Op: 67 | data[6] = BitInsert(data[6], colourOp, 4, 32 - 4); 68 | data[6] = BitInsert(data[6], colourBias, 2, 32 - 6); 69 | data[6] = BitInsert(data[6], colourScale, 2, 32 - 8); 70 | data[7] = BitInsert(data[7], colourClamp, 1, 32 - 1); 71 | data[7] = BitInsert(data[7], colourOutReg, 2, 32 - 3); 72 | 73 | // Alpha In: 74 | data[8] = BitInsert(data[8], alphaInA, 4, 32 - 4); 75 | data[8] = BitInsert(data[8], alphaInB, 4, 32 - 8); 76 | data[9] = BitInsert(data[9], alphaInC, 4, 32 - 4); 77 | data[9] = BitInsert(data[9], alphaInD, 4, 32 - 8); 78 | 79 | // Alpha Op: 80 | data[10] = BitInsert(data[10], alphaOp, 4, 32 - 4); 81 | data[10] = BitInsert(data[10], alphaBias, 2, 32 - 6); 82 | data[10] = BitInsert(data[10], alphaScale, 2, 32 - 8); 83 | data[11] = BitInsert(data[11], alphaClamp, 1, 32 - 1); 84 | data[11] = BitInsert(data[11], alphaOutReg, 2, 32 - 3); 85 | 86 | // Constants: 87 | data[7] = BitInsert(data[7], colourConst, 5, 32 - 8); 88 | data[11] = BitInsert(data[11], alphaConst, 5, 32 - 8); 89 | 90 | // Indirect: 91 | data[12] = indStage; 92 | data[15] = BitInsert(data[15], indFormat, 2, 32 - 2); 93 | data[13] = BitInsert(data[13], indBias, 3, 32 - 3); 94 | data[13] = BitInsert(data[13], indMatrix, 4, 32 - 7); 95 | data[14] = BitInsert(data[14], indWrapS, 3, 32 - 3); 96 | data[14] = BitInsert(data[14], indWrapT, 3, 32 - 6); 97 | data[15] = BitInsert(data[15], indAddPrev, 1, 32 - 3); 98 | data[15] = BitInsert(data[15], indUtcLod, 1, 32 - 4); 99 | data[15] = BitInsert(data[15], indAlphaSel, 2, 32 - 6); 100 | 101 | out.writeRawData(data, 0x10); 102 | } 103 | 104 | 105 | void LYTTevStage::readFromDataStream(QDataStream &in) { 106 | // not fun. at all. 107 | 108 | char data[0x10]; 109 | in.readRawData(data, 0x10); 110 | 111 | // TEV order: 112 | texCoord = data[0]; 113 | colour = data[1]; 114 | texMap = data[2] | (BitExtract(data[3], 1, 32 - 1) << 8); 115 | 116 | // SwapMode: 117 | rasSwapMode = BitExtract(data[3], 2, 32 - 3); 118 | texSwapMode = BitExtract(data[3], 2, 32 - 5); 119 | 120 | // Colour In: 121 | colourInA = BitExtract(data[4], 4, 32 - 4); 122 | colourInB = BitExtract(data[4], 4, 32 - 8); 123 | colourInC = BitExtract(data[5], 4, 32 - 4); 124 | colourInD = BitExtract(data[5], 4, 32 - 8); 125 | 126 | // Colour Op: 127 | colourOp = BitExtract(data[6], 4, 32 - 4); 128 | colourBias = BitExtract(data[6], 2, 32 - 6); 129 | colourScale = BitExtract(data[6], 2, 32 - 8); 130 | colourClamp = BitExtract(data[7], 1, 32 - 1); 131 | colourOutReg = BitExtract(data[7], 2, 32 - 3); 132 | 133 | // Alpha In: 134 | alphaInA = BitExtract(data[8], 4, 32 - 4); 135 | alphaInB = BitExtract(data[8], 4, 32 - 8); 136 | alphaInC = BitExtract(data[9], 4, 32 - 4); 137 | alphaInD = BitExtract(data[9], 4, 32 - 8); 138 | 139 | // Alpha Op: 140 | alphaOp = BitExtract(data[10], 4, 32 - 4); 141 | alphaBias = BitExtract(data[10], 2, 32 - 6); 142 | alphaScale = BitExtract(data[10], 2, 32 - 8); 143 | alphaClamp = BitExtract(data[11], 1, 32 - 1); 144 | alphaOutReg = BitExtract(data[11], 2, 32 - 3); 145 | 146 | // Constants: 147 | colourConst = BitExtract(data[7], 5, 32 - 8); 148 | alphaConst = BitExtract(data[11], 5, 32 - 8); 149 | 150 | // Indirect: 151 | indStage = data[12]; 152 | indFormat = BitExtract(data[15], 2, 32 - 2); 153 | indBias = BitExtract(data[13], 3, 32 - 3); 154 | indMatrix = BitExtract(data[13], 4, 32 - 7); 155 | indWrapS = BitExtract(data[14], 3, 32 - 3); 156 | indWrapT = BitExtract(data[14], 3, 32 - 6); 157 | indAddPrev = BitExtract(data[15], 1, 32 - 3); 158 | indUtcLod = BitExtract(data[15], 1, 32 - 4); 159 | indAlphaSel = BitExtract(data[15], 2, 32 - 6); 160 | } 161 | 162 | 163 | 164 | -------------------------------------------------------------------------------- /lyt/materials/tevstage.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #ifndef LYTTEVSTAGE_H 19 | #define LYTTEVSTAGE_H 20 | 21 | #include "../common.h" 22 | #include 23 | 24 | class LYTTevStage { 25 | public: 26 | LYTTevStage(); 27 | 28 | void writeToDataStream(QDataStream &out) const; 29 | void readFromDataStream(QDataStream &in); 30 | 31 | void dumpToDebug() const; 32 | 33 | // TEV order: 34 | int texCoord; 35 | int colour; 36 | int texMap; 37 | 38 | // SwapMode; 39 | int rasSwapMode; 40 | int texSwapMode; 41 | 42 | // Colour In: 43 | int colourInA; 44 | int colourInB; 45 | int colourInC; 46 | int colourInD; 47 | 48 | // Colour Op: 49 | int colourOp; 50 | int colourBias; 51 | int colourScale; 52 | int colourClamp; 53 | int colourOutReg; 54 | 55 | // Alpha In: 56 | int alphaInA; 57 | int alphaInB; 58 | int alphaInC; 59 | int alphaInD; 60 | 61 | // Alpha Op: 62 | int alphaOp; 63 | int alphaBias; 64 | int alphaScale; 65 | int alphaClamp; 66 | int alphaOutReg; 67 | 68 | // Constants: 69 | int colourConst; 70 | int alphaConst; 71 | 72 | // Indirect: 73 | int indStage; 74 | int indFormat; 75 | int indBias; 76 | int indMatrix; 77 | int indWrapS; 78 | int indWrapT; 79 | int indAddPrev; 80 | int indUtcLod; 81 | int indAlphaSel; 82 | }; 83 | 84 | 85 | #endif // LYTTEVSAGE_H 86 | -------------------------------------------------------------------------------- /lyt/materials/tevswaptable.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #include "tevswaptable.h" 19 | #include "../layout.h" 20 | 21 | LYTTevSwapTable::LYTTevSwapTable() { 22 | } 23 | 24 | void LYTTevSwapTable::dumpToDebug() const { 25 | qDebug() << "LYTTevSwapTable @" << (void*)this; 26 | 27 | for (int i = 0; i < 4; i++) { 28 | const LYTTevSwapMode *m = &mode[i]; 29 | qDebug() << i << ":" << m->red << "," << m->green << "," << m->blue << "," << m->alpha; 30 | } 31 | } 32 | 33 | 34 | 35 | void LYTTevSwapTable::writeToDataStream(QDataStream &out) const { 36 | for (int i = 0; i < 4; i++) { 37 | quint8 val = 0; 38 | val |= mode[i].red; 39 | val |= (mode[i].green) << 2; 40 | val |= (mode[i].blue) << 4; 41 | val |= (mode[i].alpha) << 6; 42 | 43 | out << (quint8)val; 44 | } 45 | } 46 | 47 | 48 | void LYTTevSwapTable::readFromDataStream(QDataStream &in) { 49 | for (int i = 0; i < 4; i++) { 50 | quint8 val; 51 | in >> (quint8&)val; 52 | 53 | mode[i].red = BitExtract(val, 2, 32 - 8); 54 | mode[i].green = BitExtract(val, 2, 32 - 6); 55 | mode[i].blue = BitExtract(val, 2, 32 - 4); 56 | mode[i].alpha = BitExtract(val, 2, 32 - 2); 57 | } 58 | } 59 | 60 | 61 | -------------------------------------------------------------------------------- /lyt/materials/tevswaptable.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #ifndef LYTTEVSWAPTABLE_H 19 | #define LYTTEVSWAPTABLE_H 20 | 21 | #include "../common.h" 22 | #include 23 | 24 | struct LYTTevSwapMode { 25 | int red; 26 | int green; 27 | int blue; 28 | int alpha; 29 | }; 30 | 31 | class LYTTevSwapTable { 32 | public: 33 | LYTTevSwapTable(); 34 | 35 | void writeToDataStream(QDataStream &out) const; 36 | void readFromDataStream(QDataStream &in); 37 | 38 | void dumpToDebug() const; 39 | 40 | LYTTevSwapMode mode[4]; 41 | }; 42 | 43 | #endif // LYTTEVSWAPTABLE_H 44 | -------------------------------------------------------------------------------- /lyt/materials/texcoordgen.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #include "texcoordgen.h" 19 | #include "../layout.h" 20 | 21 | LYTTexCoordGen::LYTTexCoordGen() { 22 | } 23 | 24 | void LYTTexCoordGen::dumpToDebug() const { 25 | qDebug() << "LYTTexCoordGen @" << (void*)this; 26 | qDebug() << "GenType:" << genType << "- Mtx:" << mtx << "- Src:" << src; 27 | } 28 | 29 | 30 | void LYTTexCoordGen::writeToDataStream(QDataStream &out) const { 31 | out << (quint8)genType; 32 | out << (quint8)src; 33 | out << (quint8)mtx; 34 | WritePadding(1, out); 35 | } 36 | 37 | 38 | void LYTTexCoordGen::readFromDataStream(QDataStream &in) { 39 | in >> (quint8&)genType; 40 | in >> (quint8&)src; 41 | in >> (quint8&)mtx; 42 | in.skipRawData(1); // padding 43 | } 44 | 45 | -------------------------------------------------------------------------------- /lyt/materials/texcoordgen.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #ifndef LYTTEXCOORDGEN_H 19 | #define LYTTEXCOORDGEN_H 20 | 21 | #include "../common.h" 22 | #include 23 | 24 | class LYTTexCoordGen { 25 | public: 26 | LYTTexCoordGen(); 27 | 28 | void writeToDataStream(QDataStream &out) const; 29 | void readFromDataStream(QDataStream &in); 30 | 31 | void dumpToDebug() const; 32 | 33 | quint8 genType; 34 | quint8 src; 35 | quint8 mtx; 36 | }; 37 | 38 | #endif // LYTTEXCOORDGEN_H 39 | -------------------------------------------------------------------------------- /lyt/materials/texmap.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #include "texmap.h" 19 | #include "../layout.h" 20 | 21 | LYTTexMap::LYTTexMap() { 22 | } 23 | 24 | void LYTTexMap::dumpToDebug() const { 25 | qDebug() << "LYTTexMap @" << (void*)this << ":" << textureName; 26 | qDebug() << "- wrap_s:" << wrap_s << "- wrap_t:" << wrap_t; 27 | qDebug() << "- mag_filter:" << mag_filter << "- min_filter:" << min_filter; 28 | } 29 | 30 | 31 | void LYTTexMap::writeToDataStream(QDataStream &out, LYTLayout &layout) const { 32 | quint16 texNum = layout.m_textureRefs.indexOf(textureName); 33 | out << (quint16)texNum; 34 | 35 | quint8 var1, var2; 36 | var1 = wrap_s | (((min_filter + 7) & 7) << 2); 37 | var2 = wrap_t | (((mag_filter + 1) & 1) << 2); 38 | out << (quint8)var1; 39 | out << (quint8)var2; 40 | } 41 | 42 | 43 | void LYTTexMap::readFromDataStream(QDataStream &in, LYTLayout &layout) { 44 | quint16 texNum; 45 | in >> (quint16&)texNum; 46 | 47 | textureName = layout.m_textureRefs[texNum]; 48 | 49 | quint8 var1, var2; 50 | in >> (quint8&)var1; 51 | in >> (quint8&)var2; 52 | 53 | wrap_s = BitExtract(var1, 2, 30); 54 | wrap_t = BitExtract(var2, 2, 30); 55 | 56 | min_filter = (BitExtract(var1, 3, 27) + 1) & 7; 57 | mag_filter = (BitExtract(var2, 1, 29) + 1) & 1; 58 | } 59 | -------------------------------------------------------------------------------- /lyt/materials/texmap.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #ifndef LYTTEXMAP_H 19 | #define LYTTEXMAP_H 20 | 21 | #include "../common.h" 22 | #include 23 | 24 | class LYTLayout; // forward declaration 25 | 26 | class LYTTexMap { 27 | public: 28 | LYTTexMap(); 29 | 30 | void writeToDataStream(QDataStream &out, LYTLayout &layout) const; 31 | void readFromDataStream(QDataStream &in, LYTLayout &layout); 32 | 33 | void dumpToDebug() const; 34 | 35 | QString textureName; 36 | int wrap_s; 37 | int wrap_t; 38 | int mag_filter; 39 | int min_filter; 40 | }; 41 | 42 | #endif // LYTTEXMAP_H 43 | -------------------------------------------------------------------------------- /lyt/materials/texsrt.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #include "texsrt.h" 19 | #include "../layout.h" 20 | 21 | LYTTexSRT::LYTTexSRT() { 22 | } 23 | 24 | void LYTTexSRT::dumpToDebug() const { 25 | qDebug() << "LYTTexSRT @" << (void*)this; 26 | qDebug() << "Scale:" << xScale << "," << yScale; 27 | qDebug() << "Rotation:" << rotate; 28 | qDebug() << "Translation:" << xTrans << "," << yTrans; 29 | } 30 | 31 | 32 | void LYTTexSRT::writeToDataStream(QDataStream &out) const { 33 | out << (float)xTrans; 34 | out << (float)yTrans; 35 | out << (float)rotate; 36 | out << (float)xScale; 37 | out << (float)yScale; 38 | } 39 | 40 | 41 | void LYTTexSRT::readFromDataStream(QDataStream &in) { 42 | in >> (float&)xTrans; 43 | in >> (float&)yTrans; 44 | in >> (float&)rotate; 45 | in >> (float&)xScale; 46 | in >> (float&)yScale; 47 | } 48 | 49 | -------------------------------------------------------------------------------- /lyt/materials/texsrt.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #ifndef LYTTEXSRT_H 19 | #define LYTTEXSRT_H 20 | 21 | #include "../common.h" 22 | #include 23 | 24 | class LYTTexSRT { 25 | public: 26 | LYTTexSRT(); 27 | 28 | void writeToDataStream(QDataStream &out) const; 29 | void readFromDataStream(QDataStream &in); 30 | 31 | void dumpToDebug() const; 32 | 33 | float xTrans; 34 | float yTrans; 35 | float rotate; 36 | float xScale; 37 | float yScale; 38 | }; 39 | 40 | #endif // LYTTEXSRT_H 41 | -------------------------------------------------------------------------------- /lyt/packagebase.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #include "packagebase.h" 19 | 20 | LYTPackageBase::LYTPackageBase(QObject *parent) : QObject(parent) { 21 | // do nothing 22 | } 23 | 24 | LYTPackageBase::~LYTPackageBase() { 25 | } 26 | 27 | 28 | 29 | QString LYTPackageBase::defaultPathForItemType(ItemType type, bool withArc) { 30 | switch (type) { 31 | case Layout: 32 | return withArc ? "arc/blyt" : "blyt"; 33 | case Animation: 34 | return withArc ? "arc/anim" : "anim"; 35 | case Texture: 36 | return withArc ? "arc/timg" : "timg"; 37 | case Font: 38 | return withArc ? "arc/font" : "font"; 39 | default: 40 | return QString(); 41 | } 42 | } 43 | 44 | 45 | QByteArray LYTPackageBase::createSkeletonItem(ItemType type) { 46 | return QByteArray(); 47 | } 48 | -------------------------------------------------------------------------------- /lyt/packagebase.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #ifndef LYTPACKAGEBASE_H 19 | #define LYTPACKAGEBASE_H 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | 26 | class LYTPackageBase : public QObject { 27 | Q_OBJECT 28 | public: 29 | LYTPackageBase(QObject *parent = 0); 30 | virtual ~LYTPackageBase(); 31 | 32 | enum ItemType { 33 | Layout = 1, 34 | Animation, 35 | Texture, 36 | Font 37 | }; 38 | 39 | static QString defaultPathForItemType(ItemType type, bool withArc=false); 40 | static QByteArray createSkeletonItem(ItemType type); 41 | 42 | virtual QStringList list(ItemType type) const = 0; 43 | virtual QByteArray get(ItemType type, const QString &name) const = 0; 44 | virtual bool write(ItemType type, const QString &name, const QByteArray &data) = 0; 45 | virtual bool rename(ItemType type, const QString &from, const QString &to) = 0; 46 | virtual bool remove(ItemType type, const QString &name) = 0; 47 | 48 | // Shortcuts 49 | #define MakeThing(THING, ENUMVAL) \ 50 | QStringList list##THING##s () const { return list(ENUMVAL); } \ 51 | QByteArray get##THING (const QString &name) const \ 52 | { return get(ENUMVAL, name); } \ 53 | \ 54 | bool write##THING (const QString &name, const QByteArray &data) \ 55 | { return write(ENUMVAL, name, data); } \ 56 | \ 57 | bool remove##THING(const QString &name) { return remove(ENUMVAL, name); } 58 | 59 | // Use it 60 | MakeThing(Layout, Layout) 61 | MakeThing(Anim, Animation) 62 | MakeThing(Texture, Texture) 63 | MakeThing(Font, Font) 64 | 65 | #undef MakeThing 66 | 67 | virtual bool needsExplicitSave() const = 0; 68 | virtual bool savePackage() = 0; 69 | virtual QString description() const = 0; 70 | 71 | signals: 72 | void aboutToAddFile(LYTPackageBase::ItemType type, QString name); 73 | void aboutToRemoveFile(LYTPackageBase::ItemType type, QString name); 74 | void aboutToRenameFile(LYTPackageBase::ItemType type, QString from, QString to); 75 | void aboutToModifyFile(LYTPackageBase::ItemType type, QString name); 76 | 77 | void fileWasAdded(LYTPackageBase::ItemType type, QString name); 78 | void fileWasRemoved(LYTPackageBase::ItemType type, QString name); 79 | void fileWasRenamed(LYTPackageBase::ItemType type, QString from, QString to); 80 | void fileWasModified(LYTPackageBase::ItemType type, QString name); 81 | }; 82 | 83 | #endif // LYTPACKAGEBASE_H 84 | -------------------------------------------------------------------------------- /lyt/pane.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #include "pane.h" 19 | #include "layout.h" 20 | 21 | LYTPane::LYTPane(LYTLayout &layout) : m_layout(layout) { 22 | this->parent = 0; 23 | m_type = PaneType; 24 | } 25 | 26 | LYTPane::~LYTPane() { 27 | foreach (LYTPane *ptr, this->children) 28 | delete ptr; 29 | } 30 | 31 | LYTPane *LYTPane::findPaneByName(QString name, bool recursive) const { 32 | foreach (LYTPane *pane, this->children) { 33 | if (pane->name == name) 34 | return pane; 35 | 36 | if (recursive) { 37 | LYTPane *tryThis = pane->findPaneByName(name, recursive); 38 | if (tryThis != 0) 39 | return tryThis; 40 | } 41 | } 42 | 43 | return 0; 44 | } 45 | 46 | LYTLayout &LYTPane::layout() const { 47 | return m_layout; 48 | } 49 | 50 | 51 | Magic LYTPane::magic() const { 52 | return Magic('pan1'); 53 | } 54 | 55 | void LYTPane::dumpToDebug(bool showHeading) const { 56 | if (showHeading) 57 | qDebug() << "LYTPane" << name << "@" << (void*)this; 58 | 59 | qDebug() << "- Translation:" << xTrans << "," << yTrans << "," << zTrans; 60 | qDebug() << "- Rotation:" << xRot << "," << yRot << "," << zRot; 61 | qDebug() << "- Scale:" << xScale << "," << yScale; 62 | qDebug() << "- Size:" << width << "x" << height; 63 | qDebug() << "- Visible:" << visible << "- Influenced Alpha:" << influencedAlpha << "- Widescreen:" << isWidescreen; 64 | qDebug() << "- Origin:" << horzOrigin << "," << vertOrigin; 65 | qDebug() << "- Alpha:" << alpha << "- Userdata:" << userdata; 66 | } 67 | 68 | 69 | 70 | void LYTPane::writeToDataStream(QDataStream &out) const { 71 | quint8 flags = 72 | (visible ? 1 : 0) | 73 | (influencedAlpha ? 2 : 0) | 74 | (isWidescreen ? 4 : 0); 75 | 76 | out << (quint8)flags; 77 | out << (quint8)((int)horzOrigin + ((int)vertOrigin * 3)); 78 | out << (quint8)alpha; 79 | WritePadding(1, out); 80 | 81 | WriteFixedLengthASCII(out, name, 0x10); 82 | WriteFixedLengthASCII(out, userdata, 8); 83 | 84 | out << (float)xTrans; 85 | out << (float)yTrans; 86 | out << (float)zTrans; 87 | out << (float)xRot; 88 | out << (float)yRot; 89 | out << (float)zRot; 90 | out << (float)xScale; 91 | out << (float)yScale; 92 | out << (float)width; 93 | out << (float)height; 94 | } 95 | 96 | void LYTPane::readFromDataStream(QDataStream &in) { 97 | quint8 flags; 98 | in >> flags; 99 | 100 | visible = (flags & 1); 101 | influencedAlpha = (flags & 2); 102 | isWidescreen = (flags & 4); 103 | 104 | quint8 rawOrigin; 105 | in >> rawOrigin; 106 | horzOrigin = (OriginType)(rawOrigin % 3); 107 | vertOrigin = (OriginType)(rawOrigin / 3); 108 | in >> (quint8&)alpha; 109 | in.skipRawData(1); // padding 110 | 111 | name = ReadFixedLengthASCII(in, 0x10); 112 | userdata = ReadFixedLengthASCII(in, 8); 113 | 114 | in >> (float&)xTrans; 115 | in >> (float&)yTrans; 116 | in >> (float&)zTrans; 117 | in >> (float&)xRot; 118 | in >> (float&)yRot; 119 | in >> (float&)zRot; 120 | in >> (float&)xScale; 121 | in >> (float&)yScale; 122 | in >> (float&)width; 123 | in >> (float&)height; 124 | } 125 | 126 | 127 | void LYTPane::addFontRefsToList(QStringList &list) const { 128 | //qDebug() << "Getting font refs for" << this->name; 129 | 130 | foreach (LYTPane *p, this->children) { 131 | p->addFontRefsToList(list); 132 | } 133 | } 134 | 135 | 136 | float LYTPane::drawnVertexX() const { 137 | switch (horzOrigin) { 138 | case Center: 139 | return -width / 2.0f; 140 | case Right: 141 | return -width; 142 | default: 143 | return 0.0f; 144 | } 145 | } 146 | 147 | float LYTPane::drawnVertexY() const { 148 | switch (vertOrigin) { 149 | case Center: 150 | return height / 2.0f; 151 | case Bottom: 152 | return height; 153 | default: 154 | return 0.0f; 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /lyt/pane.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #ifndef LYTPANE_H 19 | #define LYTPANE_H 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include "common.h" 27 | 28 | class LYTLayout; 29 | 30 | class LYTPane { 31 | public: 32 | LYTPane(LYTLayout &layout); 33 | virtual ~LYTPane(); 34 | 35 | 36 | virtual Magic magic() const; 37 | 38 | enum PaneTypes { 39 | PaneType = 0, PictureType, TextBoxType, WindowType, BoundingType, PaneTypeCount 40 | }; 41 | 42 | virtual void writeToDataStream(QDataStream &out) const; 43 | virtual void readFromDataStream(QDataStream &in); 44 | 45 | virtual void dumpToDebug(bool showHeading=true) const; 46 | 47 | virtual void addFontRefsToList(QStringList &list) const; 48 | 49 | LYTPane *findPaneByName(QString name, bool recursive) const; 50 | 51 | LYTLayout &layout() const; 52 | 53 | LYTPane *parent; 54 | QList children; 55 | 56 | bool visible, influencedAlpha, isWidescreen; 57 | 58 | enum OriginType { 59 | Left = 0, Top = 0, 60 | Center = 1, 61 | Right = 2, Bottom = 2 62 | }; 63 | OriginType horzOrigin; 64 | OriginType vertOrigin; 65 | 66 | float drawnVertexX() const; 67 | float drawnVertexY() const; 68 | 69 | quint8 alpha; 70 | 71 | QString name; 72 | QString userdata; 73 | 74 | float xTrans; 75 | float yTrans; 76 | float zTrans; 77 | 78 | float xRot; 79 | float yRot; 80 | float zRot; 81 | 82 | float xScale; 83 | float yScale; 84 | 85 | float width; 86 | float height; 87 | 88 | PaneTypes type() const { return m_type; } 89 | 90 | protected: 91 | LYTLayout &m_layout; 92 | PaneTypes m_type; 93 | }; 94 | 95 | 96 | 97 | #endif // LYTPANE_H 98 | -------------------------------------------------------------------------------- /lyt/picture.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #include "picture.h" 19 | #include "layout.h" 20 | #include "common.h" 21 | 22 | 23 | LYTPicture::LYTPicture(LYTLayout &layout) : LYTPane(layout) { 24 | m_type = PictureType; 25 | } 26 | 27 | 28 | Magic LYTPicture::magic() const { 29 | return Magic('pic1'); 30 | } 31 | 32 | 33 | void LYTPicture::dumpToDebug(bool showHeading) const { 34 | if (showHeading) 35 | qDebug() << "LYTPicture" << name << "@" << (void*)this; 36 | 37 | LYTPane::dumpToDebug(false); 38 | 39 | qDebug() << "- Vertex Colours:" << vtxColours[0] << "-" << vtxColours[1]; 40 | qDebug() << " " << vtxColours[2] << "-" << vtxColours[3]; 41 | qDebug() << "- Material:" << materialName; 42 | qDebug() << "- Tex Coords:" << texCoords.count(); 43 | 44 | foreach (LYTTexCoords texCoord, texCoords) { 45 | qDebug() << "----" << texCoord.coord[0] << "-" << texCoord.coord[1] << "-" << texCoord.coord[2] << "-" << texCoord.coord[3]; 46 | } 47 | } 48 | 49 | 50 | 51 | 52 | void LYTPicture::writeToDataStream(QDataStream &out) const { 53 | LYTPane::writeToDataStream(out); 54 | 55 | for (int i = 0; i < 4; i++) 56 | WriteRGBA8Color(vtxColours[i], out); 57 | 58 | // calculate the material number 59 | int materialNum = m_layout.materials.getIndexOfName(materialName); 60 | out << (quint16)materialNum; 61 | 62 | // write texcoords 63 | out << (quint8)texCoords.count(); 64 | WritePadding(1, out); 65 | 66 | foreach (LYTTexCoords texCoord, texCoords) { 67 | for (int i = 0; i < 4; i++) 68 | WritePointF(out, texCoord.coord[i]); 69 | } 70 | } 71 | 72 | 73 | void LYTPicture::readFromDataStream(QDataStream &in) { 74 | LYTPane::readFromDataStream(in); 75 | 76 | for (int i = 0; i < 4; i++) 77 | ReadRGBA8Color(vtxColours[i], in); 78 | 79 | // read the material name 80 | quint16 materialNum; 81 | in >> (quint16&)materialNum; 82 | 83 | materialName = m_layout.materials.getNameOfIndex(materialNum); 84 | 85 | // read texcoords 86 | quint8 texCoordNum; 87 | in >> (quint8&)texCoordNum; 88 | in.skipRawData(1); // padding 89 | 90 | texCoords.resize(texCoordNum); 91 | 92 | for (int i = 0; i < texCoordNum; i++) { 93 | for (int j = 0; j < 4; j++) 94 | ReadPointF(in, texCoords[i].coord[j]); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /lyt/picture.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #ifndef LYTPICTURE_H 19 | #define LYTPICTURE_H 20 | 21 | #include 22 | #include 23 | 24 | #include "common.h" 25 | #include "pane.h" 26 | 27 | class LYTPicture : public LYTPane { 28 | public: 29 | LYTPicture(LYTLayout &layout); 30 | 31 | 32 | Magic magic() const; 33 | 34 | void writeToDataStream(QDataStream &out) const; 35 | void readFromDataStream(QDataStream &in); 36 | 37 | void dumpToDebug(bool showHeading=true) const; 38 | 39 | QColor vtxColours[4]; 40 | QString materialName; 41 | 42 | QVector texCoords; 43 | }; 44 | 45 | 46 | #endif // LYTPICTURE_H 47 | -------------------------------------------------------------------------------- /lyt/textbox.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #include "textbox.h" 19 | #include "layout.h" 20 | #include "common.h" 21 | 22 | 23 | LYTTextBox::LYTTextBox(LYTLayout &layout) : LYTPane(layout) { 24 | m_type = TextBoxType; 25 | } 26 | 27 | 28 | Magic LYTTextBox::magic() const { 29 | return Magic('txt1'); 30 | } 31 | 32 | 33 | void LYTTextBox::dumpToDebug(bool showHeading) const { 34 | if (showHeading) 35 | qDebug() << "LYTTextBox" << name << "@" << (void*)this; 36 | 37 | LYTPane::dumpToDebug(false); 38 | 39 | qDebug() << "- Text:" << text; 40 | qDebug() << "- Buffer Length:" << bufferLength; 41 | qDebug() << "- Material:" << materialName << "- Font:" << fontName; 42 | qDebug() << "- Alignment:" << alignment << "- Alignment Override:" << alignmentOverride; 43 | qDebug() << "- Colours:" << colour1 << "--" << colour2; 44 | qDebug() << "- Font Size:" << fontSizeX << "x" << fontSizeY; 45 | qDebug() << "- Char Space:" << charSpace << "- Line Space:" << lineSpace; 46 | } 47 | 48 | 49 | 50 | void LYTTextBox::writeToDataStream(QDataStream &out) const { 51 | LYTPane::writeToDataStream(out); 52 | 53 | // lengths are stored in bytes (including zero terminator) not characters 54 | out << (quint16)((bufferLength + 1) * 2); 55 | out << (quint16)((text.length() + 1) * 2); 56 | 57 | // calculate the material and font numbers 58 | int materialNum = m_layout.materials.getIndexOfName(materialName); 59 | int fontNum = m_layout.m_fontRefs.indexOf(fontName); 60 | 61 | out << (quint16)materialNum; 62 | out << (quint16)fontNum; 63 | 64 | out << (quint8)alignment; 65 | out << (quint8)alignmentOverride; 66 | 67 | WritePadding(2, out); 68 | 69 | out << (quint32)0x74; // fixed offset to textbox contents 70 | 71 | WriteRGBA8Color(colour1, out); 72 | WriteRGBA8Color(colour2, out); 73 | 74 | out << (float)fontSizeX; 75 | out << (float)fontSizeY; 76 | out << (float)charSpace; 77 | out << (float)lineSpace; 78 | 79 | // write the textbox contents 80 | const ushort *convertedText = text.utf16(); 81 | for (int i = 0; i < text.length(); i++) 82 | out << (quint16)convertedText[i]; 83 | 84 | out << (quint16)0; // zeroterm 85 | } 86 | 87 | 88 | void LYTTextBox::readFromDataStream(QDataStream &in) { 89 | qint64 saveStartPos = in.device()->pos(); 90 | 91 | LYTPane::readFromDataStream(in); 92 | 93 | // the lengths are stored in bytes (not characters) and count the 94 | // zero terminator, and strings are UTF-16 (I think) so we need 95 | // to take it off here 96 | in >> (quint16&)bufferLength; 97 | bufferLength >>= 1; 98 | bufferLength--; 99 | 100 | quint16 stringLength; 101 | in >> (quint16&)stringLength; 102 | stringLength >>= 1; 103 | stringLength--; 104 | 105 | // read the material and font names 106 | quint16 materialNum, fontNum; 107 | in >> (quint16&)materialNum; 108 | in >> (quint16&)fontNum; 109 | 110 | materialName = m_layout.materials.getNameOfIndex(materialNum); 111 | fontName = m_layout.m_fontRefs.at(fontNum); 112 | 113 | in >> (quint8&)alignment; 114 | in >> (quint8&)alignmentOverride; 115 | 116 | in.skipRawData(2); // padding 117 | 118 | quint32 stringOffset; 119 | in >> (quint32&)stringOffset; 120 | 121 | ReadRGBA8Color(colour1, in); 122 | ReadRGBA8Color(colour2, in); 123 | 124 | in >> (float&)fontSizeX; 125 | in >> (float&)fontSizeY; 126 | in >> (float&)charSpace; 127 | in >> (float&)lineSpace; 128 | 129 | // read the textbox contents 130 | // subtract 8 to account for BinaryBlockHeader or whatever it's called 131 | in.device()->seek(saveStartPos + stringOffset - 8); 132 | 133 | ushort *rawText = new ushort[stringLength]; 134 | 135 | for (int i = 0; i < stringLength; i++) 136 | in >> (quint16&)rawText[i]; 137 | 138 | text.setUtf16(rawText, stringLength); 139 | delete[] rawText; 140 | } 141 | 142 | 143 | void LYTTextBox::addFontRefsToList(QStringList &list) const { 144 | LYTPane::addFontRefsToList(list); 145 | 146 | if (!list.contains(this->fontName)) { 147 | list.append(this->fontName); 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /lyt/textbox.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #ifndef LYTTEXTBOX_H 19 | #define LYTTEXTBOX_H 20 | 21 | #include 22 | 23 | #include "pane.h" 24 | 25 | class LYTTextBox : public LYTPane { 26 | public: 27 | LYTTextBox(LYTLayout &layout); 28 | 29 | 30 | Magic magic() const; 31 | 32 | void writeToDataStream(QDataStream &out) const; 33 | void readFromDataStream(QDataStream &in); 34 | 35 | void dumpToDebug(bool showHeading=true) const; 36 | 37 | void addFontRefsToList(QStringList &list) const; 38 | 39 | quint16 bufferLength; 40 | QString text; 41 | 42 | QString materialName; 43 | QString fontName; 44 | 45 | quint8 alignment; 46 | quint8 alignmentOverride; 47 | 48 | QColor colour1; 49 | QColor colour2; 50 | 51 | float fontSizeX; 52 | float fontSizeY; 53 | float charSpace; 54 | float lineSpace; 55 | }; 56 | 57 | 58 | #endif // LYTTEXTBOX_H 59 | -------------------------------------------------------------------------------- /lyt/window.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #include "window.h" 19 | #include "layout.h" 20 | #include "common.h" 21 | 22 | 23 | LYTWindowFrame::LYTWindowFrame(LYTWindow &window) : m_window(window) { 24 | } 25 | 26 | void LYTWindowFrame::writeToDataStream(QDataStream &out) const { 27 | // calculate the material number 28 | int materialNum = m_window.m_layout.materials.getIndexOfName(materialName); 29 | out << (quint16)materialNum; 30 | 31 | out << (quint8)type; 32 | WritePadding(1, out); 33 | } 34 | 35 | void LYTWindowFrame::readFromDataStream(QDataStream &in) { 36 | // read the material name 37 | quint16 materialNum; 38 | in >> (quint16&)materialNum; 39 | 40 | materialName = m_window.m_layout.materials.getNameOfIndex(materialNum); 41 | 42 | in >> (quint8&)type; 43 | in.skipRawData(1); // padding 44 | } 45 | 46 | void LYTWindowFrame::dumpToDebug() const { 47 | qDebug() << "LYTWindowFrame @" << (void*)this << "- type:" << type << "- material:" << materialName; 48 | } 49 | 50 | 51 | 52 | LYTWindow::LYTWindow(LYTLayout &layout) : LYTPane(layout) { 53 | m_type = WindowType; 54 | } 55 | 56 | LYTWindow::~LYTWindow() { 57 | foreach (LYTWindowFrame *frame, frames) 58 | delete frame; 59 | } 60 | 61 | 62 | 63 | Magic LYTWindow::magic() const { 64 | return Magic('wnd1'); 65 | } 66 | 67 | 68 | void LYTWindow::dumpToDebug(bool showHeading) const { 69 | if (showHeading) 70 | qDebug() << "LYTWindow" << name << "@" << (void*)this; 71 | 72 | LYTPane::dumpToDebug(false); 73 | 74 | qDebug() << "- Content VtxColours:" << contentVtxColours[0] << "-" << contentVtxColours[1]; 75 | qDebug() << " " << contentVtxColours[2] << "-" << contentVtxColours[3]; 76 | qDebug() << "- Content Material:" << contentMaterialName; 77 | qDebug() << "- Content Tex Coords:" << contentTexCoords.count(); 78 | 79 | foreach (LYTTexCoords texCoord, contentTexCoords) { 80 | qDebug() << "----" << texCoord.coord[0] << "-" << texCoord.coord[1] << "-" << texCoord.coord[2] << "-" << texCoord.coord[3]; 81 | } 82 | 83 | qDebug() << "- Content Overflow: Left" << contentOverflowLeft << "- Right" << contentOverflowRight; 84 | qDebug() << " Top" << contentOverflowTop << "- Bottom" << contentOverflowBottom; 85 | 86 | qDebug() << "- Frames:" << frames.count(); 87 | 88 | foreach (LYTWindowFrame *frame, frames) { 89 | frame->dumpToDebug(); 90 | } 91 | } 92 | 93 | 94 | 95 | void LYTWindow::writeToDataStream(QDataStream &out) const { 96 | LYTPane::writeToDataStream(out); 97 | 98 | out << (float)contentOverflowLeft; 99 | out << (float)contentOverflowRight; 100 | out << (float)contentOverflowTop; 101 | out << (float)contentOverflowBottom; 102 | 103 | out << (quint8)frames.count(); 104 | WritePadding(3, out); 105 | 106 | out << (quint32)0x68; // offset to content struct 107 | out << (quint32)(0x7C + (contentTexCoords.count()*0x20)); // offset to frame offset list 108 | 109 | for (int i = 0; i < 4; i++) 110 | WriteRGBA8Color(contentVtxColours[i], out); 111 | 112 | // calculate the material number 113 | int materialNum = m_layout.materials.getIndexOfName(contentMaterialName); 114 | out << (quint16)materialNum; 115 | 116 | // write texcoords 117 | out << (quint8)contentTexCoords.count(); 118 | WritePadding(1, out); 119 | 120 | foreach (LYTTexCoords texCoord, contentTexCoords) { 121 | for (int i = 0; i < 4; i++) 122 | WritePointF(out, texCoord.coord[i]); 123 | } 124 | 125 | // write frame offsets 126 | quint32 frameOffset = 0x7C; // end of fixed-size part of content struct 127 | frameOffset += (contentTexCoords.count() * 0x20); // end of content struct 128 | frameOffset += (frames.count() * 4); // end of offset list 129 | 130 | for (int i = 0; i < frames.count(); i++) { 131 | out << (quint32)frameOffset; 132 | frameOffset += 4; // size of frame struct 133 | } 134 | 135 | // now write frames 136 | foreach (LYTWindowFrame *frame, frames) { 137 | frame->writeToDataStream(out); 138 | } 139 | } 140 | 141 | 142 | void LYTWindow::readFromDataStream(QDataStream &in) { 143 | qint64 startPos = in.device()->pos(); 144 | 145 | LYTPane::readFromDataStream(in); 146 | 147 | in >> (float&)contentOverflowLeft; 148 | in >> (float&)contentOverflowRight; 149 | in >> (float&)contentOverflowTop; 150 | in >> (float&)contentOverflowBottom; 151 | 152 | quint8 frameCount; 153 | in >> (quint8&)frameCount; 154 | in.skipRawData(3); // padding 155 | 156 | quint32 contentOffset, frameListOffset; 157 | in >> (quint32&)contentOffset; 158 | in >> (quint32&)frameListOffset; 159 | 160 | // read content struct 161 | // subtract 8 from the offset because section.data doesn't contain 162 | // the nw4r::ut::BinaryBlockHeader whereas these offsets do count it 163 | in.device()->seek(startPos + contentOffset - 8); 164 | 165 | for (int i = 0; i < 4; i++) 166 | ReadRGBA8Color(contentVtxColours[i], in); 167 | 168 | // read the material name 169 | quint16 materialNum; 170 | in >> (quint16&)materialNum; 171 | 172 | contentMaterialName = m_layout.materials.getNameOfIndex(materialNum); 173 | 174 | // read texcoords 175 | quint8 texCoordNum; 176 | in >> (quint8&)texCoordNum; 177 | in.skipRawData(1); // padding 178 | 179 | contentTexCoords.resize(texCoordNum); 180 | 181 | for (int i = 0; i < texCoordNum; i++) { 182 | for (int j = 0; j < 4; j++) 183 | ReadPointF(in, contentTexCoords[i].coord[j]); 184 | } 185 | 186 | // read frame offset list 187 | // subtract 8 from the offset once again 188 | in.device()->seek(startPos + frameListOffset - 8); 189 | 190 | QVector frameOffsets(frameCount); 191 | 192 | for (int i = 0; i < frameCount; i++) { 193 | quint32 offset; 194 | in >> (quint32&)offset; 195 | frameOffsets[i] = offset; 196 | } 197 | 198 | // now read each frame 199 | for (int i = 0; i < frameCount; i++) { 200 | in.device()->seek(frameOffsets[i] - 8); 201 | 202 | frames.append(new LYTWindowFrame(*this)); 203 | frames.last()->readFromDataStream(in); 204 | } 205 | } 206 | -------------------------------------------------------------------------------- /lyt/window.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #ifndef LYTWINDOW_H 19 | #define LYTWINDOW_H 20 | 21 | #include 22 | #include 23 | 24 | #include "common.h" 25 | #include "pane.h" 26 | 27 | 28 | class LYTWindow; // forward declaration 29 | 30 | class LYTWindowFrame { 31 | public: 32 | LYTWindowFrame(LYTWindow &window); 33 | 34 | 35 | void writeToDataStream(QDataStream &out) const; 36 | void readFromDataStream(QDataStream &in); 37 | 38 | void dumpToDebug() const; 39 | 40 | quint8 type; // 0-5; controls texture flipping; must investigate this more 41 | QString materialName; 42 | 43 | protected: 44 | LYTWindow &m_window; 45 | }; 46 | 47 | 48 | class LYTWindow : public LYTPane { 49 | public: 50 | LYTWindow(LYTLayout &layout); 51 | ~LYTWindow(); 52 | 53 | 54 | Magic magic() const; 55 | 56 | void writeToDataStream(QDataStream &out) const; 57 | void readFromDataStream(QDataStream &in); 58 | 59 | void dumpToDebug(bool showHeading=true) const; 60 | 61 | 62 | float contentOverflowLeft; 63 | float contentOverflowRight; 64 | float contentOverflowTop; 65 | float contentOverflowBottom; 66 | 67 | QColor contentVtxColours[4]; 68 | QString contentMaterialName; 69 | QVector contentTexCoords; 70 | 71 | QList frames; 72 | 73 | 74 | protected: 75 | void writeContentInfo(QDataStream &out) const; 76 | void readContentInfo(QDataStream &in); 77 | 78 | friend class LYTWindowFrame; 79 | }; 80 | 81 | 82 | #endif // LYTWINDOW_H 83 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #include 19 | #include "lsmainwindow.h" 20 | #include "lsglobals.h" 21 | 22 | #include "lyt/directorypackage.h" 23 | #include "lyt/archivepackage.h" 24 | #include "lyt/layout.h" 25 | 26 | #include 27 | 28 | #include "wii/archiveu8.h" 29 | 30 | #include "layoutgl/widget.h" 31 | 32 | 33 | int main(int argc, char *argv[]) { 34 | QApplication a(argc, argv); 35 | 36 | LSGlobals::setup(); 37 | 38 | LSMainWindow w; 39 | w.show(); 40 | 41 | return a.exec(); 42 | 43 | /*QFile file("H:\\ISOs\\NSMBWii\\Extracted\\Layout\\continue\\continue.arc"); 44 | file.open(QFile::ReadOnly); 45 | QByteArray arc = file.readAll(); 46 | file.close();*/ 47 | 48 | //LYTArchivePackage package("H:\\ISOs\\NSMBWii\\Extracted\\Layout\\continue\\continue.arc"); 49 | QString blah1 = "preGame"; 50 | //QString blah = "preGame/preGame.arc"; 51 | QString blah = QString("%1/%1.arc").arg(blah1); 52 | QString cpath; 53 | if (QFile::exists("/home/me/Games/Newer/ISO/files/Layout/" + blah)) { 54 | cpath = "/home/me/Games/Newer/ISO/files/Layout/" + blah; 55 | } else { 56 | cpath = "Z:\\stuff\\Games\\Newer\\ISO\\files\\Layout\\" + blah; 57 | } 58 | LYTArchivePackage package(cpath); 59 | LYTLayout layout(package, package.listLayouts().first()); 60 | //LYTLayout layout(package, "continue_05.brlyt"); 61 | //QByteArray brlyt = layout.pack(); 62 | //QFile file("H:\\ISOs\\NSMBWii\\Extracted\\Layout\\continue\\continue\\arc\\blyt\\continue_05_repack.brlyt"); 63 | //file.open(QFile::WriteOnly); 64 | //file.write(brlyt); 65 | //file.close(); 66 | //package.writeLayout("continue_05.brlyt", brlyt); 67 | //package.savePackage(); 68 | 69 | 70 | //LYTDirectoryPackage package("H:\\ISOs\\NSMBWii\\Extracted\\Layout\\continue\\continue\\arc"); 71 | //LYTLayout layout(package, "continue_05.brlyt"); 72 | //LYTDirectoryPackage package("H:\\ISOs\\TP\\banner\\arc_extr"); 73 | //LYTDirectoryPackage package("/mnt/h/ISOs/TP/banner/arc_extr"); 74 | //LYTDirectoryPackage package("/mnt/h/ISOs/hbm/InetChannelNew/0001000148414450/00000000_app_OUT/meta/banner_bin_OUT/arc"); 75 | //LYTDirectoryPackage package("/mnt/h/ISOs/CSWii/BannerTools/0001000157435645/00000000_app_OUT/meta/banner_bin_OUT/arc"); 76 | //LYTLayout layout(package, "banner.brlyt"); 77 | 78 | //LSMainWindow w; 79 | w.show(); 80 | 81 | LGLWidget w2; 82 | w2.setLayout(&layout); 83 | w2.show(); 84 | 85 | return a.exec(); 86 | } 87 | -------------------------------------------------------------------------------- /resources.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | icons/bounding.png 4 | icons/pane.png 5 | icons/picture.png 6 | icons/textbox.png 7 | icons/window.png 8 | 9 | 10 | -------------------------------------------------------------------------------- /wii/archiveu8.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #include "archiveu8.h" 19 | 20 | 21 | 22 | 23 | 24 | 25 | WiiArchiveU8::WiiArchiveU8() { } 26 | 27 | WiiArchiveU8::WiiArchiveU8(QDataStream &stream) { 28 | U8ReadInfo info; 29 | info.startPos = stream.device()->pos(); 30 | 31 | quint32 magic; 32 | stream >> (quint32&)magic; 33 | 34 | if (magic != 0x55AA382D) 35 | qWarning() << "WiiArchiveU8: tried to load an archive without the U8 magic"; 36 | 37 | quint32 fstStart, fstSize, dataOffset; 38 | stream >> (quint32&)fstStart; 39 | stream >> (quint32&)fstSize; 40 | stream >> (quint32&)dataOffset; 41 | 42 | // read the FST 43 | stream.device()->seek(info.startPos + fstStart); 44 | 45 | // read the root node 46 | quint32 rootNodeLastChild; 47 | 48 | stream.skipRawData(8); // ignore type, nameOffset and dataOffset 49 | stream >> (quint32&)rootNodeLastChild; 50 | 51 | // but before we do this, read the string table 52 | qint64 savePos = stream.device()->pos(); 53 | stream.device()->seek(savePos + ((rootNodeLastChild - 1) * 12)); 54 | 55 | int stringTableLength = fstSize - (rootNodeLastChild * 12); 56 | 57 | QByteArray rawStringTable; 58 | rawStringTable.resize(stringTableLength); 59 | stream.readRawData(rawStringTable.data(), stringTableLength); 60 | 61 | info.stringTable = QString::fromAscii(rawStringTable.constData(), stringTableLength); 62 | 63 | // now read the root node 64 | stream.device()->seek(savePos); 65 | 66 | qDebug() << "Reading root node: last child is" << rootNodeLastChild; 67 | info.currentNode = 1; 68 | this->readDir(stream, this->root, rootNodeLastChild, info); 69 | } 70 | 71 | 72 | void WiiArchiveU8::readDir(QDataStream &in, WiiDirectory &dir, int lastChild, U8ReadInfo &info) { 73 | // read every node in this directory 74 | 75 | while (info.currentNode < lastChild) { 76 | info.currentNode++; 77 | 78 | //qDebug() << "Reading @ pos" << in.device()->pos(); 79 | 80 | quint32 value, dataOffset, size; 81 | in >> (quint32&)value; 82 | in >> (quint32&)dataOffset; 83 | in >> (quint32&)size; 84 | 85 | int nameOffset = value & 0xFFFFFF; 86 | int type = value >> 24; 87 | 88 | WiiFSObject *newObj; 89 | if (type == 0) 90 | newObj = new WiiFile; 91 | else if (type == 1) 92 | newObj = new WiiDirectory; 93 | else 94 | qFatal("WiiArchiveU8::readDir: Unknown fs obj type %d", type); 95 | 96 | // get the name 97 | int nameSize = info.stringTable.indexOf(QChar::Null, nameOffset) - nameOffset; 98 | newObj->name = info.stringTable.mid(nameOffset, nameSize); 99 | 100 | qDebug() << "Reading node" << info.currentNode << newObj->name << "- type:" << type << "size:" << size << "offset:" << dataOffset; 101 | 102 | // read the contents 103 | if (newObj->isFile()) { 104 | // get the file data 105 | qint64 savePos = in.device()->pos(); 106 | in.device()->seek(info.startPos + dataOffset); 107 | 108 | WiiFile *file = (WiiFile*)newObj; 109 | file->data.resize(size); 110 | in.readRawData(file->data.data(), size); 111 | 112 | in.device()->seek(savePos); 113 | 114 | } else if (newObj->isDirectory()) { 115 | // read the children 116 | this->readDir(in, *((WiiDirectory*)newObj), size, info); 117 | 118 | } 119 | 120 | qDebug() << "Adding" << newObj->name << "to" << dir.name; 121 | dir.addChild(newObj); 122 | }; 123 | } 124 | 125 | 126 | 127 | void WiiArchiveU8::writeToDataStream(QDataStream &out) const { 128 | U8WriteInfo info; 129 | 130 | // first off, before we do anything else, create the string table 131 | this->addNodeToStringTable(this->root, info.stringTableBuilder); 132 | 133 | QByteArray stringTable = info.stringTableBuilder.pack(); 134 | 135 | // calculate various fun offsets/sizes 136 | int nodeCount = 0; 137 | this->countNode(this->root, &nodeCount); 138 | 139 | info.startPos = out.device()->pos(); 140 | 141 | quint32 fstStart = 0x20; 142 | quint32 nodeDataSize = nodeCount * 12; 143 | quint32 stringTableSize = stringTable.length(); 144 | quint32 fstSize = nodeDataSize + stringTableSize; 145 | quint32 dataOffset = AlignUp(fstStart + fstSize, 0x20); 146 | 147 | qDebug() << "Writing: fstStart" << fstStart << "nodeCount" << nodeCount; 148 | qDebug() << "nodeDataSize" << nodeDataSize << "stringTableSize" << stringTableSize; 149 | qDebug() << "fstSize" << fstSize << "dataOffset" << dataOffset; 150 | 151 | // now write the header 152 | out << (quint32)0x55AA382D; 153 | out << (quint32)fstStart; 154 | out << (quint32)fstSize; 155 | out << (quint32)dataOffset; 156 | 157 | WritePadding(0x10, out); 158 | 159 | // write root node 160 | info.currentNode = 1; // root node is 1 161 | info.currentRecursionLevel = 0; 162 | info.nextDataOffset = dataOffset; 163 | 164 | out << (quint32)(0x01000000 << info.stringTableBuilder.add("")); 165 | out << (quint32)0; 166 | out << (quint32)nodeCount; 167 | 168 | this->writeDir(out, this->root, info); 169 | 170 | // write string table 171 | out.writeRawData(stringTable.constData(), stringTable.length()); 172 | 173 | // write data (after padding) 174 | WritePadding(dataOffset - fstSize - fstStart, out); 175 | 176 | this->writeNodeData(out, this->root); 177 | 178 | // looks like we are finally done 179 | } 180 | 181 | 182 | void WiiArchiveU8::addNodeToStringTable(const WiiFSObject &node, WiiStringTableBuilder &table) const { 183 | table.add(node.name); 184 | 185 | if (node.isDirectory()) { 186 | WiiDirectory *dir = (WiiDirectory*)&node; 187 | 188 | foreach (WiiFSObject *p, dir->children) 189 | this->addNodeToStringTable(*p, table); 190 | } 191 | } 192 | 193 | 194 | void WiiArchiveU8::countNode(const WiiFSObject &node, int *countPtr) const { 195 | (*countPtr)++; 196 | 197 | if (node.isDirectory()) { 198 | WiiDirectory *dir = (WiiDirectory*)&node; 199 | 200 | foreach (WiiFSObject *p, dir->children) 201 | this->countNode(*p, countPtr); 202 | } 203 | } 204 | 205 | 206 | void WiiArchiveU8::writeDir(QDataStream &out, const WiiDirectory &dir, U8WriteInfo &info) const { 207 | foreach (WiiFSObject *p, dir.children) { 208 | info.currentNode++; 209 | 210 | if (p->isDirectory()) { 211 | // write directory 212 | WiiDirectory *thisDir = (WiiDirectory*)p; 213 | 214 | out << (quint32)(0x01000000 | info.stringTableBuilder.add(thisDir->name)); 215 | out << (quint32)info.currentRecursionLevel; 216 | 217 | qint64 lastChildFieldPos = out.device()->pos(); 218 | out << (quint32)0; // placeholder 219 | 220 | info.currentRecursionLevel++; 221 | 222 | this->writeDir(out, *thisDir, info); 223 | 224 | info.currentRecursionLevel--; 225 | 226 | // write lastChild field 227 | qint64 dirEndPos = out.device()->pos(); 228 | 229 | out.device()->seek(lastChildFieldPos); 230 | out << (quint32)info.currentNode; 231 | out.device()->seek(dirEndPos); 232 | 233 | } else if (p->isFile()) { 234 | // write file 235 | WiiFile *thisFile = (WiiFile*)p; 236 | 237 | out << (quint32)info.stringTableBuilder.add(thisFile->name); 238 | out << (quint32)info.nextDataOffset; 239 | out << (quint32)thisFile->data.size(); 240 | 241 | info.nextDataOffset = AlignUp(info.nextDataOffset + thisFile->data.size(), 0x20); 242 | } 243 | } 244 | } 245 | 246 | 247 | void WiiArchiveU8::writeNodeData(QDataStream &out, const WiiFSObject &node) const { 248 | if (node.isDirectory()) { 249 | // write all the children's data 250 | WiiDirectory *thisDir = (WiiDirectory*)&node; 251 | 252 | foreach (WiiFSObject *p, thisDir->children) 253 | this->writeNodeData(out, *p); 254 | 255 | } else if (node.isFile()) { 256 | // write this file's data 257 | WiiFile *thisFile = (WiiFile*)&node; 258 | 259 | int len = thisFile->data.length(); 260 | out.writeRawData(thisFile->data.constData(), len); 261 | WritePadding(AlignUp(len, 0x20) - len, out); 262 | } 263 | } 264 | -------------------------------------------------------------------------------- /wii/archiveu8.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #ifndef WIIARCHIVEU8_H 19 | #define WIIARCHIVEU8_H 20 | 21 | #include "common.h" 22 | #include "filesystem.h" 23 | #include "stringtablebuilder.h" 24 | 25 | 26 | struct U8ReadInfo { 27 | qint64 startPos; 28 | QString stringTable; 29 | int currentNode; 30 | }; 31 | 32 | struct U8WriteInfo { 33 | qint64 startPos; 34 | WiiStringTableBuilder stringTableBuilder; 35 | int currentRecursionLevel; 36 | int currentNode; 37 | int nextDataOffset; 38 | }; 39 | 40 | 41 | class WiiArchiveU8 { 42 | public: 43 | WiiArchiveU8(); 44 | WiiArchiveU8(QDataStream &stream); 45 | 46 | WiiDirectory root; 47 | 48 | void writeToDataStream(QDataStream &out) const; 49 | 50 | private: 51 | void readDir(QDataStream &in, WiiDirectory &dir, int lastChild, U8ReadInfo &info); 52 | 53 | void addNodeToStringTable(const WiiFSObject &node, WiiStringTableBuilder &table) const; 54 | void countNode(const WiiFSObject &node, int *countPtr) const; 55 | 56 | void writeDir(QDataStream &out, const WiiDirectory &dir, U8WriteInfo &info) const; 57 | 58 | void writeNodeData(QDataStream &out, const WiiFSObject &node) const; 59 | }; 60 | 61 | #endif // WIIARCHIVEU8_H 62 | -------------------------------------------------------------------------------- /wii/common.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #include "common.h" 19 | 20 | QByteArray PadByteArray(const QByteArray original, int newLength, char padWith) { 21 | QByteArray newArray = original; 22 | 23 | if (original.length() > newLength) { 24 | // the original array is longer than the length desired, so truncate it 25 | newArray.truncate(newLength); 26 | 27 | } else if (original.length() < newLength) { 28 | // the original array is shorter, so pad it 29 | int oldLength = original.length(); 30 | newArray.resize(newLength); 31 | 32 | for (int i = oldLength; i < newLength; i++) { 33 | newArray[i] = '\0'; 34 | } 35 | } 36 | 37 | return newArray; 38 | } 39 | 40 | QStringList ReadStringList(QDataStream &in) { 41 | QStringList output; 42 | 43 | quint16 count; 44 | in >> (quint16&)count; 45 | in.skipRawData(2); // padding 46 | 47 | QVector stringOffsets(count); 48 | 49 | // save the initial offset so we can get the strings later 50 | // string offsets are based on the first offset entry (after the count) 51 | // NOT on the section offset 52 | qint64 savedPos = in.device()->pos(); 53 | 54 | for (int i = 0; i < count; i++) { 55 | quint32 offset; 56 | in >> (quint32&)offset; 57 | in.skipRawData(4); // unused? 58 | 59 | stringOffsets[i] = offset; 60 | } 61 | 62 | // ok, now we can get the strings 63 | for (int i = 0; i < count; i++) { 64 | in.device()->seek(savedPos + stringOffsets[i]); 65 | 66 | // how fun: no length is stored for each string, they're just zero 67 | // terminated. so let's try to figure it out! 68 | int stringLength = 0; 69 | char check; 70 | 71 | in >> (quint8&)check; 72 | while (check != 0) { 73 | stringLength += 1; 74 | in >> (quint8&)check; 75 | } 76 | 77 | // now read the string 78 | char *buffer = new char[stringLength]; 79 | 80 | in.device()->seek(savedPos + stringOffsets[i]); 81 | in.readRawData(buffer, stringLength); 82 | 83 | output.append(QString::fromAscii(buffer, stringLength)); 84 | 85 | delete[] buffer; 86 | 87 | 88 | qDebug() << "Read string:" << output.last(); 89 | } 90 | 91 | return output; 92 | } 93 | 94 | void WriteStringList(QDataStream &out, const QStringList list) { 95 | out << (quint16)list.count(); 96 | WritePadding(2, out); 97 | 98 | // calculate offsets for every string, and write them 99 | // offset 0 points to the first entry in the offset list, etc, so 100 | // take that into account for the string offset calculation 101 | quint32 currentOffset = list.count() * 8; 102 | 103 | foreach (QString str, list) { 104 | out << (quint32)currentOffset; 105 | WritePadding(4, out); // unused? 106 | 107 | currentOffset += str.length() + 1; 108 | } 109 | 110 | // now write the strings 111 | foreach (QString str, list) { 112 | QByteArray rawStr = str.toAscii(); 113 | rawStr.append('\0'); 114 | out.writeRawData(rawStr.constData(), rawStr.length()); 115 | } 116 | } 117 | 118 | QString ReadFixedLengthASCII(QDataStream &in, int length) { 119 | QByteArray readStr(length, '\0'); 120 | in.readRawData(readStr.data(), readStr.length()); 121 | 122 | QString str = QString::fromAscii(readStr.data(), readStr.length()); 123 | if (str.contains(QChar('\0'))) 124 | str.truncate(str.indexOf(QChar('\0'))); 125 | 126 | return str; 127 | } 128 | 129 | void WriteFixedLengthASCII(QDataStream &out, const QString str, int length) { 130 | QByteArray paddedStr = PadByteArray(str.toAscii(), length); 131 | out.writeRawData(paddedStr.constData(), paddedStr.length()); 132 | } 133 | 134 | 135 | -------------------------------------------------------------------------------- /wii/common.h: -------------------------------------------------------------------------------- 1 | #ifndef WIICOMMON_H 2 | #define WIICOMMON_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | inline quint32 AlignUp(quint32 value, quint32 alignTo) { 14 | return (value + alignTo - 1) & ~(alignTo - 1); 15 | } 16 | 17 | inline quint32 AlignDown(quint32 value, quint32 alignTo) { 18 | return value & ~(alignTo - 1); 19 | } 20 | 21 | 22 | inline quint32 BitExtract(quint32 value, int count, int start) { 23 | // this function relies on heavy compiler optimisation to be efficient :p 24 | quint32 mask = 0; 25 | for (int i = start; i < start+count; i++) { 26 | mask |= (0x80000000 >> i); 27 | } 28 | 29 | return (value & mask) >> (32 - (start + count)); 30 | } 31 | 32 | inline quint32 BitInsert(quint32 value, int newValue, int count, int start) { 33 | quint32 mask = 0; 34 | for (int i = start; i < start+count; i++) { 35 | mask |= (0x80000000 >> i); 36 | } 37 | 38 | value &= ~mask; 39 | value |= (newValue << (32 - (start + count))) & mask; 40 | return value; 41 | } 42 | 43 | inline void WritePadding(int num, QDataStream &out) { 44 | for (int i = 0; i < num; i++) 45 | out << (quint8)0; 46 | } 47 | 48 | 49 | 50 | 51 | QByteArray PadByteArray(QByteArray original, int newLength, char padWith='\0'); 52 | 53 | inline quint32 ColorToRGBA(QColor col) { 54 | return (col.red() << 24) | (col.green() << 16) | (col.blue() << 8) | (col.alpha()); 55 | } 56 | 57 | inline QColor RGBAToColor(quint32 col) { 58 | return QColor(col >> 24, (col >> 16) & 0xFF, (col >> 8) & 0xFF, col & 0xFF); 59 | } 60 | 61 | inline void ReadRGBA8Color(QColor &out, QDataStream &in) { 62 | quint32 col; 63 | in >> (quint32&)col; 64 | out = RGBAToColor(col); 65 | } 66 | 67 | inline void WriteRGBA8Color(const QColor in, QDataStream &out) { 68 | out << (quint32)ColorToRGBA(in); 69 | } 70 | 71 | inline void ReadS10Color(QColor &out, QDataStream &in) { 72 | quint16 r, g, b, a; 73 | in >> (quint16&)r; 74 | in >> (quint16&)g; 75 | in >> (quint16&)b; 76 | in >> (quint16&)a; 77 | out.setRgb(r, g, b, a); 78 | } 79 | 80 | inline void WriteS10Color(const QColor in, QDataStream &out) { 81 | out << (quint16)in.red(); 82 | out << (quint16)in.green(); 83 | out << (quint16)in.blue(); 84 | out << (quint16)in.alpha(); 85 | } 86 | 87 | inline void ReadPointF(QDataStream &stream, QPointF &point) { 88 | float x, y; 89 | stream >> x; 90 | stream >> y; 91 | point.setX(x); 92 | point.setY(y); 93 | } 94 | 95 | inline void WritePointF(QDataStream &stream, const QPointF &point) { 96 | stream << (float)point.x(); 97 | stream << (float)point.y(); 98 | } 99 | 100 | inline void InitDataStream(QDataStream &stream) { 101 | stream.setByteOrder(QDataStream::BigEndian); 102 | stream.setVersion(QDataStream::Qt_4_5); 103 | } 104 | 105 | QStringList ReadStringList(QDataStream &in); 106 | void WriteStringList(QDataStream &out, QStringList list); 107 | 108 | QString ReadFixedLengthASCII(QDataStream &in, int length); 109 | void WriteFixedLengthASCII(QDataStream &out, QString str, int length); 110 | 111 | #endif // WIICOMMON_H 112 | -------------------------------------------------------------------------------- /wii/filesystem.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #include "filesystem.h" 19 | 20 | 21 | /******************************************************************************/ 22 | 23 | WiiFSObject::WiiFSObject() { parent = 0; } 24 | WiiFSObject::~WiiFSObject() { } 25 | 26 | 27 | 28 | void WiiFSObject::unlinkFromParent() { 29 | if (this->parent == 0) 30 | return; 31 | 32 | if (this->parent->isDirectory()) { 33 | WiiDirectory *p = (WiiDirectory *)this->parent; 34 | if (p->children.contains(this)) 35 | p->children.removeAt(p->children.indexOf(this)); 36 | } 37 | 38 | this->parent = 0; 39 | } 40 | 41 | bool WiiFSObject::nameIsEqual(QString check) const { 42 | return (bool)(QString::compare(this->name, check, Qt::CaseInsensitive) == 0); 43 | } 44 | 45 | bool WiiFSObject::isFile() const { return false; } 46 | bool WiiFSObject::isDirectory() const { return false; } 47 | 48 | /******************************************************************************/ 49 | 50 | bool WiiFile::isFile() const { return true; } 51 | 52 | /******************************************************************************/ 53 | 54 | WiiDirectory::~WiiDirectory() { 55 | foreach (WiiFSObject *ptr, children) 56 | delete ptr; 57 | } 58 | 59 | bool WiiDirectory::isDirectory() const { return true; } 60 | 61 | WiiFSObject *WiiDirectory::findByName(QString name, bool recursive) const { 62 | foreach (WiiFSObject *obj, children) { 63 | if (obj->nameIsEqual(name)) 64 | return obj; 65 | 66 | if (recursive && obj->isDirectory()) { 67 | WiiDirectory *dir = (WiiDirectory*)obj; 68 | WiiFSObject *tryThis = dir->findByName(name, recursive); 69 | 70 | if (tryThis) 71 | return tryThis; 72 | } 73 | } 74 | 75 | return 0; 76 | } 77 | 78 | WiiFSObject *WiiDirectory::resolvePath(QString path) { 79 | QStringList pathComponents = path.split('/'); 80 | WiiDirectory *currentDir = this; 81 | 82 | // special case: handle absolute paths 83 | if (pathComponents.at(0) == "") { 84 | while (currentDir->parent != 0) 85 | currentDir = (WiiDirectory*)currentDir->parent; 86 | 87 | pathComponents.removeFirst(); 88 | } 89 | 90 | // now we can loop through the path 91 | while (!pathComponents.isEmpty()) { 92 | QString next = pathComponents.takeFirst(); 93 | WiiFSObject *nextObj; 94 | 95 | // get the next object in the path 96 | if (next == ".") { 97 | nextObj = currentDir; 98 | } else if (next == "..") { 99 | nextObj = currentDir->parent; 100 | } else { 101 | nextObj = currentDir->findByName(next, false); 102 | } 103 | 104 | if (nextObj == 0) { 105 | qWarning() << "Failed to resolve path" << path << ": missing component" << next; 106 | return 0; 107 | } 108 | 109 | if (pathComponents.isEmpty()) { 110 | // we've reached the end \o/ 111 | return (WiiFSObject *)nextObj; 112 | } 113 | 114 | // verify that this object is a directory 115 | if (!nextObj->isDirectory()) { 116 | qWarning() << "Failed to resolve path" << path << ": component" << next << "is not a directory"; 117 | return 0; 118 | } 119 | 120 | // ok, this has to be a directory, so let's just continue 121 | currentDir = (WiiDirectory *)nextObj; 122 | } 123 | 124 | // we should not reach here 125 | qWarning() << "Failed to resolve path" << path << ": unknown error"; 126 | return 0; 127 | } 128 | 129 | bool WiiDirectory::addChild(WiiFSObject *obj) { 130 | // verify to make sure an object does not exist with this name 131 | if (this->findByName(obj->name, false) != 0) 132 | return false; 133 | 134 | obj->unlinkFromParent(); 135 | 136 | this->children.append(obj); 137 | obj->parent = this; 138 | 139 | return true; 140 | } 141 | 142 | bool WiiDirectory::removeChild(WiiFSObject *obj) { 143 | if (obj->parent != this) 144 | return false; 145 | 146 | obj->unlinkFromParent(); 147 | delete obj; 148 | 149 | return true; 150 | } 151 | -------------------------------------------------------------------------------- /wii/filesystem.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) 3 | Copyright (c) 2010 Treeki (treeki@gmail.com) 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, version 2.0. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License 2.0 for more details. 13 | 14 | You should have received a copy of the GNU General Public License 2.0 15 | along with this program. If not, see . 16 | *******************************************************************************/ 17 | 18 | #ifndef WIIFILESYSTEM_H 19 | #define WIIFILESYSTEM_H 20 | 21 | #include "common.h" 22 | 23 | 24 | class WiiFSObject { 25 | // abstract base class of all filesystem objects 26 | public: 27 | virtual ~WiiFSObject(); 28 | 29 | WiiFSObject *parent; 30 | 31 | QString name; 32 | 33 | 34 | void unlinkFromParent(); 35 | bool nameIsEqual(QString check) const; 36 | 37 | virtual bool isFile() const; 38 | virtual bool isDirectory() const; 39 | 40 | 41 | protected: 42 | WiiFSObject(); // don't instantiate this class directly! 43 | }; 44 | 45 | 46 | /******************************************************************************/ 47 | 48 | class WiiFile : public WiiFSObject { 49 | public: 50 | QByteArray data; 51 | 52 | 53 | bool isFile() const; 54 | }; 55 | 56 | /******************************************************************************/ 57 | 58 | class WiiDirectory : public WiiFSObject { 59 | public: 60 | ~WiiDirectory(); 61 | 62 | QList children; 63 | 64 | 65 | bool isDirectory() const; 66 | 67 | WiiFSObject *findByName(QString name, bool recursive) const; 68 | WiiFSObject *resolvePath(QString path); 69 | bool addChild(WiiFSObject *obj); 70 | bool removeChild(WiiFSObject *obj); 71 | }; 72 | 73 | 74 | #endif // FILESYSTEM_H 75 | -------------------------------------------------------------------------------- /wii/gx.h: -------------------------------------------------------------------------------- 1 | #ifndef WII_GX_H 2 | #define WII_GX_H 3 | 4 | namespace GX { 5 | enum TextureFormat { 6 | I4 = 0, 7 | I8 = 1, 8 | IA4 = 2, 9 | IA8 = 3, 10 | RGB565 = 4, 11 | RGB5A3 = 5, 12 | RGBA8 = 6, 13 | CI4 = 8, 14 | CI8 = 9, 15 | CI14X2 = 10, 16 | CMPR = 14 17 | }; 18 | 19 | enum WrapType { 20 | Clamp = 0, 21 | Repeat = 1, 22 | Mirror = 2 23 | }; 24 | 25 | enum TextureFilter { 26 | Near = 0, 27 | Linear = 1, 28 | NearMipNear = 2, 29 | LinMipNear = 3, 30 | NearMipLin = 4, 31 | LinMipLin = 5 32 | }; 33 | }; 34 | 35 | #endif // WII_GX_H 36 | -------------------------------------------------------------------------------- /wii/stringtablebuilder.cpp: -------------------------------------------------------------------------------- 1 | #include "stringtablebuilder.h" 2 | 3 | WiiStringTableBuilder::WiiStringTableBuilder() { 4 | m_nextOffset = 0; 5 | m_data = ""; 6 | } 7 | 8 | quint32 WiiStringTableBuilder::add(QString str) { 9 | if (m_lookup.contains(str)) 10 | return m_lookup.value(str); 11 | 12 | quint32 added = m_nextOffset; 13 | m_lookup.insert(str, added); 14 | 15 | m_data.append(str.toAscii()); 16 | m_data.append('\0'); 17 | 18 | m_nextOffset = m_data.length(); 19 | 20 | return added; 21 | } 22 | 23 | QByteArray WiiStringTableBuilder::pack() const { 24 | return m_data; 25 | } 26 | -------------------------------------------------------------------------------- /wii/stringtablebuilder.h: -------------------------------------------------------------------------------- 1 | #ifndef STRINGTABLEBUILDER_H 2 | #define STRINGTABLEBUILDER_H 3 | 4 | #include "common.h" 5 | #include 6 | #include 7 | #include 8 | 9 | class WiiStringTableBuilder { 10 | public: 11 | WiiStringTableBuilder(); 12 | 13 | quint32 add(QString str); 14 | QByteArray pack() const; 15 | 16 | protected: 17 | int m_nextOffset; 18 | QByteArray m_data; 19 | QHash m_lookup; 20 | }; 21 | 22 | #endif // STRINGTABLEBUILDER_H 23 | -------------------------------------------------------------------------------- /wii/texpalette.h: -------------------------------------------------------------------------------- 1 | #ifndef WIITEXPALETTE_H 2 | #define WIITEXPALETTE_H 3 | 4 | #include "common.h" 5 | #include "gx.h" 6 | #include 7 | 8 | class WiiTPLTexture { 9 | public: 10 | // TODO: palette stuff 11 | 12 | QImage image; 13 | GX::TextureFormat format; 14 | 15 | GX::WrapType wrapS, wrapT; 16 | 17 | GX::TextureFilter minFilter, magFilter; 18 | 19 | float lodBias; 20 | bool edgeLODEnable; 21 | quint8 minLOD, maxLOD; 22 | }; 23 | 24 | class WiiTexPalette { 25 | public: 26 | WiiTexPalette(); 27 | WiiTexPalette(QDataStream &stream); 28 | 29 | void writeToDataStream(QDataStream &out) const; 30 | 31 | QVector textures; 32 | 33 | private: 34 | void readTexture(QDataStream &in, int textureOffs, int paletteOffs, WiiTPLTexture &tex); 35 | }; 36 | 37 | #endif // WIITEXPALETTE_H 38 | --------------------------------------------------------------------------------