If initsram/initstate points to LSS file, pull the matching member
[lsnes.git] / src / platform / wxwidgets / settings-video.cpp
blobe9a0262f0ee963b27f5fa0704f56e56d61494732
1 #include "platform/wxwidgets/settings-common.hpp"
2 #include "platform/wxwidgets/window_mainwindow.hpp"
4 namespace
6 enum
8 wxID_SCALE_FACTOR = wxID_HIGHEST + 1,
9 wxID_SCALE_ALGO = wxID_HIGHEST + 2,
10 wxID_AR_CORRECT = wxID_HIGHEST + 3,
11 wxID_ORIENT = wxID_HIGHEST + 4,
14 const char* scalealgo_choices[] = {"Fast Bilinear", "Bilinear", "Bicubic", "Experimential", "Point", "Area",
15 "Bicubic-Linear", "Gauss", "Sinc", "Lanczos", "Spline"};
16 const char* orientations[] = {"Normal", "Rotate 90° left", "Rotate 90° right", "Rotate 180°",
17 "Flip horizontal", "Flip vertical", "Transpose", "Transpose other"};
18 unsigned orientation_flags[] = {0, 7, 1, 6, 2, 4, 5, 3};
19 unsigned inv_orientation_flags[] = {0, 2, 4, 7, 5, 6, 3, 1};
21 std::string getalgo(int flags)
23 for(size_t i = 0; i < sizeof(scalealgo_choices) / sizeof(scalealgo_choices[0]); i++)
24 if(flags & (1 << i))
25 return scalealgo_choices[i];
26 return "unknown";
29 unsigned get_orientation()
31 unsigned x = 0;
32 x |= (rotate_enabled ? 1 : 0);
33 x |= (hflip_enabled ? 2 : 0);
34 x |= (vflip_enabled ? 4 : 0);
35 return inv_orientation_flags[x];
38 class wxeditor_esettings_video : public settings_tab
40 public:
41 wxeditor_esettings_video(wxWindow* parent, emulator_instance& _inst);
42 ~wxeditor_esettings_video();
43 void on_configure(wxCommandEvent& e);
44 wxCheckBox* arcorrect;
45 wxComboBox* scalealgo;
46 wxComboBox* orient;
47 wxSpinCtrl* scalefact;
48 void on_close();
49 private:
50 void refresh();
51 wxFlexGridSizer* top_s;
54 wxeditor_esettings_video::wxeditor_esettings_video(wxWindow* parent, emulator_instance& _inst)
55 : settings_tab(parent, _inst)
57 CHECK_UI_THREAD;
58 std::vector<wxString> scales;
59 std::vector<wxString> orients;
60 for(size_t i = 0; i < sizeof(scalealgo_choices)/sizeof(scalealgo_choices[0]); i++)
61 scales.push_back(towxstring(scalealgo_choices[i]));
62 for(size_t i = 0; i < sizeof(orientations)/sizeof(orientations[0]); i++)
63 orients.push_back(towxstring(orientations[i]));
65 top_s = new wxFlexGridSizer(4, 2, 0, 0);
66 SetSizer(top_s);
67 top_s->Add(new wxStaticText(this, -1, wxT("Scale %: ")), 0, wxGROW);
68 top_s->Add(scalefact = new wxSpinCtrl(this, wxID_SCALE_FACTOR, wxT(""), wxDefaultPosition,
69 wxDefaultSize, wxSP_ARROW_KEYS, 25, 1000, 100 * video_scale_factor), 1, wxGROW);
70 top_s->Add(new wxStaticText(this, -1, wxT("Scaling type: ")), 0, wxGROW);
71 top_s->Add(scalealgo = new wxComboBox(this, wxID_SCALE_ALGO, towxstring(getalgo(scaling_flags)),
72 wxDefaultPosition, wxDefaultSize, scales.size(), &scales[0], wxCB_READONLY), 1, wxGROW);
73 top_s->Add(new wxStaticText(this, -1, wxT("Orientation: ")), 0, wxGROW);
74 top_s->Add(orient = new wxComboBox(this, wxID_ORIENT, towxstring(orientations[get_orientation()]),
75 wxDefaultPosition, wxDefaultSize, orients.size(), &orients[0], wxCB_READONLY), 1, wxGROW);
77 top_s->Add(arcorrect = new wxCheckBox(this, wxID_AR_CORRECT, wxT("AR correction")), 1, wxGROW);
79 scalefact->Connect(wxEVT_COMMAND_SPINCTRL_UPDATED,
80 wxCommandEventHandler(wxeditor_esettings_video::on_configure), NULL, this);
81 scalealgo->Connect(wxEVT_COMMAND_COMBOBOX_SELECTED,
82 wxCommandEventHandler(wxeditor_esettings_video::on_configure), NULL, this);
83 arcorrect->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED,
84 wxCommandEventHandler(wxeditor_esettings_video::on_configure), NULL, this);
85 orient->Connect(wxEVT_COMMAND_COMBOBOX_SELECTED,
86 wxCommandEventHandler(wxeditor_esettings_video::on_configure), NULL, this);
88 refresh();
89 top_s->SetSizeHints(this);
90 Fit();
93 wxeditor_esettings_video::~wxeditor_esettings_video()
97 void wxeditor_esettings_video::on_configure(wxCommandEvent& e)
99 CHECK_UI_THREAD;
100 std::vector<std::string> sa_choices;
101 std::string v;
102 for(size_t i = 0; i < sizeof(scalealgo_choices) / sizeof(scalealgo_choices[0]); i++)
103 sa_choices.push_back(scalealgo_choices[i]);
104 std::string name;
105 if(e.GetId() <= wxID_HIGHEST || e.GetId() > wxID_HIGHEST + 10)
106 return;
107 try {
108 if(e.GetId() == wxID_SCALE_FACTOR) {
109 video_scale_factor = scalefact->GetValue() / 100.0;
110 } else if(e.GetId() == wxID_SCALE_ALGO) {
111 if(scalealgo->GetSelection() != wxNOT_FOUND)
112 scaling_flags = 1 << scalealgo->GetSelection();
113 } else if(e.GetId() == wxID_AR_CORRECT)
114 arcorrect_enabled = arcorrect->GetValue();
115 else if(e.GetId() == wxID_ORIENT) {
116 unsigned f = orientation_flags[orient->GetSelection()];
117 rotate_enabled = f & 1;
118 hflip_enabled = f & 2;
119 vflip_enabled = f & 4;
121 if(main_window)
122 main_window->notify_update();
123 } catch(std::exception& e) {
124 wxMessageBox(towxstring(std::string("Invalid value: ") + e.what()), wxT("Can't change value"),
125 wxICON_EXCLAMATION | wxOK);
127 refresh();
130 void wxeditor_esettings_video::refresh()
132 CHECK_UI_THREAD;
133 scalefact->SetValue(video_scale_factor * 100.0 + 0.5);
134 arcorrect->SetValue(arcorrect_enabled);
135 orient->SetSelection(get_orientation());
136 scalealgo->SetValue(towxstring(getalgo(scaling_flags)));
137 top_s->Layout();
138 Fit();
141 void wxeditor_esettings_video::on_close()
145 settings_tab_factory _settings_tab("Video", [](wxWindow* parent, emulator_instance& _inst) -> settings_tab* {
146 return new wxeditor_esettings_video(parent, _inst);