configure_graphics.cpp 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. this->setConfiguration();
  51. ui->frame_limit->setEnabled(Settings::values.use_frame_limit);
  52. connect(ui->toggle_frame_limit, &QCheckBox::stateChanged, ui->frame_limit,
  53. &QSpinBox::setEnabled);
  54. connect(ui->bg_button, &QPushButton::clicked, this, [this] {
  55. const QColor new_bg_color = QColorDialog::getColor(bg_color);
  56. if (!new_bg_color.isValid())
  57. return;
  58. bg_color = new_bg_color;
  59. ui->bg_button->setStyleSheet(
  60. QString("QPushButton { background-color: %1 }").arg(bg_color.name()));
  61. });
  62. }
  63. ConfigureGraphics::~ConfigureGraphics() = default;
  64. void ConfigureGraphics::setConfiguration() {
  65. ui->resolution_factor_combobox->setCurrentIndex(
  66. static_cast<int>(FromResolutionFactor(Settings::values.resolution_factor)));
  67. ui->toggle_frame_limit->setChecked(Settings::values.use_frame_limit);
  68. ui->frame_limit->setValue(Settings::values.frame_limit);
  69. ui->use_accurate_gpu_emulation->setChecked(Settings::values.use_accurate_gpu_emulation);
  70. bg_color = QColor::fromRgbF(Settings::values.bg_red, Settings::values.bg_green,
  71. Settings::values.bg_blue);
  72. ui->bg_button->setStyleSheet(
  73. QString("QPushButton { background-color: %1 }").arg(bg_color.name()));
  74. }
  75. void ConfigureGraphics::applyConfiguration() {
  76. Settings::values.resolution_factor =
  77. ToResolutionFactor(static_cast<Resolution>(ui->resolution_factor_combobox->currentIndex()));
  78. Settings::values.use_frame_limit = ui->toggle_frame_limit->isChecked();
  79. Settings::values.frame_limit = ui->frame_limit->value();
  80. Settings::values.use_accurate_gpu_emulation = ui->use_accurate_gpu_emulation->isChecked();
  81. Settings::values.bg_red = static_cast<float>(bg_color.redF());
  82. Settings::values.bg_green = static_cast<float>(bg_color.greenF());
  83. Settings::values.bg_blue = static_cast<float>(bg_color.blueF());
  84. }