Permalink
Browse files

Merge pull request #11162 from unknownbrackets/qt-resources

Fix resource handling on Qt and use Roboto
  • Loading branch information...
hrydgard committed Jun 9, 2018
2 parents d1b06bb + cc1fa20 commit 6884751e2528c2f38ac3bdad2cdd1a32787c328a
Showing with 29 additions and 99 deletions.
  1. +1 −1 CMakeLists.txt
  2. +3 −1 Core/Config.h
  3. +0 −16 Qt/desktop_assets.qrc
  4. +23 −6 UI/NativeApp.cpp
  5. +0 −57 ext/native/file/zip_read.cpp
  6. +0 −15 ext/native/file/zip_read.h
  7. +2 −3 ext/native/gfx_es2/draw_text_qt.cpp
View
@@ -763,7 +763,7 @@ elseif(USING_QT_UI)
Qt/mainwindow.h
)
add_definitions(-DUSING_QT_UI)
include_directories(${CMAKE_CURRENT_BINARY_DIR} Qt Qt/Debugger)
include_directories(${CMAKE_CURRENT_BINARY_DIR} Qt)
set(nativeExtraLibs ${nativeExtraLibs} Qt5::OpenGL Qt5::Gui Qt5::Core)
set(TargetBin PPSSPPQt)
View
@@ -106,10 +106,12 @@ struct Config {
#if defined(USING_WIN_UI)
bool bPauseOnLostFocus;
bool bTopMost;
std::string sFont;
bool bIgnoreWindowsKey;
bool bRestartRequired;
#endif
#if defined(USING_WIN_UI) || defined(USING_QT_UI)
std::string sFont;
#endif
bool bPauseWhenMinimized;
View

This file was deleted.

Oops, something went wrong.
View
@@ -105,6 +105,9 @@
#if !defined(MOBILE_DEVICE) && defined(USING_QT_UI)
#include "Qt/QtHost.h"
#endif
#if defined(USING_QT_UI)
#include <QFontDatabase>
#endif
// The new UI framework, for initialization
@@ -276,7 +279,7 @@ void NativeGetAppInfo(std::string *app_dir_name, std::string *app_nice_name, boo
#endif
}
#if defined(_WIN32) && !PPSSPP_PLATFORM(UWP)
#if defined(USING_WIN_UI) && !PPSSPP_PLATFORM(UWP)
static bool CheckFontIsUsable(const wchar_t *fontFace) {
wchar_t actualFontFace[1024] = { 0 };
@@ -360,9 +363,7 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch
#endif
// We want this to be FIRST.
#ifdef USING_QT_UI
VFSRegister("", new AssetsAssetReader());
#elif defined(IOS)
#if defined(IOS)
// Packed assets are included in app
VFSRegister("", new DirectoryAssetReader(external_dir));
#endif
@@ -560,7 +561,7 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch
// Note to translators: do not translate this/add this to PPSSPP-lang's files.
// It's intended to be custom for every user.
// Only add it to your own personal copies of PPSSPP.
#if defined(_WIN32) && !PPSSPP_PLATFORM(UWP)
#if defined(USING_WIN_UI) && !PPSSPP_PLATFORM(UWP)
// TODO: Could allow a setting to specify a font file to load?
// TODO: Make this a constant if we can sanely load the font on other systems?
AddFontResourceEx(L"assets/Roboto-Condensed.ttf", FR_PRIVATE, NULL);
@@ -570,6 +571,22 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch
} else {
g_Config.sFont = des->T("Font", "Roboto");
}
#elif defined(USING_QT_UI)
size_t fontSize = 0;
uint8_t *fontData = VFSReadFile("Roboto-Condensed.ttf", &fontSize);
if (fontData) {
int fontID = QFontDatabase::addApplicationFontFromData(QByteArray((const char *)fontData, fontSize));
delete [] fontData;
QStringList fontsFound = QFontDatabase::applicationFontFamilies(fontID);
if (fontsFound.size() >= 1) {
// Might be "Roboto" or "Roboto Condensed".
g_Config.sFont = des->T("Font", fontsFound.at(0).toUtf8().constData());
}
} else {
// Let's try for it being a system font.
g_Config.sFont = des->T("Font", "Roboto Condensed");
}
#endif
if (!boot_filename.empty() && stateToLoad != NULL) {
@@ -620,7 +637,7 @@ static UI::Style MakeStyle(uint32_t fg, uint32_t bg) {
}
static void UIThemeInit() {
#if defined(_WIN32) && !PPSSPP_PLATFORM(UWP)
#if (defined(USING_WIN_UI) && !PPSSPP_PLATFORM(UWP)) || defined(USING_QT_UI)
ui_theme.uiFont = UI::FontStyle(UBUNTU24, g_Config.sFont.c_str(), 22);
ui_theme.uiFontSmall = UI::FontStyle(UBUNTU24, g_Config.sFont.c_str(), 15);
ui_theme.uiFontSmaller = UI::FontStyle(UBUNTU24, g_Config.sFont.c_str(), 12);
@@ -3,11 +3,6 @@
#include <set>
#include <stdio.h>
#ifdef USING_QT_UI
#include <QFileInfo>
#include <QDir>
#endif
#ifdef __ANDROID__
#include <zip.h>
#endif
@@ -66,58 +61,6 @@ uint8_t *ReadLocalFile(const char *filename, size_t *size) {
return contents;
}
#ifdef USING_QT_UI
uint8_t *AssetsAssetReader::ReadAsset(const char *path, size_t *size) {
QFile asset(QString(":/assets/") + path);
if (!asset.open(QIODevice::ReadOnly))
return 0;
uint8_t *contents = new uint8_t[asset.size()+1];
memcpy(contents, (uint8_t*)asset.readAll().data(), asset.size());
contents[asset.size()] = 0;
*size = asset.size();
asset.close();
return contents;
}
bool AssetsAssetReader::GetFileListing(const char *path, std::vector<FileInfo> *listing, const char *filter = 0)
{
QDir assetDir(QString(":/assets/") + path);
QStringList filters = QString(filter).split(':', QString::SkipEmptyParts);
for (int i = 0; i < filters.count(); i++)
filters[i].prepend("*.");
QFileInfoList infoList = assetDir.entryInfoList(filters, QDir::AllDirs | QDir::NoDotAndDotDot | QDir::Files, QDir::Name);
foreach(QFileInfo qinfo, infoList) {
FileInfo info;
info.name = qinfo.fileName().toStdString();
info.fullName = qinfo.absoluteFilePath().remove(":/assets/").toStdString();
info.exists = true;
info.isWritable = false;
info.isDirectory = qinfo.isDir();
listing->push_back(info);
}
return true;
}
bool AssetsAssetReader::GetFileInfo(const char *path, FileInfo *info) {
QFileInfo qinfo(QString(":/assets/") + path);
if (!qinfo.exists()) {
info->exists = false;
info->size = 0;
return false;
}
info->fullName = path;
info->exists = true;
info->isWritable = false;
info->isDirectory = qinfo.isDir();
info->size = qinfo.size();
return true;
}
#endif
#ifdef __ANDROID__
ZipAssetReader::ZipAssetReader(const char *zip_file, const char *in_zip_path) {
View
@@ -26,21 +26,6 @@ class AssetReader {
virtual std::string toString() const = 0;
};
#ifdef USING_QT_UI
class AssetsAssetReader : public AssetReader {
public:
AssetsAssetReader() {}
~AssetsAssetReader() {}
// use delete[]
virtual uint8_t *ReadAsset(const char *path, size_t *size);
virtual bool GetFileListing(const char *path, std::vector<FileInfo> *listing, const char *filter);
virtual bool GetFileInfo(const char *path, FileInfo *info);
virtual std::string toString() const {
return ":assets/";
}
};
#endif
#ifdef __ANDROID__
uint8_t *ReadFromZip(zip *archive, const char* filename, size_t *size);
class ZipAssetReader : public AssetReader {
@@ -23,8 +23,7 @@ TextDrawerQt::~TextDrawerQt() {
}
uint32_t TextDrawerQt::SetFont(const char *fontName, int size, int flags) {
// We will only use the default font
uint32_t fontHash = 0; //hash::Adler32((const uint8_t *)fontName, strlen(fontName));
uint32_t fontHash = fontName && strlen(fontName) ? hash::Adler32((const uint8_t *)fontName, strlen(fontName)) : 0;
fontHash ^= size;
fontHash ^= flags << 10;
@@ -34,7 +33,7 @@ uint32_t TextDrawerQt::SetFont(const char *fontName, int size, int flags) {
return fontHash;
}
QFont* font = new QFont();
QFont* font = fontName ? new QFont(fontName) : new QFont();
font->setPixelSize(size + 6);
fontMap_[fontHash] = font;
fontHash_ = fontHash;

0 comments on commit 6884751

Please sign in to comment.