mirror of https://github.com/snes9xgit/snes9x.git
Gtk: Stringify some things.
This commit is contained in:
parent
a32d391483
commit
375a263961
|
@ -278,6 +278,9 @@ list(APPEND SOURCES
|
||||||
src/background_particles.cpp
|
src/background_particles.cpp
|
||||||
src/background_particles.h)
|
src/background_particles.h)
|
||||||
|
|
||||||
|
list(APPEND SOURCES ../external/fmt/src/format.cc)
|
||||||
|
list(APPEND INCLUDES ../external/fmt/include)
|
||||||
|
|
||||||
set(LIBJMA_SOURCES
|
set(LIBJMA_SOURCES
|
||||||
../jma/s9x-jma.cpp
|
../jma/s9x-jma.cpp
|
||||||
../jma/7zlzma.cpp
|
../jma/7zlzma.cpp
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "gtk_s9x.h"
|
#include "gtk_s9x.h"
|
||||||
#include "gtk_binding.h"
|
#include "gtk_binding.h"
|
||||||
|
#include "fmt/format.h"
|
||||||
|
|
||||||
Binding::Binding()
|
Binding::Binding()
|
||||||
{
|
{
|
||||||
|
@ -228,66 +229,53 @@ Binding::Binding(const char *raw_string)
|
||||||
|
|
||||||
std::string Binding::as_string()
|
std::string Binding::as_string()
|
||||||
{
|
{
|
||||||
char buf[PATH_MAX];
|
return to_string(false);
|
||||||
to_string(buf, false);
|
|
||||||
return std::string(buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Binding::to_string(char *str, bool translate)
|
std::string Binding::to_string(bool translate)
|
||||||
{
|
{
|
||||||
char buf[256];
|
std::string str;
|
||||||
|
|
||||||
#undef _
|
#undef _
|
||||||
#define _(String) translate ? gettext(String) : (String)
|
#define _(String) translate ? gettext(String) : (String)
|
||||||
|
|
||||||
str[0] = '\0';
|
|
||||||
|
|
||||||
if (is_key())
|
if (is_key())
|
||||||
{
|
{
|
||||||
char *keyval_name = NULL;
|
|
||||||
unsigned int keyval = gdk_keyval_to_lower(get_key());
|
unsigned int keyval = gdk_keyval_to_lower(get_key());
|
||||||
keyval_name = gdk_keyval_name(keyval);
|
char *keyval_name = gdk_keyval_name(keyval);
|
||||||
|
|
||||||
if (keyval_name == NULL)
|
if (keyval_name == nullptr)
|
||||||
{
|
str = _("Unknown");
|
||||||
sprintf(buf, _("Unknown"));
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
str = keyval_name;
|
||||||
memset(buf, 0, 256);
|
|
||||||
strncpy(buf,
|
|
||||||
keyval_name,
|
|
||||||
255);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (translate)
|
if (translate)
|
||||||
for (int i = 0; buf[i]; i++)
|
for (char &c : str)
|
||||||
if (buf[i] == '_')
|
if (c == '_')
|
||||||
buf[i] = ' ';
|
c = ' ';
|
||||||
|
|
||||||
sprintf(str, _("Keyboard %s%s%s%s"),
|
str = fmt::format(_("Keyboard {}{}{}{}"),
|
||||||
(value & BINDING_SHIFT) ? "Shift+" : "",
|
(value & BINDING_SHIFT) ? "Shift+" : "",
|
||||||
(value & BINDING_CTRL) ? "Ctrl+" : "",
|
(value & BINDING_CTRL) ? "Ctrl+" : "",
|
||||||
(value & BINDING_ALT) ? "Alt+" : "",
|
(value & BINDING_ALT) ? "Alt+" : "",
|
||||||
buf);
|
str);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (is_joy())
|
else if (is_joy())
|
||||||
{
|
{
|
||||||
if ((get_key()) >= 512)
|
if ((get_key()) >= 512)
|
||||||
sprintf(buf,
|
str = fmt::format(_("Axis {} {} {}%"),
|
||||||
_("Axis %u %s %u%%"),
|
get_axis(),
|
||||||
get_axis(),
|
is_positive() ? "+" : "-",
|
||||||
is_positive() ? "+" : "-",
|
get_threshold());
|
||||||
get_threshold());
|
|
||||||
else
|
else
|
||||||
sprintf(buf, _("Button %u"), get_key());
|
str = fmt::format(_("Button {}"), get_key());
|
||||||
|
|
||||||
sprintf(str, _("Joystick %u %s"), get_device(), buf);
|
str = fmt::format(_("Joystick {} {}"), get_device(), str);
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
str = _("Unset");
|
||||||
sprintf(str, _("Unset"));
|
|
||||||
}
|
return str;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ class Binding
|
||||||
Binding(unsigned int);
|
Binding(unsigned int);
|
||||||
Binding();
|
Binding();
|
||||||
Binding(const char *str);
|
Binding(const char *str);
|
||||||
void to_string(char *str, bool translate = true);
|
std::string to_string(bool translate = true);
|
||||||
std::string as_string();
|
std::string as_string();
|
||||||
unsigned int hex();
|
unsigned int hex();
|
||||||
unsigned int base_hex();
|
unsigned int base_hex();
|
||||||
|
|
|
@ -93,6 +93,11 @@ void GtkBuilderWindow::set_entry_text(const char *name, const char *text)
|
||||||
get_object<Gtk::Entry>(name)->set_text(text);
|
get_object<Gtk::Entry>(name)->set_text(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GtkBuilderWindow::set_entry_text(const char *name, const std::string &text)
|
||||||
|
{
|
||||||
|
get_object<Gtk::Entry>(name)->set_text(text);
|
||||||
|
}
|
||||||
|
|
||||||
float GtkBuilderWindow::get_slider(const char *name)
|
float GtkBuilderWindow::get_slider(const char *name)
|
||||||
{
|
{
|
||||||
return get_object<Gtk::Range>(name)->get_value();
|
return get_object<Gtk::Range>(name)->get_value();
|
||||||
|
|
|
@ -49,6 +49,7 @@ class GtkBuilderWindow
|
||||||
void set_check(const char *name, bool value);
|
void set_check(const char *name, bool value);
|
||||||
void set_entry_value(const char *name, unsigned int value);
|
void set_entry_value(const char *name, unsigned int value);
|
||||||
void set_entry_text(const char *name, const char *text);
|
void set_entry_text(const char *name, const char *text);
|
||||||
|
void set_entry_text(const char *name, const std::string &text);
|
||||||
void set_combo(const char *name, unsigned char value);
|
void set_combo(const char *name, unsigned char value);
|
||||||
void set_spin(const char *name, double value);
|
void set_spin(const char *name, double value);
|
||||||
void set_slider(const char *name, float value);
|
void set_slider(const char *name, float value);
|
||||||
|
|
|
@ -188,8 +188,6 @@ static void swap_controllers_1_2()
|
||||||
|
|
||||||
static void change_slot(int difference)
|
static void change_slot(int difference)
|
||||||
{
|
{
|
||||||
static char buf[256];
|
|
||||||
|
|
||||||
gui_config->current_save_slot += difference;
|
gui_config->current_save_slot += difference;
|
||||||
gui_config->current_save_slot %= 1000;
|
gui_config->current_save_slot %= 1000;
|
||||||
if (gui_config->current_save_slot < 0)
|
if (gui_config->current_save_slot < 0)
|
||||||
|
@ -197,8 +195,8 @@ static void change_slot(int difference)
|
||||||
if (!gui_config->rom_loaded)
|
if (!gui_config->rom_loaded)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
snprintf(buf, 256, "State Slot: %d", gui_config->current_save_slot);
|
auto info_string = "State Slot: " + std::to_string(gui_config->current_save_slot);
|
||||||
S9xSetInfoString(buf);
|
S9xSetInfoString(info_string.c_str());
|
||||||
GFX.InfoStringTimeout = 60;
|
GFX.InfoStringTimeout = 60;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,12 +19,13 @@
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
using namespace std::literals;
|
using namespace std::literals;
|
||||||
|
|
||||||
static std::string info_string;
|
// TODO:
|
||||||
|
// Snes9x core requires persistent memory for const char * returns, but won't
|
||||||
|
// manage them. This is used to hold the data. Functions here are Non-reentrant.
|
||||||
|
static std::string filename_common;
|
||||||
|
|
||||||
const char *S9xGetFilenameInc(const char *e, enum s9x_getdirtype dirtype)
|
const char *S9xGetFilenameInc(const char *e, enum s9x_getdirtype dirtype)
|
||||||
{
|
{
|
||||||
static std::string filename;
|
|
||||||
|
|
||||||
fs::path rom_filename(Memory.ROMFilename);
|
fs::path rom_filename(Memory.ROMFilename);
|
||||||
|
|
||||||
fs::path filename_base(S9xGetDirectory(dirtype));
|
fs::path filename_base(S9xGetDirectory(dirtype));
|
||||||
|
@ -46,13 +47,13 @@ const char *S9xGetFilenameInc(const char *e, enum s9x_getdirtype dirtype)
|
||||||
i++;
|
i++;
|
||||||
} while (fs::exists(new_filename));
|
} while (fs::exists(new_filename));
|
||||||
|
|
||||||
filename = new_filename;
|
filename_common = new_filename;
|
||||||
return filename.c_str();
|
return filename_common.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *S9xGetDirectory(enum s9x_getdirtype dirtype)
|
const char *S9xGetDirectory(enum s9x_getdirtype dirtype)
|
||||||
{
|
{
|
||||||
static std::string dirname;
|
std::string dirname;
|
||||||
|
|
||||||
switch (dirtype)
|
switch (dirtype)
|
||||||
{
|
{
|
||||||
|
@ -113,24 +114,17 @@ const char *S9xGetDirectory(enum s9x_getdirtype dirtype)
|
||||||
dirname = path;
|
dirname = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
return dirname.c_str();
|
filename_common = dirname;
|
||||||
|
return filename_common.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *S9xGetFilename(const char *ex, enum s9x_getdirtype dirtype)
|
const char *S9xGetFilename(const char *ex, enum s9x_getdirtype dirtype)
|
||||||
{
|
{
|
||||||
static std::string filename;
|
|
||||||
fs::path path(S9xGetDirectory(dirtype));
|
fs::path path(S9xGetDirectory(dirtype));
|
||||||
path /= fs::path(Memory.ROMFilename).filename();
|
path /= fs::path(Memory.ROMFilename).filename();
|
||||||
//Fixes issue with MSU-1 on linux
|
path.replace_extension(ex);
|
||||||
if(ex[0] == '-') {
|
filename_common = path.string();
|
||||||
path.replace_extension("");
|
return filename_common.c_str();
|
||||||
filename = path.string();
|
|
||||||
filename.append(ex);
|
|
||||||
} else {
|
|
||||||
path.replace_extension(ex);
|
|
||||||
filename = path.string();
|
|
||||||
}
|
|
||||||
return filename.c_str();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *S9xBasename(const char *f)
|
const char *S9xBasename(const char *f)
|
||||||
|
@ -145,22 +139,18 @@ const char *S9xBasename(const char *f)
|
||||||
|
|
||||||
const char *S9xBasenameNoExt(const char *f)
|
const char *S9xBasenameNoExt(const char *f)
|
||||||
{
|
{
|
||||||
static std::string filename;
|
filename_common = fs::path(f).stem();
|
||||||
filename = fs::path(f).stem();
|
return filename_common.c_str();
|
||||||
return filename.c_str();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool8 S9xOpenSnapshotFile(const char *filename, bool8 read_only, STREAM *file)
|
bool8 S9xOpenSnapshotFile(const char *filename, bool8 read_only, STREAM *file)
|
||||||
{
|
{
|
||||||
#ifdef ZLIB
|
|
||||||
if (read_only)
|
if (read_only)
|
||||||
{
|
{
|
||||||
if ((*file = OPEN_STREAM(filename, "rb")))
|
if ((*file = OPEN_STREAM(filename, "rb")))
|
||||||
return (true);
|
return (true);
|
||||||
else
|
else
|
||||||
fprintf(stderr,
|
fprintf(stderr, "Failed to open file stream for reading.\n");
|
||||||
"Failed to open file stream for reading. (%s)\n",
|
|
||||||
zError(errno));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -170,44 +160,18 @@ bool8 S9xOpenSnapshotFile(const char *filename, bool8 read_only, STREAM *file)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
fprintf(stderr, "Couldn't open stream with zlib.\n");
|
||||||
"Couldn't open stream with zlib. (%s)\n",
|
|
||||||
zError(errno));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, "zlib: Couldn't open snapshot file:\n%s\n", filename);
|
fprintf(stderr, "Couldn't open snapshot file:\n%s\n", filename);
|
||||||
|
|
||||||
#else
|
return false;
|
||||||
char command[PATH_MAX];
|
|
||||||
|
|
||||||
if (read_only)
|
|
||||||
{
|
|
||||||
sprintf(command, "gzip -d <\"%s\"", filename);
|
|
||||||
if (*file = popen(command, "r"))
|
|
||||||
return (true);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sprintf(command, "gzip --best >\"%s\"", filename);
|
|
||||||
if (*file = popen(command, "wb"))
|
|
||||||
return (true);
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(stderr, "gzip: Couldn't open snapshot file:\n%s\n", filename);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return (false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void S9xCloseSnapshotFile(STREAM file)
|
void S9xCloseSnapshotFile(STREAM file)
|
||||||
{
|
{
|
||||||
#ifdef ZLIB
|
|
||||||
CLOSE_STREAM(file);
|
CLOSE_STREAM(file);
|
||||||
#else
|
|
||||||
pclose(file);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void S9xAutoSaveSRAM()
|
void S9xAutoSaveSRAM()
|
||||||
|
@ -222,7 +186,7 @@ void S9xLoadState(const char *filename)
|
||||||
|
|
||||||
if (S9xUnfreezeGame(filename))
|
if (S9xUnfreezeGame(filename))
|
||||||
{
|
{
|
||||||
info_string = filename + " loaded"s;
|
auto info_string = filename + " loaded"s;
|
||||||
S9xSetInfoString(info_string.c_str());
|
S9xSetInfoString(info_string.c_str());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -235,7 +199,7 @@ void S9xSaveState(const char *filename)
|
||||||
{
|
{
|
||||||
if (S9xFreezeGame(filename))
|
if (S9xFreezeGame(filename))
|
||||||
{
|
{
|
||||||
info_string = filename + " saved"s;
|
auto info_string = filename + " saved"s;
|
||||||
S9xSetInfoString(info_string.c_str());
|
S9xSetInfoString(info_string.c_str());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -265,7 +229,7 @@ void S9xQuickSaveSlot(int slot)
|
||||||
|
|
||||||
if (S9xFreezeGame(filename.c_str()))
|
if (S9xFreezeGame(filename.c_str()))
|
||||||
{
|
{
|
||||||
info_string = filename.filename().string() + " saved";
|
auto info_string = filename.filename().string() + " saved";
|
||||||
S9xSetInfoString(info_string.c_str());
|
S9xSetInfoString(info_string.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -282,7 +246,7 @@ void S9xQuickLoadSlot(int slot)
|
||||||
|
|
||||||
if (S9xUnfreezeGame(filename.c_str()))
|
if (S9xUnfreezeGame(filename.c_str()))
|
||||||
{
|
{
|
||||||
info_string = filename.filename().string() + " loaded";
|
auto info_string = filename.filename().string() + " loaded";
|
||||||
S9xSetInfoString(info_string.c_str());
|
S9xSetInfoString(info_string.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -917,9 +917,7 @@ void Snes9xPreferences::clear_binding(const char *name)
|
||||||
|
|
||||||
if (b_links[i].button_name)
|
if (b_links[i].button_name)
|
||||||
{
|
{
|
||||||
char buf[256];
|
set_entry_text(b_links[i].button_name, unset.to_string(true));
|
||||||
unset.to_string(buf);
|
|
||||||
set_entry_text(b_links[i].button_name, buf);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -931,14 +929,14 @@ void Snes9xPreferences::bindings_to_dialog(int joypad)
|
||||||
|
|
||||||
for (int i = 0; i < NUM_JOYPAD_LINKS; i++)
|
for (int i = 0; i < NUM_JOYPAD_LINKS; i++)
|
||||||
{
|
{
|
||||||
set_entry_text(b_links[i].button_name, bindings[i].as_string().c_str());
|
set_entry_text(b_links[i].button_name, bindings[i].as_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto shortcut_names = &b_links[NUM_JOYPAD_LINKS];
|
auto shortcut_names = &b_links[NUM_JOYPAD_LINKS];
|
||||||
|
|
||||||
for (int i = 0; shortcut_names[i].button_name; i++)
|
for (int i = 0; shortcut_names[i].button_name; i++)
|
||||||
{
|
{
|
||||||
set_entry_text(shortcut_names[i].button_name, shortcut[i].as_string().c_str());
|
set_entry_text(shortcut_names[i].button_name, shortcut[i].as_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue