ocarina/ocarina/footer/controls.cpp

73 lines
1.6 KiB
C++

#include <ocarina/gtk.h>
#include <ocarina/button.h>
#include <ocarina/shortcut.h>
#include <libsaria/audio.h>
#include <libsaria/controls.h>
#include "footer.h"
static GtkWidget *controls = NULL;
static GtkWidget *make_buttons()
{
GtkWidget *buttons = gtk_hbox_new(FALSE, 0);
gtk_widget_show(buttons);
box_pack_end(buttons, make_next_button(), FALSE, FALSE, 0);
box_pack_end(buttons, make_stop_button(), FALSE, FALSE, 0);
box_pack_end(buttons, make_pause_button(), FALSE, FALSE, 0);
box_pack_end(buttons, make_play_button(), FALSE, FALSE, 0);
box_pack_end(buttons, make_forward_button(), FALSE, FALSE, 0);
box_pack_end(buttons, make_rewind_button(), FALSE, FALSE, 0);
return buttons;
}
static void toggle_pause_after()
{
libsaria::set_pause_after(!libsaria::get_pause_after());
}
static void rewind()
{
libsaria::audio::seek(-5);
}
static void forward()
{
libsaria::audio::seek(5);
}
static void toggle_play()
{
if (libsaria::audio::is_playing())
libsaria::audio::pause();
else
libsaria::audio::play();
}
static void make_controls()
{
controls = gtk_vbox_new(FALSE, 0);
gtk_widget_show(controls);
/*
* Putting the button hbox into a vbox will keep them from
* expanding vertically to take up all the space.
*/
box_pack_start(controls, make_buttons(), TRUE, FALSE, 0);
register_shortcut("Left", rewind);
register_shortcut("Right", forward);
register_shortcut("space", toggle_play);
register_shortcut("n", libsaria::next);
register_shortcut("s", libsaria::audio::stop);
register_shortcut("p", toggle_pause_after);
}
GtkWidget *get_controls()
{
if (controls == NULL)
make_controls();
return controls;
}