aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDiego Escalante Urrelo <descalante@igalia.com>2010-08-20 14:46:27 +0800
committerDiego Escalante Urrelo <descalante@igalia.com>2010-08-31 04:41:35 +0800
commit1952b09d8479b3daf29c16973d6930f11564c4af (patch)
treee24ab362eb17aeabd01c4b5cea0921ec7d837115
parent6f39ddc6d106337ff49e29870b26ee6690060f78 (diff)
downloadgsoc2013-epiphany-1952b09d8479b3daf29c16973d6930f11564c4af.tar
gsoc2013-epiphany-1952b09d8479b3daf29c16973d6930f11564c4af.tar.gz
gsoc2013-epiphany-1952b09d8479b3daf29c16973d6930f11564c4af.tar.bz2
gsoc2013-epiphany-1952b09d8479b3daf29c16973d6930f11564c4af.tar.lz
gsoc2013-epiphany-1952b09d8479b3daf29c16973d6930f11564c4af.tar.xz
gsoc2013-epiphany-1952b09d8479b3daf29c16973d6930f11564c4af.tar.zst
gsoc2013-epiphany-1952b09d8479b3daf29c16973d6930f11564c4af.zip
lib/widgets: use cairo for drawing widgets
Drop deprecated gdk_* drawing functions. Bug #627450
-rw-r--r--lib/widgets/ephy-location-entry.c82
-rw-r--r--lib/widgets/ephy-spinner.c18
2 files changed, 45 insertions, 55 deletions
diff --git a/lib/widgets/ephy-location-entry.c b/lib/widgets/ephy-location-entry.c
index 1f0381091..237490091 100644
--- a/lib/widgets/ephy-location-entry.c
+++ b/lib/widgets/ephy-location-entry.c
@@ -734,8 +734,8 @@ each_url_get_data_binder (EphyDragEachSelectedItemDataGet iteratee,
g_free (title);
}
-#define DRAG_ICON_LAYOUT_BORDER 2
-#define DRAG_ICON_ICON_SPACING DRAG_ICON_LAYOUT_BORDER * 2
+#define DRAG_ICON_LAYOUT_PADDING 2
+#define DRAG_ICON_ICON_PADDING 4
#define DRAG_ICON_MAX_WIDTH_CHARS 32
static GdkPixmap *
@@ -752,8 +752,12 @@ favicon_create_drag_pixmap (EphyLocationEntry *entry,
PangoFontMetrics *metrics;
int pixmap_height, pixmap_width;
int layout_width, layout_height;
- int icon_width = 0, icon_height = 0, offset_x = 0;
+ int icon_width = 0, icon_height = 0, favicon_offset_x = 0;
int char_width;
+ cairo_t *cr;
+ GtkStateType state;
+
+ state = gtk_widget_get_state (widget);
g_signal_emit (entry, signals[GET_LOCATION], 0, &address);
g_signal_emit (entry, signals[GET_TITLE], 0, &title);
@@ -774,8 +778,6 @@ favicon_create_drag_pixmap (EphyLocationEntry *entry,
g_string_append (text, address);
}
- /* Now build the pixmap */
-
if (priv->favicon != NULL)
{
icon_width = gdk_pixbuf_get_width (priv->favicon);
@@ -785,7 +787,6 @@ favicon_create_drag_pixmap (EphyLocationEntry *entry,
context = gtk_widget_get_pango_context (widget);
layout = pango_layout_new (context);
- context = gtk_widget_get_pango_context (widget);
style = gtk_widget_get_style (widget);
metrics = pango_context_get_metrics (context,
style->font_desc,
@@ -798,64 +799,57 @@ favicon_create_drag_pixmap (EphyLocationEntry *entry,
pango_layout_set_width (layout, char_width * DRAG_ICON_MAX_WIDTH_CHARS);
pango_layout_set_text (layout, text->str, text->len);
- pango_layout_get_size (layout, &layout_width, &layout_height);
-
- pixmap_width = layout_width / PANGO_SCALE + DRAG_ICON_LAYOUT_BORDER * 2;
+ pango_layout_get_pixel_size (layout, &layout_width, &layout_height);
if (priv->favicon != NULL)
{
- offset_x = icon_width + 2 * DRAG_ICON_ICON_SPACING;
- pixmap_width += offset_x;
- pixmap_height = MAX (layout_height / PANGO_SCALE, icon_height) + DRAG_ICON_LAYOUT_BORDER * 2;
- }
- else
- {
- pixmap_height = layout_height / PANGO_SCALE + DRAG_ICON_LAYOUT_BORDER * 2;
+ favicon_offset_x = icon_width + (2 * DRAG_ICON_ICON_PADDING);
}
+ pixmap_width = layout_width + favicon_offset_x +
+ (DRAG_ICON_LAYOUT_PADDING * 2);
+ pixmap_height = MAX (layout_height, icon_height) +
+ (DRAG_ICON_LAYOUT_PADDING * 2);
+
drawable = gdk_pixmap_new (gtk_widget_get_window (widget),
- pixmap_width + 2,
+ pixmap_width + 2,
pixmap_height + 2,
-1);
+ cr = gdk_cairo_create (drawable);
- gdk_draw_rectangle (drawable,
- style->base_gc [gtk_widget_get_state (widget)],
- TRUE,
- 0, 0,
- pixmap_width + 1,
- pixmap_height + 1);
+ cairo_rectangle (cr, 1, 1, pixmap_width, pixmap_height);
+ cairo_set_line_width (cr, 1.0);
+ cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
+ cairo_stroke_preserve (cr);
+
+ gdk_cairo_set_source_color (cr, &style->bg[state]);
+ cairo_fill (cr);
if (priv->favicon != NULL)
{
- gdk_draw_pixbuf (drawable,
- style->fg_gc[gtk_widget_get_state (widget)],
- priv->favicon,
- 0, 0,
- 1 + DRAG_ICON_LAYOUT_BORDER + DRAG_ICON_ICON_SPACING,
- 1 + DRAG_ICON_LAYOUT_BORDER + (pixmap_height - icon_height) / 2,
- -1, -1,
- GDK_RGB_DITHER_NONE, 0, 0);
+ double x;
+ double y;
+
+ x = 1 + DRAG_ICON_LAYOUT_PADDING + DRAG_ICON_ICON_PADDING;
+ y = 1 + DRAG_ICON_LAYOUT_PADDING + (pixmap_height - icon_height) / 2;
+ gdk_cairo_set_source_pixbuf (cr, priv->favicon, x, y);
+ cairo_rectangle (cr, x, y, icon_width, icon_height);
+ cairo_paint (cr);
}
- gdk_draw_layout (drawable,
- style->text_gc [gtk_widget_get_state (widget)],
- 1 + DRAG_ICON_LAYOUT_BORDER + offset_x,
- 1 + DRAG_ICON_LAYOUT_BORDER,
- layout);
-
- gdk_draw_rectangle (drawable,
- style->black_gc,
- FALSE,
- 0, 0,
- pixmap_width + 1,
- pixmap_height + 1);
+ cairo_move_to (cr,
+ 1 + DRAG_ICON_LAYOUT_PADDING + favicon_offset_x,
+ 1 + DRAG_ICON_LAYOUT_PADDING);
+ gdk_cairo_set_source_color (cr, &style->text[state]);
+ pango_cairo_show_layout (cr, layout);
+ cairo_destroy (cr);
g_object_unref (layout);
g_free (address);
g_free (title);
- g_string_free (text,TRUE);
+ g_string_free (text, TRUE);
return drawable;
}
diff --git a/lib/widgets/ephy-spinner.c b/lib/widgets/ephy-spinner.c
index 077249443..cec0deaf4 100644
--- a/lib/widgets/ephy-spinner.c
+++ b/lib/widgets/ephy-spinner.c
@@ -625,8 +625,7 @@ ephy_spinner_expose (GtkWidget *widget,
EphySpinnerImages *images;
GtkAllocation allocation;
GdkPixbuf *pixbuf;
- GdkWindow *window;
- GdkGC *gc;
+ cairo_t *cr;
int x_offset, y_offset, width, height;
GdkRectangle pix_area, dest;
@@ -675,15 +674,12 @@ ephy_spinner_expose (GtkWidget *widget,
return FALSE;
}
- window = gtk_widget_get_window (widget);
- gc = gdk_gc_new (window);
- gdk_draw_pixbuf (window, gc, pixbuf,
- dest.x - x_offset - allocation.x,
- dest.y - y_offset - allocation.y,
- dest.x, dest.y,
- dest.width, dest.height,
- GDK_RGB_DITHER_MAX, 0, 0);
- g_object_unref (gc);
+ cr = gdk_cairo_create (gtk_widget_get_window (widget));
+
+ gdk_cairo_set_source_pixbuf (cr, pixbuf, dest.x, dest.y);
+ cairo_paint (cr);
+
+ cairo_destroy (cr);
return FALSE;
}