Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GUI: Add game window resize on boot #3000

Merged
merged 2 commits into from Jul 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 16 additions & 9 deletions rpcs3/rpcs3_app.cpp
@@ -1,7 +1,6 @@
#include "rpcs3_app.h"

#include "rpcs3qt/welcome_dialog.h"
#include "rpcs3qt/gui_settings.h"

#include "Emu/System.h"
#include "rpcs3qt/gs_frame.h"
Expand Down Expand Up @@ -56,8 +55,10 @@ void rpcs3_app::Init()
{
Emu.Init();

guiSettings.reset(new gui_settings());

// Create the main window
RPCS3MainWin = new main_window(nullptr);
RPCS3MainWin = new main_window(guiSettings, nullptr);

// Reset the pads -- see the method for why this is currently needed.
ResetPads();
Expand All @@ -76,9 +77,7 @@ void rpcs3_app::Init()
// Create the thumbnail toolbar after the main_window is created
RPCS3MainWin->CreateThumbnailToolbar();

// Slightly inneficient to make a gui_settings instance right here.
// But, I don't really feel like adding this as a dependency injection into RPCS3MainWin.
if (gui_settings().GetValue(GUI::ib_show_welcome).toBool())
if (guiSettings->GetValue(GUI::ib_show_welcome).toBool())
{
welcome_dialog* welcome = new welcome_dialog();
welcome->exec();
Expand Down Expand Up @@ -148,14 +147,22 @@ void rpcs3_app::InitializeCallbacks()
extern const std::unordered_map<video_resolution, std::pair<int, int>, value_hash<video_resolution>> g_video_out_resolution_map;

const auto size = g_video_out_resolution_map.at(g_cfg.video.resolution);
int w = size.first;
int h = size.second;

if (guiSettings->GetValue(GUI::gs_resize).toBool())
{
w = guiSettings->GetValue(GUI::gs_width).toInt();
h = guiSettings->GetValue(GUI::gs_height).toInt();
}

switch (video_renderer type = g_cfg.video.renderer)
{
case video_renderer::null: return std::make_unique<gs_frame>("Null", size.first, size.second, RPCS3MainWin->GetAppIcon());
case video_renderer::opengl: return std::make_unique<gl_gs_frame>(size.first, size.second, RPCS3MainWin->GetAppIcon());
case video_renderer::vulkan: return std::make_unique<gs_frame>("Vulkan", size.first, size.second, RPCS3MainWin->GetAppIcon());
case video_renderer::null: return std::make_unique<gs_frame>("Null", w, h, RPCS3MainWin->GetAppIcon());
case video_renderer::opengl: return std::make_unique<gl_gs_frame>(w, h, RPCS3MainWin->GetAppIcon());
case video_renderer::vulkan: return std::make_unique<gs_frame>("Vulkan", w, h, RPCS3MainWin->GetAppIcon());
#ifdef _MSC_VER
case video_renderer::dx12: return std::make_unique<gs_frame>("DirectX 12", size.first, size.second, RPCS3MainWin->GetAppIcon());
case video_renderer::dx12: return std::make_unique<gs_frame>("DirectX 12", w, h, RPCS3MainWin->GetAppIcon());
#endif
default: fmt::throw_exception("Invalid video renderer: %s" HERE, type);
}
Expand Down
3 changes: 3 additions & 0 deletions rpcs3/rpcs3_app.h
Expand Up @@ -15,6 +15,7 @@

#include "rpcs3qt/msg_dialog_frame.h"
#include "rpcs3qt/main_window.h"
#include "rpcs3qt/gui_settings.h"

#include <QApplication>

Expand Down Expand Up @@ -51,4 +52,6 @@ private Q_SLOTS:
std::shared_ptr<basic_mouse_handler> m_basicMouseHandler;

main_window* RPCS3MainWin;

std::shared_ptr<gui_settings> guiSettings;
};
5 changes: 5 additions & 0 deletions rpcs3/rpcs3qt/gui_settings.h
Expand Up @@ -52,6 +52,7 @@ namespace GUI
const QString logger = "Logger";
const QString meta = "Meta";
const QString fs = "FileSystem";
const QString gs_frame = "GSFrame";

const QColor mw_tool_bar_color = QColor(227, 227, 227, 255);
const QColor mw_tool_icon_color = QColor(64, 64, 64, 255);
Expand Down Expand Up @@ -113,6 +114,10 @@ namespace GUI

const GUI_SAVE m_currentConfig = GUI_SAVE(meta, "currentConfig", QObject::tr("CurrentSettings"));
const GUI_SAVE m_currentStylesheet = GUI_SAVE(meta, "currentStylesheet", QObject::tr("default"));

const GUI_SAVE gs_resize = GUI_SAVE(gs_frame, "resize", false);
const GUI_SAVE gs_width = GUI_SAVE(gs_frame, "width", 1280);
const GUI_SAVE gs_height = GUI_SAVE(gs_frame, "height", 720);
}

/** Class for GUI settings..
Expand Down
4 changes: 1 addition & 3 deletions rpcs3/rpcs3qt/main_window.cpp
Expand Up @@ -46,7 +46,7 @@

inline std::string sstr(const QString& _in) { return _in.toUtf8().toStdString(); }

main_window::main_window(QWidget *parent) : QMainWindow(parent), m_sys_menu_opened(false), ui(new Ui::main_window)
main_window::main_window(std::shared_ptr<gui_settings> guiSettings, QWidget *parent) : QMainWindow(parent), guiSettings(guiSettings), m_sys_menu_opened(false), ui(new Ui::main_window)
{
}

Expand All @@ -69,8 +69,6 @@ void main_window::Init()
{
ui->setupUi(this);

guiSettings.reset(new gui_settings());

// Load Icons: This needs to happen before any actions or buttons are created
RepaintToolBarIcons();
appIcon = QIcon(":/rpcs3.ico");
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/rpcs3qt/main_window.h
Expand Up @@ -56,7 +56,7 @@ class main_window : public QMainWindow
#endif

public:
explicit main_window(QWidget *parent = 0);
explicit main_window(std::shared_ptr<gui_settings> guiSettings, QWidget *parent = 0);
void Init();
~main_window();
void CreateThumbnailToolbar();
Expand Down
34 changes: 34 additions & 0 deletions rpcs3/rpcs3qt/settings_dialog.cpp
Expand Up @@ -8,6 +8,9 @@
#include <QJsonObject>
#include <QJsonDocument>
#include <QColorDialog>
#include <QSpinBox>
#include <QApplication>
#include <QDesktopWidget>

#include "settings_dialog.h"

Expand Down Expand Up @@ -733,6 +736,37 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> xSettings, const
addColoredIcon(ui->pb_gl_tool_icon_color, xgui_settings->GetValue(GUI::gl_toolIconColor).value<QColor>(), QIcon(":/Icons/home_blue.png"), GUI::gl_tool_icon_color);
addColoredIcon(ui->pb_tool_icon_color, xgui_settings->GetValue(GUI::mw_toolIconColor).value<QColor>(), QIcon(":/Icons/stop.png"), GUI::mw_tool_icon_color);

bool enableButtons = xgui_settings->GetValue(GUI::gs_resize).toBool();
ui->gs_resizeOnBoot->setChecked(enableButtons);
ui->gs_width->setEnabled(enableButtons);
ui->gs_height->setEnabled(enableButtons);

QRect rec = QApplication::desktop()->screenGeometry();
int width = xgui_settings->GetValue(GUI::gs_width).toInt();
int height = xgui_settings->GetValue(GUI::gs_height).toInt();
const int max_width = rec.width();
const int max_height = rec.height();
ui->gs_width->setValue(width < max_width ? width : max_width);
ui->gs_height->setValue(height < max_height ? height : max_height);

connect(ui->gs_resizeOnBoot, &QCheckBox::clicked, [=](bool val) {
xgui_settings->SetValue(GUI::gs_resize, val);
ui->gs_width->setEnabled(val);
ui->gs_height->setEnabled(val);
});
connect(ui->gs_width, static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged), [=](int w) {
int width = QApplication::desktop()->screenGeometry().width();
w = w > width ? width : w;
ui->gs_width->setValue(w);
xgui_settings->SetValue(GUI::gs_width, w);
});
connect(ui->gs_height, static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged), [=](int h) {
int height = QApplication::desktop()->screenGeometry().height();
h = h > height ? height : h;
ui->gs_height->setValue(h);
xgui_settings->SetValue(GUI::gs_height, h);
});

AddConfigs();
AddStylesheets();
}
Expand Down
84 changes: 83 additions & 1 deletion rpcs3/rpcs3qt/settings_dialog.ui
Expand Up @@ -1147,7 +1147,89 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_19">
<item>
<widget class="QWidget" name="widget_6" native="true"/>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Viewport</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_50">
<item>
<widget class="QCheckBox" name="gs_resizeOnBoot">
<property name="text">
<string>Resize game window on boot</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_20">
<item>
<widget class="QGroupBox" name="groupBox_4">
<property name="title">
<string>Width</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_49">
<item>
<widget class="QSpinBox" name="gs_width">
<property name="accelerated">
<bool>true</bool>
</property>
<property name="correctionMode">
<enum>QAbstractSpinBox::CorrectToNearestValue</enum>
</property>
<property name="keyboardTracking">
<bool>false</bool>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>9999</number>
</property>
<property name="value">
<number>0</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_5">
<property name="title">
<string>Heigth</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_48">
<item>
<widget class="QSpinBox" name="gs_height">
<property name="frame">
<bool>true</bool>
</property>
<property name="accelerated">
<bool>true</bool>
</property>
<property name="correctionMode">
<enum>QAbstractSpinBox::CorrectToNearestValue</enum>
</property>
<property name="keyboardTracking">
<bool>false</bool>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>9999</number>
</property>
<property name="value">
<number>0</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
Expand Down