1
0
mirror of https://github.com/bsnes-emu/bsnes.git synced 2025-05-14 06:25:20 +02:00
Tim Allen 0c87bdabed Update to v094r43 release.
byuu says:

Updated to compile with all of the new hiro changes. My next step is to
write up hiro API documentation, and move the API from alpha (constantly
changing) to beta (rarely changing), in preparation for the first stable
release (backward-compatible changes only.)

Added "--fullscreen" command-line option. I like this over
a configuration file option. Lets you use the emulator in both modes
without having to modify the config file each time.

Also enhanced the command-line game loading. You can now use any of
these methods:

    higan /path/to/game-folder.sfc
    higan /path/to/game-folder.sfc/
    higan /path/to/game-folder.sfc/program.rom

The idea is to support launchers that insist on loading files only.

Technically, the file can be any name (manifest.bml also works); the
only criteria is that the file actually exists and is a file, and not
a directory. This is a requirement to support the first version (a
directory lacking the trailing / identifier), because I don't want my
nall::string class to query the file system to determine if the string
is an actual existing file or directory for its pathname() / dirname()
functions.

Anyway, every game folder I've made so far has program.rom, and that's
very unlikely to change, so this should be fine.

Now, of course, if you drop a regular "game.sfc" file on the emulator,
it won't even try to load it, unless it's in a folder that ends in .fc,
.sfc, etc. In which case, it'll bail out immediately by being unable to
produce a manifest for what is obviously not really a game folder.
2015-08-30 12:08:26 +10:00

88 lines
2.6 KiB
C++

namespace hiro {
#if defined(Hiro_Color)
static auto CreateColor(const Color& color) -> GdkColor {
GdkColor gdkColor;
gdkColor.pixel = (color.red() << 16) | (color.green() << 8) | (color.blue() << 0);
gdkColor.red = (color.red() << 8) | (color.red() << 0);
gdkColor.green = (color.green() << 8) | (color.green() << 0);
gdkColor.blue = (color.blue() << 8) | (color.blue() << 0);
return gdkColor;
}
#endif
static auto CreatePixbuf(image icon, bool scale = false) -> GdkPixbuf* {
if(!icon) return nullptr;
if(scale) icon.scale(15, 15);
icon.transform(0, 32, 255u << 24, 255u << 0, 255u << 8, 255u << 16); //GTK stores images in ABGR format
auto pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, true, 8, icon.width(), icon.height());
memory::copy(gdk_pixbuf_get_pixels(pixbuf), icon.data(), icon.size());
if(scale) {
auto scaled = gdk_pixbuf_scale_simple(pixbuf, 15, 15, GDK_INTERP_BILINEAR);
g_object_unref(pixbuf);
pixbuf = scaled;
}
return pixbuf;
}
static auto CreatePixbuf(const Image& image, bool scale = false) -> GdkPixbuf* {
if(!image.state.data) return nullptr;
auto pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, true, 8, image.width(), image.height());
//ARGB -> ABGR conversion
const uint32_t* source = image.data();
uint32_t* target = (uint32_t*)gdk_pixbuf_get_pixels(pixbuf);
for(auto n : range(image.width() * image.height())) {
uint32_t pixel = *source++;
*target++ = (pixel & 0x00ff0000) >> 16 | (pixel & 0xff00ff00) | (pixel & 0x000000ff) << 16;
}
if(scale) {
auto scaled = gdk_pixbuf_scale_simple(pixbuf, 15, 15, GDK_INTERP_BILINEAR);
g_object_unref(pixbuf);
pixbuf = scaled;
}
return pixbuf;
}
static auto CreateImage(const nall::image& image, bool scale = false) -> GtkImage* {
auto pixbuf = CreatePixbuf(image, scale);
auto gtkImage = (GtkImage*)gtk_image_new_from_pixbuf(pixbuf);
g_object_unref(pixbuf);
return gtkImage;
}
static auto CreateImage(const Image& image, bool scale = false) -> GtkImage* {
auto pixbuf = CreatePixbuf(image, scale);
auto gtkImage = (GtkImage*)gtk_image_new_from_pixbuf(pixbuf);
g_object_unref(pixbuf);
return gtkImage;
}
static auto DropPaths(GtkSelectionData* data) -> lstring {
gchar** uris = gtk_selection_data_get_uris(data);
if(uris == nullptr) return {};
lstring paths;
for(unsigned n = 0; uris[n] != nullptr; n++) {
gchar* pathname = g_filename_from_uri(uris[n], nullptr, nullptr);
if(pathname == nullptr) continue;
string path = pathname;
g_free(pathname);
if(directory::exists(path) && !path.endsWith("/")) path.append("/");
paths.append(path);
}
g_strfreev(uris);
return paths;
}
}