diff options
author | waker <wakeroid@gmail.com> | 2012-10-05 17:46:33 +0200 |
---|---|---|
committer | waker <wakeroid@gmail.com> | 2012-10-05 17:46:33 +0200 |
commit | ce2923c8f0cac7a563d1ecf22085ac62281c74d7 (patch) | |
tree | 20ce1a2fd0cebc36231882b011e34230778a1db9 /plugins/gtkui/ddbtabstrip.c | |
parent | 527ba48d8209a8e854c791d571106a5daf2fdd29 (diff) | |
parent | 708c8ba9f7aefe9f795c9c4eb30ab128f09c8b3d (diff) |
Merge branch 'master' into devel
Conflicts:
README
configure.ac
deadbeef.h
plugins.c
plugins/gtkui/Makefile.am
plugins/gtkui/ddbcellrenderertextmultiline.c
plugins/gtkui/ddblistview.c
plugins/gtkui/deadbeef.glade
plugins/gtkui/gtkui.c
plugins/gtkui/interface.c
plugins/gtkui/plcommon.c
plugins/shellexec/shellexec.c
plugins/supereq/Makefile.am
Diffstat (limited to 'plugins/gtkui/ddbtabstrip.c')
-rw-r--r-- | plugins/gtkui/ddbtabstrip.c | 122 |
1 files changed, 104 insertions, 18 deletions
diff --git a/plugins/gtkui/ddbtabstrip.c b/plugins/gtkui/ddbtabstrip.c index 18151ff4..f367b0f8 100644 --- a/plugins/gtkui/ddbtabstrip.c +++ b/plugins/gtkui/ddbtabstrip.c @@ -225,6 +225,7 @@ ddb_tabstrip_destroy(GObject *object) g_return_if_fail(DDB_IS_TABSTRIP(object)); tabstrip = DDB_TABSTRIP (object); + draw_free (&tabstrip->drawctx); } static void @@ -326,6 +327,10 @@ ddb_tabstrip_init(DdbTabStrip *tabstrip) tabstrip->dragpt[1] = 0; tabstrip->prev_x = 0; tabstrip->movepos = 0; + drawctx_init (&tabstrip->drawctx); +#if GTK_CHECK_VERSION(3,0,0) + gtk_widget_set_events (GTK_WIDGET (tabstrip), gtk_widget_get_events (GTK_WIDGET (tabstrip)) | GDK_SCROLL_MASK); +#endif } static int tab_clicked = -1; @@ -357,7 +362,11 @@ cairo_draw_poly (cairo_t *cr, GdkPoint *pts, int cnt) { void +#if !GTK_CHECK_VERSION(3,0,0) +ddb_tabstrip_draw_tab (GtkWidget *widget, GdkDrawable *drawable, int idx, int selected, int x, int y, int w, int h) { +#else ddb_tabstrip_draw_tab (GtkWidget *widget, cairo_t *cr, int idx, int selected, int x, int y, int w, int h) { +#endif GdkPoint points_filled[] = { { x+2, y + h }, { x+2, y + 2 }, @@ -366,7 +375,11 @@ ddb_tabstrip_draw_tab (GtkWidget *widget, cairo_t *cr, int idx, int selected, in }; GdkPoint points_frame1[] = { { x, y + h-2 }, +#if !GTK_CHECK_VERSION(3,0,0) + { x, y + 1 }, +#else { x, y + 0 }, +#endif { x + 1, y + 0 }, { x + w - h - 1, y + 0 }, { x + w - h, y + 1 }, @@ -377,13 +390,22 @@ ddb_tabstrip_draw_tab (GtkWidget *widget, cairo_t *cr, int idx, int selected, in }; GdkPoint points_frame2[] = { { x + 1, y + h + 1 }, +#if !GTK_CHECK_VERSION(3,0,0) + { x + 1, y + 1 }, +#else { x + 1, y + 0 }, +#endif { x + w - h - 1, y + 1 }, { x + w - h, y + 2 }, { x + w - h + 1, y + 2 }, { x + w-3, y + h - 2 }, { x + w-2, y + h - 2 }, }; +#if !GTK_CHECK_VERSION(3,0,0) + GdkGC *bg = gdk_gc_new (drawable); + GdkGC *outer_frame = gdk_gc_new (drawable); + GdkGC *inner_frame = gdk_gc_new (drawable); +#endif GdkColor clr_bg; GdkColor clr_outer_frame; GdkColor clr_inner_frame; @@ -406,17 +428,37 @@ ddb_tabstrip_draw_tab (GtkWidget *widget, cairo_t *cr, int idx, int selected, in if (fallback) { gtkui_get_tabstrip_base_color (&clr_bg); } +#if !GTK_CHECK_VERSION(3,0,0) + gdk_gc_set_rgb_fg_color (bg, &clr_bg); + gdk_gc_set_rgb_fg_color (outer_frame, (gtkui_get_tabstrip_dark_color (&clr_outer_frame), &clr_outer_frame)); + gdk_gc_set_rgb_fg_color (inner_frame, (gtkui_get_tabstrip_light_color (&clr_inner_frame), &clr_inner_frame)); +#else gtkui_get_tabstrip_dark_color (&clr_outer_frame); gtkui_get_tabstrip_light_color (&clr_inner_frame); +#endif } else { if (fallback) { gtkui_get_tabstrip_mid_color (&clr_bg); } +#if !GTK_CHECK_VERSION(3,0,0) + gdk_gc_set_rgb_fg_color (bg, &clr_bg); + gdk_gc_set_rgb_fg_color (outer_frame, (gtkui_get_tabstrip_dark_color (&clr_outer_frame), &clr_outer_frame)); + gdk_gc_set_rgb_fg_color (inner_frame, (gtkui_get_tabstrip_mid_color (&clr_inner_frame), &clr_inner_frame)); +#else gtkui_get_tabstrip_dark_color (&clr_outer_frame); gtkui_get_tabstrip_mid_color (&clr_inner_frame); +#endif } +#if !GTK_CHECK_VERSION(3,0,0) + gdk_draw_polygon (drawable, bg, TRUE, points_filled, 4); + gdk_draw_lines (drawable, outer_frame, points_frame1, 9); + gdk_draw_lines (drawable, inner_frame, points_frame2, 7); + g_object_unref (bg); + g_object_unref (outer_frame); + g_object_unref (inner_frame); +#else cairo_set_source_rgb (cr, clr_bg.red/65535.f, clr_bg.green/65535.f, clr_bg.blue/65535.0); cairo_new_path (cr); cairo_draw_poly (cr, points_filled, 4); @@ -428,6 +470,7 @@ ddb_tabstrip_draw_tab (GtkWidget *widget, cairo_t *cr, int idx, int selected, in cairo_set_source_rgb (cr, clr_inner_frame.red/65535.f, clr_inner_frame.green/65535.f, clr_inner_frame.blue/65535.0); cairo_draw_lines (cr, points_frame2, 7); cairo_stroke (cr); +#endif } int @@ -436,7 +479,7 @@ ddb_tabstrip_get_tab_width (DdbTabStrip *ts, int tab) { char title[100]; plt_get_title_wrapper (tab, title, sizeof (title)); int h = 0; - draw_get_text_extents (title, strlen (title), &width, &h); + draw_get_text_extents (&ts->drawctx, title, strlen (title), &width, &h); width += text_left_padding + text_right_padding; if (width < min_tab_size) { width = min_tab_size; @@ -532,7 +575,7 @@ tabstrip_adjust_hscroll (DdbTabStrip *ts) { } void -set_tab_text_color (int idx, int selected) { +set_tab_text_color (DdbTabStrip *ts, int idx, int selected) { if (idx == -1) { return; } @@ -545,7 +588,7 @@ set_tab_text_color (int idx, int selected) { if (3 == sscanf (clr, "%02x%02x%02x", &r, &g, &b)) { fallback = 0; float fg[3] = {(float)r/0xff, (float)g/0xff, (float)b/0xff}; - draw_set_fg_color (fg); + draw_set_fg_color (&ts->drawctx, fg); } } deadbeef->plt_unref (plt); @@ -553,7 +596,7 @@ set_tab_text_color (int idx, int selected) { GdkColor color; gtkui_get_tabstrip_text_color (&color); float fg[3] = {(float)color.red/0xffff, (float)color.green/0xffff, (float)color.blue/0xffff}; - draw_set_fg_color (fg); + draw_set_fg_color (&ts->drawctx, fg); } deadbeef->pl_unlock (); } @@ -561,6 +604,9 @@ set_tab_text_color (int idx, int selected) { void tabstrip_render (DdbTabStrip *ts, cairo_t *cr) { GtkWidget *widget = GTK_WIDGET (ts); +#if !GTK_CHECK_VERSION(3,0,0) + GdkDrawable *backbuf = gtk_widget_get_window (widget); +#endif GtkAllocation a; gtk_widget_get_allocation (widget, &a); @@ -578,7 +624,7 @@ tabstrip_render (DdbTabStrip *ts, cairo_t *cr) { int x = -hscroll; int w = 0; - int h = draw_get_font_size (); + int h = draw_get_font_size (&ts->drawctx); h = a.height; tab_overlap_size = (h-4)/2; text_right_padding = h - 3; @@ -589,6 +635,16 @@ tabstrip_render (DdbTabStrip *ts, cairo_t *cr) { return; } +#if !GTK_CHECK_VERSION(3,0,0) + GdkGC *gc = gdk_gc_new (backbuf); + // fill background + GdkColor clr; + gdk_gc_set_rgb_fg_color (gc, (gtkui_get_tabstrip_mid_color (&clr), &clr)); + gdk_draw_rectangle (backbuf, gc, TRUE, 0, 0, widget->allocation.width, widget->allocation.height); + gdk_gc_set_rgb_fg_color (gc, (gtkui_get_tabstrip_dark_color (&clr), &clr)); + gdk_draw_line (backbuf, gc, 0, 0, widget->allocation.width, 0); +#else + // fill background GdkColor clr; gtkui_get_tabstrip_mid_color (&clr); @@ -601,10 +657,11 @@ tabstrip_render (DdbTabStrip *ts, cairo_t *cr) { cairo_move_to (cr, 0, 1); cairo_line_to (cr, a.width, 1); cairo_stroke (cr); +#endif int y = 4; h = a.height - 4; - draw_begin (cr); + draw_begin (&ts->drawctx, cr); int need_draw_moving = 0; int idx; int widths[cnt]; @@ -612,7 +669,7 @@ tabstrip_render (DdbTabStrip *ts, cairo_t *cr) { char title[100]; plt_get_title_wrapper (idx, title, sizeof (title)); int h = 0; - draw_get_text_extents (title, strlen (title), &widths[idx], &h); + draw_get_text_extents (&ts->drawctx, title, strlen (title), &widths[idx], &h); widths[idx] += text_left_padding + text_right_padding; if (widths[idx] < min_tab_size) { widths[idx] = min_tab_size; @@ -629,15 +686,23 @@ tabstrip_render (DdbTabStrip *ts, cairo_t *cr) { area.width = w; area.height = 24; if (idx != tab_selected) { +#if !GTK_CHECK_VERSION(3,0,0) + ddb_tabstrip_draw_tab (widget, backbuf, idx, idx == tab_selected, x, y, w, h); +#else ddb_tabstrip_draw_tab (widget, cr, idx, idx == tab_selected, x, y, w, h); +#endif char tab_title[100]; plt_get_title_wrapper (idx, tab_title, sizeof (tab_title)); - set_tab_text_color (idx, tab_selected); - draw_text (x + text_left_padding, y - text_vert_offset, w, 0, tab_title); + set_tab_text_color (ts, idx, tab_selected); + draw_text (&ts->drawctx, x + text_left_padding, y - text_vert_offset, w, 0, tab_title); } x += w - tab_overlap_size; } +#if !GTK_CHECK_VERSION(3,0,0) + gdk_draw_line (backbuf, widget->style->dark_gc[GTK_STATE_NORMAL], 0, widget->allocation.height-2, widget->allocation.width, widget->allocation.height-2); + gdk_draw_line (backbuf, widget->style->light_gc[GTK_STATE_NORMAL], 0, widget->allocation.height-1, widget->allocation.width, widget->allocation.height-1); +#else GdkColor *pclr = >k_widget_get_style (widget)->dark[GTK_STATE_NORMAL]; cairo_set_source_rgb (cr, pclr->red/65535.f, pclr->green/65535.f, pclr->blue/65535.0); cairo_move_to (cr, 0, a.height-1); @@ -648,6 +713,7 @@ tabstrip_render (DdbTabStrip *ts, cairo_t *cr) { cairo_move_to (cr, 0, a.height); cairo_line_to (cr, a.width, a.height); cairo_stroke (cr); +#endif // calc position for drawin selected tab x = -hscroll; for (idx = 0; idx < tab_selected; idx++) { @@ -663,11 +729,15 @@ tabstrip_render (DdbTabStrip *ts, cairo_t *cr) { area.y = 0; area.width = w; area.height = 24; +#if !GTK_CHECK_VERSION(3,0,0) + ddb_tabstrip_draw_tab (widget, backbuf, idx, 1, x, y, w, h); +#else ddb_tabstrip_draw_tab (widget, cr, idx, 1, x, y, w, h); +#endif char tab_title[100]; plt_get_title_wrapper (idx, tab_title, sizeof (tab_title)); - set_tab_text_color (idx, tab_selected); - draw_text (x + text_left_padding, y - text_vert_offset, w, 0, tab_title); + set_tab_text_color (ts, idx, tab_selected); + draw_text (&ts->drawctx, x + text_left_padding, y - text_vert_offset, w, 0, tab_title); } else { need_draw_moving = 1; @@ -682,17 +752,32 @@ tabstrip_render (DdbTabStrip *ts, cairo_t *cr) { break; } if (w > 0) { +#if !GTK_CHECK_VERSION(3,0,0) + ddb_tabstrip_draw_tab (widget, backbuf, idx, 1, x, y, w, h); +#else ddb_tabstrip_draw_tab (widget, cr, idx, 1, x, y, w, h); +#endif char tab_title[100]; plt_get_title_wrapper (idx, tab_title, sizeof (tab_title)); - set_tab_text_color (idx, tab_selected); - draw_text (x + text_left_padding, y - text_vert_offset, w, 0, tab_title); + set_tab_text_color (ts, idx, tab_selected); + draw_text (&ts->drawctx, x + text_left_padding, y - text_vert_offset, w, 0, tab_title); } break; } x += w - tab_overlap_size; } } +#if !GTK_CHECK_VERSION(3,0,0) + if (need_arrows) { + int sz = widget->allocation.height-3; + GdkColor clr; + gdk_gc_set_rgb_fg_color (gc, (gtkui_get_tabstrip_mid_color (&clr), &clr)); + gdk_draw_rectangle (backbuf, gc, TRUE, 0, 1, arrow_widget_width, sz); + gtk_paint_arrow (widget->style, widget->window, GTK_STATE_NORMAL, GTK_SHADOW_NONE, NULL, widget, NULL, GTK_ARROW_LEFT, TRUE, 2, sz/2-arrow_sz/2, arrow_sz, arrow_sz); + gdk_draw_rectangle (backbuf, gc, TRUE, widget->allocation.width-arrow_widget_width, 1, arrow_widget_width, sz); + gtk_paint_arrow (widget->style, widget->window, GTK_STATE_NORMAL, GTK_SHADOW_NONE, NULL, widget, NULL, GTK_ARROW_RIGHT, TRUE, widget->allocation.width-arrow_sz-2, 1+sz/2-arrow_sz/2, arrow_sz, arrow_sz); + } +#else if (need_arrows) { int sz = a.height-3; gtkui_get_tabstrip_mid_color (&clr); @@ -713,8 +798,9 @@ tabstrip_render (DdbTabStrip *ts, cairo_t *cr) { gtk_paint_arrow (gtk_widget_get_style (widget), gtk_widget_get_window(widget), GTK_STATE_NORMAL, GTK_SHADOW_NONE, NULL, widget, NULL, GTK_ARROW_RIGHT, TRUE, a.width-arrow_sz-2, 1+sz/2-arrow_sz/2, arrow_sz, arrow_sz); #endif } +#endif - draw_end (); + draw_end (&ts->drawctx); } static int @@ -733,7 +819,7 @@ get_tab_under_cursor (DdbTabStrip *ts, int x) { plt_get_title_wrapper (idx, title, sizeof (title)); int w = 0; int h = 0; - draw_get_text_extents (title, strlen (title), &w, &h); + draw_get_text_extents (&ts->drawctx, title, strlen (title), &w, &h); w += text_left_padding + text_right_padding; if (w < min_tab_size) { w = min_tab_size; @@ -1151,10 +1237,10 @@ gboolean on_tabstrip_configure_event (GtkWidget *widget, GdkEventConfigure *event) { - draw_init_font (gtk_widget_get_style (widget)); DdbTabStrip *ts = DDB_TABSTRIP (widget); + draw_init_font (&ts->drawctx, gtk_widget_get_style (widget)); tabstrip_adjust_hscroll (ts); - int height = draw_get_listview_rowheight () + 4; + int height = draw_get_listview_rowheight (&ts->drawctx) + 4; GtkAllocation a; gtk_widget_get_allocation (widget, &a); if (height != a.height) { @@ -1189,7 +1275,7 @@ on_tabstrip_motion_notify_event (GtkWidget *widget, ev_x = event->x; ev_y = event->y; ev_state = event->state; -#if GTK_CHECK_VERSION(2,12,0) && !defined(ULTRA_COMPATIBLE) +#if GTK_CHECK_VERSION(2,12,0) gdk_event_request_motions (event); #endif if ((ev_state & GDK_BUTTON1_MASK) && ts->prepare) { |