ocarina: Load images using the full path
relative paths can't be trusted once the program has been installed. To get around this, I assume that the install directory has been configured correctly and then point to images located in the subdirectory next to the executable.
This commit is contained in:
parent
11d92eef89
commit
66f70249ad
|
@ -6,6 +6,7 @@ namespace ocarina
|
|||
|
||||
void quit();
|
||||
void idle_add();
|
||||
string full_path(string);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
#include <ocarina/gtk.h>
|
||||
#include <ocarina/button.h>
|
||||
#include <ocarina/ocarina.h>
|
||||
#include <libsaria/prefs.h>
|
||||
|
||||
static GtkWidget *get_toggle_button(void (* func)(GtkWidget *, GdkEvent *, gpointer),
|
||||
|
@ -41,7 +42,7 @@ static void toggle_random(GtkWidget *b, GdkEvent *e, gpointer d)
|
|||
|
||||
GtkWidget *make_random_button()
|
||||
{
|
||||
return make_toggle_button("images/random.png",
|
||||
return make_toggle_button(ocarina::full_path("images/random.png"),
|
||||
toggle_random,
|
||||
libsaria::prefs::get_bool("random"),
|
||||
true);
|
||||
|
|
|
@ -12,6 +12,22 @@
|
|||
#include <libsaria/print.h>
|
||||
#include <libsaria/idle.h>
|
||||
|
||||
static string path_prefix;
|
||||
|
||||
void set_path_prefix(string prefix)
|
||||
{
|
||||
unsigned int stop = 0;
|
||||
|
||||
for (stop = prefix.size() - 1; stop > 0; stop--) {
|
||||
if (prefix[stop] == '/')
|
||||
break;
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < stop; i++)
|
||||
path_prefix += prefix[i];
|
||||
println("Path prefix: " + path_prefix);
|
||||
}
|
||||
|
||||
namespace ocarina
|
||||
{
|
||||
|
||||
|
@ -27,9 +43,16 @@ namespace ocarina
|
|||
g_idle_add(idle, NULL);
|
||||
}
|
||||
|
||||
string full_path(string path)
|
||||
{
|
||||
string res = path_prefix + "/" + path;
|
||||
println("Expanding to path: " + res);
|
||||
return res;
|
||||
}
|
||||
|
||||
void init(int argc, char **argv)
|
||||
{
|
||||
window_init("Ocarina " + vers_str(), "images/ocarina.png");
|
||||
window_init("Ocarina " + vers_str(), full_path("images/ocarina.png"));
|
||||
window_add(get_tabs());
|
||||
ocarina::library::init();
|
||||
settings_init();
|
||||
|
@ -45,6 +68,7 @@ namespace ocarina
|
|||
int main(int argc, char **argv)
|
||||
{
|
||||
println("Ocarina " + vers_str());
|
||||
set_path_prefix(argv[0]);
|
||||
|
||||
libsaria::init(argc, argv);
|
||||
setup_callbacks();
|
||||
|
|
Loading…
Reference in New Issue