Skip to content

Commit

Permalink
Initializes CPU settings page
Browse files Browse the repository at this point in the history
  • Loading branch information
ultimaweapon committed Sep 8, 2024
1 parent 46c4ec8 commit 1a293ad
Show file tree
Hide file tree
Showing 14 changed files with 113 additions and 23 deletions.
5 changes: 3 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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})

Expand Down
5 changes: 4 additions & 1 deletion src/core/src/profile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
}
}
Expand Down
55 changes: 55 additions & 0 deletions src/cpu_settings.cpp
Original file line number Diff line number Diff line change
@@ -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 changes: 11 additions & 0 deletions src/cpu_settings.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include <QWidget>

class CpuSettings final : public QWidget {
public:
CpuSettings(QWidget *parent = nullptr);
~CpuSettings() override;
private:
QWidget *buildCount();
};
24 changes: 18 additions & 6 deletions src/launch_settings.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "launch_settings.hpp"
#include "cpu_settings.hpp"
#include "display_settings.hpp"
#include "game_models.hpp"
#include "game_settings.hpp"
Expand Down Expand Up @@ -31,6 +32,7 @@ LaunchSettings::LaunchSettings(
#endif
QWidget(parent),
m_display(nullptr),
m_cpu(nullptr),
m_games(nullptr),
m_profiles(nullptr)
{
Expand Down Expand Up @@ -73,6 +75,7 @@ QWidget *LaunchSettings::buildSettings(GameListModel *games, QList<VkPhysicalDev
{
// Tab.
auto tab = new QTabWidget();
auto iconSize = tab->iconSize();

// Display settings.
#ifdef __APPLE__
Expand All @@ -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();
Expand All @@ -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;
}
Expand All @@ -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();
Expand All @@ -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(); });

Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/launch_settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#endif
#include <QWidget>

class CpuSettings;
class DisplaySettings;
class GameListModel;
class ProfileList;
Expand Down Expand Up @@ -45,6 +46,7 @@ class LaunchSettings final : public QWidget {
void profileChanged(int index);

DisplaySettings *m_display;
CpuSettings *m_cpu;
QTableView *m_games;
QComboBox *m_profiles;
};
5 changes: 0 additions & 5 deletions src/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 14 additions & 2 deletions src/resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 4 additions & 1 deletion src/resources.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
4 changes: 1 addition & 3 deletions src/resources.qrc
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
1 change: 0 additions & 1 deletion src/resources/archive-arrow-down-outline.svg

This file was deleted.

1 change: 0 additions & 1 deletion src/resources/cog-outline.svg

This file was deleted.

1 change: 1 addition & 0 deletions src/resources/cpu-64-bit.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion src/resources/folder-open-outline.svg

This file was deleted.

0 comments on commit 1a293ad

Please sign in to comment.