Initial screen resizing implementation

This feature allows the user to resize the game screen to a predefined
multiple of native.
There are some issues that will be addressed in future commits.
Namely:
-interaction with layout change
-a way to change in the configurations menu
-singe window off
-maybe game list needs a separate geometry
This commit is contained in:
Vitor Kiguchi 2020-07-28 14:10:15 -03:00
parent 9ff97270cf
commit a54ea07d6f
5 changed files with 116 additions and 0 deletions

View File

@ -606,6 +606,8 @@ void Config::ReadUIValues() {
ReadShortcutValues();
ReadMultiplayerValues();
UISettings::values.fixed_screen_size =
ReadSetting(QStringLiteral("FixedScreenSize"), 0).toInt();
UISettings::values.single_window_mode =
ReadSetting(QStringLiteral("singleWindowMode"), true).toBool();
UISettings::values.fullscreen = ReadSetting(QStringLiteral("fullscreen"), false).toBool();
@ -1096,6 +1098,7 @@ void Config::SaveUIValues() {
SaveShortcutValues();
SaveMultiplayerValues();
WriteSetting(QStringLiteral("FixedScreenSize"), UISettings::values.fixed_screen_size, 0);
WriteSetting(QStringLiteral("singleWindowMode"), UISettings::values.single_window_mode, true);
WriteSetting(QStringLiteral("fullscreen"), UISettings::values.fullscreen, false);
WriteSetting(QStringLiteral("displayTitleBars"), UISettings::values.display_titlebar, true);

View File

@ -314,6 +314,12 @@ void GMainWindow::InitializeWidgets() {
actionGroup_ScreenLayouts->addAction(ui->action_Screen_Layout_Single_Screen);
actionGroup_ScreenLayouts->addAction(ui->action_Screen_Layout_Large_Screen);
actionGroup_ScreenLayouts->addAction(ui->action_Screen_Layout_Side_by_Side);
QActionGroup* actionGroup_ScreenSizes = new QActionGroup(this);
actionGroup_ScreenSizes->addAction(ui->action_Screen_Size_1x);
actionGroup_ScreenSizes->addAction(ui->action_Screen_Size_2x);
actionGroup_ScreenSizes->addAction(ui->action_Screen_Size_3x);
actionGroup_ScreenSizes->addAction(ui->action_Screen_Size_4x);
}
void GMainWindow::InitializeDebugWidgets() {
@ -752,6 +758,11 @@ void GMainWindow::ConnectMenuEvents() {
connect(ui->action_Screen_Layout_Upright_Screens, &QAction::triggered, this,
&GMainWindow::OnRotateScreens);
connect(ui->action_Screen_Size_1x, &QAction::triggered, this, &GMainWindow::ChangeScreenSize);
connect(ui->action_Screen_Size_2x, &QAction::triggered, this, &GMainWindow::ChangeScreenSize);
connect(ui->action_Screen_Size_3x, &QAction::triggered, this, &GMainWindow::ChangeScreenSize);
connect(ui->action_Screen_Size_4x, &QAction::triggered, this, &GMainWindow::ChangeScreenSize);
// Movie
connect(ui->action_Record_Movie, &QAction::triggered, this, &GMainWindow::OnRecordMovie);
connect(ui->action_Play_Movie, &QAction::triggered, this, &GMainWindow::OnPlayMovie);
@ -1665,6 +1676,37 @@ void GMainWindow::ToggleWindowMode() {
}
}
void GMainWindow::ResizeScreen(const int scale) {
const auto size = Layout::GetMinimumSizeFromLayout(Settings::values.layout_option,
Settings::values.upright_screen);
auto_resized = true;
render_window->setMinimumSize(scale * size.first, scale * size.second);
render_window->UpdateCurrentFramebufferLayout(scale * size.first, scale * size.second);
ui->centralwidget->resize(scale * size.first, scale * size.second);
resize(sizeHint());
render_window->setMinimumSize(size.first, size.second);
}
void GMainWindow::ChangeScreenSize() {
int new_scale = 0;
if (ui->action_Screen_Size_1x->isChecked()) {
new_scale = 1;
} else if (ui->action_Screen_Size_2x->isChecked()) {
new_scale = 2;
} else if (ui->action_Screen_Size_3x->isChecked()) {
new_scale = 3;
} else if (ui->action_Screen_Size_4x->isChecked()) {
new_scale = 4;
}
UISettings::values.fixed_screen_size = new_scale;
ResizeScreen(new_scale);
}
void GMainWindow::ChangeScreenLayout() {
Settings::LayoutOption new_layout = Settings::LayoutOption::Default;
@ -2126,6 +2168,15 @@ void GMainWindow::mouseReleaseEvent([[maybe_unused]] QMouseEvent* event) {
OnMouseActivity();
}
void GMainWindow::resizeEvent(QResizeEvent* event) {
// This resize event was not triggered by the user
if (auto_resized) {
auto_resized = false;
} else {
UncheckWindowSize();
}
}
void GMainWindow::OnCoreError(Core::System::ResultStatus result, std::string details) {
QString status_message;
@ -2372,6 +2423,13 @@ void GMainWindow::UpdateWindowTitle() {
}
}
void GMainWindow::UncheckWindowSize() {
ui->action_Screen_Size_1x->setChecked(false);
ui->action_Screen_Size_2x->setChecked(false);
ui->action_Screen_Size_3x->setChecked(false);
ui->action_Screen_Size_4x->setChecked(false);
}
void GMainWindow::UpdateUISettings() {
if (!ui->action_Fullscreen->isChecked()) {
UISettings::values.geometry = saveGeometry();
@ -2401,6 +2459,11 @@ void GMainWindow::SyncMenuUISettings() {
Settings::LayoutOption::SideScreen);
ui->action_Screen_Layout_Swap_Screens->setChecked(Settings::values.swap_screen);
ui->action_Screen_Layout_Upright_Screens->setChecked(Settings::values.upright_screen);
ui->action_Screen_Size_1x->setChecked(UISettings::values.fixed_screen_size == 1);
ui->action_Screen_Size_2x->setChecked(UISettings::values.fixed_screen_size == 2);
ui->action_Screen_Size_3x->setChecked(UISettings::values.fixed_screen_size == 3);
ui->action_Screen_Size_4x->setChecked(UISettings::values.fixed_screen_size == 4);
}
void GMainWindow::RetranslateStatusBar() {

View File

@ -120,6 +120,9 @@ private:
void ConnectWidgetEvents();
void ConnectMenuEvents();
void ResizeScreen(int scale);
void UncheckWindowSize();
void PreventOSSleep();
void AllowOSSleep();
@ -197,6 +200,7 @@ private slots:
void OnDisplayTitleBars(bool);
void InitializeHotkeys();
void ToggleFullscreen();
void ChangeScreenSize();
void ChangeScreenLayout();
void ToggleScreenLayout();
void OnSwapScreens();
@ -261,8 +265,10 @@ private:
// The path to the game currently running
QString game_path;
// Internal states of misc features
bool auto_paused = false;
QTimer mouse_hide_timer;
bool auto_resized = false;
// Movie
bool movie_record_on_start = false;
@ -316,6 +322,7 @@ protected:
void mouseMoveEvent(QMouseEvent* event) override;
void mousePressEvent(QMouseEvent* event) override;
void mouseReleaseEvent(QMouseEvent* event) override;
void resizeEvent(QResizeEvent* event) override;
};
Q_DECLARE_METATYPE(std::size_t);

View File

@ -129,9 +129,19 @@
<addaction name="action_Screen_Layout_Upright_Screens"/>
<addaction name="action_Screen_Layout_Swap_Screens"/>
</widget>
<widget class="QMenu" name="menu_Screen_Size">
<property name="title">
<string>Screen Size</string>
</property>
<addaction name="action_Screen_Size_1x"/>
<addaction name="action_Screen_Size_2x"/>
<addaction name="action_Screen_Size_3x"/>
<addaction name="action_Screen_Size_4x"/>
</widget>
<addaction name="action_Fullscreen"/>
<addaction name="action_Single_Window_Mode"/>
<addaction name="menu_Screen_Layout"/>
<addaction name="menu_Screen_Size"/>
<addaction name="separator"/>
<addaction name="action_Display_Dock_Widget_Headers"/>
<addaction name="action_Show_Filter_Bar"/>
@ -477,6 +487,38 @@
<string>Rotate Upright</string>
</property>
</action>
<action name="action_Screen_Size_1x">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>1x</string>
</property>
</action>
<action name="action_Screen_Size_2x">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>2x</string>
</property>
</action>
<action name="action_Screen_Size_3x">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>3x</string>
</property>
</action>
<action name="action_Screen_Size_4x">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>4x</string>
</property>
</action>
<action name="action_Check_For_Updates">
<property name="text">
<string>Check for Updates</string>

View File

@ -72,6 +72,7 @@ struct Values {
bool display_titlebar;
bool show_filter_bar;
bool show_status_bar;
int fixed_screen_size;
bool confirm_before_closing;
bool first_start;