diff options
author | Alexey Yakovenko <wakeroid@gmail.com> | 2009-09-13 12:18:21 +0200 |
---|---|---|
committer | Alexey Yakovenko <wakeroid@gmail.com> | 2009-09-13 12:18:21 +0200 |
commit | fb55d80aec8d8c7e6bbab4f6ccff32fadd699e90 (patch) | |
tree | 34318f5aa05aad0d36e278f23d14702997d00007 /gtkplaylist.c | |
parent | 9363a7b0cda727042d3e5dfc67ee8094ec993651 (diff) |
added horizontal scrolling
Diffstat (limited to 'gtkplaylist.c')
-rw-r--r-- | gtkplaylist.c | 65 |
1 files changed, 49 insertions, 16 deletions
diff --git a/gtkplaylist.c b/gtkplaylist.c index 11bac24c..4a41f6d6 100644 --- a/gtkplaylist.c +++ b/gtkplaylist.c @@ -194,6 +194,34 @@ gtkpl_setup_scrollbar (gtkplaylist_t *ps) { } void +gtkpl_setup_hscrollbar (gtkplaylist_t *ps) { + GtkWidget *playlist = ps->playlist; + int w = playlist->allocation.width; + int size = 0; + int i; + for (i = 0; i < pl_ncolumns; i++) { + size += ps->colwidths[i]; + } + if (w >= size) { + size = 0; + } + GtkWidget *scroll = ps->hscrollbar; + if (ps->hscrollpos >= size-w) { + int n = size-w-1; + ps->hscrollpos = max (0, n); + gtk_range_set_value (GTK_RANGE (scroll), ps->hscrollpos); + } + if (size == 0) { + gtk_widget_hide (scroll); + } + else { + GtkAdjustment *adj = (GtkAdjustment*)gtk_adjustment_new (gtk_range_get_value (GTK_RANGE (scroll)), 0, size, 1, w, w); + gtk_range_set_adjustment (GTK_RANGE (scroll), adj); + gtk_widget_show (scroll); + } +} + +void gtkpl_redraw_pl_row_novis (gtkplaylist_t *ps, int row, playItem_t *it) { draw_begin ((uintptr_t)ps->backbuf); if (it) { @@ -260,7 +288,7 @@ gtkpl_draw_pl_row (gtkplaylist_t *ps, int row, playItem_t *it) { draw_get_canvas_size ((uintptr_t)ps->backbuf, &width, &height); if (it == playlist_current_ptr && ps->colwidths[0] > 0/* && !p_isstopped ()*/) { uintptr_t pixbuf = p_ispaused () ? pause16_pixbuf : play16_pixbuf; - draw_pixbuf ((uintptr_t)ps->backbuf, pixbuf, ps->colwidths[0]/2-8, (row - ps->scrollpos) * rowheight + rowheight/2 - 8, 0, 0, 16, 16); + draw_pixbuf ((uintptr_t)ps->backbuf, pixbuf, ps->colwidths[0]/2-8-ps->hscrollpos, (row - ps->scrollpos) * rowheight + rowheight/2 - 8, 0, 0, 16, 16); } if (it && ((it->selected && ps->multisel) || (row == ps->row && !ps->multisel))) { if (row % 2) { @@ -315,8 +343,7 @@ gtkpl_draw_pl_row (gtkplaylist_t *ps, int row, playItem_t *it) { title, dur }; - int x = 0; -#if 1 + int x = -ps->hscrollpos; for (int i = 0; i < pl_ncolumns; i++) { char str[512]; if (i > 0) { @@ -349,12 +376,6 @@ gtkpl_draw_pl_row (gtkplaylist_t *ps, int row, playItem_t *it) { } x += ps->colwidths[i]; } -#endif -#if 0 - char dname[512]; - pl_format_item_display_name (it, dname, 512); - text_draw (cr, rowheight, row * rowheight - ps->scrollpos * rowheight, dname); -#endif } @@ -398,6 +419,7 @@ gtkpl_draw_playlist (gtkplaylist_t *ps, int x, int y, int w, int h) { void gtkpl_configure (gtkplaylist_t *ps) { gtkpl_setup_scrollbar (ps); + gtkpl_setup_hscrollbar (ps); GtkWidget *widget = ps->playlist; if (ps->backbuf) { g_object_unref (ps->backbuf); @@ -752,6 +774,18 @@ gtkpl_scroll (gtkplaylist_t *ps, int newscroll) { } void +gtkpl_hscroll (gtkplaylist_t *ps, int newscroll) { + if (newscroll != ps->hscrollpos) { + ps->hscrollpos = newscroll; + GtkWidget *widget = ps->playlist; + gtkpl_header_draw (ps); + gtkpl_expose_header (ps, 0, 0, ps->header->allocation.width, ps->header->allocation.height); + gtkpl_draw_playlist (ps, 0, 0, widget->allocation.width, widget->allocation.height); + gdk_draw_drawable (widget->window, widget->style->black_gc, ps->backbuf, 0, 0, 0, 0, widget->allocation.width, widget->allocation.height); + } +} + +void gtkpl_randomsong (void) { p_stop (); pl_randomsong (); @@ -1156,7 +1190,7 @@ gtkpl_handle_fm_drag_drop (gtkplaylist_t *ps, int drop_y, void *ptr, int length) void gtkpl_header_draw (gtkplaylist_t *ps) { GtkWidget *widget = ps->header; - int x = 0; + int x = -ps->hscrollpos; int w = 100; int h = widget->allocation.height; const char *detail = "toolbar"; @@ -1178,8 +1212,7 @@ gtkpl_header_draw (gtkplaylist_t *ps) { gtk_paint_box (widget->style, ps->backbuf_header, GTK_STATE_INSENSITIVE, GTK_SHADOW_OUT, NULL, NULL, detail, x, 0, widget->allocation.width-x, h); } draw_begin ((uintptr_t)ps->backbuf_header); - x = 0; -// gtkpl_set_cairo_header_font (cr); + x = -ps->hscrollpos; for (int i = 0; i < pl_ncolumns; i++) { if (x >= widget->allocation.width) { break; @@ -1187,7 +1220,6 @@ gtkpl_header_draw (gtkplaylist_t *ps) { w = ps->colwidths[i]; if (w > 0) { if (!ps->header_fitted[i]) { - //gtkpl_set_cairo_header_font (cr); gtkpl_fit_text (ps->colnames_fitted[i], NULL, pl_colname_max, colnames[i], ps->colwidths[i]-10); ps->header_fitted[i] = 1; } @@ -1268,7 +1300,7 @@ on_header_motion_notify_event (GtkWidget *widget, prev_header_x = event->x; gdk_window_set_cursor (widget->window, cursor_sz); // get column start pos - int x = 0; + int x = -ps->hscrollpos; for (int i = 0; i < header_sizing; i++) { int w = ps->colwidths[i]; x += w; @@ -1281,13 +1313,14 @@ on_header_motion_notify_event (GtkWidget *widget, int cidx = (k * pl_ncolumns + header_sizing) * 3; ps->fmtcache[cidx+2] = 0; } + gtkpl_setup_hscrollbar (ps); gtkpl_header_draw (ps); gtkpl_expose_header (ps, 0, 0, ps->header->allocation.width, ps->header->allocation.height); gtkpl_draw_playlist (ps, 0, 0, ps->playlist->allocation.width, ps->playlist->allocation.height); gtkpl_expose (ps, 0, 0, ps->playlist->allocation.width, ps->playlist->allocation.height); } else { - int x = 0; + int x = -ps->hscrollpos; for (int i = 0; i < pl_ncolumns; i++) { int w = ps->colwidths[i]; if (w > 0) { // ignore collapsed columns (hack for search window) @@ -1320,7 +1353,7 @@ on_header_button_press_event (GtkWidget *widget, header_sizing = -1; header_dragpt[0] = event->x; header_dragpt[1] = event->y; - int x = 0; + int x = -ps->hscrollpos; for (int i = 0; i < pl_ncolumns; i++) { int w = ps->colwidths[i]; if (event->x >= x + w - 2 && event->x <= x + w) { |