mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-06-07 19:41:38 +12:00
Qt: Optionally remember window pos/size
This commit is contained in:
parent
7ae8412919
commit
818271c7ad
3 changed files with 66 additions and 10 deletions
|
@ -43,7 +43,21 @@ void EmulatorConfig::load() {
|
|||
defaultRomPath = toml::find_or<std::string>(general, "DefaultRomPath", "");
|
||||
|
||||
printAppVersion = toml::find_or<toml::boolean>(general, "PrintAppVersion", true);
|
||||
appVersionOnWindow = toml::find_or<toml::boolean>(general, "AppVersionOnWindow", false);
|
||||
}
|
||||
}
|
||||
|
||||
if (data.contains("Window")) {
|
||||
auto windowResult = toml::expect<toml::value>(data.at("Window"));
|
||||
if (windowResult.is_ok()) {
|
||||
auto window = windowResult.unwrap();
|
||||
|
||||
windowSettings.showAppVersion = toml::find_or<toml::boolean>(window, "AppVersionOnWindow", false);
|
||||
windowSettings.rememberPosition = toml::find_or<toml::boolean>(window, "RememberWindowPosition", false);
|
||||
|
||||
windowSettings.x = toml::find_or<toml::integer>(window, "WindowPosX", WindowSettings::defaultX);
|
||||
windowSettings.y = toml::find_or<toml::integer>(window, "WindowPosY", WindowSettings::defaultY);
|
||||
windowSettings.width = toml::find_or<toml::integer>(window, "WindowWidth", WindowSettings::defaultWidth);
|
||||
windowSettings.height = toml::find_or<toml::integer>(window, "WindowHeight", WindowSettings::defaultHeight);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,7 +147,13 @@ void EmulatorConfig::save() {
|
|||
data["General"]["UsePortableBuild"] = usePortableBuild;
|
||||
data["General"]["DefaultRomPath"] = defaultRomPath.string();
|
||||
data["General"]["PrintAppVersion"] = printAppVersion;
|
||||
data["General"]["AppVersionOnWindow"] = appVersionOnWindow;
|
||||
|
||||
data["Window"]["AppVersionOnWindow"] = windowSettings.showAppVersion;
|
||||
data["Window"]["RememberWindowPosition"] = windowSettings.rememberPosition;
|
||||
data["Window"]["WindowPosX"] = windowSettings.x;
|
||||
data["Window"]["WindowPosY"] = windowSettings.y;
|
||||
data["Window"]["WindowWidth"] = windowSettings.width;
|
||||
data["Window"]["WindowHeight"] = windowSettings.height;
|
||||
|
||||
data["GPU"]["EnableShaderJIT"] = shaderJitEnabled;
|
||||
data["GPU"]["Renderer"] = std::string(Renderer::typeToString(rendererType));
|
||||
|
|
|
@ -99,12 +99,22 @@ MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent)
|
|||
}
|
||||
}
|
||||
|
||||
if (emu->getConfig().appVersionOnWindow) {
|
||||
setWindowTitle("Alber v" PANDA3DS_VERSION);
|
||||
}
|
||||
// Handle UI configs before setting up the emulator thread
|
||||
{
|
||||
auto& config = emu->getConfig();
|
||||
auto& windowSettings = config.windowSettings;
|
||||
|
||||
if (emu->getConfig().printAppVersion) {
|
||||
printf("Welcome to Panda3DS v%s!\n", PANDA3DS_VERSION);
|
||||
if (windowSettings.showAppVersion) {
|
||||
setWindowTitle("Alber v" PANDA3DS_VERSION);
|
||||
}
|
||||
|
||||
if (windowSettings.rememberPosition) {
|
||||
setGeometry(windowSettings.x, windowSettings.y, windowSettings.width, config.windowSettings.height);
|
||||
}
|
||||
|
||||
if (config.printAppVersion) {
|
||||
printf("Welcome to Panda3DS v%s!\n", PANDA3DS_VERSION);
|
||||
}
|
||||
}
|
||||
|
||||
// The emulator graphics context for the thread should be initialized in the emulator thread due to how GL contexts work
|
||||
|
@ -221,6 +231,15 @@ void MainWindow::closeEvent(QCloseEvent *event) {
|
|||
if (emuThread.joinable()) {
|
||||
emuThread.join();
|
||||
}
|
||||
|
||||
// Cache window position/size in config file to restore next time
|
||||
const QRect& windowGeometry = geometry();
|
||||
auto& windowConfig = emu->getConfig().windowSettings;
|
||||
|
||||
windowConfig.x = windowGeometry.x();
|
||||
windowConfig.y = windowGeometry.y();
|
||||
windowConfig.width = windowGeometry.width();
|
||||
windowConfig.height = windowGeometry.height();
|
||||
}
|
||||
|
||||
// Cleanup when the main window closes
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue