Wxwidgets: Move screen scaling into main settings dialog
This commit is contained in:
parent
e570ea43aa
commit
036ce8dc0b
4 changed files with 113 additions and 185 deletions
|
@ -37,7 +37,6 @@ void wxeditor_authors_display(wxWindow* parent);
|
|||
void wxeditor_settings_display(wxWindow* parent);
|
||||
void wxeditor_hotkeys_display(wxWindow* parent);
|
||||
std::string wxeditor_keyselect(wxWindow* parent, bool clearable);
|
||||
void wxeditor_screen_display(wxWindow* parent);
|
||||
void wxsetingsdialog_display(wxWindow* parent);
|
||||
|
||||
//Auxillary windows.
|
||||
|
|
|
@ -1,179 +0,0 @@
|
|||
#include "platform/wxwidgets/platform.hpp"
|
||||
#include "library/string.hpp"
|
||||
|
||||
#include <wx/wx.h>
|
||||
#include <wx/event.h>
|
||||
#include <wx/control.h>
|
||||
#include <wx/combobox.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <sstream>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#ifndef UINT64_C
|
||||
#define UINT64_C(val) val##ULL
|
||||
#endif
|
||||
#include <libswscale/swscale.h>
|
||||
}
|
||||
|
||||
const char* algo_choices[] = {"Fast Bilinear", "Bilinear", "Bicubic", "Experimential", "Point", "Area",
|
||||
"Bicubic-Linear", "Gauss", "Sinc", "Lanczos", "Spline"};
|
||||
|
||||
class wxeditor_screen : public wxDialog
|
||||
{
|
||||
public:
|
||||
wxeditor_screen(wxWindow* parent);
|
||||
~wxeditor_screen();
|
||||
bool ShouldPreventAppExit() const;
|
||||
void on_value_change(wxCommandEvent& e);
|
||||
void on_cancel(wxCommandEvent& e);
|
||||
void on_ok(wxCommandEvent& e);
|
||||
private:
|
||||
wxButton* okbutton;
|
||||
wxButton* cancel;
|
||||
wxTextCtrl* horizbox;
|
||||
wxTextCtrl* vertbox;
|
||||
wxComboBox* algo;
|
||||
};
|
||||
|
||||
wxeditor_screen::wxeditor_screen(wxWindow* parent)
|
||||
: wxDialog(parent, wxID_ANY, wxT("lsnes: Screen scaling"), wxDefaultPosition, wxSize(-1, -1))
|
||||
{
|
||||
std::set<std::string> axisnames;
|
||||
std::string h_x, v_x;
|
||||
int algoidx;
|
||||
wxString _algo_choices[sizeof(algo_choices) / sizeof(algo_choices[0])];
|
||||
|
||||
for(size_t i = 0; i < sizeof(_algo_choices) / sizeof(_algo_choices[0]); i++)
|
||||
_algo_choices[i] = towxstring(algo_choices[i]);
|
||||
|
||||
h_x = (stringfmt() << horizontal_scale_factor).str();
|
||||
v_x = (stringfmt() << vertical_scale_factor).str();
|
||||
algoidx = 0;
|
||||
for(size_t i = 0; i < sizeof(algo_choices) / sizeof(_algo_choices[0]); i++)
|
||||
if(scaling_flags & (1 << i)) {
|
||||
algoidx = i;
|
||||
break;
|
||||
}
|
||||
|
||||
Centre();
|
||||
wxFlexGridSizer* top_s = new wxFlexGridSizer(2, 1, 0, 0);
|
||||
SetSizer(top_s);
|
||||
|
||||
wxFlexGridSizer* t_s = new wxFlexGridSizer(3, 2, 0, 0);
|
||||
t_s->Add(new wxStaticText(this, wxID_ANY, wxT("Horizontal factor:")), 0, wxGROW);
|
||||
t_s->Add(horizbox = new wxTextCtrl(this, wxID_ANY, towxstring(h_x), wxDefaultPosition, wxSize(100, -1)), 1,
|
||||
wxGROW);
|
||||
t_s->Add(new wxStaticText(this, wxID_ANY, wxT("Vertical factor:")), 0, wxGROW);
|
||||
t_s->Add(vertbox = new wxTextCtrl(this, wxID_ANY, towxstring(v_x), wxDefaultPosition, wxSize(100, -1)), 1,
|
||||
wxGROW);
|
||||
t_s->Add(new wxStaticText(this, wxID_ANY, wxT("Method:")), 0, wxGROW);
|
||||
t_s->Add(algo = new wxComboBox(this, wxID_ANY, _algo_choices[algoidx], wxDefaultPosition,
|
||||
wxDefaultSize, sizeof(_algo_choices) / sizeof(_algo_choices[0]), _algo_choices, wxCB_READONLY), 1,
|
||||
wxGROW);
|
||||
top_s->Add(t_s);
|
||||
|
||||
horizbox->Connect(wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler(wxeditor_screen::on_value_change), NULL,
|
||||
this);
|
||||
vertbox->Connect(wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler(wxeditor_screen::on_value_change), NULL,
|
||||
this);
|
||||
algo->Connect(wxEVT_COMMAND_COMBOBOX_SELECTED,
|
||||
wxCommandEventHandler(wxeditor_screen::on_value_change), NULL, this);
|
||||
|
||||
wxBoxSizer* pbutton_s = new wxBoxSizer(wxHORIZONTAL);
|
||||
pbutton_s->AddStretchSpacer();
|
||||
pbutton_s->Add(okbutton = new wxButton(this, wxID_OK, wxT("OK")), 0, wxGROW);
|
||||
pbutton_s->Add(cancel = new wxButton(this, wxID_CANCEL, wxT("Cancel")), 0, wxGROW);
|
||||
okbutton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxeditor_screen::on_ok), NULL, this);
|
||||
cancel->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
|
||||
wxCommandEventHandler(wxeditor_screen::on_cancel), NULL, this);
|
||||
top_s->Add(pbutton_s, 0, wxGROW);
|
||||
|
||||
t_s->SetSizeHints(this);
|
||||
top_s->SetSizeHints(this);
|
||||
Fit();
|
||||
|
||||
}
|
||||
|
||||
wxeditor_screen::~wxeditor_screen()
|
||||
{
|
||||
}
|
||||
|
||||
bool wxeditor_screen::ShouldPreventAppExit() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void wxeditor_screen::on_value_change(wxCommandEvent& e)
|
||||
{
|
||||
double hscale;
|
||||
double vscale;
|
||||
int newflags = 0;
|
||||
bool valid = true;
|
||||
try {
|
||||
hscale = parse_value<double>(tostdstring(horizbox->GetValue()));
|
||||
vscale = parse_value<double>(tostdstring(vertbox->GetValue()));
|
||||
if(hscale < 0.25 || hscale > 10)
|
||||
throw std::runtime_error("Specified scale out of range");
|
||||
if(vscale < 0.25 || vscale > 10)
|
||||
throw std::runtime_error("Specified scale out of range");
|
||||
std::string a = tostdstring(algo->GetValue());
|
||||
for(size_t i = 0; i < sizeof(algo_choices) / sizeof(algo_choices[0]); i++)
|
||||
if(a == algo_choices[i])
|
||||
newflags = (1 << i);
|
||||
if(newflags == 0)
|
||||
throw std::runtime_error("Specified algorithm invalid");
|
||||
} catch(...) {
|
||||
valid = false;
|
||||
}
|
||||
okbutton->Enable(valid);
|
||||
}
|
||||
|
||||
void wxeditor_screen::on_cancel(wxCommandEvent& e)
|
||||
{
|
||||
EndModal(wxID_CANCEL);
|
||||
}
|
||||
|
||||
void wxeditor_screen::on_ok(wxCommandEvent& e)
|
||||
{
|
||||
double hscale;
|
||||
double vscale;
|
||||
int newflags = 0;
|
||||
|
||||
try {
|
||||
hscale = parse_value<double>(tostdstring(horizbox->GetValue()));
|
||||
vscale = parse_value<double>(tostdstring(vertbox->GetValue()));
|
||||
if(hscale < 0.25 || hscale > 10)
|
||||
throw std::runtime_error("Specified scale out of range");
|
||||
if(vscale < 0.25 || vscale > 10)
|
||||
throw std::runtime_error("Specified scale out of range");
|
||||
std::string a = tostdstring(algo->GetValue());
|
||||
for(size_t i = 0; i < sizeof(algo_choices) / sizeof(algo_choices[0]); i++)
|
||||
if(a == algo_choices[i])
|
||||
newflags = (1 << i);
|
||||
if(newflags == 0)
|
||||
throw std::runtime_error("Specified algorithm invalid");
|
||||
} catch(...) {
|
||||
return;
|
||||
}
|
||||
|
||||
horizontal_scale_factor = hscale;
|
||||
vertical_scale_factor = vscale;
|
||||
scaling_flags = newflags;
|
||||
EndModal(wxID_OK);
|
||||
}
|
||||
|
||||
void wxeditor_screen_display(wxWindow* parent)
|
||||
{
|
||||
modal_pause_holder hld;
|
||||
wxDialog* editor;
|
||||
try {
|
||||
editor = new wxeditor_screen(parent);
|
||||
editor->ShowModal();
|
||||
} catch(...) {
|
||||
}
|
||||
editor->Destroy();
|
||||
}
|
|
@ -79,7 +79,6 @@ enum
|
|||
wxID_SHOW_STATUS,
|
||||
wxID_SET_SPEED,
|
||||
wxID_SET_VOLUME,
|
||||
wxID_SET_SCREEN,
|
||||
wxID_SPEED_5,
|
||||
wxID_SPEED_10,
|
||||
wxID_SPEED_17,
|
||||
|
@ -774,7 +773,6 @@ wxwin_mainwindow::wxwin_mainwindow()
|
|||
menu_entry(wxID_EDIT_ALIAS, wxT("Configure aliases..."));
|
||||
menu_entry(wxID_EDIT_JUKEBOX, wxT("Configure jukebox..."));
|
||||
menu_separator();
|
||||
menu_entry(wxID_SET_SCREEN, wxT("Set screen scaling..."));
|
||||
menu_entry(wxID_EDIT_HOTKEYS, wxT("Configure hotkeys..."));
|
||||
}
|
||||
|
||||
|
@ -1123,9 +1121,6 @@ void wxwin_mainwindow::handle_menu_click_cancelable(wxCommandEvent& e)
|
|||
runemufn([parsed]() { platform::global_volume = parsed; });
|
||||
return;
|
||||
}
|
||||
case wxID_SET_SCREEN:
|
||||
wxeditor_screen_display(this);
|
||||
return;
|
||||
case wxID_SPEED_5:
|
||||
set_speed(5);
|
||||
break;
|
||||
|
|
|
@ -240,6 +240,14 @@ namespace
|
|||
return (stringfmt() << name << ": " << formattype(s.ktype) << " low:" << s.cal_left << " mid:"
|
||||
<< s.cal_center << " high:" << s.cal_right << " tolerance:" << s.cal_tolerance).str();
|
||||
}
|
||||
|
||||
std::string getalgo(int flags)
|
||||
{
|
||||
for(size_t i = 0; i < sizeof(scalealgo_choices) / sizeof(scalealgo_choices[0]); i++)
|
||||
if(flags & (1 << i))
|
||||
return scalealgo_choices[i];
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
wxeditor_esettings_joystick::wxeditor_esettings_joystick(wxWindow* parent)
|
||||
|
@ -389,6 +397,110 @@ void wxeditor_esettings_paths::refresh()
|
|||
Fit();
|
||||
}
|
||||
|
||||
class wxeditor_esettings_screen : public wxPanel
|
||||
{
|
||||
public:
|
||||
wxeditor_esettings_screen(wxWindow* parent);
|
||||
~wxeditor_esettings_screen();
|
||||
void on_configure(wxCommandEvent& e);
|
||||
private:
|
||||
void refresh();
|
||||
wxStaticText* xscale;
|
||||
wxStaticText* yscale;
|
||||
wxStaticText* algo;
|
||||
wxFlexGridSizer* top_s;
|
||||
};
|
||||
|
||||
wxeditor_esettings_screen::wxeditor_esettings_screen(wxWindow* parent)
|
||||
: wxPanel(parent, -1)
|
||||
{
|
||||
wxButton* tmp;
|
||||
top_s = new wxFlexGridSizer(3, 3, 0, 0);
|
||||
SetSizer(top_s);
|
||||
top_s->Add(new wxStaticText(this, -1, wxT("X scale factor: ")), 0, wxGROW);
|
||||
top_s->Add(xscale = new wxStaticText(this, -1, wxT("")), 1, wxGROW);
|
||||
top_s->Add(tmp = new wxButton(this, wxID_HIGHEST + 1, wxT("Change...")), 0, wxGROW);
|
||||
tmp->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxeditor_esettings_screen::on_configure),
|
||||
NULL, this);
|
||||
top_s->Add(new wxStaticText(this, -1, wxT("Y scale factor: ")), 0, wxGROW);
|
||||
top_s->Add(yscale = new wxStaticText(this, -1, wxT("")), 1, wxGROW);
|
||||
top_s->Add(tmp = new wxButton(this, wxID_HIGHEST + 2, wxT("Change...")), 0, wxGROW);
|
||||
tmp->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxeditor_esettings_screen::on_configure),
|
||||
NULL, this);
|
||||
top_s->Add(new wxStaticText(this, -1, wxT("Scaling type: ")), 0, wxGROW);
|
||||
top_s->Add(algo = new wxStaticText(this, -1, wxT("")), 1, wxGROW);
|
||||
top_s->Add(tmp = new wxButton(this, wxID_HIGHEST + 3, wxT("Change...")), 0, wxGROW);
|
||||
tmp->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxeditor_esettings_screen::on_configure),
|
||||
NULL, this);
|
||||
refresh();
|
||||
top_s->SetSizeHints(this);
|
||||
Fit();
|
||||
}
|
||||
wxeditor_esettings_screen::~wxeditor_esettings_screen()
|
||||
{
|
||||
}
|
||||
|
||||
void wxeditor_esettings_screen::on_configure(wxCommandEvent& e)
|
||||
{
|
||||
if(e.GetId() == wxID_HIGHEST + 1) {
|
||||
std::string v = (stringfmt() << horizontal_scale_factor).str();
|
||||
v = pick_text(this, "Set X scaling factor", "Enter new horizontal scale factor:", v);
|
||||
double x;
|
||||
try {
|
||||
x = parse_value<double>(v);
|
||||
if(x < 0.25 || x > 10)
|
||||
throw 42;
|
||||
} catch(...) {
|
||||
wxMessageBox(wxT("Bad horizontal scale factor (0.25-10)"), wxT("Input error"),
|
||||
wxICON_EXCLAMATION | wxOK);
|
||||
refresh();
|
||||
return;
|
||||
}
|
||||
horizontal_scale_factor = x;
|
||||
} else if(e.GetId() == wxID_HIGHEST + 2) {
|
||||
std::string v = (stringfmt() << vertical_scale_factor).str();
|
||||
v = pick_text(this, "Set Y scaling factor", "Enter new vertical scale factor:", v);
|
||||
double x;
|
||||
try {
|
||||
x = parse_value<double>(v);
|
||||
if(x < 0.25 || x > 10)
|
||||
throw 42;
|
||||
} catch(...) {
|
||||
wxMessageBox(wxT("Bad vertical scale factor (0.25-10)"), wxT("Input error"),
|
||||
wxICON_EXCLAMATION | wxOK);
|
||||
refresh();
|
||||
return;
|
||||
}
|
||||
vertical_scale_factor = x;
|
||||
} else if(e.GetId() == wxID_HIGHEST + 3) {
|
||||
std::vector<std::string> choices;
|
||||
std::string v;
|
||||
int newflags = 1;
|
||||
for(size_t i = 0; i < sizeof(scalealgo_choices) / sizeof(scalealgo_choices[0]); i++)
|
||||
choices.push_back(scalealgo_choices[i]);
|
||||
try {
|
||||
v = pick_among(this, "Select algorithm", "Select scaling algorithm", choices);
|
||||
} catch(...) {
|
||||
refresh();
|
||||
return;
|
||||
}
|
||||
for(size_t i = 0; i < sizeof(scalealgo_choices) / sizeof(scalealgo_choices[0]); i++)
|
||||
if(v == scalealgo_choices[i])
|
||||
newflags = 1 << i;
|
||||
scaling_flags = newflags;
|
||||
}
|
||||
refresh();
|
||||
}
|
||||
|
||||
void wxeditor_esettings_screen::refresh()
|
||||
{
|
||||
xscale->SetLabel(towxstring((stringfmt() << horizontal_scale_factor).str()));
|
||||
yscale->SetLabel(towxstring((stringfmt() << vertical_scale_factor).str()));
|
||||
algo->SetLabel(towxstring(getalgo(scaling_flags)));
|
||||
top_s->Layout();
|
||||
Fit();
|
||||
}
|
||||
|
||||
class wxeditor_esettings : public wxDialog
|
||||
{
|
||||
public:
|
||||
|
@ -412,6 +524,7 @@ wxeditor_esettings::wxeditor_esettings(wxWindow* parent)
|
|||
tabset = new wxNotebook(this, -1, wxDefaultPosition, wxDefaultSize, wxNB_TOP);
|
||||
tabset->AddPage(new wxeditor_esettings_joystick(tabset), wxT("Joysticks"));
|
||||
tabset->AddPage(new wxeditor_esettings_paths(tabset), wxT("Paths"));
|
||||
tabset->AddPage(new wxeditor_esettings_screen(tabset), wxT("Scaling"));
|
||||
top_s->Add(tabset, 1, wxGROW);
|
||||
|
||||
wxBoxSizer* pbutton_s = new wxBoxSizer(wxHORIZONTAL);
|
||||
|
|
Loading…
Add table
Reference in a new issue