app: Layer expansion while using ink tool

Now layers will expand when trying to draw beyond layer borders with ink tool.
Tool options similar to paint tools have been added (expand_use and
expand_amount).
This commit is contained in:
Shubham 2023-06-26 09:50:11 +05:30 committed by Jehan
parent 97a2627867
commit e33618a650
5 changed files with 63 additions and 8 deletions

View File

@ -466,6 +466,21 @@ gimp_blob_duplicate (GimpBlob *b)
return g_memdup2 (b, sizeof (GimpBlob) + sizeof (GimpBlobSpan) * (b->height - 1));
}
void
gimp_blob_move (GimpBlob *b,
gint x,
gint y)
{
gint i = 0;
b->y += y;
for (i = 0; i < b->height; i++)
{
b->data[i].left += x;
b->data[i].right += x;
}
}
#if 0
void
gimp_blob_dump (GimpBlob *b)

View File

@ -82,6 +82,9 @@ void gimp_blob_bounds (GimpBlob *b,
GimpBlob * gimp_blob_convex_union (GimpBlob *b1,
GimpBlob *b2);
GimpBlob * gimp_blob_duplicate (GimpBlob *b);
void gimp_blob_move (GimpBlob *b,
gint x,
gint y);
#endif /* __GIMP_INK_BLOB_H__ */

View File

@ -238,17 +238,40 @@ gimp_ink_get_paint_buffer (GimpPaintCore *paint_core,
gint *paint_width,
gint *paint_height)
{
GimpInk *ink = GIMP_INK (paint_core);
gint x, y;
gint width, height;
gint dwidth, dheight;
gint x1, y1, x2, y2;
GimpInk *ink = GIMP_INK (paint_core);
gint x, y;
gint width, height;
gint dwidth, dheight;
gint x1, y1, x2, y2;
gint offset_change_x, offset_change_y;
GimpCoords new_coords;
GList *iter;
gimp_blob_bounds (ink->cur_blob, &x, &y, &width, &height);
x1 = x / SUBSAMPLE - 1;
y1 = y / SUBSAMPLE - 1;
x2 = (x + width) / SUBSAMPLE + 2;
y2 = (y + height) / SUBSAMPLE + 2;
gimp_paint_core_expand_drawable (paint_core, drawable, paint_options,
x1, x2, y1, y2,
&offset_change_x, &offset_change_y);
dwidth = gimp_item_get_width (GIMP_ITEM (drawable));
dheight = gimp_item_get_height (GIMP_ITEM (drawable));
if (offset_change_x || offset_change_y)
{
x += SUBSAMPLE * offset_change_x;
y += SUBSAMPLE * offset_change_y;
for (iter = ink->last_blobs; iter; iter = g_list_next (iter))
gimp_blob_move (iter->data,
SUBSAMPLE * offset_change_x,
SUBSAMPLE * offset_change_y);
}
x1 = CLAMP (x / SUBSAMPLE - 1, 0, dwidth);
y1 = CLAMP (y / SUBSAMPLE - 1, 0, dheight);
x2 = CLAMP ((x + width) / SUBSAMPLE + 2, 0, dwidth);
@ -418,6 +441,7 @@ gimp_ink_motion (GimpPaintCore *paint_core,
gimp_pickable_srgb_to_image_color (GIMP_PICKABLE (drawable),
&foreground, &foreground);
color = gimp_gegl_color_new (&foreground, gimp_drawable_get_space (drawable));
ink->blobs_to_render = blobs_to_render;
for (i = 0; i < n_strokes; i++)
{

View File

@ -37,10 +37,11 @@ struct _GimpInk
{
GimpPaintCore parent_instance;
GList *start_blobs; /* starting blobs per stroke (for undo) */
GList *start_blobs; /* starting blobs per stroke (for undo) */
GimpBlob *cur_blob; /* current blob */
GList *last_blobs; /* blobs for last stroke positions */
GimpBlob *cur_blob; /* current blob */
GList *last_blobs; /* blobs for last stroke positions */
GList *blobs_to_render;
};
struct _GimpInkClass

View File

@ -129,6 +129,18 @@ gimp_ink_options_gui (GimpToolOptions *tool_options)
gtk_container_add (GTK_CONTAINER (frame), editor);
gtk_widget_show (editor);
/* Extend layer options */
scale = gimp_prop_spin_scale_new (config, "expand-amount",
1, 10, 2);
gimp_spin_scale_set_constrain_drag (GIMP_SPIN_SCALE (scale), TRUE);
gimp_spin_scale_set_scale_limits (GIMP_SPIN_SCALE (scale), 1.0, 1000.0);
gimp_spin_scale_set_gamma (GIMP_SPIN_SCALE (scale), 1.0);
frame = gimp_prop_expanding_frame_new (config, "expand-use", NULL,
scale, NULL);
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
gimp_config_connect (config, G_OBJECT (editor), "blob-type");
gimp_config_connect (config, G_OBJECT (editor), "blob-aspect");
gimp_config_connect (config, G_OBJECT (editor), "blob-angle");