ocarina/ocarina/buttons/button.cpp

73 lines
1.7 KiB
C++

#include <ocarina/button.h>
#include <ocarina/chooser.h>
#include <libsaria/audio.h>
#include <libsaria/print.h>
static GtkWidget *get_button(void (* func)(GtkWidget *, GdkEvent *, gpointer),
bool show)
{
GtkWidget *button = gtk_button_new();
GTK_CONNECT(button, "clicked", func, NULL);
if (show == true)
gtk_widget_show(button);
return button;
}
static GtkWidget *get_image(const gchar *stockid, GtkIconSize size)
{
GtkWidget *img = gtk_image_new_from_stock(stockid, size);
gtk_widget_show(img);
return img;
}
static GtkWidget *get_label(string text)
{
GtkWidget *label = gtk_label_new(text.c_str());
gtk_widget_show(label);
return label;
}
GtkWidget *make_button(const gchar *stockid,
void (* func)(GtkWidget *, GdkEvent *, gpointer),
bool show)
{
GtkWidget *button = get_button(func, show);
GtkWidget *image = get_image(stockid, GTK_ICON_SIZE_MENU);
container_add(button, image);
return button;
}
GtkWidget *make_text_button(const gchar *stockid,
string text,
void (* func)(GtkWidget *, GdkEvent *, gpointer),
bool show)
{
GtkWidget *button = get_button(func, show);
GtkWidget *image = get_image(stockid, GTK_ICON_SIZE_BUTTON);
GtkWidget *label = get_label(text);
GtkWidget *box = gtk_hbox_new(FALSE, 0);
box_pack_start(box, image, FALSE, FALSE, 0);
box_pack_start(box, label, FALSE, FALSE, 0);
container_add(button, box);
gtk_widget_show(box);
return button;
}
static void on_click_open_file(GtkWidget *b, GdkEvent *e, gpointer d)
{
string file = ocarina::choose_file();
if (file != "") {
println("Playing file: " + file);
libsaria::audio::load(file);
}
}
GtkWidget *make_open_button()
{
return make_button(GTK_STOCK_OPEN, on_click_open_file, true);
}