2018-11-16 00:42:29 +01:00
|
|
|
/*****************************************************************************\
|
|
|
|
Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
|
|
|
|
This file is licensed under the Snes9x License.
|
|
|
|
For further information, consult the LICENSE file in the root directory.
|
|
|
|
\*****************************************************************************/
|
|
|
|
|
2020-07-05 00:53:38 +02:00
|
|
|
#include "gtk_compat.h"
|
2018-05-13 01:17:19 +02:00
|
|
|
#include <vector>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include "gtk_s9x.h"
|
|
|
|
#include "gtk_display.h"
|
|
|
|
#include "gtk_shader_parameters.h"
|
|
|
|
#include "shaders/glsl.h"
|
|
|
|
|
2020-07-05 00:53:38 +02:00
|
|
|
#include "gfx.h"
|
|
|
|
|
|
|
|
static Gtk::Dialog *dialog = nullptr;
|
|
|
|
static std::vector<GLSLParam> *params = nullptr;
|
2018-05-24 19:18:59 +02:00
|
|
|
static std::vector<GLSLParam> saved_params;
|
|
|
|
|
2019-01-31 23:33:17 +01:00
|
|
|
static inline double snap_to_interval(double value, double interval)
|
2018-05-13 01:17:19 +02:00
|
|
|
{
|
2020-07-05 00:53:38 +02:00
|
|
|
if (interval == 0.0)
|
|
|
|
return value;
|
2019-01-31 23:33:17 +01:00
|
|
|
return round(value / interval) * interval;
|
2018-05-13 01:17:19 +02:00
|
|
|
}
|
|
|
|
|
2020-07-05 00:53:38 +02:00
|
|
|
static void dialog_response(int response_id)
|
2018-05-13 01:17:19 +02:00
|
|
|
{
|
2020-07-05 00:53:38 +02:00
|
|
|
gui_config->shader_parameters_width = dialog->get_width();
|
|
|
|
gui_config->shader_parameters_height = dialog->get_height();
|
2018-05-24 19:18:59 +02:00
|
|
|
|
|
|
|
switch (response_id)
|
|
|
|
{
|
2020-07-05 00:53:38 +02:00
|
|
|
case Gtk::RESPONSE_OK:
|
2018-11-18 20:08:42 +01:00
|
|
|
{
|
2018-12-29 01:36:23 +01:00
|
|
|
char path[PATH_MAX];
|
2019-01-26 00:54:55 +01:00
|
|
|
std::string config_file = get_config_dir();
|
2019-01-26 19:37:03 +01:00
|
|
|
if (gui_config->shader_filename.find(".slang") != std::string::npos)
|
2019-01-26 00:54:55 +01:00
|
|
|
config_file += "/snes9x.slangp";
|
|
|
|
else
|
|
|
|
config_file = get_config_dir() + "/snes9x.glslp";
|
2019-01-31 23:33:17 +01:00
|
|
|
S9xDisplayGetDriver()->save(config_file.c_str());
|
|
|
|
realpath(config_file.c_str(), path);
|
2018-12-29 01:36:23 +01:00
|
|
|
gui_config->shader_filename = path;
|
2018-05-24 19:18:59 +02:00
|
|
|
|
|
|
|
if (dialog)
|
2020-07-05 00:53:38 +02:00
|
|
|
delete dialog;
|
|
|
|
dialog = nullptr;
|
2018-05-24 19:18:59 +02:00
|
|
|
break;
|
2018-11-18 20:08:42 +01:00
|
|
|
}
|
2018-05-24 19:18:59 +02:00
|
|
|
|
2020-07-05 00:53:38 +02:00
|
|
|
case Gtk::RESPONSE_CANCEL:
|
|
|
|
case Gtk::RESPONSE_DELETE_EVENT:
|
|
|
|
case Gtk::RESPONSE_NONE:
|
2018-05-24 19:18:59 +02:00
|
|
|
if (dialog)
|
2020-07-05 00:53:38 +02:00
|
|
|
delete dialog;
|
|
|
|
dialog = nullptr;
|
2018-05-24 19:18:59 +02:00
|
|
|
*params = saved_params;
|
|
|
|
if (Settings.Paused)
|
2019-01-31 23:33:17 +01:00
|
|
|
S9xDeinitUpdate(top_level->last_width, top_level->last_height);
|
2018-05-24 19:18:59 +02:00
|
|
|
break;
|
|
|
|
|
2019-01-31 23:33:17 +01:00
|
|
|
case 15: // Save As
|
|
|
|
{
|
2020-07-05 00:53:38 +02:00
|
|
|
Gtk::FileChooserDialog dialog(_("Export Shader Preset to:"), Gtk::FILE_CHOOSER_ACTION_SAVE);
|
|
|
|
dialog.add_button(Gtk::StockID("gtk-cancel"), Gtk::RESPONSE_CANCEL);
|
|
|
|
dialog.add_button(Gtk::StockID("gtk-save"), Gtk::RESPONSE_ACCEPT);
|
|
|
|
dialog.set_current_folder(gui_config->last_shader_directory);
|
|
|
|
|
|
|
|
std::string name;
|
|
|
|
std::string extension;
|
2019-01-31 23:33:17 +01:00
|
|
|
|
|
|
|
if (gui_config->shader_filename.find(".slang") != std::string::npos)
|
|
|
|
{
|
|
|
|
name = "new.slangp";
|
|
|
|
extension = "*.slangp";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
name = "new.glslp";
|
|
|
|
extension = "*.glslp";
|
|
|
|
}
|
|
|
|
|
2020-07-05 00:53:38 +02:00
|
|
|
dialog.set_current_name(name);
|
|
|
|
dialog.set_do_overwrite_confirmation();
|
|
|
|
|
|
|
|
auto filter = Gtk::FileFilter::create();
|
|
|
|
filter->set_name(_("Shader Preset"));
|
|
|
|
filter->add_pattern(extension);
|
|
|
|
dialog.add_filter(filter);
|
2019-01-31 23:33:17 +01:00
|
|
|
|
2020-07-05 00:53:38 +02:00
|
|
|
auto result = dialog.run();
|
2019-01-31 23:33:17 +01:00
|
|
|
|
|
|
|
if (result == GTK_RESPONSE_ACCEPT)
|
2020-07-05 00:53:38 +02:00
|
|
|
S9xDisplayGetDriver()->save(dialog.get_filename().c_str());
|
2019-01-31 23:33:17 +01:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2020-07-05 00:53:38 +02:00
|
|
|
|
2018-05-24 19:18:59 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-31 23:33:17 +01:00
|
|
|
void gtk_shader_parameters_dialog_close()
|
2018-05-24 19:18:59 +02:00
|
|
|
{
|
|
|
|
if (dialog)
|
|
|
|
{
|
|
|
|
*params = saved_params;
|
2020-07-05 00:53:38 +02:00
|
|
|
delete dialog;
|
|
|
|
dialog = nullptr;
|
2018-05-24 19:18:59 +02:00
|
|
|
}
|
|
|
|
}
|
2018-05-13 01:17:19 +02:00
|
|
|
|
2019-01-31 23:33:17 +01:00
|
|
|
bool gtk_shader_parameters_dialog(GtkWindow *parent)
|
2018-05-13 01:17:19 +02:00
|
|
|
{
|
2018-05-24 19:18:59 +02:00
|
|
|
if (dialog)
|
|
|
|
{
|
2020-07-05 00:53:38 +02:00
|
|
|
dialog->present();
|
2018-05-24 19:18:59 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-01-31 23:33:17 +01:00
|
|
|
params = (std::vector<GLSLParam> *)S9xDisplayGetDriver()->get_parameters();
|
2018-05-24 19:18:59 +02:00
|
|
|
saved_params = *params;
|
2018-05-13 01:17:19 +02:00
|
|
|
|
|
|
|
if (!params || params->size() == 0)
|
|
|
|
return false;
|
|
|
|
|
2020-07-05 00:53:38 +02:00
|
|
|
dialog = new Gtk::Dialog(_("Shader Parameters"), Gtk::DIALOG_DESTROY_WITH_PARENT);
|
|
|
|
dialog->add_button(Gtk::StockID("gtk-cancel"), Gtk::RESPONSE_CANCEL);
|
|
|
|
dialog->add_button(Gtk::StockID("gtk-save-as"), 15);
|
|
|
|
dialog->add_button(Gtk::StockID("gtk-save"), GTK_RESPONSE_OK);
|
|
|
|
dialog->signal_response().connect(sigc::ptr_fun(dialog_response));
|
2018-05-13 01:17:19 +02:00
|
|
|
|
2020-07-05 00:53:38 +02:00
|
|
|
dialog->set_size_request(640, 480);
|
2019-01-31 23:33:17 +01:00
|
|
|
if (gui_config->shader_parameters_width > 0 && gui_config->shader_parameters_height > 0)
|
2020-07-05 00:53:38 +02:00
|
|
|
dialog->resize(gui_config->shader_parameters_width, gui_config->shader_parameters_height);
|
|
|
|
|
|
|
|
auto scrolled_window = new Gtk::ScrolledWindow;
|
|
|
|
scrolled_window->set_hexpand();
|
|
|
|
scrolled_window->set_vexpand();
|
|
|
|
scrolled_window->set_margin_start(5);
|
|
|
|
scrolled_window->set_margin_end(5);
|
|
|
|
scrolled_window->set_margin_top(5);
|
|
|
|
dialog->get_content_area()->add(*scrolled_window);
|
|
|
|
|
|
|
|
auto grid = new Gtk::Grid;
|
|
|
|
grid->set_margin_end(5);
|
|
|
|
grid->set_row_homogeneous();
|
|
|
|
grid->set_row_spacing(2);
|
|
|
|
grid->set_column_spacing(12);
|
|
|
|
auto vbox = new Gtk::VBox;
|
2020-07-28 00:58:03 +02:00
|
|
|
vbox->pack_start(*grid, Gtk::PACK_SHRINK);
|
2020-07-05 00:53:38 +02:00
|
|
|
scrolled_window->add(*vbox);
|
|
|
|
|
|
|
|
auto sizegroup = Gtk::SizeGroup::create(Gtk::SIZE_GROUP_HORIZONTAL);
|
2018-05-13 01:17:19 +02:00
|
|
|
for (unsigned int i = 0; i < params->size(); i++)
|
|
|
|
{
|
2020-07-05 00:53:38 +02:00
|
|
|
GLSLParam &p = (*params)[i];
|
|
|
|
auto label = new Gtk::Label(p.name);
|
|
|
|
label->set_xalign(0.0f);
|
|
|
|
label->show();
|
|
|
|
grid->attach(*label, 0, i, 1, 1);
|
2018-05-13 01:17:19 +02:00
|
|
|
|
2020-07-05 00:53:38 +02:00
|
|
|
if (p.min == 0.0 && p.max == 1.0 && p.step == 1.0)
|
2018-05-13 01:17:19 +02:00
|
|
|
{
|
2020-07-05 00:53:38 +02:00
|
|
|
auto check = new Gtk::CheckButton;
|
|
|
|
grid->attach(*check, 1, i, 1, 1);
|
|
|
|
check->set_active(p.val);
|
|
|
|
check->signal_toggled().connect([check, ¶m = p.val] {
|
|
|
|
double new_value = check->get_active();
|
|
|
|
if (param != new_value)
|
|
|
|
{
|
|
|
|
param = new_value;
|
|
|
|
if (Settings.Paused)
|
|
|
|
S9xDeinitUpdate(top_level->last_width, top_level->last_height);
|
|
|
|
}
|
|
|
|
});
|
2018-05-13 01:17:19 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-05 00:53:38 +02:00
|
|
|
auto spin = new Gtk::SpinButton(0.0, p.digits);
|
|
|
|
spin->set_range(p.min, p.max);
|
|
|
|
spin->get_adjustment()->set_step_increment(p.step);
|
|
|
|
spin->set_width_chars(6);
|
|
|
|
grid->attach(*spin, 1, i, 1, 1);
|
|
|
|
sizegroup->add_widget(*spin);
|
|
|
|
|
|
|
|
auto scale = new Gtk::Scale(spin->get_adjustment());
|
|
|
|
scale->set_hexpand();
|
|
|
|
grid->attach(*scale, 2, i, 1, 1);
|
|
|
|
scale->set_draw_value(false);
|
|
|
|
scale->set_value(p.val);
|
|
|
|
scale->signal_value_changed().connect([spin, ¶m = p.val] {
|
|
|
|
double new_value = snap_to_interval(spin->get_value(), spin->get_adjustment()->get_step_increment());
|
|
|
|
spin->set_value(new_value);
|
|
|
|
if (param != new_value)
|
|
|
|
{
|
|
|
|
param = new_value;
|
|
|
|
if (Settings.Paused)
|
|
|
|
S9xDeinitUpdate(top_level->last_width, top_level->last_height);
|
|
|
|
}
|
|
|
|
});
|
2018-05-13 01:17:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-05 00:53:38 +02:00
|
|
|
dialog->show_all();
|
2018-05-13 01:17:19 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|