[nautilus] canvas-item: Draw the selected icon surface as the drag surface
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus] canvas-item: Draw the selected icon surface as the drag surface
- Date: Tue, 3 Sep 2013 21:55:24 +0000 (UTC)
commit 9ba38b7feab7d7bca27d61f3a07051f7d228934e
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Wed Aug 7 05:53:38 2013 -0400
canvas-item: Draw the selected icon surface as the drag surface
libnautilus-private/nautilus-canvas-item.c | 139 +++++++++++++---------------
1 files changed, 65 insertions(+), 74 deletions(-)
---
diff --git a/libnautilus-private/nautilus-canvas-item.c b/libnautilus-private/nautilus-canvas-item.c
index 009334b..4fc41a4 100644
--- a/libnautilus-private/nautilus-canvas-item.c
+++ b/libnautilus-private/nautilus-canvas-item.c
@@ -166,10 +166,6 @@ G_DEFINE_TYPE_WITH_CODE (NautilusCanvasItem, nautilus_canvas_item, EEL_TYPE_CANV
nautilus_canvas_item_text_interface_init));
/* private */
-static void draw_label_text (NautilusCanvasItem *item,
- cairo_t *cr,
- EelIRect icon_rect);
-static void measure_label_text (NautilusCanvasItem *item);
static void get_icon_rectangle (NautilusCanvasItem *item,
EelIRect *rect);
static void draw_pixbuf (GdkPixbuf *pixbuf,
@@ -182,10 +178,7 @@ static PangoLayout *get_label_layout (PangoLayout
static gboolean hit_test_stretch_handle (NautilusCanvasItem *item,
EelIRect icon_rect,
GtkCornerType *corner);
-static void draw_embedded_text (NautilusCanvasItem *canvas_item,
- cairo_t *cr,
- int x,
- int y);
+;
static void nautilus_canvas_item_ensure_bounds_up_to_date (NautilusCanvasItem *canvas_item);
@@ -449,72 +442,6 @@ get_scaled_icon_size (NautilusCanvasItem *item,
*height = (pixbuf == NULL) ? 0 : (gdk_pixbuf_get_height (pixbuf) / scale);
}
-cairo_surface_t *
-nautilus_canvas_item_get_drag_surface (NautilusCanvasItem *item)
-{
- cairo_surface_t *surface;
- EelCanvas *canvas;
- int width, height;
- int pix_width, pix_height;
- int item_offset_x, item_offset_y;
- EelIRect icon_rect;
- double item_x, item_y;
- cairo_t *cr;
- GtkStyleContext *context;
- cairo_surface_t *drag_surface;
-
- g_return_val_if_fail (NAUTILUS_IS_CANVAS_ITEM (item), NULL);
-
- canvas = EEL_CANVAS_ITEM (item)->canvas;
- context = gtk_widget_get_style_context (GTK_WIDGET (canvas));
-
- gtk_style_context_save (context);
- gtk_style_context_add_class (context, "nautilus-canvas-item");
-
- /* Assume we're updated so canvas item data is right */
-
- /* Calculate the offset from the top-left corner of the
- new image to the item position (where the pixmap is placed) */
- eel_canvas_world_to_window (canvas,
- item->details->x, item->details->y,
- &item_x, &item_y);
-
- item_offset_x = item_x - EEL_CANVAS_ITEM (item)->x1;
- item_offset_y = item_y - EEL_CANVAS_ITEM (item)->y1;
-
- /* Calculate the width of the item */
- width = EEL_CANVAS_ITEM (item)->x2 - EEL_CANVAS_ITEM (item)->x1;
- height = EEL_CANVAS_ITEM (item)->y2 - EEL_CANVAS_ITEM (item)->y1;
-
- surface = gdk_window_create_similar_surface (gtk_widget_get_window (GTK_WIDGET (canvas)),
- CAIRO_CONTENT_COLOR_ALPHA,
- width, height);
- cr = cairo_create (surface);
-
- drag_surface = gdk_cairo_surface_create_from_pixbuf (item->details->pixbuf,
- gtk_widget_get_scale_factor (GTK_WIDGET
(canvas)),
- gtk_widget_get_window (GTK_WIDGET (canvas)));
- gtk_render_icon_surface (context, cr, drag_surface,
- item_offset_x, item_offset_y);
- cairo_surface_destroy (drag_surface);
-
- get_scaled_icon_size (item, &pix_width, &pix_height);
-
- icon_rect.x0 = item_offset_x;
- icon_rect.y0 = item_offset_y;
- icon_rect.x1 = item_offset_x + pix_width;
- icon_rect.y1 = item_offset_y + pix_height;
-
- draw_embedded_text (item, cr,
- item_offset_x, item_offset_y);
- draw_label_text (item, cr, icon_rect);
- cairo_destroy (cr);
-
- gtk_style_context_restore (context);
-
- return surface;
-}
-
void
nautilus_canvas_item_set_image (NautilusCanvasItem *item,
GdkPixbuf *image)
@@ -1393,6 +1320,70 @@ draw_embedded_text (NautilusCanvasItem *item,
cairo_restore (cr);
}
+cairo_surface_t *
+nautilus_canvas_item_get_drag_surface (NautilusCanvasItem *item)
+{
+ cairo_surface_t *surface;
+ EelCanvas *canvas;
+ int width, height;
+ int pix_width, pix_height;
+ int item_offset_x, item_offset_y;
+ EelIRect icon_rect;
+ double item_x, item_y;
+ cairo_t *cr;
+ GtkStyleContext *context;
+ cairo_surface_t *drag_surface;
+
+ g_return_val_if_fail (NAUTILUS_IS_CANVAS_ITEM (item), NULL);
+
+ canvas = EEL_CANVAS_ITEM (item)->canvas;
+ context = gtk_widget_get_style_context (GTK_WIDGET (canvas));
+
+ gtk_style_context_save (context);
+ gtk_style_context_add_class (context, "nautilus-canvas-item");
+
+ /* Assume we're updated so canvas item data is right */
+
+ /* Calculate the offset from the top-left corner of the
+ new image to the item position (where the pixmap is placed) */
+ eel_canvas_world_to_window (canvas,
+ item->details->x, item->details->y,
+ &item_x, &item_y);
+
+ item_offset_x = item_x - EEL_CANVAS_ITEM (item)->x1;
+ item_offset_y = item_y - EEL_CANVAS_ITEM (item)->y1;
+
+ /* Calculate the width of the item */
+ width = EEL_CANVAS_ITEM (item)->x2 - EEL_CANVAS_ITEM (item)->x1;
+ height = EEL_CANVAS_ITEM (item)->y2 - EEL_CANVAS_ITEM (item)->y1;
+
+ surface = gdk_window_create_similar_surface (gtk_widget_get_window (GTK_WIDGET (canvas)),
+ CAIRO_CONTENT_COLOR_ALPHA,
+ width, height);
+ cr = cairo_create (surface);
+
+ drag_surface = map_surface (item);
+ gtk_render_icon_surface (context, cr, drag_surface,
+ item_offset_x, item_offset_y);
+ cairo_surface_destroy (drag_surface);
+
+ get_scaled_icon_size (item, &pix_width, &pix_height);
+
+ icon_rect.x0 = item_offset_x;
+ icon_rect.y0 = item_offset_y;
+ icon_rect.x1 = item_offset_x + pix_width;
+ icon_rect.y1 = item_offset_y + pix_height;
+
+ draw_embedded_text (item, cr,
+ item_offset_x, item_offset_y);
+ draw_label_text (item, cr, icon_rect);
+ cairo_destroy (cr);
+
+ gtk_style_context_restore (context);
+
+ return surface;
+}
+
/* Draw the canvas item for non-anti-aliased mode. */
static void
nautilus_canvas_item_draw (EelCanvasItem *item,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]