From b2d16c9b51b80be4ae9e29d2a5766e2f690846f4 Mon Sep 17 00:00:00 2001 From: waker Date: Fri, 18 May 2012 12:35:38 +0200 Subject: fixed weird gtkstyle usage in playlist and tabstrip --- plugins/gtkui/gdkdrawing.c | 179 ++++++++++++++++++++++----------------------- 1 file changed, 87 insertions(+), 92 deletions(-) (limited to 'plugins/gtkui/gdkdrawing.c') diff --git a/plugins/gtkui/gdkdrawing.c b/plugins/gtkui/gdkdrawing.c index 9580af40..e6f5d7e4 100644 --- a/plugins/gtkui/gdkdrawing.c +++ b/plugins/gtkui/gdkdrawing.c @@ -27,145 +27,152 @@ #include "support.h" #include "gtkui.h" -static cairo_t *drawable; -//static GdkGC *gc; -static GdkColor clrfg; -static GdkColor clrbg; -static int pango_ready; -static PangoContext *pangoctx; -static PangoLayout *pangolayout; - void -draw_begin (cairo_t *cr) { - drawable = cr; +draw_begin (drawctx_t *ctx, cairo_t *cr) { + ctx->drawable = cr; } void -draw_end (void) { - drawable = NULL; +draw_end (drawctx_t *ctx) { + ctx->drawable = NULL; } void -draw_set_fg_color (float *rgb) { - cairo_set_source_rgb (drawable, rgb[0], rgb[1], rgb[2]); +draw_set_fg_color (drawctx_t *ctx, float *rgb) { + cairo_set_source_rgb (ctx->drawable, rgb[0], rgb[1], rgb[2]); } void -draw_line (float x1, float y1, float x2, float y2) { - cairo_move_to (drawable, x1, y1); - cairo_line_to (drawable, x2, y2); - cairo_stroke (drawable); +draw_line (drawctx_t *ctx, float x1, float y1, float x2, float y2) { + cairo_move_to (ctx->drawable, x1, y1); + cairo_line_to (ctx->drawable, x2, y2); + cairo_stroke (ctx->drawable); } void -draw_rect (float x, float y, float w, float h, int fill) { - cairo_rectangle (drawable, x, y, w, h); - fill ? cairo_fill (drawable) : cairo_stroke (drawable); +draw_rect (drawctx_t *ctx, float x, float y, float w, float h, int fill) { + cairo_rectangle (ctx->drawable, x, y, w, h); + fill ? cairo_fill (ctx->drawable) : cairo_stroke (ctx->drawable); } -static GtkStyle *font_style = NULL; -static PangoWeight font_weight = PANGO_WEIGHT_NORMAL; - void -draw_free (void) { - draw_end (); - if (pangoctx) { - g_object_unref (pangoctx); - pangoctx = NULL; +draw_free (drawctx_t *ctx) { + draw_end (ctx); + if (ctx->pangoctx) { + g_object_unref (ctx->pangoctx); + ctx->pangoctx = NULL; } - if (pangolayout) { - g_object_unref (pangolayout); - pangolayout = NULL; + if (ctx->pangolayout) { + g_object_unref (ctx->pangolayout); + ctx->pangolayout = NULL; } } void -draw_init_font (GtkStyle *new_font_style) { - if (!pango_ready || (new_font_style && font_style != new_font_style)) { - if (pangoctx) { - g_object_unref (pangoctx); - pangoctx = NULL; +draw_init_font (drawctx_t *ctx, GtkStyle *new_font_style) { + if (!ctx->pango_ready || (new_font_style && ctx->font_style != new_font_style)) { + if (ctx->pangoctx) { + g_object_unref (ctx->pangoctx); + ctx->pangoctx = NULL; } - if (pangolayout) { - g_object_unref (pangolayout); - pangolayout = NULL; + if (ctx->pangolayout) { + g_object_unref (ctx->pangolayout); + ctx->pangolayout = NULL; } - font_style = new_font_style ? new_font_style : gtk_widget_get_default_style (); + ctx->font_style = new_font_style ? new_font_style : gtk_widget_get_default_style (); - pangoctx = gdk_pango_context_get (); - pangolayout = pango_layout_new (pangoctx); - pango_layout_set_ellipsize (pangolayout, PANGO_ELLIPSIZE_END); - PangoFontDescription *desc = font_style->font_desc; - font_weight = pango_font_description_get_weight (desc); - pango_layout_set_font_description (pangolayout, desc); - pango_ready = 1; + ctx->pangoctx = gdk_pango_context_get (); + ctx->pangolayout = pango_layout_new (ctx->pangoctx); + pango_layout_set_ellipsize (ctx->pangolayout, PANGO_ELLIPSIZE_END); + PangoFontDescription *desc = ctx->font_style->font_desc; + ctx->font_weight = pango_font_description_get_weight (desc); + pango_layout_set_font_description (ctx->pangolayout, desc); + ctx->pango_ready = 1; } else if (new_font_style) { - PangoFontDescription *desc = font_style->font_desc; - pango_layout_set_font_description (pangolayout, desc); + PangoFontDescription *desc = ctx->font_style->font_desc; + pango_layout_set_font_description (ctx->pangolayout, desc); } } void -draw_init_font_bold (void) { - PangoFontDescription *desc = pango_font_description_copy (font_style->font_desc); +draw_init_font_bold (drawctx_t *ctx) { + PangoFontDescription *desc = pango_font_description_copy (ctx->font_style->font_desc); pango_font_description_set_weight (desc, PANGO_WEIGHT_BOLD); - pango_layout_set_font_description (pangolayout, desc); + pango_layout_set_font_description (ctx->pangolayout, desc); pango_font_description_free(desc); } void -draw_init_font_normal (void) { - pango_font_description_set_weight (font_style->font_desc, font_weight); - pango_layout_set_font_description (pangolayout, font_style->font_desc); +draw_init_font_normal (drawctx_t *ctx) { + pango_font_description_set_weight (ctx->font_style->font_desc, ctx->font_weight); + pango_layout_set_font_description (ctx->pangolayout, ctx->font_style->font_desc); } float -draw_get_font_size (void) { - draw_init_font (NULL); +draw_get_font_size (drawctx_t *ctx) { + draw_init_font (ctx, NULL); GdkScreen *screen = gdk_screen_get_default (); float dpi = gdk_screen_get_resolution (screen); - PangoFontDescription *desc = font_style->font_desc; + PangoFontDescription *desc = ctx->font_style->font_desc; return (float)(pango_font_description_get_size (desc) / PANGO_SCALE * dpi / 72); } void -draw_text (float x, float y, int width, int align, const char *text) { - draw_init_font (NULL); - pango_layout_set_width (pangolayout, width*PANGO_SCALE); - pango_layout_set_alignment (pangolayout, align ? PANGO_ALIGN_RIGHT : PANGO_ALIGN_LEFT); - pango_layout_set_text (pangolayout, text, -1); - cairo_move_to (drawable, x, y); - pango_cairo_show_layout (drawable, pangolayout); +draw_text (drawctx_t *ctx, float x, float y, int width, int align, const char *text) { + draw_init_font (ctx, NULL); + pango_layout_set_width (ctx->pangolayout, width*PANGO_SCALE); + pango_layout_set_alignment (ctx->pangolayout, align ? PANGO_ALIGN_RIGHT : PANGO_ALIGN_LEFT); + pango_layout_set_text (ctx->pangolayout, text, -1); + cairo_move_to (ctx->drawable, x, y); + pango_cairo_show_layout (ctx->drawable, ctx->pangolayout); } void -draw_text_with_colors (float x, float y, int width, int align, const char *text) { - draw_init_font (NULL); - pango_layout_set_width (pangolayout, width*PANGO_SCALE); - pango_layout_set_alignment (pangolayout, align ? PANGO_ALIGN_RIGHT : PANGO_ALIGN_LEFT); - pango_layout_set_text (pangolayout, text, -1); -// gdk_draw_layout_with_colors (drawable, gc, x, y, pangolayout, &clrfg, &clrbg); - cairo_move_to (drawable, x, y); - pango_cairo_show_layout (drawable, pangolayout); +draw_text_with_colors (drawctx_t *ctx, float x, float y, int width, int align, const char *text) { + draw_init_font (ctx, NULL); + pango_layout_set_width (ctx->pangolayout, width*PANGO_SCALE); + pango_layout_set_alignment (ctx->pangolayout, align ? PANGO_ALIGN_RIGHT : PANGO_ALIGN_LEFT); + pango_layout_set_text (ctx->pangolayout, text, -1); +// gdk_draw_layout_with_colors (ctx->drawable, gc, x, y, ctx->pangolayout, &clrfg, &clrbg); + cairo_move_to (ctx->drawable, x, y); + pango_cairo_show_layout (ctx->drawable, ctx->pangolayout); } void -draw_get_text_extents (const char *text, int len, int *w, int *h) { - draw_init_font (NULL); - pango_layout_set_width (pangolayout, 1000 * PANGO_SCALE); - pango_layout_set_alignment (pangolayout, PANGO_ALIGN_LEFT); - pango_layout_set_text (pangolayout, text, len); +draw_get_text_extents (drawctx_t *ctx, const char *text, int len, int *w, int *h) { + draw_init_font (ctx, NULL); + pango_layout_set_width (ctx->pangolayout, 1000 * PANGO_SCALE); + pango_layout_set_alignment (ctx->pangolayout, PANGO_ALIGN_LEFT); + pango_layout_set_text (ctx->pangolayout, text, len); PangoRectangle ink; PangoRectangle log; - pango_layout_get_pixel_extents (pangolayout, &ink, &log); + pango_layout_get_pixel_extents (ctx->pangolayout, &ink, &log); *w = ink.width; *h = ink.height; } +int +draw_get_listview_rowheight (drawctx_t *ctx) { + PangoFontDescription *font_desc = ctx->font_style->font_desc; + PangoFontMetrics *metrics = pango_context_get_metrics (ctx->pangoctx, + font_desc, + pango_context_get_language (ctx->pangoctx)); + int row_height = (pango_font_metrics_get_ascent (metrics) + + pango_font_metrics_get_descent (metrics)); + pango_font_metrics_unref (metrics); + return PANGO_PIXELS(row_height)+6; +} + +void +drawctx_init (drawctx_t *ctx) { + memset (ctx, 0, sizeof (drawctx_t)); + ctx->font_weight = PANGO_WEIGHT_NORMAL; +} + static GdkColor gtkui_bar_foreground_color; static GdkColor gtkui_bar_background_color; @@ -358,15 +365,3 @@ gtkui_get_listview_cursor_color (GdkColor *clr) { memcpy (clr, >kui_listview_cursor_color, sizeof (GdkColor)); } -int -draw_get_listview_rowheight (void) { - PangoFontDescription *font_desc = font_style->font_desc; - PangoFontMetrics *metrics = pango_context_get_metrics (pangoctx, - font_desc, - pango_context_get_language (pangoctx)); - int row_height = (pango_font_metrics_get_ascent (metrics) + - pango_font_metrics_get_descent (metrics)); - pango_font_metrics_unref (metrics); - return PANGO_PIXELS(row_height)+6; -} - -- cgit v1.2.3