summaryrefslogtreecommitdiff
path: root/libcaja-private/caja-icon-canvas-item.c
diff options
context:
space:
mode:
authorJasmine Hassan <[email protected]>2012-10-18 14:47:33 +0200
committerJasmine Hassan <[email protected]>2012-11-14 09:42:33 +0200
commitd51a2a8235d5d6dc380e0482d2fdddeb60b29dc1 (patch)
treec174774e2fd7dc6dea396a0a98ce8cb22210c39b /libcaja-private/caja-icon-canvas-item.c
parentfada3fccfa2e72360fc932a9d58a01268bff0fea (diff)
downloadcaja-d51a2a8235d5d6dc380e0482d2fdddeb60b29dc1.tar.bz2
caja-d51a2a8235d5d6dc380e0482d2fdddeb60b29dc1.tar.xz
[lc-p] port CajaIconCanvasItem to cairo drawing
http://git.gnome.org/browse/nautilus/commit/?id=89bd44de6bb11450b88d9d160593b65d62467579
Diffstat (limited to 'libcaja-private/caja-icon-canvas-item.c')
-rw-r--r--libcaja-private/caja-icon-canvas-item.c181
1 files changed, 77 insertions, 104 deletions
diff --git a/libcaja-private/caja-icon-canvas-item.c b/libcaja-private/caja-icon-canvas-item.c
index db0b5280..cfb16105 100644
--- a/libcaja-private/caja-icon-canvas-item.c
+++ b/libcaja-private/caja-icon-canvas-item.c
@@ -243,8 +243,7 @@ static void draw_label_layout (CajaIconCanvasItem
gboolean highlight,
GdkColor *label_color,
int x,
- int y,
- GdkGC *gc);
+ int y);
static gboolean hit_test_stretch_handle (CajaIconCanvasItem *item,
EelIRect canvas_rect,
GtkCornerType *corner);
@@ -548,7 +547,6 @@ caja_icon_canvas_item_get_image (CajaIconCanvasItem *item,
GdkPixmap *pixmap;
EelCanvas *canvas;
GdkScreen *screen;
- GdkGC *gc;
int width, height;
int item_offset_x, item_offset_y;
EelIRect icon_rect;
@@ -618,34 +616,21 @@ caja_icon_canvas_item_get_image (CajaIconCanvasItem *item,
GDK_INTERP_BILINEAR, 255);
}
- /* clear the pixmap */
+ /* draw pixbuf to mask and pixmap */
cr = gdk_cairo_create (pixmap);
- cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
+ cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
+ gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
cairo_paint (cr);
cairo_destroy (cr);
- gc = gdk_gc_new (pixmap);
- gdk_draw_pixbuf (pixmap, gc, pixbuf,
- 0, 0, 0, 0,
- gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf),
- GDK_RGB_DITHER_NORMAL,
- 0, 0);
- g_object_unref (gc);
-
*mask = gdk_pixmap_new (gdk_screen_get_root_window (screen),
width, height,
1);
- gc = gdk_gc_new (*mask);
- gdk_draw_rectangle (*mask, gc,
- TRUE,
- 0, 0,
- width, height);
- g_object_unref (gc);
-
- gdk_pixbuf_render_threshold_alpha (pixbuf, *mask,
- 0, 0, 0, 0,
- gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf),
- 128);
+ cr = gdk_cairo_create (*mask);
+ cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
+ gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
+ cairo_paint (cr);
+ cairo_destroy (cr);
draw_embedded_text (item, GDK_DRAWABLE (pixmap),
item_offset_x, item_offset_y);
@@ -1389,7 +1374,6 @@ draw_label_text (CajaIconCanvasItem *item,
PangoLayout *editable_layout;
PangoLayout *additional_layout;
GdkColor *label_color;
- GdkGC *gc;
gboolean have_editable, have_additional;
gboolean needs_frame, needs_highlight, prelight_label, is_rtl_label_beside;
EelIRect text_rect;
@@ -1400,8 +1384,6 @@ draw_label_text (CajaIconCanvasItem *item,
return;
#endif
- gc = NULL;
-
canvas_item = EEL_CANVAS_ITEM (item);
details = item->details;
@@ -1497,7 +1479,7 @@ draw_label_text (CajaIconCanvasItem *item,
}
}
- gc = caja_icon_container_get_label_color_and_gc
+ caja_icon_container_get_label_color
(CAJA_ICON_CONTAINER (canvas_item->canvas),
&label_color, TRUE, needs_highlight,
prelight_label & item->details->is_prelit);
@@ -1506,7 +1488,7 @@ draw_label_text (CajaIconCanvasItem *item,
editable_layout, needs_highlight,
label_color,
x,
- text_rect.y0 + TEXT_BACK_PADDING_Y, gc);
+ text_rect.y0 + TEXT_BACK_PADDING_Y);
}
if (have_additional)
@@ -1514,7 +1496,7 @@ draw_label_text (CajaIconCanvasItem *item,
additional_layout = get_label_layout (&item->details->additional_text_layout, item, item->details->additional_text);
prepare_pango_layout_for_draw (item, additional_layout);
- gc = caja_icon_container_get_label_color_and_gc
+ caja_icon_container_get_label_color
(CAJA_ICON_CONTAINER (canvas_item->canvas),
&label_color, FALSE, needs_highlight,
FALSE);
@@ -1523,7 +1505,7 @@ draw_label_text (CajaIconCanvasItem *item,
additional_layout, needs_highlight,
label_color,
x,
- text_rect.y0 + details->editable_text_height + LABEL_LINE_SPACING + TEXT_BACK_PADDING_Y, gc);
+ text_rect.y0 + details->editable_text_height + LABEL_LINE_SPACING + TEXT_BACK_PADDING_Y);
}
if (!create_mask && item->details->is_highlighted_as_keyboard_focus)
@@ -1615,11 +1597,10 @@ draw_stretch_handles (CajaIconCanvasItem *item, GdkDrawable *drawable,
const EelIRect *rect)
{
GtkWidget *widget;
- GdkGC *gc;
GdkPixbuf *knob_pixbuf;
- GdkBitmap *stipple;
int knob_width, knob_height;
- GtkStyle *style;
+ double dash[2] = { 1.0, 1.0 };
+ cairo_t *cr;
if (!item->details->show_stretch_handles)
{
@@ -1627,44 +1608,41 @@ draw_stretch_handles (CajaIconCanvasItem *item, GdkDrawable *drawable,
}
widget = GTK_WIDGET (EEL_CANVAS_ITEM (item)->canvas);
- style = gtk_widget_get_style (widget);
- gc = gdk_gc_new (drawable);
+ cr = gdk_cairo_create (drawable);
knob_pixbuf = get_knob_pixbuf ();
knob_width = gdk_pixbuf_get_width (knob_pixbuf);
knob_height = gdk_pixbuf_get_height (knob_pixbuf);
- stipple = eel_stipple_bitmap_for_screen (
- gdk_drawable_get_screen (GDK_DRAWABLE (drawable)));
-
/* first draw the box */
- gdk_gc_set_rgb_fg_color (gc, &style->white);
- gdk_draw_rectangle
- (drawable, gc, FALSE,
- rect->x0,
- rect->y0,
- rect->x1 - rect->x0 - 1,
- rect->y1 - rect->y0 - 1);
-
- gdk_gc_set_rgb_fg_color (gc, &style->black);
- gdk_gc_set_stipple (gc, stipple);
- gdk_gc_set_fill (gc, GDK_STIPPLED);
- gdk_draw_rectangle
- (drawable, gc, FALSE,
- rect->x0,
- rect->y0,
- rect->x1 - rect->x0 - 1,
- rect->y1 - rect->y0 - 1);
+ cairo_set_source_rgb (cr, 1, 1, 1);
+ cairo_set_line_width (cr, 1.0);
+ cairo_rectangle (cr,
+ rect->x0 + 0.5,
+ rect->y0 + 0.5,
+ rect->x1 - rect->x0 - 1,
+ rect->y1 - rect->y0 - 1);
+ cairo_stroke (cr);
+
+ cairo_set_source_rgb (cr, 0, 0, 0);
+ cairo_set_dash (cr, dash, G_N_ELEMENTS (dash), 0);
+ cairo_rectangle (cr,
+ rect->x0 + 0.5,
+ rect->y0 + 0.5,
+ rect->x1 - rect->x0 - 1,
+ rect->y1 - rect->y0 - 1);
+ cairo_stroke (cr);
/* draw the stretch handles themselves */
- draw_pixbuf (knob_pixbuf, drawable, rect->x0, rect->y0);
- draw_pixbuf (knob_pixbuf, drawable, rect->x0, rect->y1 - knob_height);
- draw_pixbuf (knob_pixbuf, drawable, rect->x1 - knob_width, rect->y0);
- draw_pixbuf (knob_pixbuf, drawable, rect->x1 - knob_width, rect->y1 - knob_height);
- g_object_unref (knob_pixbuf);
+ gdk_cairo_set_source_pixbuf (cr, knob_pixbuf, rect->x0, rect->y0);
+ cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_REPEAT);
+ cairo_rectangle (cr,
+ rect->x1 - knob_width, rect->y1 - knob_height,
+ 2 * knob_width, 2 * knob_height);
+ cairo_fill (cr);
- g_object_unref (gc);
+ cairo_destroy (cr);
}
static void
@@ -1827,13 +1805,12 @@ emblem_layout_next (EmblemLayout *layout,
static void
draw_pixbuf (GdkPixbuf *pixbuf, GdkDrawable *drawable, int x, int y)
{
- /* FIXME bugzilla.gnome.org 40703:
- * Dither would be better if we passed dither values.
- */
- gdk_draw_pixbuf (drawable, NULL, pixbuf, 0, 0, x, y,
- gdk_pixbuf_get_width (pixbuf),
- gdk_pixbuf_get_height (pixbuf),
- GDK_RGB_DITHER_NORMAL, 0, 0);
+ cairo_t *cr = gdk_cairo_create (drawable);
+
+ gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
+ cairo_paint (cr);
+
+ cairo_destroy (cr);
}
/* shared code to highlight or dim the passed-in pixbuf */
@@ -2003,11 +1980,10 @@ draw_embedded_text (CajaIconCanvasItem *item,
GdkDrawable *drawable,
int x, int y)
{
- GdkGC *gc;
- GdkRectangle clip_rect;
PangoLayout *layout;
PangoContext *context;
PangoFontDescription *desc;
+ cairo_t *cr;
if (item->details->embedded_text == NULL ||
item->details->embedded_text_rect.width == 0 ||
@@ -2036,22 +2012,22 @@ draw_embedded_text (CajaIconCanvasItem *item,
}
}
- gc = gdk_gc_new (drawable);
-
- clip_rect.x = x + item->details->embedded_text_rect.x;
- clip_rect.y = y + item->details->embedded_text_rect.y;
- clip_rect.width = item->details->embedded_text_rect.width;
- clip_rect.height = item->details->embedded_text_rect.height;
-
- gdk_gc_set_clip_rectangle (gc, &clip_rect);
+ cr = gdk_cairo_create (drawable);
- gdk_draw_layout (drawable, gc,
+ cairo_rectangle (cr,
x + item->details->embedded_text_rect.x,
y + item->details->embedded_text_rect.y,
- layout);
+ item->details->embedded_text_rect.width,
+ item->details->embedded_text_rect.height);
+ cairo_clip (cr);
- g_object_unref (gc);
- g_object_unref (layout);
+ cairo_set_source_rgb (cr, 0, 0, 0);
+ cairo_move_to (cr,
+ x + item->details->embedded_text_rect.x,
+ y + item->details->embedded_text_rect.y);
+ pango_cairo_show_layout (cr, layout);
+
+ cairo_destroy (cr);
}
/* Draw the icon item for non-anti-aliased mode. */
@@ -2064,8 +2040,9 @@ caja_icon_canvas_item_draw (EelCanvasItem *item, GdkDrawable *drawable,
EelIRect icon_rect, emblem_rect;
EmblemLayout emblem_layout;
GdkPixbuf *emblem_pixbuf, *temp_pixbuf;
- GdkRectangle draw_rect, pixbuf_rect;
+ GdkRectangle pixbuf_rect;
gboolean is_rtl;
+ cairo_t *cr;
icon_item = CAJA_ICON_CANVAS_ITEM (item);
details = icon_item->details;
@@ -2085,20 +2062,14 @@ caja_icon_canvas_item_draw (EelCanvasItem *item, GdkDrawable *drawable,
pixbuf_rect.y = icon_rect.y0;
pixbuf_rect.width = gdk_pixbuf_get_width (temp_pixbuf);
pixbuf_rect.height = gdk_pixbuf_get_height (temp_pixbuf);
- if (gdk_rectangle_intersect (&(expose->area), &pixbuf_rect, &draw_rect))
- {
- gdk_draw_pixbuf (drawable,
- NULL,
- temp_pixbuf,
- draw_rect.x - pixbuf_rect.x,
- draw_rect.y - pixbuf_rect.y,
- draw_rect.x,
- draw_rect.y,
- draw_rect.width,
- draw_rect.height,
- GDK_RGB_DITHER_NORMAL,
- 0,0);
- }
+
+ cr = gdk_cairo_create (drawable);
+ gdk_cairo_rectangle (cr, &expose->area);
+ cairo_clip (cr);
+ gdk_cairo_set_source_pixbuf (cr, temp_pixbuf, pixbuf_rect.x, pixbuf_rect.y);
+ gdk_cairo_rectangle (cr, &pixbuf_rect);
+ cairo_fill (cr);
+ cairo_destroy (cr);
g_object_unref (temp_pixbuf);
draw_embedded_text (icon_item, drawable, icon_rect.x0, icon_rect.y0);
@@ -2239,8 +2210,7 @@ draw_label_layout (CajaIconCanvasItem *item,
gboolean highlight,
GdkColor *label_color,
int x,
- int y,
- GdkGC *gc)
+ int y)
{
if (drawable == NULL)
{
@@ -2255,7 +2225,7 @@ draw_label_layout (CajaIconCanvasItem *item,
if (!highlight && (CAJA_ICON_CONTAINER (EEL_CANVAS_ITEM (item)->canvas)->details->use_drop_shadows))
{
/* draw a drop shadow */
- eel_gdk_draw_layout_with_drop_shadow (drawable, gc,
+ eel_gdk_draw_layout_with_drop_shadow (drawable,
label_color,
&gtk_widget_get_style (GTK_WIDGET (EEL_CANVAS_ITEM (item)->canvas))->black,
x, y,
@@ -2263,9 +2233,12 @@ draw_label_layout (CajaIconCanvasItem *item,
}
else
{
- gdk_draw_layout (drawable, gc,
- x, y,
- layout);
+ cairo_t *cr = gdk_cairo_create (drawable);
+
+ gdk_cairo_set_source_color (cr, label_color);
+ cairo_move_to (cr, x, y);
+ pango_cairo_show_layout (cr, layout);
+ cairo_destroy (cr);
}
}