Created an open button
Clicking the button will open a file chooser to select a file to play.
This commit is contained in:
parent
7d3769a1a2
commit
20756aac14
|
@ -1,23 +1,10 @@
|
||||||
|
|
||||||
#include <ocarina/button.h>
|
#include <ocarina/button.h>
|
||||||
|
#include <ocarina/chooser.h>
|
||||||
|
|
||||||
#include <libsaria/audio.h>
|
#include <libsaria/audio.h>
|
||||||
#include <libsaria/libsaria.h>
|
#include <libsaria/libsaria.h>
|
||||||
|
|
||||||
static void on_click_play(GtkWidget *b, GdkEvent *e, gpointer d)
|
|
||||||
{
|
|
||||||
libsaria_get()->play();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void on_click_pause(GtkWidget *b, GdkEvent *e, gpointer d)
|
|
||||||
{
|
|
||||||
libsaria_get()->pause();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void on_click_stop(GtkWidget *b, GdkEvent *e, gpointer d)
|
|
||||||
{
|
|
||||||
libsaria_get()->stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
static GtkWidget *make_button(const gchar *stockid, GtkIconSize size,
|
static GtkWidget *make_button(const gchar *stockid, GtkIconSize size,
|
||||||
void (* func)(GtkWidget *, GdkEvent *, gpointer))
|
void (* func)(GtkWidget *, GdkEvent *, gpointer))
|
||||||
{
|
{
|
||||||
|
@ -33,17 +20,43 @@ static GtkWidget *make_button(const gchar *stockid, GtkIconSize size,
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void on_click_play(GtkWidget *b, GdkEvent *e, gpointer d)
|
||||||
|
{
|
||||||
|
libsaria_get()->play();
|
||||||
|
}
|
||||||
|
|
||||||
GtkWidget *make_play_button(GtkIconSize size)
|
GtkWidget *make_play_button(GtkIconSize size)
|
||||||
{
|
{
|
||||||
return make_button(GTK_STOCK_MEDIA_PLAY, size, on_click_play);
|
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)
|
GtkWidget *make_pause_button(GtkIconSize size)
|
||||||
{
|
{
|
||||||
return make_button(GTK_STOCK_MEDIA_PAUSE, size, on_click_pause);
|
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)
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
|
||||||
|
#include <ocarina/gtk.h>
|
||||||
|
#include <ocarina/chooser.h>
|
||||||
|
|
||||||
|
string ocarina_choose_file()
|
||||||
|
{
|
||||||
|
GtkWidget *chooser = gtk_file_chooser_dialog_new(
|
||||||
|
"Open File",
|
||||||
|
NULL,
|
||||||
|
GTK_FILE_CHOOSER_ACTION_OPEN,
|
||||||
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
||||||
|
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
|
||||||
|
NULL);
|
||||||
|
char *c_file;
|
||||||
|
string filename = "";
|
||||||
|
|
||||||
|
if ( gtk_dialog_run(GTK_DIALOG(chooser)) == GTK_RESPONSE_ACCEPT) {
|
||||||
|
c_file = gtk_file_chooser_get_filename(
|
||||||
|
GTK_FILE_CHOOSER(chooser));
|
||||||
|
filename = c_file;
|
||||||
|
g_free(c_file);
|
||||||
|
}
|
||||||
|
gtk_widget_destroy(chooser);
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
void ocarina_init(int argc, char **argv)
|
void ocarina_init(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
GtkWidget *open;
|
||||||
GtkWidget *play;
|
GtkWidget *play;
|
||||||
GtkWidget *pause;
|
GtkWidget *pause;
|
||||||
GtkWidget *stop;
|
GtkWidget *stop;
|
||||||
|
@ -17,10 +18,12 @@ void ocarina_init(int argc, char **argv)
|
||||||
window_icon("images/ocarina.png");
|
window_icon("images/ocarina.png");
|
||||||
|
|
||||||
hbox = gtk_hbox_new(FALSE, 0);
|
hbox = gtk_hbox_new(FALSE, 0);
|
||||||
|
open = make_open_button(GTK_ICON_SIZE_MENU);
|
||||||
play = make_play_button(GTK_ICON_SIZE_MENU);
|
play = make_play_button(GTK_ICON_SIZE_MENU);
|
||||||
pause = make_pause_button(GTK_ICON_SIZE_MENU);
|
pause = make_pause_button(GTK_ICON_SIZE_MENU);
|
||||||
stop = make_stop_button(GTK_ICON_SIZE_MENU);
|
stop = make_stop_button(GTK_ICON_SIZE_MENU);
|
||||||
|
|
||||||
|
box_pack_start(hbox, open, FALSE, FALSE, 0);
|
||||||
box_pack_start(hbox, play, FALSE, FALSE, 0);
|
box_pack_start(hbox, play, FALSE, FALSE, 0);
|
||||||
box_pack_start(hbox, pause, FALSE, FALSE, 0);
|
box_pack_start(hbox, pause, FALSE, FALSE, 0);
|
||||||
box_pack_start(hbox, stop, FALSE, FALSE, 0);
|
box_pack_start(hbox, stop, FALSE, FALSE, 0);
|
||||||
|
|
|
@ -9,5 +9,6 @@ using namespace std;
|
||||||
GtkWidget *make_play_button(GtkIconSize);
|
GtkWidget *make_play_button(GtkIconSize);
|
||||||
GtkWidget *make_pause_button(GtkIconSize);
|
GtkWidget *make_pause_button(GtkIconSize);
|
||||||
GtkWidget *make_stop_button(GtkIconSize);
|
GtkWidget *make_stop_button(GtkIconSize);
|
||||||
|
GtkWidget *make_open_button(GtkIconSize);
|
||||||
|
|
||||||
#endif /* OCARINA_BUTTON_H */
|
#endif /* OCARINA_BUTTON_H */
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
#ifndef OCARINA_CHOOSER_H
|
||||||
|
#define OCARINA_CHOOSER_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
string ocarina_choose_file();
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue