[gimp/wip/Jehan/classy-GIMP: 56/60] plug-ins: port gfig to GimpImage|Drawable.



commit 8a342840c18bc99d663a70c4e3ab788775a8ac34
Author: Jehan <jehan girinstud io>
Date:   Sat Aug 17 11:27:37 2019 +0200

    plug-ins: port gfig to GimpImage|Drawable.

 plug-ins/gfig/Makefile.am      |  1 -
 plug-ins/gfig/gfig-arc.c       |  2 +-
 plug-ins/gfig/gfig-bezier.c    |  2 +-
 plug-ins/gfig/gfig-circle.c    |  6 ++---
 plug-ins/gfig/gfig-dialog.c    | 54 +++++++++++++++++++++---------------------
 plug-ins/gfig/gfig-ellipse.c   |  6 ++---
 plug-ins/gfig/gfig-line.c      |  2 +-
 plug-ins/gfig/gfig-poly.c      |  6 ++---
 plug-ins/gfig/gfig-preview.c   |  2 +-
 plug-ins/gfig/gfig-rectangle.c |  6 ++---
 plug-ins/gfig/gfig-spiral.c    |  2 +-
 plug-ins/gfig/gfig-star.c      |  6 ++---
 plug-ins/gfig/gfig.c           | 32 +++++++++++++------------
 plug-ins/gfig/gfig.h           | 12 +++++-----
 14 files changed, 70 insertions(+), 69 deletions(-)
---
diff --git a/plug-ins/gfig/Makefile.am b/plug-ins/gfig/Makefile.am
index 8942ff9063..266ebbc323 100644
--- a/plug-ins/gfig/Makefile.am
+++ b/plug-ins/gfig/Makefile.am
@@ -65,7 +65,6 @@ gfig_SOURCES = \
 EXTRA_DIST = README
 
 AM_CPPFLAGS = \
-       -DGIMP_DEPRECATED_REPLACE_NEW_API \
        -I$(top_srcdir) \
        $(GTK_CFLAGS)   \
        $(GEGL_CFLAGS) \
diff --git a/plug-ins/gfig/gfig-arc.c b/plug-ins/gfig/gfig-arc.c
index 5e8be02e9f..5798eafb79 100644
--- a/plug-ins/gfig/gfig-arc.c
+++ b/plug-ins/gfig/gfig-arc.c
@@ -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);
     }
 
diff --git a/plug-ins/gfig/gfig-bezier.c b/plug-ins/gfig/gfig-bezier.c
index 9156d7cff6..13530dd5e3 100644
--- a/plug-ins/gfig/gfig-bezier.c
+++ b/plug-ins/gfig/gfig-bezier.c
@@ -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);
     }
 
diff --git a/plug-ins/gfig/gfig-circle.c b/plug-ins/gfig/gfig-circle.c
index e3b779597b..aa77ae9d84 100644
--- a/plug-ins/gfig/gfig-circle.c
+++ b/plug-ins/gfig/gfig-circle.c
@@ -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);
     }
 }
 
diff --git a/plug-ins/gfig/gfig-dialog.c b/plug-ins/gfig/gfig-dialog.c
index 410418a218..26ce348864 100644
--- a/plug-ins/gfig/gfig-dialog.c
+++ b/plug-ins/gfig/gfig-dialog.c
@@ -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)
     {
diff --git a/plug-ins/gfig/gfig-ellipse.c b/plug-ins/gfig/gfig-ellipse.c
index eac8091cb1..ff25795694 100644
--- a/plug-ins/gfig/gfig-ellipse.c
+++ b/plug-ins/gfig/gfig-ellipse.c
@@ -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);
     }
 }
 
diff --git a/plug-ins/gfig/gfig-line.c b/plug-ins/gfig/gfig-line.c
index f842d7b9aa..73676a7e19 100644
--- a/plug-ins/gfig/gfig-line.c
+++ b/plug-ins/gfig/gfig-line.c
@@ -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);
     }
 
diff --git a/plug-ins/gfig/gfig-poly.c b/plug-ins/gfig/gfig-poly.c
index 2fe9e5d38c..a8c9b5c9e0 100644
--- a/plug-ins/gfig/gfig-poly.c
+++ b/plug-ins/gfig/gfig-poly.c
@@ -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);
diff --git a/plug-ins/gfig/gfig-preview.c b/plug-ins/gfig/gfig-preview.c
index 26d23a2280..6af5ed7e92 100644
--- a/plug-ins/gfig/gfig-preview.c
+++ b/plug-ins/gfig/gfig-preview.c
@@ -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);
 
diff --git a/plug-ins/gfig/gfig-rectangle.c b/plug-ins/gfig/gfig-rectangle.c
index d3688f1c46..4bea045af7 100644
--- a/plug-ins/gfig/gfig-rectangle.c
+++ b/plug-ins/gfig/gfig-rectangle.c
@@ -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);
     }
 }
 
diff --git a/plug-ins/gfig/gfig-spiral.c b/plug-ins/gfig/gfig-spiral.c
index a7873934e6..f35e87b121 100644
--- a/plug-ins/gfig/gfig-spiral.c
+++ b/plug-ins/gfig/gfig-spiral.c
@@ -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);
     }
 
diff --git a/plug-ins/gfig/gfig-star.c b/plug-ins/gfig/gfig-star.c
index 6ef68481b9..da33828250 100644
--- a/plug-ins/gfig/gfig-star.c
+++ b/plug-ins/gfig/gfig-star.c
@@ -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);
diff --git a/plug-ins/gfig/gfig.c b/plug-ins/gfig/gfig.c
index a3e8773a76..bcdc0a7fc0 100644
--- a/plug-ins/gfig/gfig.c
+++ b/plug-ins/gfig/gfig.c
@@ -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;
 
diff --git a/plug-ins/gfig/gfig.h b/plug-ins/gfig/gfig.h
index a2ed727c49..3435f292a5 100644
--- a/plug-ins/gfig/gfig.h
+++ b/plug-ins/gfig/gfig.h
@@ -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);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]