plug-ins: port gfig to GimpImage|Drawable.

This commit is contained in:
Jehan 2019-08-17 11:27:37 +02:00
parent 7838c7f2b2
commit 962e8b995e
14 changed files with 70 additions and 69 deletions

View File

@ -65,7 +65,6 @@ gfig_SOURCES = \
EXTRA_DIST = README
AM_CPPFLAGS = \
-DGIMP_DEPRECATED_REPLACE_NEW_API \
-I$(top_srcdir) \
$(GTK_CFLAGS) \
$(GEGL_CFLAGS) \

View File

@ -541,7 +541,7 @@ d_paint_arc (GfigObject *obj)
if (obj->style.paint_type == PAINT_BRUSH_TYPE)
{
gfig_paint (selvals.brshtype,
gfig_context->drawable_id,
gfig_context->drawable,
i, line_pnts);
}

View File

@ -266,7 +266,7 @@ d_paint_bezier (GfigObject *obj)
if (obj->style.paint_type == PAINT_BRUSH_TYPE)
{
gfig_paint (selvals.brshtype,
gfig_context->drawable_id,
gfig_context->drawable,
i, line_pnts);
}

View File

@ -123,7 +123,7 @@ d_paint_circle (GfigObject *obj)
gimp_context_set_antialias (selopt.antia);
gimp_context_set_feather (selopt.feather);
gimp_context_set_feather_radius (selopt.feather_radius, selopt.feather_radius);
gimp_image_select_ellipse (gfig_context->image_id,
gimp_image_select_ellipse (gfig_context->image,
selopt.type,
dpnts[0], dpnts[1],
dpnts[2], dpnts[3]);
@ -133,7 +133,7 @@ d_paint_circle (GfigObject *obj)
center_pnt->pnt.y - radius,
center_pnt->pnt.x + radius,
center_pnt->pnt.y + radius);
gimp_selection_none (gfig_context->image_id);
gimp_selection_none (gfig_context->image);
}
/* Drawing a circle may be harder than stroking a circular selection,
@ -156,7 +156,7 @@ d_paint_circle (GfigObject *obj)
angle += step;
}
gfig_paint (selvals.brshtype, gfig_context->drawable_id, i, line_pnts);
gfig_paint (selvals.brshtype, gfig_context->drawable, i, line_pnts);
}
}

View File

@ -199,7 +199,7 @@ gfig_dialog (void)
GtkWidget *vbox;
GFigObj *gfig;
GimpParasite *parasite;
gint newlayer;
GimpLayer *newlayer;
GtkWidget *menubar;
GtkWidget *toolbar;
GtkWidget *combo;
@ -216,9 +216,9 @@ gfig_dialog (void)
gimp_ui_init (PLUG_IN_BINARY, TRUE);
img_width = gimp_drawable_width (gfig_context->drawable_id);
img_height = gimp_drawable_height (gfig_context->drawable_id);
img_type = gimp_drawable_type_with_alpha (gfig_context->drawable_id);
img_width = gimp_drawable_width (gfig_context->drawable);
img_height = gimp_drawable_height (gfig_context->drawable);
img_type = gimp_drawable_type_with_alpha (gfig_context->drawable);
/*
* See if there is a "gfig" parasite. If so, this is a gfig layer,
@ -227,7 +227,7 @@ gfig_dialog (void)
*/
gfig_list = NULL;
undo_level = -1;
parasite = gimp_item_get_parasite (gfig_context->drawable_id, "gfig");
parasite = gimp_item_get_parasite (GIMP_ITEM (gfig_context->drawable), "gfig");
gfig_context->enable_repaint = FALSE;
/* debug */
@ -239,20 +239,20 @@ gfig_dialog (void)
if (parasite)
{
gimp_drawable_fill (gfig_context->drawable_id, GIMP_FILL_TRANSPARENT);
gimp_drawable_fill (gfig_context->drawable, GIMP_FILL_TRANSPARENT);
gfig_context->using_new_layer = FALSE;
gimp_parasite_free (parasite);
}
else
{
newlayer = gimp_layer_new (gfig_context->image_id, "GFig",
newlayer = gimp_layer_new (gfig_context->image, "GFig",
img_width, img_height,
img_type,
100.0,
gimp_image_get_default_new_layer_mode (gfig_context->image_id));
gimp_drawable_fill (newlayer, GIMP_FILL_TRANSPARENT);
gimp_image_insert_layer (gfig_context->image_id, newlayer, -1, -1);
gfig_context->drawable_id = newlayer;
gimp_image_get_default_new_layer_mode (gfig_context->image));
gimp_drawable_fill (GIMP_DRAWABLE (newlayer), GIMP_FILL_TRANSPARENT);
gimp_image_insert_layer (gfig_context->image, newlayer, NULL, -1);
gfig_context->drawable = GIMP_DRAWABLE (newlayer);
gfig_context->using_new_layer = TRUE;
}
@ -553,8 +553,8 @@ gfig_response (GtkWidget *widget,
/* if we created a new layer, delete it */
if (gfig_context->using_new_layer)
{
gimp_image_remove_layer (gfig_context->image_id,
gfig_context->drawable_id);
gimp_image_remove_layer (gfig_context->image,
GIMP_LAYER (gfig_context->drawable));
}
else /* revert back to the original figure */
{
@ -1757,15 +1757,15 @@ num_sides_widget (const gchar *d_title,
}
void
gfig_paint (BrushType brush_type,
gint32 drawable_ID,
gint seg_count,
gdouble line_pnts[])
gfig_paint (BrushType brush_type,
GimpDrawable *drawable,
gint seg_count,
gdouble line_pnts[])
{
switch (brush_type)
{
case BRUSH_BRUSH_TYPE:
gimp_paintbrush (drawable_ID,
gimp_paintbrush (drawable,
selvals.brushfade,
seg_count, line_pnts,
GIMP_PAINT_CONSTANT,
@ -1773,19 +1773,19 @@ gfig_paint (BrushType brush_type,
break;
case BRUSH_PENCIL_TYPE:
gimp_pencil (drawable_ID,
gimp_pencil (drawable,
seg_count, line_pnts);
break;
case BRUSH_AIRBRUSH_TYPE:
gimp_airbrush (drawable_ID,
gimp_airbrush (drawable,
selvals.airbrushpressure,
seg_count, line_pnts);
break;
case BRUSH_PATTERN_TYPE:
gimp_clone (drawable_ID,
drawable_ID,
gimp_clone (drawable,
drawable,
GIMP_CLONE_PATTERN,
0.0, 0.0,
seg_count, line_pnts);
@ -1929,7 +1929,7 @@ paint_layer_fill (gdouble x1, gdouble y1, gdouble x2, gdouble y2)
break;
case FILL_GRADIENT:
gimp_drawable_edit_gradient_fill (gfig_context->drawable_id,
gimp_drawable_edit_gradient_fill (gfig_context->drawable,
GIMP_GRADIENT_SHAPEBURST_DIMPLED,
0.0, /* offset */
FALSE, /* supersampling */
@ -1940,7 +1940,7 @@ paint_layer_fill (gdouble x1, gdouble y1, gdouble x2, gdouble y2)
0.0, 0.0); /* (x2, y2) - ignored */
return;
case FILL_VERTICAL:
gimp_drawable_edit_gradient_fill (gfig_context->drawable_id,
gimp_drawable_edit_gradient_fill (gfig_context->drawable,
GIMP_GRADIENT_LINEAR,
0.0,
FALSE,
@ -1951,7 +1951,7 @@ paint_layer_fill (gdouble x1, gdouble y1, gdouble x2, gdouble y2)
x1, y2);
return;
case FILL_HORIZONTAL:
gimp_drawable_edit_gradient_fill (gfig_context->drawable_id,
gimp_drawable_edit_gradient_fill (gfig_context->drawable,
GIMP_GRADIENT_LINEAR,
0.0,
FALSE,
@ -1965,7 +1965,7 @@ paint_layer_fill (gdouble x1, gdouble y1, gdouble x2, gdouble y2)
gimp_context_set_opacity (current_style->fill_opacity);
gimp_drawable_edit_fill (gfig_context->drawable_id,
gimp_drawable_edit_fill (gfig_context->drawable,
fill_type);
gimp_context_pop ();
@ -1983,7 +1983,7 @@ gfig_paint_callback (void)
objs = gfig_context->current_obj->obj_list;
gimp_drawable_fill (gfig_context->drawable_id, GIMP_FILL_TRANSPARENT);
gimp_drawable_fill (gfig_context->drawable, GIMP_FILL_TRANSPARENT);
while (objs)
{

View File

@ -130,14 +130,14 @@ d_paint_ellipse (GfigObject *obj)
gimp_context_set_antialias (selopt.antia);
gimp_context_set_feather (selopt.feather);
gimp_context_set_feather_radius (selopt.feather_radius, selopt.feather_radius);
gimp_image_select_ellipse (gfig_context->image_id,
gimp_image_select_ellipse (gfig_context->image,
selopt.type,
dpnts[0], dpnts[1],
dpnts[2], dpnts[3]);
gimp_context_pop ();
paint_layer_fill (top_x, top_y, top_x + bound_wx, top_y + bound_wy);
gimp_selection_none (gfig_context->image_id);
gimp_selection_none (gfig_context->image);
}
if (obj->style.paint_type == PAINT_BRUSH_TYPE)
@ -157,7 +157,7 @@ d_paint_ellipse (GfigObject *obj)
angle += step;
}
gfig_paint (selvals.brshtype, gfig_context->drawable_id, i, line_pnts);
gfig_paint (selvals.brshtype, gfig_context->drawable, i, line_pnts);
}
}

View File

@ -115,7 +115,7 @@ d_paint_line (GfigObject *obj)
if (obj->style.paint_type == PAINT_BRUSH_TYPE)
{
gfig_paint (selvals.brshtype,
gfig_context->drawable_id,
gfig_context->drawable,
seg_count * 2, line_pnts);
}

View File

@ -254,17 +254,17 @@ d_paint_poly (GfigObject *obj)
gimp_context_set_antialias (selopt.antia);
gimp_context_set_feather (selopt.feather);
gimp_context_set_feather_radius (selopt.feather_radius, selopt.feather_radius);
gimp_image_select_polygon (gfig_context->image_id,
gimp_image_select_polygon (gfig_context->image,
selopt.type,
i, line_pnts);
gimp_context_pop ();
paint_layer_fill (min_max[0], min_max[1], min_max[2], min_max[3]);
gimp_selection_none (gfig_context->image_id);
gimp_selection_none (gfig_context->image);
}
if (obj->style.paint_type == PAINT_BRUSH_TYPE)
gfig_paint (selvals.brshtype, gfig_context->drawable_id, i, line_pnts);
gfig_paint (selvals.brshtype, gfig_context->drawable, i, line_pnts);
g_free (line_pnts);
g_free (min_max);

View File

@ -146,7 +146,7 @@ static void
draw_background (cairo_t *cr)
{
if (! back_pixbuf)
back_pixbuf = gimp_image_get_thumbnail (gfig_context->image_id,
back_pixbuf = gimp_image_get_thumbnail (gfig_context->image,
preview_width, preview_height,
GIMP_PIXBUF_LARGE_CHECKS);

View File

@ -120,7 +120,7 @@ d_paint_rectangle (GfigObject *obj)
gimp_context_push ();
gimp_context_set_feather (selopt.feather);
gimp_context_set_feather_radius (selopt.feather_radius, selopt.feather_radius);
gimp_image_select_rectangle (gfig_context->image_id,
gimp_image_select_rectangle (gfig_context->image,
selopt.type,
dpnts[0], dpnts[1],
dpnts[2] - dpnts[0],
@ -128,7 +128,7 @@ d_paint_rectangle (GfigObject *obj)
gimp_context_pop ();
paint_layer_fill (dpnts[0], dpnts[1], dpnts[2], dpnts[3]);
gimp_selection_none (gfig_context->image_id);
gimp_selection_none (gfig_context->image);
}
if (obj->style.paint_type == PAINT_BRUSH_TYPE)
@ -137,7 +137,7 @@ d_paint_rectangle (GfigObject *obj)
dpnts[2], dpnts[3], dpnts[0], dpnts[3],
dpnts[0], dpnts[1] };
gfig_paint (selvals.brshtype, gfig_context->drawable_id, 10, line_pnts);
gfig_paint (selvals.brshtype, gfig_context->drawable, 10, line_pnts);
}
}

View File

@ -242,7 +242,7 @@ d_paint_spiral (GfigObject *obj)
if (obj->style.paint_type == PAINT_BRUSH_TYPE)
{
gfig_paint (selvals.brshtype,
gfig_context->drawable_id,
gfig_context->drawable,
i, line_pnts);
}

View File

@ -315,17 +315,17 @@ d_paint_star (GfigObject *obj)
gimp_context_set_antialias (selopt.antia);
gimp_context_set_feather (selopt.feather);
gimp_context_set_feather_radius (selopt.feather_radius, selopt.feather_radius);
gimp_image_select_polygon (gfig_context->image_id,
gimp_image_select_polygon (gfig_context->image,
selopt.type,
i, line_pnts);
gimp_context_pop ();
paint_layer_fill (min_max[0], min_max[1], min_max[2], min_max[3]);
gimp_selection_none (gfig_context->image_id);
gimp_selection_none (gfig_context->image);
}
if (obj->style.paint_type == PAINT_BRUSH_TYPE)
gfig_paint (selvals.brshtype, gfig_context->drawable_id, i, line_pnts);
gfig_paint (selvals.brshtype, gfig_context->drawable, i, line_pnts);
g_free (line_pnts);
g_free (min_max);

View File

@ -82,8 +82,8 @@ static GimpProcedure * gfig_create_procedure (GimpPlugIn *plug_in,
static GimpValueArray * gfig_run (GimpProcedure *procedure,
GimpRunMode run_mode,
gint32 image_id,
gint32 drawable_id,
GimpImage *image,
GimpDrawable *drawable,
const GimpValueArray *args,
gpointer run_data);
@ -188,8 +188,8 @@ gfig_create_procedure (GimpPlugIn *plug_in,
static GimpValueArray *
gfig_run (GimpProcedure *procedure,
GimpRunMode run_mode,
gint32 image_id,
gint32 drawable_id,
GimpImage *image,
GimpDrawable *drawable,
const GimpValueArray *args,
gpointer run_data)
{
@ -203,23 +203,23 @@ gfig_run (GimpProcedure *procedure,
gfig_context->show_background = TRUE;
gfig_context->selected_obj = NULL;
gfig_context->image_id = image_id;
gfig_context->drawable_id = drawable_id;
gfig_context->image = image;
gfig_context->drawable = drawable;
gimp_image_undo_group_start (gfig_context->image_id);
gimp_image_undo_group_start (gfig_context->image);
gimp_context_push ();
/* TMP Hack - clear any selections */
if (! gimp_selection_is_empty (gfig_context->image_id))
gimp_selection_none (gfig_context->image_id);
if (! gimp_selection_is_empty (gfig_context->image))
gimp_selection_none (gfig_context->image);
if (! gimp_drawable_mask_intersect (drawable_id, &sel_x, &sel_y,
if (! gimp_drawable_mask_intersect (drawable, &sel_x, &sel_y,
&sel_width, &sel_height))
{
gimp_context_pop ();
gimp_image_undo_group_end (gfig_context->image_id);
gimp_image_undo_group_end (gfig_context->image);
return gimp_procedure_new_return_values (procedure, status, NULL);
}
@ -254,7 +254,7 @@ gfig_run (GimpProcedure *procedure,
case GIMP_RUN_WITH_LAST_VALS:
if (! gfig_dialog ())
{
gimp_image_undo_group_end (gfig_context->image_id);
gimp_image_undo_group_end (gfig_context->image);
return gimp_procedure_new_return_values (procedure, GIMP_PDB_CANCEL,
NULL);
@ -271,7 +271,7 @@ gfig_run (GimpProcedure *procedure,
gimp_context_pop ();
gimp_image_undo_group_end (gfig_context->image_id);
gimp_image_undo_group_end (gfig_context->image);
if (run_mode != GIMP_RUN_NONINTERACTIVE)
gimp_displays_flush ();
@ -753,7 +753,8 @@ gfig_save_as_parasite (void)
g_string_free (string, TRUE);
if (!gimp_item_attach_parasite (gfig_context->drawable_id, parasite))
if (!gimp_item_attach_parasite (GIMP_ITEM (gfig_context->drawable),
parasite))
{
g_message (_("Error trying to save figure as a parasite: "
"can't attach parasite to drawable."));
@ -773,7 +774,8 @@ gfig_load_from_parasite (void)
GimpParasite *parasite;
GFigObj *gfig;
parasite = gimp_item_get_parasite (gfig_context->drawable_id, "gfig");
parasite = gimp_item_get_parasite (GIMP_ITEM (gfig_context->drawable),
"gfig");
if (! parasite)
return NULL;

View File

@ -131,8 +131,8 @@ typedef struct
{
gboolean debug_styles;
gboolean show_background; /* show thumbnail of image behind figure */
gint32 image_id; /* Gimp image id */
gint32 drawable_id; /* Gimp drawable to paint on */
GimpImage *image; /* Gimp image */
GimpDrawable *drawable; /* Gimp drawable to paint on */
GFigObj *current_obj;
GfigObject *selected_obj;
GtkWidget *preview;
@ -171,10 +171,10 @@ void scale_to_xy (gdouble *list,
void scale_to_original_xy (gdouble *list,
gint size);
void gfig_paint (BrushType brush_type,
gint32 drawable_ID,
gint seg_count,
gdouble line_pnts[]);
void gfig_paint (BrushType brush_type,
GimpDrawable *drawable,
gint seg_count,
gdouble line_pnts[]);
void draw_item (cairo_t *cr,
gboolean fill);