ocarina: Resize window to match preference
I initialize the window size preferences to (800, 600) and then resize the window to match. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
3c19e4a3d9
commit
a0da654fc6
|
@ -4,6 +4,12 @@
|
|||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
enum FileState {
|
||||
UNLOADED,
|
||||
DIRTY,
|
||||
CLEAN,
|
||||
};
|
||||
|
||||
namespace libsaria
|
||||
{
|
||||
|
||||
|
|
|
@ -8,13 +8,16 @@ namespace libsaria
|
|||
{
|
||||
namespace prefs
|
||||
{
|
||||
void load();
|
||||
int get(string);
|
||||
void set(string, int);
|
||||
int init(string, int);
|
||||
/*void load();
|
||||
|
||||
void set(string, bool);
|
||||
void set(string, float);
|
||||
|
||||
bool get_bool(string);
|
||||
float get_float(string, float);
|
||||
float get_float(string, float);*/
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,10 +17,7 @@ namespace ocarina
|
|||
|
||||
}; /* Namespace: window */
|
||||
/*void window_resize(int, int);
|
||||
void window_init(string, string);
|
||||
void window_add(GtkWidget *);
|
||||
void window_title(string);
|
||||
void window_icon(string);
|
||||
void window_focus();*/
|
||||
|
||||
}; /* Namespace: ocarina */
|
||||
|
|
|
@ -85,7 +85,8 @@ namespace libsaria
|
|||
|
||||
bool audio::using_alsa()
|
||||
{
|
||||
return prefs::get_bool("alsa");
|
||||
return false;
|
||||
//return prefs::get_bool("alsa");
|
||||
}
|
||||
|
||||
void audio::init_alsa()
|
||||
|
|
|
@ -22,12 +22,13 @@ namespace libsaria
|
|||
|
||||
void audio::init_volume()
|
||||
{
|
||||
configure_volume(prefs::get_float("volume", 1.0));
|
||||
//configure_volume(prefs::get_float("volume", 1.0));
|
||||
}
|
||||
|
||||
float audio::get_volume()
|
||||
{
|
||||
return prefs::get_float("volume", 1.0);
|
||||
//return prefs::get_float("volume", 1.0);
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -11,7 +11,7 @@ static unsigned int CHECK_RAND_PREF = PL_RANDOM | PL_SEQUENTIAL;
|
|||
static inline bool choose_randomly(unsigned int flags)
|
||||
{
|
||||
if ((flags & CHECK_RAND_PREF) == CHECK_RAND_PREF)
|
||||
return libsaria::prefs::get_bool("random");
|
||||
return true; //libsaria::prefs::get_bool("random");
|
||||
return (flags & PL_RANDOM) == PL_RANDOM;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,25 +2,26 @@
|
|||
#include <map>
|
||||
using namespace std;
|
||||
|
||||
#include <libsaria/files.h>
|
||||
#include <libsaria/print.h>
|
||||
#include <libsaria/prefs.h>
|
||||
#include <libsaria/fs.h>
|
||||
|
||||
enum pref_t {
|
||||
INT,
|
||||
BOOL,
|
||||
FLOAT,
|
||||
};
|
||||
|
||||
struct Preference {
|
||||
pref_t type;
|
||||
union value {
|
||||
bool boolean;
|
||||
float floating;
|
||||
} value_u;
|
||||
union Preference {
|
||||
int integer;
|
||||
bool boolean;
|
||||
float floating;
|
||||
};
|
||||
|
||||
static map<string, Preference> preferences;
|
||||
static FileState state = UNLOADED;
|
||||
static map<string, union Preference> preferences;
|
||||
|
||||
static void load_pref(InFile &in)
|
||||
/*static void load_pref(InFile &in)
|
||||
{
|
||||
Preference p;
|
||||
string key;
|
||||
|
@ -62,14 +63,21 @@ static void save()
|
|||
out << preferences.size() << "\n";
|
||||
for (it = preferences.begin(); it != preferences.end(); it++)
|
||||
save_pref(it->first, it->second, out);
|
||||
}*/
|
||||
|
||||
static void save()
|
||||
{
|
||||
println("Saving!");
|
||||
state = CLEAN;
|
||||
}
|
||||
|
||||
static void set_preference(string key, struct Preference &p)
|
||||
static void set_preference(string key, Preference &p)
|
||||
{
|
||||
preferences[key] = p;
|
||||
save();
|
||||
if (state != UNLOADED)
|
||||
save();
|
||||
}
|
||||
|
||||
/*
|
||||
namespace libsaria
|
||||
{
|
||||
|
||||
|
@ -124,4 +132,37 @@ namespace libsaria
|
|||
return it->second.value_u.floating;
|
||||
}
|
||||
|
||||
}
|
||||
}*/
|
||||
|
||||
namespace libsaria
|
||||
{
|
||||
|
||||
int prefs::get(string key)
|
||||
{
|
||||
map<string, union Preference>::iterator it;
|
||||
it = preferences.find(key);
|
||||
if (it == preferences.end())
|
||||
return 0;
|
||||
return it->second.integer;
|
||||
}
|
||||
|
||||
void prefs::set(string key, int value)
|
||||
{
|
||||
union Preference p;
|
||||
p.integer = value;
|
||||
set_preference(key, p);
|
||||
}
|
||||
|
||||
int prefs::init(string key, int value)
|
||||
{
|
||||
map<string, union Preference>::iterator it;
|
||||
it = preferences.find(key);
|
||||
if (it == preferences.end()) {
|
||||
set(key, value);
|
||||
return value;
|
||||
} else
|
||||
return it->second.integer;
|
||||
}
|
||||
|
||||
|
||||
}; /* Namespace: libsaria */
|
||||
|
|
|
@ -44,6 +44,6 @@ GtkWidget *make_random_button()
|
|||
{
|
||||
return make_toggle_button(ocarina::full_path("images/random.png"),
|
||||
toggle_random,
|
||||
libsaria::prefs::get_bool("random"),
|
||||
true, //libsaria::prefs::get_bool("random"),
|
||||
true);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#include <ocarina/ocarina.h>
|
||||
#include <ocarina/window.h>
|
||||
|
||||
#include <libsaria/prefs.h>
|
||||
|
||||
/*#include <ocarina/gtk.h>
|
||||
#include <ocarina/ocarina.h>
|
||||
#include <ocarina/window.h>
|
||||
|
@ -11,6 +13,11 @@
|
|||
*/
|
||||
static GtkWidget *win;
|
||||
|
||||
static void resize(int w, int h)
|
||||
{
|
||||
gtk_window_resize(GTK_WINDOW(win), w, h);
|
||||
}
|
||||
|
||||
static void destroy(GtkWidget *widget, GdkEvent *event, gpointer data)
|
||||
{
|
||||
ocarina::quit();
|
||||
|
@ -52,6 +59,8 @@ namespace ocarina
|
|||
|
||||
set_title("Ocarina " + vers_str());
|
||||
set_icon(full_path("images/ocarina.png"));
|
||||
resize(libsaria::prefs::init("ocarina.window.w", 800),
|
||||
libsaria::prefs::init("ocarina.window.h", 600));
|
||||
gtk_widget_show(win);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue