ocarina/gui/button.cpp

63 lines
1.4 KiB
C++

#include <ocarina/button.h>
#include <ocarina/chooser.h>
#include <libsaria/audio.h>
#include <libsaria/libsaria.h>
static GtkWidget *make_button(const gchar *stockid, GtkIconSize size,
void (* func)(GtkWidget *, GdkEvent *, gpointer))
{
GtkWidget *button = gtk_button_new();
GtkWidget *box = gtk_hbox_new(FALSE, 0);
GtkWidget *image = gtk_image_new_from_stock(stockid, size);
GTK_CONNECT(button, "clicked", func, NULL);
box_pack_start(box, image, FALSE, FALSE, 0);
container_add(button, box);
gtk_widget_show_all(button);
return button;
}
static void on_click_play(GtkWidget *b, GdkEvent *e, gpointer d)
{
libsaria_get()->play();
}
GtkWidget *make_play_button(GtkIconSize size)
{
return make_button(GTK_STOCK_MEDIA_PLAY, size, on_click_play);
}
static void on_click_pause(GtkWidget *b, GdkEvent *e, gpointer d)
{
libsaria_get()->pause();
}
GtkWidget *make_pause_button(GtkIconSize size)
{
return make_button(GTK_STOCK_MEDIA_PAUSE, size, on_click_pause);
}
static void on_click_stop(GtkWidget *b, GdkEvent *e, gpointer d)
{
libsaria_get()->stop();
}
GtkWidget *make_stop_button(GtkIconSize size)
{
return make_button(GTK_STOCK_MEDIA_STOP, size, on_click_stop);
}
static void on_click_open_file(GtkWidget *b, GdkEvent *e, gpointer d)
{
string file = ocarina_choose_file();
print("Playing file: " + file);
}
GtkWidget *make_open_button(GtkIconSize size)
{
return make_button(GTK_STOCK_OPEN, size, on_click_open_file);
}