58 lines
1.6 KiB
C++
58 lines
1.6 KiB
C++
|
|
#include <ocarina/gtk.h>
|
|
#include <libsaria/audio.h>
|
|
#include <libsaria/print.h>
|
|
#include "footer.h"
|
|
|
|
static GtkWidget *progress_box = NULL; /* gtk hbox */
|
|
static GtkWidget *position = NULL; /* gtk label */
|
|
static GtkWidget *progress = NULL; /* gtk hscale */
|
|
static GtkWidget *duration = NULL; /* gtk label */
|
|
|
|
static gboolean update_progress(gpointer data)
|
|
{
|
|
gtk_label_set_text(GTK_LABEL(position), libsaria::audio::posstr().c_str());
|
|
gtk_range_set_range(GTK_RANGE(progress), 0, libsaria::audio::duration() + 1);
|
|
gtk_range_set_value(GTK_RANGE(progress), libsaria::audio::position());
|
|
return TRUE;
|
|
}
|
|
|
|
static void slider_changed(GtkWidget *slider, GtkScrollType scroll,
|
|
gdouble value, gpointer data)
|
|
{
|
|
libsaria::audio::seek_to(value);
|
|
}
|
|
|
|
static void make_scale()
|
|
{
|
|
progress = gtk_hscale_new_with_range(0, 1, 1000000000);
|
|
gtk_scale_set_draw_value(GTK_SCALE(progress), FALSE);
|
|
gtk_timeout_add(100, update_progress, NULL);
|
|
GTK_CONNECT(progress, "change-value", slider_changed, NULL);
|
|
}
|
|
|
|
static void make_progress()
|
|
{
|
|
position = gtk_label_new("");
|
|
progress_box = gtk_hbox_new(FALSE, 0);
|
|
duration = gtk_label_new("");
|
|
make_scale();
|
|
|
|
box_pack_start(progress_box, position, FALSE, FALSE, 0);
|
|
box_pack_start(progress_box, progress, TRUE, TRUE, 0);
|
|
box_pack_start(progress_box, duration, FALSE, FALSE, 0);
|
|
gtk_widget_show_all(progress_box);
|
|
}
|
|
|
|
GtkWidget *get_progress()
|
|
{
|
|
if (progress_box == NULL)
|
|
make_progress();
|
|
return progress_box;
|
|
}
|
|
|
|
void set_duration(Track &track)
|
|
{
|
|
gtk_label_set_text(GTK_LABEL(duration), track.get_lenstr().c_str());
|
|
}
|