2015-11-27 09:33:07 +01:00
|
|
|
// Copyright 2015 Dolphin Emulator Project
|
2021-07-05 03:22:19 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2015-11-27 09:33:07 +01:00
|
|
|
|
2021-12-10 03:22:16 +01:00
|
|
|
#include "DolphinQt/Resources.h"
|
|
|
|
|
2017-05-30 22:42:21 +02:00
|
|
|
#include <QGuiApplication>
|
|
|
|
#include <QIcon>
|
|
|
|
#include <QPixmap>
|
|
|
|
#include <QScreen>
|
2015-11-27 09:33:07 +01:00
|
|
|
|
|
|
|
#include "Common/FileUtil.h"
|
2018-05-28 03:48:04 +02:00
|
|
|
|
2021-12-31 03:00:39 +01:00
|
|
|
#include "Core/Config/MainSettings.h"
|
2018-05-28 03:48:04 +02:00
|
|
|
|
2018-07-07 00:40:15 +02:00
|
|
|
#include "DolphinQt/Settings.h"
|
2015-11-27 09:33:07 +01:00
|
|
|
|
2018-03-26 08:13:15 +02:00
|
|
|
#ifdef _WIN32
|
2018-07-07 00:40:15 +02:00
|
|
|
#include "DolphinQt/QtUtils/WinIconHelper.h"
|
2018-03-26 08:13:15 +02:00
|
|
|
#endif
|
|
|
|
|
2015-11-27 09:33:07 +01:00
|
|
|
QList<QPixmap> Resources::m_platforms;
|
|
|
|
QList<QPixmap> Resources::m_countries;
|
|
|
|
QList<QPixmap> Resources::m_misc;
|
|
|
|
|
2021-05-17 21:00:13 +02:00
|
|
|
QIcon Resources::GetIcon(std::string_view name, const QString& dir)
|
2017-05-30 22:42:21 +02:00
|
|
|
{
|
2021-05-17 21:00:13 +02:00
|
|
|
QString name_owned = QString::fromLatin1(name.data(), static_cast<int>(name.size()));
|
|
|
|
QString base_path = dir + QLatin1Char{'/'} + name_owned;
|
2017-05-30 22:42:21 +02:00
|
|
|
|
|
|
|
const auto dpr = QGuiApplication::primaryScreen()->devicePixelRatio();
|
|
|
|
|
|
|
|
QIcon icon(base_path.append(QStringLiteral(".png")));
|
|
|
|
|
|
|
|
if (dpr > 2)
|
|
|
|
{
|
|
|
|
QPixmap pixmap(base_path.append(QStringLiteral("@4x.png")));
|
|
|
|
if (!pixmap.isNull())
|
|
|
|
{
|
|
|
|
pixmap.setDevicePixelRatio(4.0);
|
|
|
|
icon.addPixmap(pixmap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
|
2021-05-17 21:00:13 +02:00
|
|
|
QPixmap Resources::GetPixmap(std::string_view name, const QString& dir)
|
2017-05-30 22:42:21 +02:00
|
|
|
{
|
|
|
|
const auto icon = GetIcon(name, dir);
|
|
|
|
return icon.pixmap(icon.availableSizes()[0]);
|
|
|
|
}
|
|
|
|
|
2017-06-23 00:11:53 +02:00
|
|
|
static QString GetCurrentThemeDir()
|
|
|
|
{
|
2021-12-31 03:00:39 +01:00
|
|
|
return QString::fromStdString(File::GetThemeDir(Config::Get(Config::MAIN_THEME_NAME)));
|
2017-06-23 00:11:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static QString GetResourcesDir()
|
|
|
|
{
|
|
|
|
return QString::fromStdString(File::GetSysDirectory() + "Resources");
|
|
|
|
}
|
|
|
|
|
2021-05-17 21:00:13 +02:00
|
|
|
QIcon Resources::GetScaledIcon(std::string_view name)
|
2017-05-30 22:42:21 +02:00
|
|
|
{
|
2021-05-17 21:00:13 +02:00
|
|
|
return GetIcon(name, GetResourcesDir());
|
2017-05-30 22:42:21 +02:00
|
|
|
}
|
|
|
|
|
2021-05-17 21:00:13 +02:00
|
|
|
QIcon Resources::GetScaledThemeIcon(std::string_view name)
|
2017-05-30 22:42:21 +02:00
|
|
|
{
|
2021-05-17 21:00:13 +02:00
|
|
|
return GetIcon(name, GetCurrentThemeDir());
|
2017-05-30 22:42:21 +02:00
|
|
|
}
|
|
|
|
|
2021-05-17 21:00:13 +02:00
|
|
|
QPixmap Resources::GetScaledPixmap(std::string_view name)
|
2017-05-30 22:42:21 +02:00
|
|
|
{
|
2021-05-17 21:00:13 +02:00
|
|
|
return GetPixmap(name, GetResourcesDir());
|
2017-05-30 22:42:21 +02:00
|
|
|
}
|
|
|
|
|
2015-11-27 09:33:07 +01:00
|
|
|
void Resources::Init()
|
|
|
|
{
|
2021-05-17 21:00:13 +02:00
|
|
|
for (std::string_view platform :
|
2017-05-30 22:42:21 +02:00
|
|
|
{"Platform_Gamecube", "Platform_Wii", "Platform_Wad", "Platform_File"})
|
|
|
|
{
|
|
|
|
m_platforms.append(GetScaledPixmap(platform));
|
|
|
|
}
|
|
|
|
|
2021-05-17 21:00:13 +02:00
|
|
|
for (std::string_view country :
|
2017-05-30 22:42:21 +02:00
|
|
|
{"Flag_Europe", "Flag_Japan", "Flag_USA", "Flag_Australia", "Flag_France", "Flag_Germany",
|
|
|
|
"Flag_Italy", "Flag_Korea", "Flag_Netherlands", "Flag_Russia", "Flag_Spain", "Flag_Taiwan",
|
|
|
|
"Flag_International", "Flag_Unknown"})
|
|
|
|
{
|
|
|
|
m_countries.append(GetScaledPixmap(country));
|
|
|
|
}
|
|
|
|
|
|
|
|
m_misc.append(GetScaledPixmap("nobanner"));
|
|
|
|
m_misc.append(GetScaledPixmap("dolphin_logo"));
|
|
|
|
m_misc.append(GetScaledPixmap("Dolphin"));
|
2015-11-27 09:33:07 +01:00
|
|
|
}
|
|
|
|
|
2018-07-10 21:10:03 +02:00
|
|
|
QPixmap Resources::GetPlatform(DiscIO::Platform platform)
|
2015-11-27 09:33:07 +01:00
|
|
|
{
|
2018-07-10 21:10:03 +02:00
|
|
|
return m_platforms[static_cast<int>(platform)];
|
2015-11-27 09:33:07 +01:00
|
|
|
}
|
|
|
|
|
2018-07-10 21:10:03 +02:00
|
|
|
QPixmap Resources::GetCountry(DiscIO::Country country)
|
2015-11-27 09:33:07 +01:00
|
|
|
{
|
2018-07-10 21:10:03 +02:00
|
|
|
return m_countries[static_cast<int>(country)];
|
2015-11-27 09:33:07 +01:00
|
|
|
}
|
|
|
|
|
2018-07-10 21:10:03 +02:00
|
|
|
QPixmap Resources::GetMisc(MiscID id)
|
2015-11-27 09:33:07 +01:00
|
|
|
{
|
2018-07-10 21:10:03 +02:00
|
|
|
return m_misc[static_cast<int>(id)];
|
2015-11-27 09:33:07 +01:00
|
|
|
}
|
2018-03-26 08:13:15 +02:00
|
|
|
|
|
|
|
QIcon Resources::GetAppIcon()
|
|
|
|
{
|
|
|
|
QIcon icon;
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
icon = WinIconHelper::GetNativeIcon();
|
|
|
|
#else
|
|
|
|
icon.addPixmap(GetScaledPixmap("dolphin_logo"));
|
|
|
|
icon.addPixmap(GetScaledPixmap("Dolphin"));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return icon;
|
|
|
|
}
|