ocarina: Clean up button code

I didn't like using macros...
This commit is contained in:
Bryan Schumaker 2011-08-23 07:53:25 -04:00
parent b23d912f64
commit 7d3769a1a2
2 changed files with 20 additions and 20 deletions

View File

@ -3,46 +3,47 @@
#include <libsaria/audio.h>
#include <libsaria/libsaria.h>
#define ls_on_click(func) \
static void on_click_##func(GtkWidget *button, GdkEvent *event, gpointer data)\
{ \
libsaria_get()->func(); \
static void on_click_play(GtkWidget *b, GdkEvent *e, gpointer d)
{
libsaria_get()->play();
}
#define on_click(func) \
on_click_##func
static void on_click_pause(GtkWidget *b, GdkEvent *e, gpointer d)
{
libsaria_get()->pause();
}
GtkWidget *make_button(const gchar *stockid, GtkIconSize size)
static void on_click_stop(GtkWidget *b, GdkEvent *e, gpointer d)
{
libsaria_get()->stop();
}
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;
}
ls_on_click(play);
GtkWidget *make_play_button(GtkIconSize size)
{
GtkWidget *button = make_button(GTK_STOCK_MEDIA_PLAY, size);
GTK_CONNECT(button, "clicked", on_click(play), NULL);
return button;
return make_button(GTK_STOCK_MEDIA_PLAY, size, on_click_play);
}
ls_on_click(pause);
GtkWidget *make_pause_button(GtkIconSize size)
{
GtkWidget *button = make_button(GTK_STOCK_MEDIA_PAUSE, size);
GTK_CONNECT(button, "clicked", on_click(pause), NULL);
return button;
return make_button(GTK_STOCK_MEDIA_PAUSE, size, on_click_pause);
}
ls_on_click(stop);
GtkWidget *make_stop_button(GtkIconSize size)
{
GtkWidget *button = make_button(GTK_STOCK_MEDIA_STOP, size);
GTK_CONNECT(button, "clicked", on_click(stop), NULL);
return button;
return make_button(GTK_STOCK_MEDIA_STOP, size, on_click_stop);
}

View File

@ -6,7 +6,6 @@ using namespace std;
#include <ocarina/gtk.h>
GtkWidget *make_button(const gchar *, GtkIconSize);
GtkWidget *make_play_button(GtkIconSize);
GtkWidget *make_pause_button(GtkIconSize);
GtkWidget *make_stop_button(GtkIconSize);