ocarina: Show and hide play and pause buttons
I hide the play button when music is playing and show it when music has been stopped. I hide the pause button when music is not playing and show it when music has been stopped. This can give the effect of one button replacing the other.
This commit is contained in:
parent
31c777dc8a
commit
ac03eed3f5
|
@ -1,22 +1,42 @@
|
|||
|
||||
#include <list>
|
||||
using namespace std;
|
||||
|
||||
#include <ocarina/button.h>
|
||||
#include <ocarina/chooser.h>
|
||||
|
||||
#include <libsaria/audio.h>
|
||||
#include <libsaria/libsaria.h>
|
||||
|
||||
static list<GtkWidget *> play_buttons;
|
||||
static list<GtkWidget *> pause_buttons;
|
||||
|
||||
static void show_list(list<GtkWidget *> &l)
|
||||
{
|
||||
list<GtkWidget *>::iterator it;
|
||||
for(it = l.begin(); it != l.end(); it++)
|
||||
gtk_widget_show(*it);
|
||||
}
|
||||
|
||||
static void hide_list(list<GtkWidget *> &l)
|
||||
{
|
||||
list<GtkWidget *>::iterator it;
|
||||
for(it = l.begin(); it != l.end(); it++)
|
||||
gtk_widget_hide(*it);
|
||||
}
|
||||
|
||||
static GtkWidget *make_button(const gchar *stockid, GtkIconSize size,
|
||||
void (* func)(GtkWidget *, GdkEvent *, gpointer))
|
||||
void (* func)(GtkWidget *, GdkEvent *, gpointer),
|
||||
bool show)
|
||||
{
|
||||
GtkWidget *button = gtk_button_new();
|
||||
GtkWidget *box = gtk_hbox_new(FALSE, 0);
|
||||
GtkWidget *image = gtk_image_new_from_stock(stockid, size);
|
||||
|
||||
gtk_widget_show(image);
|
||||
GTK_CONNECT(button, "clicked", func, NULL);
|
||||
|
||||
box_pack_start(box, image, FALSE, FALSE, 0);
|
||||
container_add(button, box);
|
||||
gtk_widget_show_all(button);
|
||||
container_add(button, image);
|
||||
if (show == true)
|
||||
gtk_widget_show_all(button);
|
||||
return button;
|
||||
}
|
||||
|
||||
|
@ -27,7 +47,19 @@ static void on_click_play(GtkWidget *b, GdkEvent *e, gpointer d)
|
|||
|
||||
GtkWidget *make_play_button(GtkIconSize size)
|
||||
{
|
||||
return make_button(GTK_STOCK_MEDIA_PLAY, size, on_click_play);
|
||||
GtkWidget *b = make_button(GTK_STOCK_MEDIA_PLAY, size, on_click_play, true);
|
||||
play_buttons.push_back(b);
|
||||
return b;
|
||||
}
|
||||
|
||||
void show_play_buttons()
|
||||
{
|
||||
show_list(play_buttons);
|
||||
}
|
||||
|
||||
void hide_play_buttons()
|
||||
{
|
||||
hide_list(play_buttons);
|
||||
}
|
||||
|
||||
static void on_click_pause(GtkWidget *b, GdkEvent *e, gpointer d)
|
||||
|
@ -37,7 +69,19 @@ static void on_click_pause(GtkWidget *b, GdkEvent *e, gpointer d)
|
|||
|
||||
GtkWidget *make_pause_button(GtkIconSize size)
|
||||
{
|
||||
return make_button(GTK_STOCK_MEDIA_PAUSE, size, on_click_pause);
|
||||
GtkWidget *b = make_button(GTK_STOCK_MEDIA_PAUSE, size, on_click_pause, false);
|
||||
pause_buttons.push_back(b);
|
||||
return b;
|
||||
}
|
||||
|
||||
void show_pause_buttons()
|
||||
{
|
||||
show_list(pause_buttons);
|
||||
}
|
||||
|
||||
void hide_pause_buttons()
|
||||
{
|
||||
hide_list(pause_buttons);
|
||||
}
|
||||
|
||||
static void on_click_stop(GtkWidget *b, GdkEvent *e, gpointer d)
|
||||
|
@ -47,7 +91,7 @@ static void on_click_stop(GtkWidget *b, GdkEvent *e, gpointer d)
|
|||
|
||||
GtkWidget *make_stop_button(GtkIconSize size)
|
||||
{
|
||||
return make_button(GTK_STOCK_MEDIA_STOP, size, on_click_stop);
|
||||
return make_button(GTK_STOCK_MEDIA_STOP, size, on_click_stop, true);
|
||||
}
|
||||
|
||||
static void on_click_open_file(GtkWidget *b, GdkEvent *e, gpointer d)
|
||||
|
@ -59,5 +103,5 @@ static void on_click_open_file(GtkWidget *b, GdkEvent *e, gpointer d)
|
|||
|
||||
GtkWidget *make_open_button(GtkIconSize size)
|
||||
{
|
||||
return make_button(GTK_STOCK_OPEN, size, on_click_open_file);
|
||||
return make_button(GTK_STOCK_OPEN, size, on_click_open_file, true);
|
||||
}
|
||||
|
|
|
@ -1,13 +1,19 @@
|
|||
|
||||
#include <libsaria/libsaria.h>
|
||||
#include <ocarina/button.h>
|
||||
|
||||
void cb_play()
|
||||
{
|
||||
print("Ocarina PLAY callback!");
|
||||
hide_play_buttons();
|
||||
show_pause_buttons();
|
||||
}
|
||||
|
||||
void cb_pause()
|
||||
{
|
||||
print("Ocarina PAUSE callback!");
|
||||
hide_pause_buttons();
|
||||
show_play_buttons();
|
||||
}
|
||||
|
||||
static void add_callback(callback_t type, void (* func)())
|
||||
|
|
|
@ -30,7 +30,6 @@ void ocarina_init(int argc, char **argv)
|
|||
box_pack_start(hbox, stop, FALSE, FALSE, 0);
|
||||
gtk_widget_show(hbox);
|
||||
window_add(hbox);
|
||||
gtk_main();
|
||||
}
|
||||
|
||||
void ocarina_quit()
|
||||
|
@ -44,11 +43,13 @@ int main(int argc, char **argv)
|
|||
|
||||
libsaria_init(argc, argv);
|
||||
setup_callbacks();
|
||||
gtk_init(&argc, &argv);
|
||||
ocarina_init(argc, argv);
|
||||
|
||||
if (argc > 1)
|
||||
libsaria_get()->load(argv[1]);
|
||||
|
||||
gtk_init(&argc, &argv);
|
||||
ocarina_init(argc, argv);
|
||||
gtk_main();
|
||||
libsaria_quit();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -11,4 +11,9 @@ GtkWidget *make_pause_button(GtkIconSize);
|
|||
GtkWidget *make_stop_button(GtkIconSize);
|
||||
GtkWidget *make_open_button(GtkIconSize);
|
||||
|
||||
void show_play_buttons();
|
||||
void hide_play_buttons();
|
||||
void show_pause_buttons();
|
||||
void hide_pause_buttons();
|
||||
|
||||
#endif /* OCARINA_BUTTON_H */
|
||||
|
|
Loading…
Reference in New Issue