summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/gtkui/ddblistview.c39
-rw-r--r--plugins/gtkui/ddblistview.h5
-rw-r--r--plugins/gtkui/ddbtabstrip.c36
-rw-r--r--plugins/gtkui/ddbtabstrip.h2
-rw-r--r--plugins/gtkui/drawing.h44
-rw-r--r--plugins/gtkui/gdkdrawing.c179
-rw-r--r--plugins/gtkui/gtkui.c2
-rw-r--r--plugins/gtkui/mainplaylist.c10
-rw-r--r--plugins/gtkui/plcommon.c12
9 files changed, 172 insertions, 157 deletions
diff --git a/plugins/gtkui/ddblistview.c b/plugins/gtkui/ddblistview.c
index 6312a103..66be0fcc 100644
--- a/plugins/gtkui/ddblistview.c
+++ b/plugins/gtkui/ddblistview.c
@@ -288,9 +288,9 @@ static void
ddb_listview_init(DdbListview *listview)
{
// init instance - create all subwidgets, and insert into table
- draw_init_font (gtk_widget_get_style (GTK_WIDGET(listview)));
-
- listview->rowheight = draw_get_listview_rowheight ();
+ drawctx_init (&listview->listctx);
+ drawctx_init (&listview->hdrctx);
+ listview->rowheight = -1;
listview->col_movepos = -1;
listview->drag_motion_y = -1;
@@ -355,7 +355,6 @@ ddb_listview_init(DdbListview *listview)
listview->header = gtk_drawing_area_new ();
gtk_widget_show (listview->header);
gtk_box_pack_start (GTK_BOX (vbox), listview->header, FALSE, TRUE, 0);
- gtk_widget_set_size_request (listview->header, -1, draw_get_listview_rowheight ());
gtk_widget_set_events (listview->header, GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
listview->list = gtk_drawing_area_new ();
@@ -490,6 +489,8 @@ ddb_listview_destroy(GObject *object)
gdk_cursor_unref (listview->cursor_drag);
listview->cursor_drag = NULL;
}
+ draw_free (&listview->listctx);
+ draw_free (&listview->hdrctx);
}
void
@@ -533,8 +534,8 @@ ddb_listview_list_configure_event (GtkWidget *widget,
{
DdbListview *ps = DDB_LISTVIEW (g_object_get_data (G_OBJECT (widget), "owner"));
- draw_init_font (gtk_widget_get_style (widget));
- int height = draw_get_listview_rowheight ();
+ draw_init_font (&ps->listctx, gtk_widget_get_style (widget));
+ int height = draw_get_listview_rowheight (&ps->listctx);
if (height != ps->rowheight) {
ps->rowheight = height;
ddb_listview_build_groups (ps);
@@ -643,7 +644,7 @@ ddb_listview_list_render (DdbListview *listview, cairo_t *cr, int x, int y, int
grp = grp->next;
}
- draw_begin (cr);
+ draw_begin (&listview->listctx, cr);
int ii = 0;
while (grp && grp_y < y + h + listview->scrollpos) {
@@ -735,7 +736,7 @@ ddb_listview_list_render (DdbListview *listview, cairo_t *cr, int x, int y, int
}
}
deadbeef->pl_unlock ();
- draw_end ();
+ draw_end (&listview->listctx);
}
static void
@@ -1310,12 +1311,12 @@ ddb_listview_list_render_row_foreground (DdbListview *ps, cairo_t *cr, DdbListvi
if (it && ps->binding->is_selected (it)) {
GdkColor *clr = &gtk_widget_get_style (theme_treeview)->fg[GTK_STATE_SELECTED];
float rgb[3] = { clr->red/65535.f, clr->green/65535.f, clr->blue/65535.f };
- draw_set_fg_color (rgb);
+ draw_set_fg_color (&ps->listctx, rgb);
}
else {
GdkColor *clr = &gtk_widget_get_style (theme_treeview)->fg[GTK_STATE_NORMAL];
float rgb[3] = { clr->red/65535.f, clr->green/65535.f, clr->blue/65535.f };
- draw_set_fg_color (rgb);
+ draw_set_fg_color (&ps->listctx, rgb);
}
DdbListviewColumn *c;
int cidx = 0;
@@ -2158,7 +2159,7 @@ ddb_listview_header_render (DdbListview *ps, cairo_t *cr) {
cairo_line_to (cr, a.width, a.height-1);
cairo_stroke (cr);
#endif
- draw_begin (cr);
+ draw_begin (&ps->hdrctx, cr);
x = -ps->hscrollpos;
DdbListviewColumn *c;
int need_draw_moving = 0;
@@ -2205,7 +2206,7 @@ ddb_listview_header_render (DdbListview *ps, cairo_t *cr) {
#endif
GdkColor *gdkfg = &gtk_widget_get_style (theme_button)->fg[0];
float fg[3] = {(float)gdkfg->red/0xffff, (float)gdkfg->green/0xffff, (float)gdkfg->blue/0xffff};
- draw_set_fg_color (fg);
+ draw_set_fg_color (&ps->hdrctx, fg);
int ww = w-10;
if (sort) {
ww -= arrow_sz;
@@ -2213,7 +2214,7 @@ ddb_listview_header_render (DdbListview *ps, cairo_t *cr) {
ww = 0;
}
}
- draw_text (xx + 5, 3, ww, 0, c->title);
+ draw_text (&ps->hdrctx, xx + 5, 3, ww, 0, c->title);
}
if (sort) {
int dir = sort == 1 ? GTK_ARROW_DOWN : GTK_ARROW_UP;
@@ -2265,15 +2266,15 @@ ddb_listview_header_render (DdbListview *ps, cairo_t *cr) {
#endif
GdkColor *gdkfg = &gtk_widget_get_style (theme_button)->fg[GTK_STATE_SELECTED];
float fg[3] = {(float)gdkfg->red/0xffff, (float)gdkfg->green/0xffff, (float)gdkfg->blue/0xffff};
- draw_set_fg_color (fg);
- draw_text (x + 5, 3, c->width-10, 0, c->title);
+ draw_set_fg_color (&ps->hdrctx, fg);
+ draw_text (&ps->hdrctx, x + 5, 3, c->width-10, 0, c->title);
}
break;
}
x += w;
}
}
- draw_end ();
+ draw_end (&ps->hdrctx);
}
gboolean
@@ -2312,8 +2313,8 @@ ddb_listview_header_configure_event (GtkWidget *widget,
gpointer user_data)
{
DdbListview *ps = DDB_LISTVIEW (g_object_get_data (G_OBJECT (widget), "owner"));
- draw_init_font (gtk_widget_get_style (widget));
- int height = draw_get_listview_rowheight ();
+ draw_init_font (&ps->hdrctx, gtk_widget_get_style (widget));
+ int height = draw_get_listview_rowheight (&ps->hdrctx);
GtkAllocation a;
gtk_widget_get_allocation (widget, &a);
if (height != a.height) {
@@ -2342,7 +2343,7 @@ ddb_listview_header_realize (GtkWidget *widget,
{
// create cursor for sizing headers
DdbListview *listview = DDB_LISTVIEW (g_object_get_data (G_OBJECT (widget), "owner"));
- int h = draw_get_font_size ();
+ int h = draw_get_font_size (&listview->hdrctx);
gtk_widget_set_size_request (widget, -1, h + 10);
listview->cursor_sz = gdk_cursor_new (GDK_SB_H_DOUBLE_ARROW);
listview->cursor_drag = gdk_cursor_new (GDK_FLEUR);
diff --git a/plugins/gtkui/ddblistview.h b/plugins/gtkui/ddblistview.h
index d03cd240..b2855000 100644
--- a/plugins/gtkui/ddblistview.h
+++ b/plugins/gtkui/ddblistview.h
@@ -21,6 +21,7 @@
#include <gtk/gtk.h>
#include <sys/time.h>
#include <stdint.h>
+#include "drawing.h"
// drag and drop targets
enum {
@@ -153,6 +154,10 @@ struct _DdbListview {
GdkCursor *cursor_sz;
GdkCursor *cursor_drag;
+
+ // drawing contexts
+ drawctx_t listctx;
+ drawctx_t hdrctx;
};
struct _DdbListviewClass {
diff --git a/plugins/gtkui/ddbtabstrip.c b/plugins/gtkui/ddbtabstrip.c
index ab8fad1e..26a05c39 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,7 @@ ddb_tabstrip_init(DdbTabStrip *tabstrip)
tabstrip->dragpt[1] = 0;
tabstrip->prev_x = 0;
tabstrip->movepos = 0;
+ drawctx_init (&tabstrip->drawctx);
}
static int tab_clicked = -1;
@@ -436,7 +438,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 +534,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 +547,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 +555,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 ();
}
@@ -578,7 +580,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;
@@ -604,7 +606,7 @@ tabstrip_render (DdbTabStrip *ts, cairo_t *cr) {
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 +614,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;
@@ -633,8 +635,8 @@ tabstrip_render (DdbTabStrip *ts, cairo_t *cr) {
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;
}
@@ -666,8 +668,8 @@ tabstrip_render (DdbTabStrip *ts, cairo_t *cr) {
ddb_tabstrip_draw_tab (widget, cr, idx, 1, x, y, w, h);
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;
@@ -685,8 +687,8 @@ tabstrip_render (DdbTabStrip *ts, cairo_t *cr) {
ddb_tabstrip_draw_tab (widget, cr, idx, 1, x, y, w, h);
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;
}
@@ -714,7 +716,7 @@ tabstrip_render (DdbTabStrip *ts, cairo_t *cr) {
#endif
}
- draw_end ();
+ draw_end (&ts->drawctx);
}
static int
@@ -733,7 +735,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;
@@ -1155,10 +1157,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) {
diff --git a/plugins/gtkui/ddbtabstrip.h b/plugins/gtkui/ddbtabstrip.h
index a34eb5eb..f5f95599 100644
--- a/plugins/gtkui/ddbtabstrip.h
+++ b/plugins/gtkui/ddbtabstrip.h
@@ -20,6 +20,7 @@
#define __DDBTABSTRIP_H
#include <gtk/gtk.h>
+#include "drawing.h"
G_BEGIN_DECLS
@@ -46,6 +47,7 @@ struct _DdbTabStrip {
int movepos;
guint scroll_timer;
int scroll_direction;
+ drawctx_t drawctx;
};
struct _DdbTabStripClass {
diff --git a/plugins/gtkui/drawing.h b/plugins/gtkui/drawing.h
index 6d573346..0a7fd17f 100644
--- a/plugins/gtkui/drawing.h
+++ b/plugins/gtkui/drawing.h
@@ -21,50 +21,63 @@
#include <stdint.h>
+typedef struct {
+ cairo_t *drawable;
+ GdkColor clrfg;
+ GdkColor clrbg;
+ int pango_ready;
+ PangoContext *pangoctx;
+ PangoLayout *pangolayout;
+ GtkStyle *font_style;
+ PangoWeight font_weight;
+} drawctx_t;
+
// abstract api for drawing primitives
void
-draw_init (void);
+drawctx_init (drawctx_t *ctx);
void
-draw_free (void);
+draw_begin (drawctx_t *ctx, cairo_t *cr);
void
-draw_begin (cairo_t *cr);
+draw_end (drawctx_t *ctx);
void
-draw_end (void);
+draw_free (drawctx_t *ctx);
void
-draw_set_fg_color (float *rgb);
+draw_set_fg_color (drawctx_t *ctx, float *rgb);
void
-draw_line (float x1, float y1, float x2, float y2);
+draw_line (drawctx_t *ctx, float x1, float y1, float x2, float y2);
void
-draw_rect (float x, float y, float w, float h, int fill);
+draw_rect (drawctx_t *ctx, float x, float y, float w, float h, int fill);
float
-draw_get_font_size (void);
+draw_get_font_size (drawctx_t *ctx);
void
-draw_init_font (GtkStyle *style);
+draw_init_font (drawctx_t *ctx, GtkStyle *style);
void
-draw_init_font_bold (void);
+draw_init_font_bold (drawctx_t *ctx);
void
-draw_init_font_normal (void);
+draw_init_font_normal (drawctx_t *ctx);
void
-draw_text (float x, float y, int width, int align, const char *text);
+draw_text (drawctx_t *ctx, float x, float y, int width, int align, const char *text);
void
-draw_text_with_colors (float x, float y, int width, int align, const char *text);
+draw_text_with_colors (drawctx_t *ctx, float x, float y, int width, int align, const char *text);
void
-draw_get_text_extents (const char *text, int len, int *w, int *h);
+draw_get_text_extents (drawctx_t *ctx, const char *text, int len, int *w, int *h);
+int
+draw_get_listview_rowheight (drawctx_t *ctx);
void
gtkui_get_bar_foreground_color (GdkColor *clr);
@@ -117,7 +130,4 @@ gtkui_override_bar_colors (void);
int
gtkui_override_tabstrip_colors (void);
-int
-draw_get_listview_rowheight (void);
-
#endif // __DRAWING_H
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, &gtkui_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;
-}
-
diff --git a/plugins/gtkui/gtkui.c b/plugins/gtkui/gtkui.c
index b96eb301..a7ff1e66 100644
--- a/plugins/gtkui/gtkui.c
+++ b/plugins/gtkui/gtkui.c
@@ -1179,7 +1179,7 @@ gtkui_thread (void *ctx) {
trkproperties_destroy ();
progress_destroy ();
gtkui_hide_status_icon ();
- draw_free ();
+// draw_free ();
if (theme_treeview) {
gtk_widget_destroy (theme_treeview);
theme_treeview = NULL;
diff --git a/plugins/gtkui/mainplaylist.c b/plugins/gtkui/mainplaylist.c
index e193d8e3..f056d2f4 100644
--- a/plugins/gtkui/mainplaylist.c
+++ b/plugins/gtkui/mainplaylist.c
@@ -171,18 +171,18 @@ void main_draw_group_title (DdbListview *listview, cairo_t *drawable, DdbListvie
if (theming) {
GdkColor *clr = &gtk_widget_get_style(theme_treeview)->fg[GTK_STATE_NORMAL];
float rgb[] = {clr->red/65535.f, clr->green/65535.f, clr->blue/65535.f};
- draw_set_fg_color (rgb);
+ draw_set_fg_color (&listview->listctx, rgb);
}
else {
GdkColor clr;
gtkui_get_listview_text_color (&clr);
float rgb[] = {clr.red/65535.f, clr.green/65535.f, clr.blue/65535.f};
- draw_set_fg_color (rgb);
+ draw_set_fg_color (&listview->listctx, rgb);
}
int ew, eh;
- draw_get_text_extents (str, -1, &ew, &eh);
- draw_text (x + 5, y + height/2 - draw_get_font_size ()/2 - 2, ew+5, 0, str);
- draw_line (x + 5 + ew + 3, y+height/2, x + width, y+height/2);
+ draw_get_text_extents (&listview->listctx, str, -1, &ew, &eh);
+ draw_text (&listview->listctx, x + 5, y + height/2 - draw_get_font_size (&listview->listctx)/2 - 2, ew+5, 0, str);
+ draw_line (&listview->listctx, x + 5 + ew + 3, y+height/2, x + width, y+height/2);
}
}
void
diff --git a/plugins/gtkui/plcommon.c b/plugins/gtkui/plcommon.c
index 3d747e91..a7b1e21d 100644
--- a/plugins/gtkui/plcommon.c
+++ b/plugins/gtkui/plcommon.c
@@ -190,20 +190,20 @@ void draw_column_data (DdbListview *listview, cairo_t *cr, DdbListviewIter it, D
}
}
float fg[3] = {(float)color->red/0xffff, (float)color->green/0xffff, (float)color->blue/0xffff};
- draw_set_fg_color (fg);
+ draw_set_fg_color (&listview->listctx, fg);
- draw_init_font (gtk_widget_get_style (GTK_WIDGET (listview)));
+ draw_init_font (&listview->listctx, gtk_widget_get_style (GTK_WIDGET (listview)));
if (gtkui_embolden_current_track && it && it == playing_track) {
- draw_init_font_bold ();
+ draw_init_font_bold (&listview->listctx);
}
if (calign_right) {
- draw_text (x+5, y + 3, cwidth-10, 1, text);
+ draw_text (&listview->listctx, x+5, y + 3, cwidth-10, 1, text);
}
else {
- draw_text (x + 5, y + 3, cwidth-10, 0, text);
+ draw_text (&listview->listctx, x + 5, y + 3, cwidth-10, 0, text);
}
if (gtkui_embolden_current_track && it && it == playing_track) {
- draw_init_font_normal ();
+ draw_init_font_normal (&listview->listctx);
}
}
if (playing_track) {