ocarina/gui/buttons/button.cpp

43 lines
1017 B
C++

#include <ocarina/button.h>
#include <ocarina/chooser.h>
#include <libsaria/libsaria.h>
GtkWidget *make_button(const gchar *stockid, GtkIconSize size,
void (* func)(GtkWidget *, GdkEvent *, gpointer),
bool show)
{
GtkWidget *button = gtk_button_new();
GtkWidget *image = gtk_image_new_from_stock(stockid, size);
gtk_widget_show(image);
GTK_CONNECT(button, "clicked", func, NULL);
container_add(button, image);
if (show == true)
gtk_widget_show_all(button);
return button;
}
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, true);
}
static void on_click_open_file(GtkWidget *b, GdkEvent *e, gpointer d)
{
string file = ocarina_choose_file();
print("Playing file: " + file);
libsaria_get()->load(file);
}
GtkWidget *make_open_button(GtkIconSize size)
{
return make_button(GTK_STOCK_OPEN, size, on_click_open_file, true);
}