libgimpwidgets: new gimp_preview_area_reset() function.

The various drawing APIs are cumulative which is not right when we want to
change a preview (especially if the preview changes dimensions! Then we end up
with pieces of the previous drawing behind the new one).

This new function will allow to reset the whole drawing. Note that we may end up
with some black background if the preview are doesn't have the right dimensions.
This should be improved later too.
This commit is contained in:
Jehan 2023-08-28 19:19:50 +02:00
parent 63a97d3be6
commit 236fd01a1c
3 changed files with 32 additions and 4 deletions

View File

@ -572,7 +572,7 @@ gimp_preview_area_draw (GimpPreviewArea *area,
if (! priv->buf)
{
priv->rowstride = ((priv->width * 3) + 3) & ~3;
priv->buf = g_new (guchar, priv->rowstride * priv->height);
priv->buf = g_new0 (guchar, priv->rowstride * priv->height);
}
size = 1 << (2 + priv->check_size);
@ -880,7 +880,7 @@ gimp_preview_area_blend (GimpPreviewArea *area,
if (! priv->buf)
{
priv->rowstride = ((priv->width * 3) + 3) & ~3;
priv->buf = g_new (guchar, priv->rowstride * priv->height);
priv->buf = g_new0 (guchar, priv->rowstride * priv->height);
}
size = 1 << (2 + priv->check_size);
@ -1279,7 +1279,7 @@ gimp_preview_area_mask (GimpPreviewArea *area,
if (! priv->buf)
{
priv->rowstride = ((priv->width * 3) + 3) & ~3;
priv->buf = g_new (guchar, priv->rowstride * priv->height);
priv->buf = g_new0 (guchar, priv->rowstride * priv->height);
}
size = 1 << (2 + priv->check_size);
@ -1852,7 +1852,7 @@ gimp_preview_area_fill (GimpPreviewArea *area,
if (! priv->buf)
{
priv->rowstride = ((priv->width * 3) + 3) & ~3;
priv->buf = g_new (guchar, priv->rowstride * priv->height);
priv->buf = g_new0 (guchar, priv->rowstride * priv->height);
}
dest = priv->buf + x * 3 + y * priv->rowstride;
@ -1875,6 +1875,32 @@ gimp_preview_area_fill (GimpPreviewArea *area,
gimp_preview_area_queue_draw (area, x, y, width, height);
}
/**
* gimp_preview_area_reset:
* @area: a #GimpPreviewArea widget.
*
* Reset any previous drawing done through [class@Gimp.PreviewArea] functions.
*
* Since: 3.0
**/
void
gimp_preview_area_reset (GimpPreviewArea *area)
{
GimpPreviewAreaPrivate *priv = GET_PRIVATE (area);
GtkAllocation allocation;
if (priv->buf)
{
g_free (priv->buf);
priv->buf = NULL;
priv->rowstride = 0;
}
gtk_widget_get_allocation (GTK_WIDGET (area), &allocation);
gimp_preview_area_queue_draw (area, 0, 0, allocation.width, allocation.height);
}
/**
* gimp_preview_area_set_offsets:
* @area: a #GimpPreviewArea

View File

@ -103,6 +103,7 @@ void gimp_preview_area_fill (GimpPreviewArea *area,
guchar red,
guchar green,
guchar blue);
void gimp_preview_area_reset (GimpPreviewArea *area);
void gimp_preview_area_set_offsets (GimpPreviewArea *area,
gint x,

View File

@ -336,6 +336,7 @@ EXPORTS
gimp_preview_area_mask
gimp_preview_area_menu_popup
gimp_preview_area_new
gimp_preview_area_reset
gimp_preview_area_set_color_config
gimp_preview_area_set_colormap
gimp_preview_area_set_max_size