static gboolean
fade_and_request_redraw (GtkWidget     *canvas,
                         GdkFrameClock *frame_clock,
                         gpointer       user_data)
{
    NautilusSelectionCanvasItem *self = user_data;
    gint64 frame_time;
    gdouble percentage;

    frame_time = gdk_frame_clock_get_frame_time (frame_clock);
    if (frame_time >= self->priv->fade_out_end_time)
    {
        self->priv->fade_out_tick_id = 0;
        eel_canvas_item_destroy (EEL_CANVAS_ITEM (self));

        return G_SOURCE_REMOVE;
    }

    percentage = 1.0 - (gdouble) (frame_time - self->priv->fade_out_start_time) /
                 (gdouble) (self->priv->fade_out_end_time - self->priv->fade_out_start_time);

    self->priv->fade_out_fill_alpha = self->priv->fill_color.alpha * percentage;
    self->priv->fade_out_outline_alpha = self->priv->outline_color.alpha * percentage;

    eel_canvas_item_request_redraw (EEL_CANVAS_ITEM (self));

    return G_SOURCE_CONTINUE;
}
Example #2
0
static void
drag_begin_callback (GtkWidget      *widget,
		     GdkDragContext *context,
		     gpointer        data)
{
	NemoIconContainer *container;
	cairo_surface_t *surface;
	double x1, y1, x2, y2, winx, winy;
	int x_offset, y_offset;
	int start_x, start_y;

	container = NEMO_ICON_CONTAINER (widget);

	start_x = container->details->dnd_info->drag_info.start_x +
		gtk_adjustment_get_value (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container)));
	start_y = container->details->dnd_info->drag_info.start_y +
		gtk_adjustment_get_value (gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (container)));

        /* create a pixmap and mask to drag with */
        surface = nemo_icon_canvas_item_get_drag_surface (container->details->drag_icon->item);

        /* compute the image's offset */
	eel_canvas_item_get_bounds (EEL_CANVAS_ITEM (container->details->drag_icon->item),
				    &x1, &y1, &x2, &y2);
	eel_canvas_world_to_window (EEL_CANVAS (container), 
				    x1, y1,  &winx, &winy);
        x_offset = start_x - winx;
        y_offset = start_y - winy;

        cairo_surface_set_device_offset (surface, -x_offset, -y_offset);
        gtk_drag_set_icon_surface (context, surface);
        cairo_surface_destroy (surface);
}
static void
do_set_outline (NautilusSelectionCanvasItem *self,
		gboolean outline_set)
{
	if (self->priv->outline_set != outline_set) {
		self->priv->outline_set = outline_set;
		eel_canvas_item_request_update (EEL_CANVAS_ITEM (self));
	}
}
static void
do_set_fill (NautilusSelectionCanvasItem *self,
	     gboolean fill_set)
{
	if (self->priv->fill_set != fill_set) {
		self->priv->fill_set = fill_set;
		eel_canvas_item_request_update (EEL_CANVAS_ITEM (self));
	}
}
static gboolean
fade_and_request_redraw (gpointer user_data)
{
	NautilusSelectionCanvasItem *self = user_data;

	if (self->priv->fade_out_fill_alpha <= 0 ||
	    self->priv->fade_out_outline_alpha <= 0) {
		self->priv->fade_out_handler_id = 0;
		eel_canvas_item_destroy (EEL_CANVAS_ITEM (self));

		return FALSE;
	}

	self->priv->fade_out_fill_alpha -= self->priv->fade_out_fill_delta;
	self->priv->fade_out_outline_alpha -= self->priv->fade_out_outline_delta;

	eel_canvas_item_request_redraw (EEL_CANVAS_ITEM (self));

	return TRUE;
}
static void
nautilus_selection_canvas_item_dispose (GObject *obj)
{
    NautilusSelectionCanvasItem *self = NAUTILUS_SELECTION_CANVAS_ITEM (obj);

    if (self->priv->fade_out_tick_id != 0)
    {
        gtk_widget_remove_tick_callback (GTK_WIDGET (EEL_CANVAS_ITEM (self)->canvas), self->priv->fade_out_tick_id);
        self->priv->fade_out_tick_id = 0;
    }

    G_OBJECT_CLASS (nautilus_selection_canvas_item_parent_class)->dispose (obj);
}
void
nautilus_selection_canvas_item_fade_out (NautilusSelectionCanvasItem *self,
                                         guint                        transition_time)
{
    EelCanvasItem *item = EEL_CANVAS_ITEM (self);
    GtkWidget *widget;
    GdkFrameClock *clock;

    self->priv->fade_out_fill_alpha = self->priv->fill_color.alpha;
    self->priv->fade_out_outline_alpha = self->priv->outline_color.alpha;

    widget = GTK_WIDGET (item->canvas);
    clock = gtk_widget_get_frame_clock (widget);
    self->priv->fade_out_start_time = gdk_frame_clock_get_frame_time (clock);
    self->priv->fade_out_end_time = self->priv->fade_out_start_time + 1000 * transition_time;

    self->priv->fade_out_tick_id =
        gtk_widget_add_tick_callback (GTK_WIDGET (item->canvas), fade_and_request_redraw, self, NULL);
}
Example #8
0
static EelCanvasItem *
create_selection_shadow (NemoIconContainer *container,
			 GList *list)
{
	EelCanvasGroup *group;
	EelCanvas *canvas;
	int max_x, max_y;
	int min_x, min_y;
	GList *p;
	GtkAllocation allocation;

	if (list == NULL) {
		return NULL;
	}

	/* if we're only dragging a single item, don't worry about the shadow */
	if (list->next == NULL) {
		return NULL;
	}
		
	canvas = EEL_CANVAS (container);
	gtk_widget_get_allocation (GTK_WIDGET (container), &allocation);

	/* Creating a big set of rectangles in the canvas can be expensive, so
           we try to be smart and only create the maximum number of rectangles
           that we will need, in the vertical/horizontal directions.  */

	max_x = allocation.width;
	min_x = -max_x;

	max_y = allocation.height;
	min_y = -max_y;

	/* Create a group, so that it's easier to move all the items around at
           once.  */
	group = EEL_CANVAS_GROUP
		(eel_canvas_item_new (EEL_CANVAS_GROUP (canvas->root),
					eel_canvas_group_get_type (),
					NULL));
	
	for (p = list; p != NULL; p = p->next) {
		NemoDragSelectionItem *item;
		int x1, y1, x2, y2;
		GdkRGBA black = { 0, 0, 0, 1 };

		item = p->data;

		if (!item->got_icon_position) {
			continue;
		}

		x1 = item->icon_x;
		y1 = item->icon_y;
		x2 = x1 + item->icon_width;
		y2 = y1 + item->icon_height;
			
		if (x2 >= min_x && x1 <= max_x && y2 >= min_y && y1 <= max_y)
			eel_canvas_item_new
				(group,
				 NEMO_TYPE_SELECTION_CANVAS_ITEM,
				 "x1", (double) x1,
				 "y1", (double) y1,
				 "x2", (double) x2,
				 "y2", (double) y2,
				 "outline-color-rgba", &black,
				 "outline-stippling", TRUE,
				 "width_pixels", 1,
				 NULL);
	}

	return EEL_CANVAS_ITEM (group);
}
static void
nautilus_selection_canvas_item_set_property (GObject *object,
					     guint param_id,
					     const GValue *value,
					     GParamSpec *pspec)
{
	EelCanvasItem *item;
	NautilusSelectionCanvasItem *self;

	self = NAUTILUS_SELECTION_CANVAS_ITEM (object);
	item = EEL_CANVAS_ITEM (object);

	switch (param_id) {
	case PROP_X1:
		self->priv->x1 = g_value_get_double (value);

		eel_canvas_item_request_update (item);
		break;

	case PROP_Y1:
		self->priv->y1 = g_value_get_double (value);

		eel_canvas_item_request_update (item);
		break;

	case PROP_X2:
		self->priv->x2 = g_value_get_double (value);

		eel_canvas_item_request_update (item);
		break;

	case PROP_Y2:
		self->priv->y2 = g_value_get_double (value);

		eel_canvas_item_request_update (item);
		break;

	case PROP_FILL_COLOR_RGBA: {
		GdkRGBA *color;

		color = g_value_get_boxed (value);

		do_set_fill (self, color != NULL);

		if (color != NULL) {
			self->priv->fill_color = *color;
		}

		eel_canvas_item_request_redraw (item);		
		break;
	}

	case PROP_OUTLINE_COLOR_RGBA: {
		GdkRGBA *color;

		color = g_value_get_boxed (value);

		do_set_outline (self, color != NULL);

		if (color != NULL) {
			self->priv->outline_color = *color;
		}

		eel_canvas_item_request_redraw (item);		
		break;
	}

	case PROP_OUTLINE_STIPPLING:
		self->priv->outline_stippling = g_value_get_boolean (value);

		eel_canvas_item_request_redraw (item);
		break;

	case PROP_WIDTH_PIXELS:
		self->priv->width = g_value_get_uint (value);

		eel_canvas_item_request_update (item);
		break;

	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
		break;
	}
}