diff options
author | waker <waker@xps.localdomain> | 2009-07-04 20:08:10 +0200 |
---|---|---|
committer | waker <waker@xps.localdomain> | 2009-07-04 20:08:10 +0200 |
commit | 033c0a7c702e709ba0ddac5406712c403dd0440b (patch) | |
tree | b76d7981b088466295f9409246d33567637a6022 /callbacks.c | |
parent | 9107b42c99d6226c2f7dcfb63ba4a7d99036de26 (diff) |
fixed mp3 playback
Diffstat (limited to 'callbacks.c')
-rw-r--r-- | callbacks.c | 202 |
1 files changed, 117 insertions, 85 deletions
diff --git a/callbacks.c b/callbacks.c index 766887d7..244701fa 100644 --- a/callbacks.c +++ b/callbacks.c @@ -38,53 +38,12 @@ setup_ps_scrollbar (void) { size = 0; } GtkWidget *scroll = lookup_widget (mainwin, "playscroll"); - printf ("%d\n", size); // gtk_range_set_range (GTK_RANGE (scroll), 0, size); // gtk_range_set_increments (GTK_RANGE (scroll), 1, h); GtkAdjustment *adj = (GtkAdjustment*)gtk_adjustment_new (gtk_range_get_value (GTK_RANGE (scroll)), 0, size, 1, h, h); gtk_range_set_adjustment (GTK_RANGE (scroll), adj); } - -void -on_playbtn_clicked (GtkButton *button, - gpointer user_data) -{ - -} - - -void -on_volume_value_changed (GtkRange *range, - gpointer user_data) -{ - psdl_set_volume (gtk_range_get_value (range) / 100); -} - - -void -on_playpos_value_changed (GtkRange *range, - gpointer user_data) -{ - -} - - -// change properties -gboolean -on_playlist_configure_event (GtkWidget *widget, - GdkEventConfigure *event, - gpointer user_data) -{ - setup_ps_scrollbar (); - if (backbuf) { - g_object_unref (backbuf); - } - backbuf = gdk_pixmap_new (widget->window, widget->allocation.width, widget->allocation.height, -1); - - return FALSE; -} - void draw_ps_row_back (GdkDrawable *drawable, cairo_t *cr, int row) { // draw background @@ -95,12 +54,12 @@ draw_ps_row_back (GdkDrawable *drawable, cairo_t *cr, int row) { gdk_drawable_get_size (drawable, &width, &height); w = width; if (row == playlist_row) { + cairo_set_source_rgb (cr, 0x7f/255.f, 0x7f/255.f, 0x7f/255.f); + cairo_rectangle (cr, 0, row * rowheight - trackerscroll * rowheight, width, rowheight); + cairo_fill (cr); cairo_set_source_rgb (cr, 0xae/255.f, 0xa6/255.f, 0x9d/255.f); cairo_rectangle (cr, 1, row * rowheight - trackerscroll * rowheight+1, width-2, rowheight-2); cairo_fill (cr); - cairo_set_source_rgb (cr, 0x7f/255.f, 0x7f/255.f, 0x7f/255.f); - cairo_rectangle (cr, 0, row * rowheight - trackerscroll * rowheight, width, rowheight); - cairo_stroke (cr); } else { if (row % 2) { @@ -133,6 +92,8 @@ text_draw (cairo_t *cr, int x, int y, const char *text) { void draw_ps_row (GdkDrawable *drawable, cairo_t *cr, int row, playItem_t *it) { + int width, height; + gdk_drawable_get_size (drawable, &width, &height); if (row == playlist_row) { cairo_set_source_rgb (cr, 0, 0, 0); } @@ -156,6 +117,7 @@ redraw_ps_row (GtkWidget *widget, int row) { if (!cr) { return; } + //cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE); // cairo_select_font_face (cr, "fixed", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); // cairo_set_font_size (cr, rowheight); @@ -169,12 +131,14 @@ redraw_ps_row (GtkWidget *widget, int row) { gdk_draw_drawable (widget->window, widget->style->black_gc, backbuf, x, y, x, y, w, h); } + void draw_playlist (GtkWidget *widget, int x, int y, int w, int h) { cairo_t *cr; cr = gdk_cairo_create (backbuf); if (!cr) { return; } + //cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE); // cairo_select_font_face (cr, "fixed", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); // cairo_set_font_size (cr, rowheight); @@ -196,10 +160,49 @@ void draw_playlist (GtkWidget *widget, int x, int y, int w, int h) { } cairo_destroy (cr); - gdk_draw_drawable (widget->window, widget->style->black_gc, backbuf, x, y, x, y, w, h); } +void +on_playbtn_clicked (GtkButton *button, + gpointer user_data) +{ + +} + + +void +on_volume_value_changed (GtkRange *range, + gpointer user_data) +{ + psdl_set_volume (gtk_range_get_value (range) / 100); +} + + +void +on_playpos_value_changed (GtkRange *range, + gpointer user_data) +{ + +} + + +// change properties +gboolean +on_playlist_configure_event (GtkWidget *widget, + GdkEventConfigure *event, + gpointer user_data) +{ + setup_ps_scrollbar (); + if (backbuf) { + g_object_unref (backbuf); + } + backbuf = gdk_pixmap_new (widget->window, widget->allocation.width, widget->allocation.height, -1); + draw_playlist (widget, 0, 0, widget->allocation.width, widget->allocation.height); + + return FALSE; +} + // redraw gboolean on_playlist_expose_event (GtkWidget *widget, @@ -207,7 +210,7 @@ on_playlist_expose_event (GtkWidget *widget, gpointer user_data) { // draw visible area of playlist - draw_playlist (widget, event->area.x, event->area.y, event->area.width, event->area.height); + gdk_draw_drawable (widget->window, widget->style->black_gc, backbuf, event->area.x, event->area.y, event->area.x, event->area.y, event->area.width, event->area.height); return FALSE; } @@ -226,44 +229,46 @@ on_playlist_button_press_event (GtkWidget *widget, GdkEventButton *event, gpointer user_data) { - // remember mouse coords for doubleclick detection - ps_lastpos[0] = event->x; - ps_lastpos[1] = event->y; - // select item - int y = event->y/rowheight + trackerscroll; - if (y < 0 || y >= ps_getcount ()) { - y = -1; - } - - if (playlist_row != y) { - int old = playlist_row; - playlist_row = y; - if (old != -1) { - redraw_ps_row (widget, old); - } - if (playlist_row != -1) { - redraw_ps_row (widget, playlist_row); + if (event->button == 1) { + // remember mouse coords for doubleclick detection + ps_lastpos[0] = event->x; + ps_lastpos[1] = event->y; + // select item + int y = event->y/rowheight + trackerscroll; + if (y < 0 || y >= ps_getcount ()) { + y = -1; } - } - if (event->time - playlist_clicktime < 0.5 - && fabs(ps_lastpos[0] - event->x) < 3 - && fabs(ps_lastpos[1] - event->y) < 3) { - // doubleclick - play this item - if (playlist_row != -1) { - playItem_t *it = ps_get_for_idx (playlist_row); - if (it) { - psdl_stop (); - psdl_play (it); + if (playlist_row != y) { + int old = playlist_row; + playlist_row = y; + if (old != -1) { + redraw_ps_row (widget, old); + } + if (playlist_row != -1) { + redraw_ps_row (widget, playlist_row); } } + if (event->time - playlist_clicktime < 0.5 + && fabs(ps_lastpos[0] - event->x) < 3 + && fabs(ps_lastpos[1] - event->y) < 3) { + // doubleclick - play this item + if (playlist_row != -1) { + playItem_t *it = ps_get_for_idx (playlist_row); + if (it) { + psdl_stop (); + psdl_play (it); + } + } - // prevent next click to trigger doubleclick - playlist_clicktime = event->time-1; - } - else { - playlist_clicktime = event->time; + + // prevent next click to trigger doubleclick + playlist_clicktime = event->time-1; + } + else { + playlist_clicktime = event->time; + } } return FALSE; } @@ -273,9 +278,13 @@ void on_playscroll_value_changed (GtkRange *range, gpointer user_data) { - trackerscroll = gtk_range_get_value (GTK_RANGE (range)); - GtkWidget *playlist = lookup_widget (mainwin, "playlist"); - draw_playlist (playlist, 0, 0, playlist->allocation.width, playlist->allocation.height); + int newscroll = gtk_range_get_value (GTK_RANGE (range)); + if (newscroll != trackerscroll) { + trackerscroll = newscroll; + GtkWidget *widget = lookup_widget (mainwin, "playlist"); + draw_playlist (widget, 0, 0, widget->allocation.width, widget->allocation.height); + gdk_draw_drawable (widget->window, widget->style->black_gc, backbuf, 0, 0, 0, 0, widget->allocation.width, widget->allocation.height); + } } @@ -315,8 +324,9 @@ on_add_files_activate (GtkMenuItem *menuitem, } gtk_widget_destroy (dlg); setup_ps_scrollbar (); - GtkWidget *playlist = lookup_widget (mainwin, "playlist"); - draw_playlist (playlist, 0, 0, playlist->allocation.width, playlist->allocation.height); + GtkWidget *widget = lookup_widget (mainwin, "playlist"); + draw_playlist (widget, 0, 0, widget->allocation.width, widget->allocation.height); + gdk_draw_drawable (widget->window, widget->style->black_gc, backbuf, 0, 0, 0, 0, widget->allocation.width, widget->allocation.height); } @@ -337,8 +347,9 @@ on_add_folder1_activate (GtkMenuItem *menuitem, } gtk_widget_destroy (dlg); setup_ps_scrollbar (); - GtkWidget *playlist = lookup_widget (mainwin, "playlist"); - draw_playlist (playlist, 0, 0, playlist->allocation.width, playlist->allocation.height); + GtkWidget *widget = lookup_widget (mainwin, "playlist"); + draw_playlist (widget, 0, 0, widget->allocation.width, widget->allocation.height); + gdk_draw_drawable (widget->window, widget->style->black_gc, backbuf, 0, 0, 0, 0, widget->allocation.width, widget->allocation.height); } @@ -397,3 +408,24 @@ on_about1_activate (GtkMenuItem *menuitem, } + +gboolean +on_playlist_scroll_event (GtkWidget *widget, + GdkEvent *event, + gpointer user_data) +{ + // pass event to scrollbar + GtkWidget *range = lookup_widget (mainwin, "playscroll"); + GdkEventScroll *ev = (GdkEventScroll*)event; + GtkAdjustment* adj = gtk_range_get_adjustment (GTK_RANGE (range)); + int newscroll = gtk_range_get_value (GTK_RANGE (range)); + if (ev->direction == GDK_SCROLL_UP) { + newscroll -= gtk_adjustment_get_page_increment (adj); + } + else if (ev->direction == GDK_SCROLL_DOWN) { + newscroll += gtk_adjustment_get_page_increment (adj); + } + gtk_range_set_value (GTK_RANGE (range), newscroll); + return FALSE; +} + |