From 1630250351e46acc0a2be6a444599afac0d742e2 Mon Sep 17 00:00:00 2001 From: Alexey Yakovenko Date: Mon, 8 Feb 2010 20:44:55 +0100 Subject: tabbed playlists WIP --- plugins/gtkui/deadbeef.glade | 1 + plugins/gtkui/gdkdrawing.c | 2 - plugins/gtkui/interface.c | 1 + plugins/gtkui/tabs.c | 131 ++++++++++++++++++++++++++----------------- 4 files changed, 83 insertions(+), 52 deletions(-) (limited to 'plugins') diff --git a/plugins/gtkui/deadbeef.glade b/plugins/gtkui/deadbeef.glade index 34ea1a3f..0bc0cad0 100644 --- a/plugins/gtkui/deadbeef.glade +++ b/plugins/gtkui/deadbeef.glade @@ -797,6 +797,7 @@ 24 True + GDK_POINTER_MOTION_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK diff --git a/plugins/gtkui/gdkdrawing.c b/plugins/gtkui/gdkdrawing.c index 29238689..c78f5d54 100644 --- a/plugins/gtkui/gdkdrawing.c +++ b/plugins/gtkui/gdkdrawing.c @@ -150,6 +150,4 @@ draw_get_text_extents (const char *text, int len, int *w, int *h) { pango_layout_get_pixel_extents (pangolayout, &ink, &log); *w = ink.width; *h = ink.height; - printf ("ink: %d %d %d %d\n", ink.x, ink.y, ink.width, ink.height); - printf ("log: %d %d %d %d\n", log.x, log.y, log.width, log.height); } diff --git a/plugins/gtkui/interface.c b/plugins/gtkui/interface.c index c0897f13..94d115ac 100644 --- a/plugins/gtkui/interface.c +++ b/plugins/gtkui/interface.c @@ -506,6 +506,7 @@ create_mainwin (void) gtk_widget_show (tabbar); gtk_box_pack_start (GTK_BOX (vbox1), tabbar, FALSE, TRUE, 0); gtk_widget_set_size_request (tabbar, -1, 24); + gtk_widget_set_events (tabbar, GDK_POINTER_MOTION_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK); frame1 = gtk_frame_new (NULL); gtk_widget_show (frame1); diff --git a/plugins/gtkui/tabs.c b/plugins/gtkui/tabs.c index 43810498..be6e703c 100644 --- a/plugins/gtkui/tabs.c +++ b/plugins/gtkui/tabs.c @@ -27,44 +27,12 @@ #include "support.h" #include "drawing.h" +static int margin_size = 10; static int tab_dragging = -1; static int tab_movepos; -gboolean -on_tabbar_button_press_event (GtkWidget *widget, - GdkEventButton *event, - gpointer user_data) -{ - - return FALSE; -} - - -gboolean -on_tabbar_button_release_event (GtkWidget *widget, - GdkEventButton *event, - gpointer user_data) -{ - - return FALSE; -} - - -gboolean -on_tabbar_configure_event (GtkWidget *widget, - GdkEventConfigure *event, - gpointer user_data) -{ - - return FALSE; -} - - -gboolean -on_tabbar_expose_event (GtkWidget *widget, - GdkEventExpose *event, - gpointer user_data) -{ +void +tabbar_draw (GtkWidget *widget) { GdkDrawable *backbuf = widget->window; int hscrollpos = 0; int x = -hscrollpos; @@ -86,48 +54,52 @@ on_tabbar_expose_event (GtkWidget *widget, widths[idx] = 0; int h = 0; draw_get_text_extents (title, strlen (title), &widths[idx], &h); - widths[idx] += 10; - printf ("width %s %d %d\n", title, strlen (title), widths[idx]); + widths[idx] += margin_size + 10; fullwidth += widths[idx]; - printf ("fullwidth %d\n", fullwidth); } - x = -hscrollpos + fullwidth/* - widths[cnt-1]*/; + fullwidth += margin_size; + + x = -hscrollpos + fullwidth; for (idx = cnt-1; idx >= 0; idx--) { w = widths[idx]; - x -= w; + x -= w + margin_size; GdkRectangle area; area.x = x; area.y = 0; - area.width = w+5; + area.width = w + margin_size; area.height = 24; if (idx != tab_selected) { - gtk_paint_box (widget->style, widget->window, idx == tab_selected ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL, GTK_SHADOW_OUT, &area, widget, "button", x, idx == tab_selected ? 0 : 1, w+5, 32); + gtk_paint_box (widget->style, widget->window, idx == tab_selected ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL, GTK_SHADOW_OUT, &area, widget, "button", x, idx == tab_selected ? 0 : 1, w+margin_size, 32); GdkColor *gdkfg = &widget->style->fg[0]; float fg[3] = {(float)gdkfg->red/0xffff, (float)gdkfg->green/0xffff, (float)gdkfg->blue/0xffff}; draw_set_fg_color (fg); const char *tab_title = deadbeef->plt_get_title (idx); - draw_text (x + 10, h/2-draw_get_font_size()/2, w, 0, tab_title); + draw_text (x + margin_size + 5, h/2-draw_get_font_size()/2, w - margin_size, 0, tab_title); } + x += margin_size; } gdk_draw_line (backbuf, widget->style->dark_gc[GTK_STATE_NORMAL], 0, widget->allocation.height-1, widget->allocation.width, widget->allocation.height-1); + // calc position for drawin selected tab + x = -hscrollpos; + for (idx = 0; idx < tab_selected; idx++) { + x += widths[idx]; + } // draw selected { idx = tab_selected; - w = widths[idx]; - x = -hscrollpos + fullwidth - w; + w = widths[tab_selected] + margin_size; GdkRectangle area; area.x = x; area.y = 0; - area.width = w+5; + area.width = w; area.height = 24; - gtk_paint_box (widget->style, widget->window, GTK_STATE_PRELIGHT, GTK_SHADOW_OUT, &area, widget, "button", x, idx == tab_selected ? 0 : 1, w+5, 32); + gtk_paint_box (widget->style, widget->window, GTK_STATE_PRELIGHT, GTK_SHADOW_OUT, &area, widget, "button", x, idx == tab_selected ? 0 : 1, w, 32); GdkColor *gdkfg = &widget->style->fg[0]; float fg[3] = {(float)gdkfg->red/0xffff, (float)gdkfg->green/0xffff, (float)gdkfg->blue/0xffff}; draw_set_fg_color (fg); const char *tab_title = deadbeef->plt_get_title (idx); - draw_text (x + 10, h/2-draw_get_font_size()/2, w, 0, tab_title); + draw_text (x + margin_size + 5, h/2-draw_get_font_size()/2, w - margin_size, 0, tab_title); } - if (need_draw_moving) { x = -hscrollpos; for (idx = 0; idx < 10; idx++) { @@ -154,6 +126,66 @@ on_tabbar_expose_event (GtkWidget *widget, } } draw_end (); +} + +gboolean +on_tabbar_button_press_event (GtkWidget *widget, + GdkEventButton *event, + gpointer user_data) +{ + if (event->button == 1) + { + int idx; + int cnt = deadbeef->plt_get_count (); + int fw = 0; + int tab_selected = deadbeef->plt_get_curr (); + for (idx = 0; idx < cnt; idx++) { + const char *title = deadbeef->plt_get_title (idx); + int w = 0; + int h = 0; + draw_get_text_extents (title, strlen (title), &w, &h); + w += margin_size + 10; + if (tab_selected == idx) { + w += margin_size; + } + fw += w; + if (fw > event->x) { + deadbeef->plt_set_curr (idx); + tabbar_draw (widget); + break; + } + } + } + return FALSE; +} + + +gboolean +on_tabbar_button_release_event (GtkWidget *widget, + GdkEventButton *event, + gpointer user_data) +{ + + return FALSE; +} + + +gboolean +on_tabbar_configure_event (GtkWidget *widget, + GdkEventConfigure *event, + gpointer user_data) +{ + + return FALSE; +} + + +gboolean +on_tabbar_expose_event (GtkWidget *widget, + GdkEventExpose *event, + gpointer user_data) +{ + tabbar_draw (widget); return FALSE; } @@ -163,7 +195,6 @@ on_tabbar_motion_notify_event (GtkWidget *widget, GdkEventMotion *event, gpointer user_data) { - return FALSE; } -- cgit v1.2.3