Initializes CPU settings page (#975)

This commit is contained in:
Putta Khunchalee 2024-09-09 01:40:09 +07:00 committed by GitHub
parent 46c4ec806c
commit 1e68099365
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 113 additions and 23 deletions

View File

@ -1,5 +1,5 @@
# External dependencies.
find_package(Qt6 COMPONENTS Widgets REQUIRED)
find_package(Qt6 REQUIRED COMPONENTS Svg Widgets)
find_package(Threads REQUIRED)
if(WIN32 OR (UNIX AND NOT APPLE))
find_package(Vulkan REQUIRED)
@ -58,6 +58,7 @@ add_executable(obliteration WIN32 MACOSX_BUNDLE
ansi_escape.cpp
app_data.cpp
core.cpp
cpu_settings.cpp
display_settings.cpp
game_graphic_settings.cpp
game_models.cpp
@ -109,7 +110,7 @@ endif()
target_compile_features(obliteration PRIVATE cxx_std_17)
target_link_libraries(obliteration PRIVATE Qt6::Widgets)
target_link_libraries(obliteration PRIVATE Qt6::Svg Qt6::Widgets)
target_link_libraries(obliteration PRIVATE Threads::Threads)
target_link_libraries(obliteration PRIVATE ${LIBCORE})

View File

@ -4,6 +4,7 @@ use obconf::Config;
use serde::{Deserialize, Serialize};
use std::ffi::{c_char, CStr, CString};
use std::fs::File;
use std::num::NonZero;
use std::path::Path;
use std::ptr::null_mut;
use std::time::SystemTime;
@ -131,7 +132,9 @@ impl Default for Profile {
id: Uuid::new_v4(),
name: CString::new("Default").unwrap(),
display_resolution: DisplayResolution::Hd,
kernel_config: Config::default(),
kernel_config: Config {
max_cpu: NonZero::new(8).unwrap(),
},
created: SystemTime::now(),
}
}

55
src/cpu_settings.cpp Normal file
View File

@ -0,0 +1,55 @@
#include "cpu_settings.hpp"
#include <QGridLayout>
#include <QGroupBox>
#include <QLabel>
#include <QSlider>
CpuSettings::CpuSettings(QWidget *parent) :
QWidget(parent)
{
auto layout = new QGridLayout();
layout->addWidget(buildCount(), 0, 0);
layout->setRowStretch(1, 1);
setLayout(layout);
}
CpuSettings::~CpuSettings()
{
}
QWidget *CpuSettings::buildCount()
{
auto group = new QGroupBox("Count");
auto layout = new QGridLayout();
// Slider.
auto slider = new QSlider(Qt::Horizontal);
slider->setTickInterval(1);
slider->setTickPosition(QSlider::TicksAbove);
slider->setRange(1, 16);
slider->setValue(8);
layout->addWidget(slider, 0, 0);
// Value.
auto value = new QLabel("8");
connect(slider, &QAbstractSlider::valueChanged, value, qOverload<int>(&QLabel::setNum));
layout->addWidget(value, 0, 1);
// Description.
auto desc = new QLabel("Changing this value to other than 8 may crash the game.");
desc->setWordWrap(true);
layout->addWidget(desc, 1, 0, 1, -1);
group->setLayout(layout);
return group;
}

11
src/cpu_settings.hpp Normal file
View File

@ -0,0 +1,11 @@
#pragma once
#include <QWidget>
class CpuSettings final : public QWidget {
public:
CpuSettings(QWidget *parent = nullptr);
~CpuSettings() override;
private:
QWidget *buildCount();
};

View File

@ -1,4 +1,5 @@
#include "launch_settings.hpp"
#include "cpu_settings.hpp"
#include "display_settings.hpp"
#include "game_models.hpp"
#include "game_settings.hpp"
@ -31,6 +32,7 @@ LaunchSettings::LaunchSettings(
#endif
QWidget(parent),
m_display(nullptr),
m_cpu(nullptr),
m_games(nullptr),
m_profiles(nullptr)
{
@ -73,6 +75,7 @@ QWidget *LaunchSettings::buildSettings(GameListModel *games, QList<VkPhysicalDev
{
// Tab.
auto tab = new QTabWidget();
auto iconSize = tab->iconSize();
// Display settings.
#ifdef __APPLE__
@ -81,7 +84,12 @@ QWidget *LaunchSettings::buildSettings(GameListModel *games, QList<VkPhysicalDev
m_display = new DisplaySettings(std::move(vkDevices));
#endif
tab->addTab(m_display, loadIcon(":/resources/monitor.svg"), "Display");
tab->addTab(m_display, loadIcon(":/resources/monitor.svg", iconSize), "Display");
// CPU settings.
m_cpu = new CpuSettings();
tab->addTab(m_cpu, loadIcon(":/resources/cpu-64-bit.svg", iconSize), "CPU");
// Game list.
m_games = new QTableView();
@ -96,7 +104,7 @@ QWidget *LaunchSettings::buildSettings(GameListModel *games, QList<VkPhysicalDev
connect(m_games, &QWidget::customContextMenuRequested, this, &LaunchSettings::requestGamesContextMenu);
tab->addTab(m_games, loadIcon(":/resources/view-comfy.svg"), "Games");
tab->addTab(m_games, loadIcon(":/resources/view-comfy.svg", iconSize), "Games");
return tab;
}
@ -119,7 +127,9 @@ QLayout *LaunchSettings::buildActions(ProfileList *profiles)
layout->addWidget(actions);
// Save button.
auto save = new QPushButton(loadIcon(":/resources/content-save.svg"), "Save");
auto save = new QPushButton("Save");
save->setIcon(loadIcon(":/resources/content-save.svg", save->iconSize()));
connect(save, &QAbstractButton::clicked, [this]() {
auto index = m_profiles->currentIndex();
@ -134,7 +144,9 @@ QLayout *LaunchSettings::buildActions(ProfileList *profiles)
actions->addButton(save, QDialogButtonBox::ApplyRole);
// Start button.
auto start = new QPushButton(loadIcon(":/resources/play.svg"), "Start");
auto start = new QPushButton("Start");
start->setIcon(loadIcon(":/resources/play.svg", start->iconSize()));
connect(start, &QAbstractButton::clicked, [this]() { emit startClicked(); });
@ -157,8 +169,8 @@ void LaunchSettings::requestGamesContextMenu(const QPoint &pos)
// Setup menu.
QMenu menu(this);
QAction openFolder(loadIcon(":/resources/folder-open-outline.svg"), "Open &Folder", this);
QAction settings(loadIcon(":/resources/cog-outline.svg"), "&Settings", this);
QAction openFolder("Open &Folder", this);
QAction settings("&Settings", this);
menu.addAction(&openFolder);
menu.addAction(&settings);

View File

@ -8,6 +8,7 @@
#endif
#include <QWidget>
class CpuSettings;
class DisplaySettings;
class GameListModel;
class ProfileList;
@ -45,6 +46,7 @@ private:
void profileChanged(int index);
DisplaySettings *m_display;
CpuSettings *m_cpu;
QTableView *m_games;
QComboBox *m_profiles;
};

View File

@ -53,11 +53,6 @@ MainWindow::MainWindow(QVulkanInstance *vulkan, QList<VkPhysicalDevice> &&vkDevi
auto openSystemFolder = new QAction("Open System &Folder", this);
auto quit = new QAction("&Quit", this);
#ifndef __APPLE__
installPkg->setIcon(loadIcon(":/resources/archive-arrow-down-outline.svg"));
openSystemFolder->setIcon(loadIcon(":/resources/folder-open-outline.svg"));
#endif
connect(installPkg, &QAction::triggered, this, &MainWindow::installPkg);
connect(openSystemFolder, &QAction::triggered, this, &MainWindow::openSystemFolder);
connect(quit, &QAction::triggered, this, &MainWindow::close);

View File

@ -2,14 +2,26 @@
#include <QGuiApplication>
#include <QImage>
#include <QPainter>
#include <QPixmap>
#include <QStyleHints>
#include <QSvgRenderer>
#include <utility>
QIcon loadIcon(const QString &fileName)
QIcon loadIcon(const QString &fileName, const QSize &size)
{
QImage icon(fileName);
// Prepare to render the icon. We use the highest pixel ratio here so the icon will look sharp
// on any screen if the user have multiple monitors.
QSvgRenderer renderer(fileName);
QImage icon(size * qGuiApp->devicePixelRatio(), QImage::Format_ARGB32);
icon.fill(0);
// Render.
QPainter painter(&icon);
renderer.render(&painter);
if (QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark) {
icon.invertPixels();

View File

@ -2,4 +2,7 @@
#include <QIcon>
QIcon loadIcon(const QString &fileName);
class QSize;
/// Only SVG file is supported.
QIcon loadIcon(const QString &fileName, const QSize &size);

View File

@ -1,11 +1,9 @@
<!DOCTYPE RCC>
<RCC version="1.0">
<qresource>
<file>resources/archive-arrow-down-outline.svg</file>
<file>resources/cog-outline.svg</file>
<file>resources/content-save.svg</file>
<file>resources/cpu-64-bit.svg</file>
<file>resources/fallbackicon0.png</file>
<file>resources/folder-open-outline.svg</file>
<file>resources/monitor.svg</file>
<file>resources/obliteration-icon.png</file>
<file>resources/play.svg</file>

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 21H4V10H6V19H18V10H20V21M3 3H21V9H3V3M5 5V7H19V5M10.5 11V14H8L12 18L16 14H13.5V11" /></svg>

Before

Width:  |  Height:  |  Size: 164 B

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12,8A4,4 0 0,1 16,12A4,4 0 0,1 12,16A4,4 0 0,1 8,12A4,4 0 0,1 12,8M12,10A2,2 0 0,0 10,12A2,2 0 0,0 12,14A2,2 0 0,0 14,12A2,2 0 0,0 12,10M10,22C9.75,22 9.54,21.82 9.5,21.58L9.13,18.93C8.5,18.68 7.96,18.34 7.44,17.94L4.95,18.95C4.73,19.03 4.46,18.95 4.34,18.73L2.34,15.27C2.21,15.05 2.27,14.78 2.46,14.63L4.57,12.97L4.5,12L4.57,11L2.46,9.37C2.27,9.22 2.21,8.95 2.34,8.73L4.34,5.27C4.46,5.05 4.73,4.96 4.95,5.05L7.44,6.05C7.96,5.66 8.5,5.32 9.13,5.07L9.5,2.42C9.54,2.18 9.75,2 10,2H14C14.25,2 14.46,2.18 14.5,2.42L14.87,5.07C15.5,5.32 16.04,5.66 16.56,6.05L19.05,5.05C19.27,4.96 19.54,5.05 19.66,5.27L21.66,8.73C21.79,8.95 21.73,9.22 21.54,9.37L19.43,11L19.5,12L19.43,13L21.54,14.63C21.73,14.78 21.79,15.05 21.66,15.27L19.66,18.73C19.54,18.95 19.27,19.04 19.05,18.95L16.56,17.95C16.04,18.34 15.5,18.68 14.87,18.93L14.5,21.58C14.46,21.82 14.25,22 14,22H10M11.25,4L10.88,6.61C9.68,6.86 8.62,7.5 7.85,8.39L5.44,7.35L4.69,8.65L6.8,10.2C6.4,11.37 6.4,12.64 6.8,13.8L4.68,15.36L5.43,16.66L7.86,15.62C8.63,16.5 9.68,17.14 10.87,17.38L11.24,20H12.76L13.13,17.39C14.32,17.14 15.37,16.5 16.14,15.62L18.57,16.66L19.32,15.36L17.2,13.81C17.6,12.64 17.6,11.37 17.2,10.2L19.31,8.65L18.56,7.35L16.15,8.39C15.38,7.5 14.32,6.86 13.12,6.62L12.75,4H11.25Z" /></svg>

Before

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9,3V5H7A2,2 0 0,0 5,7V9H3V11H5V13H3V15H5V17A2,2 0 0,0 7,19H9V21H11V19H13V21H15V19H17A2,2 0 0,0 19,17V15H21V13H19V11H21V9H19V7A2,2 0 0,0 17,5H15V3H13V5H11V3M8,9H11.5V10.5H8.5V11.25H10.5A1,1 0 0,1 11.5,12.25V14A1,1 0 0,1 10.5,15H8A1,1 0 0,1 7,14V10A1,1 0 0,1 8,9M12.5,9H14V11H15.5V9H17V15H15.5V12.5H12.5M8.5,12.75V13.5H10V12.75" /></svg>

After

Width:  |  Height:  |  Size: 405 B

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M6.1,10L4,18V8H21A2,2 0 0,0 19,6H12L10,4H4A2,2 0 0,0 2,6V18A2,2 0 0,0 4,20H19C19.9,20 20.7,19.4 20.9,18.5L23.2,10H6.1M19,18H6L7.6,12H20.6L19,18Z" /></svg>

Before

Width:  |  Height:  |  Size: 223 B