ocarina: Added a random button
Random hasn't been implemented in libsaria yet, but I can still create the button to test preferences. The random button should set itself to the value store in the preferences file.
This commit is contained in:
parent
b6f21d5705
commit
e409c2317f
|
@ -23,6 +23,8 @@ GtkWidget *make_rewind_button();
|
|||
GtkWidget *make_forward_button();
|
||||
GtkWidget *make_next_button();
|
||||
|
||||
GtkWidget *make_random_button();
|
||||
|
||||
GtkWidget *make_open_button();
|
||||
GtkWidget *make_volume_button();
|
||||
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
|
||||
#include <ocarina/gtk.h>
|
||||
#include <ocarina/button.h>
|
||||
#include <libsaria/prefs.h>
|
||||
|
||||
static GtkWidget *get_toggle_button(void (* func)(GtkWidget *, GdkEvent *, gpointer),
|
||||
bool state, bool show)
|
||||
{
|
||||
GtkWidget *button = gtk_toggle_button_new();
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), state == TRUE);
|
||||
GTK_CONNECT(button, "toggled", func, NULL);
|
||||
if (show == true)
|
||||
gtk_widget_show(button);
|
||||
return button;
|
||||
}
|
||||
|
||||
static GtkWidget *get_image(string path)
|
||||
{
|
||||
GtkWidget *image = gtk_image_new();
|
||||
gtk_image_set_from_file(GTK_IMAGE(image), path.c_str());
|
||||
gtk_widget_show(image);
|
||||
return image;
|
||||
}
|
||||
|
||||
static GtkWidget *make_toggle_button(string file,
|
||||
void (* func)(GtkWidget *, GdkEvent *, gpointer),
|
||||
bool state,
|
||||
bool show)
|
||||
{
|
||||
GtkWidget *button = get_toggle_button(func, state, show);
|
||||
GtkWidget *image = get_image(file);
|
||||
container_add(button, image);
|
||||
return button;
|
||||
}
|
||||
|
||||
static void toggle_random(GtkWidget *b, GdkEvent *e, gpointer d)
|
||||
{
|
||||
bool active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(b)) == TRUE;
|
||||
libsaria::prefs::set("random", active);
|
||||
}
|
||||
|
||||
GtkWidget *make_random_button()
|
||||
{
|
||||
return make_toggle_button("images/random.png",
|
||||
toggle_random,
|
||||
libsaria::prefs::get_bool("random"),
|
||||
true);
|
||||
}
|
|
@ -25,7 +25,8 @@ static GtkWidget *make_top_row()
|
|||
GtkWidget *buttons = gtk_hbox_new(FALSE, 0);
|
||||
|
||||
box_pack_end(buttons, make_volume_button(), FALSE, FALSE, 0);
|
||||
box_pack_end(buttons, make_open_button(), FALSE, FALSE, 0);
|
||||
box_pack_end(buttons, make_random_button(), FALSE, FALSE, 0);
|
||||
box_pack_end(buttons, make_open_button(), FALSE, FALSE, 0);
|
||||
|
||||
gtk_widget_show_all(buttons);
|
||||
return buttons;
|
||||
|
|
Loading…
Reference in New Issue