# HG changeset patch # User unc0rr # Date 1412112005 -14400 # Node ID 084e046f6bd5853ed13dd6b9f14247d4e0b24f87 # Parent 1614b13ad35ecc01b3a46fcb58d54c1291f43bcb flib provides theme icons, qmlFrontend shows them diff -r 1614b13ad35e -r 084e046f6bd5 hedgewars/hwLibrary.pas --- a/hedgewars/hwLibrary.pas Tue Sep 30 00:54:04 2014 +0400 +++ b/hedgewars/hwLibrary.pas Wed Oct 01 01:20:05 2014 +0400 @@ -154,6 +154,7 @@ getSeed, getThemesList, freeThemesList, + getThemeIcon, LoadLocaleWrapper, HW_versionInfo, HW_versionString, diff -r 1614b13ad35e -r 084e046f6bd5 hedgewars/uFLData.pas --- a/hedgewars/uFLData.pas Tue Sep 30 00:54:04 2014 +0400 +++ b/hedgewars/uFLData.pas Wed Oct 01 01:20:05 2014 +0400 @@ -3,6 +3,7 @@ function getThemesList: PPChar; cdecl; procedure freeThemesList(list: PPChar); cdecl; +function getThemeIcon(themeName: PChar; buffer: PChar; buflen: Longword): Longword; cdecl; implementation uses uPhysFSLayer; @@ -17,4 +18,21 @@ pfsFreeList(list) end; +function getThemeIcon(themeName: PChar; buffer: PChar; buflen: Longword): Longword; cdecl; +var s: shortstring; + f: PFSFile; +begin + s:= '/Themes/' + shortstring(themeName) + '/icon@2x.png'; + + f:= pfsOpenRead(s); + + if f = nil then + getThemeIcon:= 0 + else + begin + getThemeIcon:= pfsBlockRead(f, buffer, buflen); + pfsClose(f) + end; +end; + end. diff -r 1614b13ad35e -r 084e046f6bd5 qmlFrontend/flib.h --- a/qmlFrontend/flib.h Tue Sep 30 00:54:04 2014 +0400 +++ b/qmlFrontend/flib.h Wed Oct 01 01:20:05 2014 +0400 @@ -33,6 +33,7 @@ typedef char **getThemesList_t(); typedef void freeThemesList_t(char **list); +typedef uint32_t getThemeIcon_t(char * theme, char * buffer, uint32_t size); #ifdef __cplusplus } diff -r 1614b13ad35e -r 084e046f6bd5 qmlFrontend/hwengine.cpp --- a/qmlFrontend/hwengine.cpp Tue Sep 30 00:54:04 2014 +0400 +++ b/qmlFrontend/hwengine.cpp Wed Oct 01 01:20:05 2014 +0400 @@ -6,6 +6,7 @@ #include "hwengine.h" #include "previewimageprovider.h" +#include "themeiconprovider.h" extern "C" { RunEngine_t *flibRunEngine; @@ -18,6 +19,7 @@ flibFree_t *flibFree; getThemesList_t *flibGetThemesList; freeThemesList_t *flibFreeThemesList; + getThemeIcon_t *flibGetThemeIcon; } Q_DECLARE_METATYPE(MessageType); @@ -44,10 +46,14 @@ flibGetThemesList = (getThemesList_t*) hwlib.resolve("getThemesList"); flibFreeThemesList = (freeThemesList_t*) hwlib.resolve("freeThemesList"); + flibGetThemeIcon = (getThemeIcon_t*) hwlib.resolve("getThemeIcon"); flibInit("/usr/home/unC0Rr/Sources/Hedgewars/Hedgewars-GC/share/hedgewars/Data", "/usr/home/unC0Rr/.hedgewars"); flibRegisterGUIMessagesCallback(this, &guiMessagesCallback); + ThemeIconProvider * themeIcon = (ThemeIconProvider *)m_engine->imageProvider(QLatin1String("theme")); + themeIcon->setFileContentsFunction(flibGetThemeIcon); + fillModels(); } diff -r 1614b13ad35e -r 084e046f6bd5 qmlFrontend/main.cpp --- a/qmlFrontend/main.cpp Tue Sep 30 00:54:04 2014 +0400 +++ b/qmlFrontend/main.cpp Wed Oct 01 01:20:05 2014 +0400 @@ -4,6 +4,7 @@ #include "qtquick2applicationviewer/qtquick2applicationviewer.h" #include "hwengine.h" #include "previewimageprovider.h" +#include "themeiconprovider.h" int main(int argc, char *argv[]) @@ -15,6 +16,7 @@ QtQuick2ApplicationViewer viewer; viewer.engine()->addImageProvider(QLatin1String("preview"), new PreviewImageProvider()); + viewer.engine()->addImageProvider(QLatin1String("theme"), new ThemeIconProvider()); viewer.setMainQmlFile(QStringLiteral("qml/qmlFrontend/main.qml")); viewer.showExpanded(); diff -r 1614b13ad35e -r 084e046f6bd5 qmlFrontend/qml/qmlFrontend/GameConfig.qml --- a/qmlFrontend/qml/qmlFrontend/GameConfig.qml Tue Sep 30 00:54:04 2014 +0400 +++ b/qmlFrontend/qml/qmlFrontend/GameConfig.qml Wed Oct 01 01:20:05 2014 +0400 @@ -26,16 +26,48 @@ } } - ListView { - x: 330 + Rectangle { + x: 320 y: 16 - width: 100; height: 100 + width: 100 + height: 256 + color: "#15193a" + radius: 8 + border.width: 4 + border.color: "#eaea00" + Image { + id: themeImage + x: 0 + y: 0 + width: 64 + height: 64 + fillMode: Image.Pad + } - model: themesModel - delegate: Rectangle { - height: 25 + ListView { + id: themesList + x: 0 + y: 64 width: 100 - Text { text: modelData } + height: 192 + highlight: Rectangle { color: "#eaea00"; radius: 4 } + focus: true + + model: themesModel + delegate: Rectangle { + height: 25 + width: 100 + color: "transparent" + Text {id: themeName; text: modelData } + MouseArea { + z: 1 + anchors.fill: parent + onClicked: { + themeImage.source = "image://theme/" + themeName.text + themesList.currentIndex = index + } + } + } } } } diff -r 1614b13ad35e -r 084e046f6bd5 qmlFrontend/qmlFrontend.pro --- a/qmlFrontend/qmlFrontend.pro Tue Sep 30 00:54:04 2014 +0400 +++ b/qmlFrontend/qmlFrontend.pro Wed Oct 01 01:20:05 2014 +0400 @@ -14,7 +14,8 @@ # The .cpp file which was generated for your project. Feel free to hack it. SOURCES += main.cpp \ hwengine.cpp \ - previewimageprovider.cpp + previewimageprovider.cpp \ + themeiconprovider.cpp # Installation path # target.path = @@ -27,7 +28,8 @@ qtquick2applicationviewer/qtquick2applicationviewer.h \ hwengine.h \ flib.h \ - previewimageprovider.h + previewimageprovider.h \ + themeiconprovider.h OTHER_FILES += \ qtquick2applicationviewer/qtquick2applicationviewer.pri \ diff -r 1614b13ad35e -r 084e046f6bd5 qmlFrontend/themeiconprovider.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qmlFrontend/themeiconprovider.cpp Wed Oct 01 01:20:05 2014 +0400 @@ -0,0 +1,37 @@ +#include +#include + +#include "themeiconprovider.h" +#include "flib.h" + +ThemeIconProvider::ThemeIconProvider() + : QQuickImageProvider(QQuickImageProvider::Image) +{ + getThemeIcon = 0; +} + +void ThemeIconProvider::setFileContentsFunction(getThemeIcon_t *f) +{ + getThemeIcon = f; +} + +QImage ThemeIconProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize) +{ + Q_UNUSED(requestedSize); + + if(!getThemeIcon) + return QImage(); + + QByteArray buf; + buf.resize(65536); + + uint32_t fileSize = getThemeIcon(id.toUtf8().data(), buf.data(), buf.size()); + buf.truncate(fileSize); + qDebug() << "ThemeIconProvider file size = " << fileSize; + + QImage img = QImage::fromData(buf); + + if (size) + *size = img.size(); + return img; +} diff -r 1614b13ad35e -r 084e046f6bd5 qmlFrontend/themeiconprovider.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qmlFrontend/themeiconprovider.h Wed Oct 01 01:20:05 2014 +0400 @@ -0,0 +1,21 @@ +#ifndef THEMEICONPROVIDER_H +#define THEMEICONPROVIDER_H + +#include +#include + +#include "flib.h" + +class ThemeIconProvider : public QQuickImageProvider +{ +public: + ThemeIconProvider(); + + void setFileContentsFunction(getThemeIcon_t *f); + + QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize); +private: + getThemeIcon_t *getThemeIcon; +}; + +#endif // THEMEICONPROVIDER_H