configure_graphics.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // Copyright 2016 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <QColorDialog>
  5. #include "core/core.h"
  6. #include "core/settings.h"
  7. #include "ui_configure_graphics.h"
  8. #include "yuzu/configuration/configure_graphics.h"
  9. namespace {
  10. enum class Resolution : int {
  11. Auto,
  12. Scale1x,
  13. Scale2x,
  14. Scale3x,
  15. Scale4x,
  16. };
  17. float ToResolutionFactor(Resolution option) {
  18. switch (option) {
  19. case Resolution::Auto:
  20. return 0.f;
  21. case Resolution::Scale1x:
  22. return 1.f;
  23. case Resolution::Scale2x:
  24. return 2.f;
  25. case Resolution::Scale3x:
  26. return 3.f;
  27. case Resolution::Scale4x:
  28. return 4.f;
  29. }
  30. return 0.f;
  31. }
  32. Resolution FromResolutionFactor(float factor) {
  33. if (factor == 0.f) {
  34. return Resolution::Auto;
  35. } else if (factor == 1.f) {
  36. return Resolution::Scale1x;
  37. } else if (factor == 2.f) {
  38. return Resolution::Scale2x;
  39. } else if (factor == 3.f) {
  40. return Resolution::Scale3x;
  41. } else if (factor == 4.f) {
  42. return Resolution::Scale4x;
  43. }
  44. return Resolution::Auto;
  45. }
  46. } // Anonymous namespace
  47. ConfigureGraphics::ConfigureGraphics(QWidget* parent)
  48. : QWidget(parent), ui(new Ui::ConfigureGraphics) {
  49. ui->setupUi(this);
  50. setConfiguration();
  51. connect(ui->toggle_frame_limit, &QCheckBox::toggled, ui->frame_limit, &QSpinBox::setEnabled);
  52. connect(ui->bg_button, &QPushButton::clicked, this, [this] {
  53. const QColor new_bg_color = QColorDialog::getColor(bg_color);
  54. if (!new_bg_color.isValid()) {
  55. return;
  56. }
  57. UpdateBackgroundColorButton(new_bg_color);
  58. });
  59. }
  60. ConfigureGraphics::~ConfigureGraphics() = default;
  61. void ConfigureGraphics::setConfiguration() {
  62. const bool runtime_lock = !Core::System::GetInstance().IsPoweredOn();
  63. ui->resolution_factor_combobox->setCurrentIndex(
  64. static_cast<int>(FromResolutionFactor(Settings::values.resolution_factor)));
  65. ui->toggle_frame_limit->setChecked(Settings::values.use_frame_limit);
  66. ui->frame_limit->setEnabled(ui->toggle_frame_limit->isChecked());
  67. ui->frame_limit->setValue(Settings::values.frame_limit);
  68. ui->use_compatibility_profile->setEnabled(runtime_lock);
  69. ui->use_compatibility_profile->setChecked(Settings::values.use_compatibility_profile);
  70. ui->use_disk_shader_cache->setEnabled(runtime_lock);
  71. ui->use_disk_shader_cache->setChecked(Settings::values.use_disk_shader_cache);
  72. ui->use_accurate_gpu_emulation->setChecked(Settings::values.use_accurate_gpu_emulation);
  73. ui->use_asynchronous_gpu_emulation->setEnabled(runtime_lock);
  74. ui->use_asynchronous_gpu_emulation->setChecked(Settings::values.use_asynchronous_gpu_emulation);
  75. ui->force_30fps_mode->setEnabled(runtime_lock);
  76. ui->force_30fps_mode->setChecked(Settings::values.force_30fps_mode);
  77. UpdateBackgroundColorButton(QColor::fromRgbF(Settings::values.bg_red, Settings::values.bg_green,
  78. Settings::values.bg_blue));
  79. }
  80. void ConfigureGraphics::applyConfiguration() {
  81. Settings::values.resolution_factor =
  82. ToResolutionFactor(static_cast<Resolution>(ui->resolution_factor_combobox->currentIndex()));
  83. Settings::values.use_frame_limit = ui->toggle_frame_limit->isChecked();
  84. Settings::values.frame_limit = ui->frame_limit->value();
  85. Settings::values.use_compatibility_profile = ui->use_compatibility_profile->isChecked();
  86. Settings::values.use_disk_shader_cache = ui->use_disk_shader_cache->isChecked();
  87. Settings::values.use_accurate_gpu_emulation = ui->use_accurate_gpu_emulation->isChecked();
  88. Settings::values.use_asynchronous_gpu_emulation =
  89. ui->use_asynchronous_gpu_emulation->isChecked();
  90. Settings::values.force_30fps_mode = ui->force_30fps_mode->isChecked();
  91. Settings::values.bg_red = static_cast<float>(bg_color.redF());
  92. Settings::values.bg_green = static_cast<float>(bg_color.greenF());
  93. Settings::values.bg_blue = static_cast<float>(bg_color.blueF());
  94. }
  95. void ConfigureGraphics::UpdateBackgroundColorButton(QColor color) {
  96. bg_color = color;
  97. QPixmap pixmap(ui->bg_button->size());
  98. pixmap.fill(bg_color);
  99. const QIcon color_icon(pixmap);
  100. ui->bg_button->setIcon(color_icon);
  101. }