Exemple #1
0
/**
 * eel_gdk_pixbuf_new_from_existing_buffer:
 * @buffer: The existing buffer.
 * @buffer_rowstride: The existing buffer's rowstride.
 * @buffer_has_alpha: A boolean value indicating whether the buffer has alpha.
 * @area: The area within the existing buffer to use for the pixbuf.
 *        This area needs to be contained within the bounds of the
 *        buffer, otherwise memory will be trashed.
 *
 * Return value: A newly allocated pixbuf that uses the existing buffer
 *               for its pixel data.
 *
 * Create a pixbuf from an existing buffer.
 *
 * The resulting pixbuf is only valid for as long as &buffer is valid.  It is
 * up to the caller to make sure they both exist in the same scope.
 * Also, it is up to the caller to make sure that the given area is fully
 * contained in the buffer, otherwise memory trashing will happen.
 */
GdkPixbuf *
eel_gdk_pixbuf_new_from_existing_buffer (guchar *buffer,
        int buffer_rowstride,
        gboolean buffer_has_alpha,
        EelIRect area)
{
    GdkPixbuf *pixbuf;
    guchar *pixels;

    g_return_val_if_fail (buffer != NULL, NULL);
    g_return_val_if_fail (buffer_rowstride > 0, NULL);
    g_return_val_if_fail (!eel_irect_is_empty (&area), NULL);

    /* Compute the offset into the buffer */
    pixels =
        buffer
        + (area.y0 * buffer_rowstride)
        + (area.x0 * (buffer_has_alpha ? 4 : 3));

    pixbuf = gdk_pixbuf_new_from_data (pixels,
                                       GDK_COLORSPACE_RGB,
                                       buffer_has_alpha,
                                       8,
                                       eel_irect_get_width (area),
                                       eel_irect_get_height (area),
                                       buffer_rowstride,
                                       NULL,
                                       NULL);

    return pixbuf;
}
/**
 * eel_gtk_container_child_size_allocate:
 *
 * @container: A GtkContainer widget.
 * @child: A child of @container or NULL;
 *
 * Invoke the "GtkWidget::size_allocate" method of @child.
 * This function is usually called from the "GtkWidget::size_allocate"
 * method of @container.  The child can be NULL, in which case this
 * function is a noop.
 */
void
eel_gtk_container_child_size_allocate (GtkContainer *container,
                                       GtkWidget *child,
                                       EelIRect child_geometry)
{
    GtkAllocation child_allocation;

    g_return_if_fail (GTK_IS_CONTAINER (container));

    if (child == NULL)
    {
        return;
    }

    g_return_if_fail (GTK_IS_WIDGET (child));
    g_return_if_fail (gtk_widget_get_parent (child) == GTK_WIDGET (container));

    if (eel_irect_is_empty (&child_geometry))
    {
        return;
    }

    child_allocation.x = child_geometry.x0;
    child_allocation.y = child_geometry.y0;
    child_allocation.width = eel_irect_get_width (child_geometry);
    child_allocation.height = eel_irect_get_height (child_geometry);

    gtk_widget_size_allocate (child, &child_allocation);
}
GdkRectangle
eel_irect_to_gdk_rectangle (EelIRect rectangle)
{
	GdkRectangle gdk_rect;

	gdk_rect.x = rectangle.x0;
	gdk_rect.y = rectangle.y0;
	gdk_rect.width = eel_irect_get_width (rectangle);
	gdk_rect.height = eel_irect_get_height (rectangle);

	return gdk_rect;
}
Exemple #4
0
/**
 * eel_gdk_pixbuf_new_from_pixbuf_sub_area:
 * @pixbuf: The source pixbuf.
 * @area: The area within the source pixbuf to use for the sub pixbuf.
 *        This area needs to be contained within the bounds of the
 *        source pixbuf, otherwise it will be clipped to that.
 *
 * Return value: A newly allocated pixbuf that shares the pixel data
 *               of the source pixbuf in order to represent a sub area.
 *
 * Create a pixbuf from a sub area of another pixbuf.  The resulting pixbuf
 * will share the pixel data of the source pixbuf.  Memory bookeeping is
 * all taken care for the caller.  All you need to do is g_object_unref()
 * the resulting pixbuf to properly free resources.
 */
GdkPixbuf *
eel_gdk_pixbuf_new_from_pixbuf_sub_area (GdkPixbuf *pixbuf,
        EelIRect area)
{
    GdkPixbuf *sub_pixbuf;
    EelIRect target;
    guchar *pixels;

    g_return_val_if_fail (eel_gdk_pixbuf_is_valid (pixbuf), NULL);
    g_return_val_if_fail (!eel_irect_is_empty (&area), NULL);

    /* Clip the pixbuf by the given area; bail if no work */
    target = eel_gdk_pixbuf_intersect (pixbuf, 0, 0, area);
    if (eel_irect_is_empty (&target))
    {
        return NULL;
    }

    /* Since we are going to be sharing the given pixbuf's data, we need
     * to ref it.  It will be unreffed in the destroy function above */
    g_object_ref (pixbuf);

    /* Compute the offset into the pixel data */
    pixels =
        gdk_pixbuf_get_pixels (pixbuf)
        + (target.y0 * gdk_pixbuf_get_rowstride (pixbuf))
        + (target.x0 * (gdk_pixbuf_get_has_alpha (pixbuf) ? 4 : 3));

    /* Make a pixbuf pretending its real estate is the sub area */
    sub_pixbuf = gdk_pixbuf_new_from_data (pixels,
                                           GDK_COLORSPACE_RGB,
                                           gdk_pixbuf_get_has_alpha (pixbuf),
                                           8,
                                           eel_irect_get_width (target),
                                           eel_irect_get_height (target),
                                           gdk_pixbuf_get_rowstride (pixbuf),
                                           pixbuf_destroy_callback,
                                           pixbuf);

    return sub_pixbuf;
}