[gimp] plug-ins: port map-object to GimpPlugIn



commit 4ded322edf139a1ed2ca9b54bd98a852b31bb43e
Author: Michael Natterer <mitch gimp org>
Date:   Tue Sep 3 21:00:23 2019 +0200

    plug-ins: port map-object to GimpPlugIn

 plug-ins/map-object/map-object-main.c | 656 ++++++++++++++++++++++++----------
 1 file changed, 458 insertions(+), 198 deletions(-)
---
diff --git a/plug-ins/map-object/map-object-main.c b/plug-ins/map-object/map-object-main.c
index 76ddf9aceb..270c01dcbd 100644
--- a/plug-ins/map-object/map-object-main.c
+++ b/plug-ins/map-object/map-object-main.c
@@ -35,18 +35,356 @@
 #include "libgimp/stdplugins-intl.h"
 
 
-/* Global variables */
-/* ================ */
-
 MapObjectValues mapvals;
 
-/******************/
-/* Implementation */
-/******************/
 
-/*************************************/
-/* Set parameters to standard values */
-/*************************************/
+typedef struct _Map      Map;
+typedef struct _MapClass MapClass;
+
+struct _Map
+{
+  GimpPlugIn parent_instance;
+};
+
+struct _MapClass
+{
+  GimpPlugInClass parent_class;
+};
+
+
+#define MAP_TYPE  (map_get_type ())
+#define MAP (obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MAP_TYPE, Map))
+
+GType                   map_get_type         (void) G_GNUC_CONST;
+
+static GList          * map_query_procedures (GimpPlugIn           *plug_in);
+static GimpProcedure  * map_create_procedure (GimpPlugIn           *plug_in,
+                                                   const gchar          *name);
+
+static GimpValueArray * map_run              (GimpProcedure        *procedure,
+                                              GimpRunMode           run_mode,
+                                              GimpImage            *image,
+                                              GimpDrawable         *drawable,
+                                              const GimpValueArray *args,
+                                              gpointer              run_data);
+
+static void             set_default_settings (void);
+static void             check_drawables      (GimpDrawable         *drawable);
+
+
+G_DEFINE_TYPE (Map, map, GIMP_TYPE_PLUG_IN)
+
+GIMP_MAIN (MAP_TYPE)
+
+
+static void
+map_class_init (MapClass *klass)
+{
+  GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass);
+
+  plug_in_class->query_procedures = map_query_procedures;
+  plug_in_class->create_procedure = map_create_procedure;
+}
+
+static void
+map_init (Map *map)
+{
+}
+
+static GList *
+map_query_procedures (GimpPlugIn *plug_in)
+{
+  return g_list_append (NULL, g_strdup (PLUG_IN_PROC));
+}
+
+static GimpProcedure *
+map_create_procedure (GimpPlugIn  *plug_in,
+                      const gchar *name)
+{
+  GimpProcedure *procedure = NULL;
+
+  if (! strcmp (name, PLUG_IN_PROC))
+    {
+      GimpRGB white = { 1.0, 1.0, 1.0, 1.0 };
+
+      procedure = gimp_image_procedure_new (plug_in, name,
+                                            GIMP_PDB_PROC_TYPE_PLUGIN,
+                                            map_run, NULL, NULL);
+
+      gimp_procedure_set_image_types (procedure, "RGB*");
+
+      gimp_procedure_set_menu_label (procedure, N_("Map _Object..."));
+      gimp_procedure_add_menu_path (procedure, "<Image>/Filters/Map");
+
+      gimp_procedure_set_documentation (procedure,
+                                        N_("Map the image to an object "
+                                           "(plane, sphere, box or cylinder)"),
+                                        "No help yet",
+                                        name);
+      gimp_procedure_set_attribution (procedure,
+                                      "Tom Bech & Federico Mena Quintero",
+                                      "Tom Bech & Federico Mena Quintero",
+                                      "Version 1.2.0, July 16 1998");
+
+      GIMP_PROC_ARG_INT (procedure, "map-type",
+                         "Map type",
+                         "Type of mapping (0=plane, 1=sphere, 2=box, "
+                         "3=cylinder)",
+                         0, 2, MAP_PLANE,
+                         G_PARAM_READWRITE);
+
+      GIMP_PROC_ARG_DOUBLE (procedure, "viewpoint-x",
+                            "Viewpoint X",
+                            "Position of viewpoint (x,y,z)",
+                            -G_MAXDOUBLE, G_MAXDOUBLE, 0.5,
+                            G_PARAM_READWRITE);
+      GIMP_PROC_ARG_DOUBLE (procedure, "viewpoint-y",
+                            "Viewpoint Y",
+                            "Position of viewpoint (x,y,z)",
+                            -G_MAXDOUBLE, G_MAXDOUBLE, 0.5,
+                            G_PARAM_READWRITE);
+      GIMP_PROC_ARG_DOUBLE (procedure, "viewpoint-z",
+                            "Viewpoint Z",
+                            "Position of viewpoint (x,y,z)",
+                            -G_MAXDOUBLE, G_MAXDOUBLE, 2.0,
+                            G_PARAM_READWRITE);
+
+      GIMP_PROC_ARG_DOUBLE (procedure, "position-x",
+                            "Position X",
+                            "Object position (x,y,z)",
+                            -G_MAXDOUBLE, G_MAXDOUBLE, 0.5,
+                            G_PARAM_READWRITE);
+      GIMP_PROC_ARG_DOUBLE (procedure, "position-y",
+                            "Position Y",
+                            "Object position (x,y,z)",
+                            -G_MAXDOUBLE, G_MAXDOUBLE, 0.5,
+                            G_PARAM_READWRITE);
+      GIMP_PROC_ARG_DOUBLE (procedure, "position-z",
+                            "Position Z",
+                            "Object position (x,y,z)",
+                            -G_MAXDOUBLE, G_MAXDOUBLE, 0.0,
+                            G_PARAM_READWRITE);
+
+      GIMP_PROC_ARG_DOUBLE (procedure, "first-axis-x",
+                            "First axis X",
+                            "First axis of object (x,y,z)",
+                            -G_MAXDOUBLE, G_MAXDOUBLE, 1.0,
+                            G_PARAM_READWRITE);
+      GIMP_PROC_ARG_DOUBLE (procedure, "first-axis-y",
+                            "First axis y",
+                            "First axis of object (x,y,z)",
+                            -G_MAXDOUBLE, G_MAXDOUBLE, 0.0,
+                            G_PARAM_READWRITE);
+      GIMP_PROC_ARG_DOUBLE (procedure, "first-axis-z",
+                            "First axis Z",
+                            "First axis of object (x,y,z)",
+                            -G_MAXDOUBLE, G_MAXDOUBLE, 0.0,
+                            G_PARAM_READWRITE);
+
+      GIMP_PROC_ARG_DOUBLE (procedure, "second-axis-x",
+                            "Second axis X",
+                            "Second axis of object (x,y,z)",
+                            -G_MAXDOUBLE, G_MAXDOUBLE, 0.0,
+                            G_PARAM_READWRITE);
+      GIMP_PROC_ARG_DOUBLE (procedure, "second-axis-y",
+                            "Second axis Y",
+                            "Second axis of object (x,y,z)",
+                            -G_MAXDOUBLE, G_MAXDOUBLE, 1.0,
+                            G_PARAM_READWRITE);
+      GIMP_PROC_ARG_DOUBLE (procedure, "second-axis-z",
+                            "Second axis Z",
+                            "Second axis of object (x,y,z)",
+                            -G_MAXDOUBLE, G_MAXDOUBLE, 0.0,
+                            G_PARAM_READWRITE);
+
+      GIMP_PROC_ARG_DOUBLE (procedure, "rotation-angle-x",
+                            "Rotation angle X",
+                            "Rotation about X axis in degrees",
+                            -G_MAXDOUBLE, G_MAXDOUBLE, 0.0,
+                            G_PARAM_READWRITE);
+      GIMP_PROC_ARG_DOUBLE (procedure, "rotation-angle-y",
+                            "Rotation angle Y",
+                            "Rotation about Y axis in degrees",
+                            -G_MAXDOUBLE, G_MAXDOUBLE, 0.0,
+                            G_PARAM_READWRITE);
+      GIMP_PROC_ARG_DOUBLE (procedure, "rotation-angle-z",
+                            "Rotation angle Z",
+                            "Rotation about Z axis in degrees",
+                            -G_MAXDOUBLE, G_MAXDOUBLE, 0.0,
+                            G_PARAM_READWRITE);
+
+      GIMP_PROC_ARG_INT (procedure, "light-type",
+                         "Light type",
+                         "Type of lightsource (0=point, 1=directional, 2=none)",
+                         0, 2, POINT_LIGHT,
+                         G_PARAM_READWRITE);
+
+      GIMP_PROC_ARG_RGB (procedure, "light-color",
+                         "Light color",
+                         "Light source color",
+                         TRUE, &white,
+                         G_PARAM_READWRITE);
+
+      GIMP_PROC_ARG_DOUBLE (procedure, "light-position-x",
+                            "Light position X",
+                            "Light source position (x,y,z)",
+                            -G_MAXDOUBLE, G_MAXDOUBLE, -0.5,
+                            G_PARAM_READWRITE);
+      GIMP_PROC_ARG_DOUBLE (procedure, "light-position-y",
+                            "Light position Y",
+                            "Light source position (x,y,z)",
+                            -G_MAXDOUBLE, G_MAXDOUBLE, -0.5,
+                            G_PARAM_READWRITE);
+      GIMP_PROC_ARG_DOUBLE (procedure, "light-position-z",
+                            "Light position Z",
+                            "Light source position (x,y,z)",
+                            -G_MAXDOUBLE, G_MAXDOUBLE, 2.0,
+                            G_PARAM_READWRITE);
+
+      GIMP_PROC_ARG_DOUBLE (procedure, "light-direction-x",
+                            "Light direction X",
+                            "Light source direction (x,y,z)",
+                            -G_MAXDOUBLE, G_MAXDOUBLE, -1.0,
+                            G_PARAM_READWRITE);
+      GIMP_PROC_ARG_DOUBLE (procedure, "light-direction-y",
+                            "Light direction Y",
+                            "Light source direction (x,y,z)",
+                            -G_MAXDOUBLE, G_MAXDOUBLE, -1.0,
+                            G_PARAM_READWRITE);
+      GIMP_PROC_ARG_DOUBLE (procedure, "light-direction-z",
+                            "Light direction Z",
+                            "Light source direction (x,y,z)",
+                            -G_MAXDOUBLE, G_MAXDOUBLE, 1.0,
+                            G_PARAM_READWRITE);
+
+      GIMP_PROC_ARG_DOUBLE (procedure, "ambient-intensity",
+                            "Ambient intensity",
+                            "Material ambient intensity",
+                            0, 1, 0.3,
+                            G_PARAM_READWRITE);
+
+      GIMP_PROC_ARG_DOUBLE (procedure, "diffuse-intensity",
+                            "Diffuse intensity",
+                            "Material diffuse intensity",
+                            0, 1, 1.0,
+                            G_PARAM_READWRITE);
+
+      GIMP_PROC_ARG_DOUBLE (procedure, "diffuse-reflectivity",
+                            "Diffuse reflectivity",
+                            "Material diffuse reflectivity",
+                            0, 1, 0.5,
+                            G_PARAM_READWRITE);
+
+      GIMP_PROC_ARG_DOUBLE (procedure, "specular-reflectivity",
+                            "Specular reflectivity",
+                            "Material specular reflectivity",
+                            0, 1, 0.5,
+                            G_PARAM_READWRITE);
+
+      GIMP_PROC_ARG_DOUBLE (procedure, "highlight",
+                            "Highlight",
+                            "Material highlight (note, it's exponential)",
+                            0, G_MAXDOUBLE, 27.0,
+                            G_PARAM_READWRITE);
+
+      GIMP_PROC_ARG_BOOLEAN (procedure, "antialiasing",
+                             "Antialiasing",
+                             "Apply antialiasing",
+                             TRUE,
+                             G_PARAM_READWRITE);
+
+      GIMP_PROC_ARG_BOOLEAN (procedure, "tiled",
+                             "Tiled",
+                             "Tile source image",
+                             FALSE,
+                             G_PARAM_READWRITE);
+
+      GIMP_PROC_ARG_BOOLEAN (procedure, "new-image",
+                             "New image",
+                             "Create a new image",
+                             FALSE,
+                             G_PARAM_READWRITE);
+
+      GIMP_PROC_ARG_BOOLEAN (procedure, "transparent-background",
+                             "Transparent background",
+                             "Make background transparent",
+                             FALSE,
+                             G_PARAM_READWRITE);
+
+      GIMP_PROC_ARG_DOUBLE (procedure, "radius",
+                            "Radius",
+                            "Sphere/cylinder radius (only used when "
+                            "maptype=1 or 3)",
+                            0, G_MAXDOUBLE, 0.25,
+                            G_PARAM_READWRITE);
+
+      GIMP_PROC_ARG_DOUBLE (procedure, "x-scale",
+                            "X scale",
+                            "Box X size",
+                            0, G_MAXDOUBLE, 0.5,
+                            G_PARAM_READWRITE);
+      GIMP_PROC_ARG_DOUBLE (procedure, "y-scale",
+                            "Y scale",
+                            "Box Y size",
+                            0, G_MAXDOUBLE, 0.5,
+                            G_PARAM_READWRITE);
+      GIMP_PROC_ARG_DOUBLE (procedure, "z-scale",
+                            "Z scale",
+                            "Box Z size",
+                            0, G_MAXDOUBLE, 0.5,
+                            G_PARAM_READWRITE);
+
+      GIMP_PROC_ARG_DOUBLE (procedure, "cylinder-length",
+                            "Cylinder length",
+                            "Cylinder length",
+                            0, G_MAXDOUBLE, 0.25,
+                            G_PARAM_READWRITE);
+
+      GIMP_PROC_ARG_DRAWABLE (procedure, "box-front-drawable",
+                              "Box front drawable",
+                              "Box front face (set these to NULL if not used)",
+                              TRUE,
+                              G_PARAM_READWRITE);
+      GIMP_PROC_ARG_DRAWABLE (procedure, "box-back-drawable",
+                              "Box back drawable",
+                              "Box back face",
+                              TRUE,
+                              G_PARAM_READWRITE);
+      GIMP_PROC_ARG_DRAWABLE (procedure, "box-top-drawable",
+                              "Box top drawable",
+                              "Box top face",
+                              TRUE,
+                              G_PARAM_READWRITE);
+      GIMP_PROC_ARG_DRAWABLE (procedure, "box-bottom-drawable",
+                              "Box bottom drawable",
+                              "Box bottom face",
+                              TRUE,
+                              G_PARAM_READWRITE);
+      GIMP_PROC_ARG_DRAWABLE (procedure, "box-left-drawable",
+                              "Box left drawable",
+                              "Box left face",
+                              TRUE,
+                              G_PARAM_READWRITE);
+      GIMP_PROC_ARG_DRAWABLE (procedure, "box-right-drawable",
+                              "Box right drawable",
+                              "Box right face",
+                              TRUE,
+                              G_PARAM_READWRITE);
+
+      GIMP_PROC_ARG_DRAWABLE (procedure, "cyl-top-drawable",
+                              "Cyl top drawable",
+                              "Cylinder top face (set these to NULL if not used)",
+                              TRUE,
+                              G_PARAM_READWRITE);
+      GIMP_PROC_ARG_DRAWABLE (procedure, "cyl-bottom-drawable",
+                              "Cyl bottom drawable",
+                              "Cylinder bottom face",
+                              TRUE,
+                              G_PARAM_READWRITE);
+    }
+
+  return procedure;
+}
 
 static void
 set_default_settings (void)
@@ -129,206 +467,128 @@ check_drawables (GimpDrawable *drawable)
     }
 }
 
-static void
-query (void)
-{
-  static const GimpParamDef args[] =
-  {
-    { GIMP_PDB_INT32,    "run-mode",              "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE 
(1) }" },
-    { GIMP_PDB_IMAGE,    "image",                 "Input image" },
-    { GIMP_PDB_DRAWABLE, "drawable",              "Input drawable" },
-    { GIMP_PDB_INT32,    "maptype",               "Type of mapping (0=plane,1=sphere,2=box,3=cylinder)" },
-    { GIMP_PDB_FLOAT,    "viewpoint-x",           "Position of viewpoint (x,y,z)" },
-    { GIMP_PDB_FLOAT,    "viewpoint-y",           "Position of viewpoint (x,y,z)" },
-    { GIMP_PDB_FLOAT,    "viewpoint-z",           "Position of viewpoint (x,y,z)" },
-    { GIMP_PDB_FLOAT,    "position-x",            "Object position (x,y,z)" },
-    { GIMP_PDB_FLOAT,    "position-y",            "Object position (x,y,z)" },
-    { GIMP_PDB_FLOAT,    "position-z",            "Object position (x,y,z)" },
-    { GIMP_PDB_FLOAT,    "firstaxis-x",           "First axis of object [x,y,z]" },
-    { GIMP_PDB_FLOAT,    "firstaxis-y",           "First axis of object [x,y,z]" },
-    { GIMP_PDB_FLOAT,    "firstaxis-z",           "First axis of object [x,y,z]" },
-    { GIMP_PDB_FLOAT,    "secondaxis-x",          "Second axis of object [x,y,z]" },
-    { GIMP_PDB_FLOAT,    "secondaxis-y",          "Second axis of object [x,y,z]" },
-    { GIMP_PDB_FLOAT,    "secondaxis-z",          "Second axis of object [x,y,z]" },
-    { GIMP_PDB_FLOAT,    "rotationangle-x",       "Rotation about X axis in degrees" },
-    { GIMP_PDB_FLOAT,    "rotationangle-y",       "Rotation about Y axis in degrees" },
-    { GIMP_PDB_FLOAT,    "rotationangle-z",       "Rotation about Z axis in degrees" },
-    { GIMP_PDB_INT32,    "lighttype",             "Type of lightsource (0=point,1=directional,2=none)" },
-    { GIMP_PDB_COLOR,    "lightcolor",            "Lightsource color (r,g,b)" },
-    { GIMP_PDB_FLOAT,    "lightposition-x",       "Lightsource position (x,y,z)" },
-    { GIMP_PDB_FLOAT,    "lightposition-y",       "Lightsource position (x,y,z)" },
-    { GIMP_PDB_FLOAT,    "lightposition-z",       "Lightsource position (x,y,z)" },
-    { GIMP_PDB_FLOAT,    "lightdirection-x",      "Lightsource direction [x,y,z]" },
-    { GIMP_PDB_FLOAT,    "lightdirection-y",      "Lightsource direction [x,y,z]" },
-    { GIMP_PDB_FLOAT,    "lightdirection-z",      "Lightsource direction [x,y,z]" },
-    { GIMP_PDB_FLOAT,    "ambient_intensity",     "Material ambient intensity (0..1)" },
-    { GIMP_PDB_FLOAT,    "diffuse_intensity",     "Material diffuse intensity (0..1)" },
-    { GIMP_PDB_FLOAT,    "diffuse_reflectivity",  "Material diffuse reflectivity (0..1)" },
-    { GIMP_PDB_FLOAT,    "specular_reflectivity", "Material specular reflectivity (0..1)" },
-    { GIMP_PDB_FLOAT,    "highlight",             "Material highlight (0..->), note: it's exponential" },
-    { GIMP_PDB_INT32,    "antialiasing",          "Apply antialiasing (TRUE/FALSE)" },
-    { GIMP_PDB_INT32,    "tiled",                 "Tile source image (TRUE/FALSE)" },
-    { GIMP_PDB_INT32,    "newimage",              "Create a new image (TRUE/FALSE)" },
-    { GIMP_PDB_INT32,    "transparentbackground", "Make background transparent (TRUE/FALSE)" },
-    { GIMP_PDB_FLOAT,    "radius",                "Sphere/cylinder radius (only used when maptype=1 or 3)" },
-    { GIMP_PDB_FLOAT,    "x-scale",               "Box x size (0..->)" },
-    { GIMP_PDB_FLOAT,    "y-scale",               "Box y size (0..->)" },
-    { GIMP_PDB_FLOAT,    "z-scale",               "Box z size (0..->)"},
-    { GIMP_PDB_FLOAT,    "cylinder-length",       "Cylinder length (0..->)"},
-    { GIMP_PDB_DRAWABLE, "box-front-drawable",    "Box front face (set these to -1 if not used)" },
-    { GIMP_PDB_DRAWABLE, "box-back-drawable",     "Box back face" },
-    { GIMP_PDB_DRAWABLE, "box-top-drawable",      "Box top face" },
-    { GIMP_PDB_DRAWABLE, "box-bottom-drawable",   "Box bottom face" },
-    { GIMP_PDB_DRAWABLE, "box-left-drawable",     "Box left face" },
-    { GIMP_PDB_DRAWABLE, "box-right-drawable",    "Box right face" },
-    { GIMP_PDB_DRAWABLE, "cyl-top-drawable",      "Cylinder top face (set these to -1 if not used)" },
-    { GIMP_PDB_DRAWABLE, "cyl-bottom-drawable",   "Cylinder bottom face" }
-  };
-
-  gimp_install_procedure (PLUG_IN_PROC,
-                          N_("Map the image to an object (plane, sphere, box or cylinder)"),
-                          "No help yet",
-                          "Tom Bech & Federico Mena Quintero",
-                          "Tom Bech & Federico Mena Quintero",
-                          "Version 1.2.0, July 16 1998",
-                          N_("Map _Object..."),
-                          "RGB*",
-                          GIMP_PDB_PROC_TYPE_PLUGIN,
-                          G_N_ELEMENTS (args), 0,
-                          args, NULL);
-
-  gimp_plugin_menu_register (PLUG_IN_PROC, "<Image>/Filters/Map");
-}
-
-static void
-run (const gchar      *name,
-     gint              nparams,
-     const GimpParam  *param,
-     gint             *nreturn_vals,
-     GimpParam       **return_vals)
+static GimpValueArray *
+map_run (GimpProcedure        *procedure,
+         GimpRunMode           run_mode,
+         GimpImage            *_image,
+         GimpDrawable         *drawable,
+         const GimpValueArray *args,
+         gpointer              run_data)
 {
-  static GimpParam   values[1];
-  GimpRunMode        run_mode;
-  GimpDrawable      *drawable;
-  GimpPDBStatusType  status = GIMP_PDB_SUCCESS;
-  gint               i;
+  GimpDrawable *side;
+  gint          i;
 
   INIT_I18N ();
+  gegl_init (NULL, NULL);
 
-  values[0].type = GIMP_PDB_STATUS;
-  values[0].data.d_status = status;
-
-  *nreturn_vals = 1;
-  *return_vals = values;
-
-  /* Set default values */
-  /* ================== */
+  image = _image;
 
   set_default_settings ();
 
-  /* Get the specified drawable */
-  /* ========================== */
-
-  run_mode = param[0].data.d_int32;
-  image    = gimp_image_get_by_id (param[1].data.d_int32);
-  drawable = gimp_drawable_get_by_id (param[2].data.d_int32);
-
   switch (run_mode)
     {
-      case GIMP_RUN_INTERACTIVE:
-
-        /* Possibly retrieve data */
-        /* ====================== */
-
-        gimp_get_data (PLUG_IN_PROC, &mapvals);
-        check_drawables (drawable);
-        if (main_dialog (drawable))
-          {
-            compute_image ();
-
-            gimp_set_data (PLUG_IN_PROC, &mapvals, sizeof (MapObjectValues));
-          }
-        break;
-
-      case GIMP_RUN_WITH_LAST_VALS:
-        gimp_get_data (PLUG_IN_PROC, &mapvals);
-        check_drawables (drawable);
-        if (image_setup (drawable, FALSE))
-          compute_image ();
-        break;
-
-      case GIMP_RUN_NONINTERACTIVE:
-        if (nparams != 49)
-          {
-            status = GIMP_PDB_CALLING_ERROR;
-          }
-        else
-          {
-            mapvals.maptype                 = (MapType) param[3].data.d_int32;
-            mapvals.viewpoint.x             = param[4].data.d_float;
-            mapvals.viewpoint.y             = param[5].data.d_float;
-            mapvals.viewpoint.z             = param[6].data.d_float;
-            mapvals.position.x              = param[7].data.d_float;
-            mapvals.position.y              = param[8].data.d_float;
-            mapvals.position.z              = param[9].data.d_float;
-            mapvals.firstaxis.x             = param[10].data.d_float;
-            mapvals.firstaxis.y             = param[11].data.d_float;
-            mapvals.firstaxis.z             = param[12].data.d_float;
-            mapvals.secondaxis.x            = param[13].data.d_float;
-            mapvals.secondaxis.y            = param[14].data.d_float;
-            mapvals.secondaxis.z            = param[15].data.d_float;
-            mapvals.alpha                   = param[16].data.d_float;
-            mapvals.beta                    = param[17].data.d_float;
-            mapvals.gamma                   = param[18].data.d_float;
-            mapvals.lightsource.type        = (LightType) param[19].data.d_int32;
-            mapvals.lightsource.color       = param[20].data.d_color;
-            mapvals.lightsource.position.x  = param[21].data.d_float;
-            mapvals.lightsource.position.y  = param[22].data.d_float;
-            mapvals.lightsource.position.z  = param[23].data.d_float;
-            mapvals.lightsource.direction.x = param[24].data.d_float;
-            mapvals.lightsource.direction.y = param[25].data.d_float;
-            mapvals.lightsource.direction.z = param[26].data.d_float;
-            mapvals.material.ambient_int    = param[27].data.d_float;
-            mapvals.material.diffuse_int    = param[28].data.d_float;
-            mapvals.material.diffuse_ref    = param[29].data.d_float;
-            mapvals.material.specular_ref   = param[30].data.d_float;
-            mapvals.material.highlight      = param[31].data.d_float;
-            mapvals.antialiasing            = (gint) param[32].data.d_int32;
-            mapvals.tiled                   = (gint) param[33].data.d_int32;
-            mapvals.create_new_image        = (gint) param[34].data.d_int32;
-            mapvals.transparent_background  = (gint) param[35].data.d_int32;
-            mapvals.radius                  = param[36].data.d_float;
-            mapvals.cylinder_radius         = param[36].data.d_float;
-            mapvals.scale.x                 = param[37].data.d_float;
-            mapvals.scale.y                 = param[38].data.d_float;
-            mapvals.scale.z                 = param[39].data.d_float;
-            mapvals.cylinder_length         = param[40].data.d_float;
-
-            for (i = 0; i < 6; i++)
-              mapvals.boxmap_id[i] = param[41+i].data.d_drawable;
-
-            for (i = 0; i < 2; i++)
-              mapvals.cylindermap_id[i] = param[47+i].data.d_drawable;
-
-            check_drawables (drawable);
-            if (image_setup (drawable, FALSE))
-              compute_image ();
-          }
-        break;
+    case GIMP_RUN_INTERACTIVE:
+      gimp_get_data (PLUG_IN_PROC, &mapvals);
+      check_drawables (drawable);
+
+      if (! main_dialog (drawable))
+        {
+          return gimp_procedure_new_return_values (procedure,
+                                                   GIMP_PDB_CANCEL,
+                                                   NULL);
+        }
+
+      compute_image ();
+
+      gimp_set_data (PLUG_IN_PROC, &mapvals, sizeof (MapObjectValues));
+      break;
+
+    case GIMP_RUN_WITH_LAST_VALS:
+      gimp_get_data (PLUG_IN_PROC, &mapvals);
+      check_drawables (drawable);
+
+      if (! image_setup (drawable, FALSE))
+        {
+          return gimp_procedure_new_return_values (procedure,
+                                                   GIMP_PDB_SUCCESS,
+                                                   NULL);
+        }
+
+      compute_image ();
+      break;
+
+    case GIMP_RUN_NONINTERACTIVE:
+      mapvals.maptype                 = GIMP_VALUES_GET_INT     (args, 0);
+      mapvals.viewpoint.x             = GIMP_VALUES_GET_DOUBLE  (args, 1);
+      mapvals.viewpoint.y             = GIMP_VALUES_GET_DOUBLE  (args, 2);
+      mapvals.viewpoint.z             = GIMP_VALUES_GET_DOUBLE  (args, 3);
+      mapvals.position.x              = GIMP_VALUES_GET_DOUBLE  (args, 4);
+      mapvals.position.y              = GIMP_VALUES_GET_DOUBLE  (args, 5);
+      mapvals.position.z              = GIMP_VALUES_GET_DOUBLE  (args, 6);
+      mapvals.firstaxis.x             = GIMP_VALUES_GET_DOUBLE  (args, 7);
+      mapvals.firstaxis.y             = GIMP_VALUES_GET_DOUBLE  (args, 8);
+      mapvals.firstaxis.z             = GIMP_VALUES_GET_DOUBLE  (args, 9);
+      mapvals.secondaxis.x            = GIMP_VALUES_GET_DOUBLE  (args, 10);
+      mapvals.secondaxis.y            = GIMP_VALUES_GET_DOUBLE  (args, 11);
+      mapvals.secondaxis.z            = GIMP_VALUES_GET_DOUBLE  (args, 12);
+      mapvals.alpha                   = GIMP_VALUES_GET_DOUBLE  (args, 13);
+      mapvals.beta                    = GIMP_VALUES_GET_DOUBLE  (args, 14);
+      mapvals.gamma                   = GIMP_VALUES_GET_DOUBLE  (args, 15);
+      mapvals.lightsource.type        = GIMP_VALUES_GET_INT     (args, 16);
+
+      GIMP_VALUES_GET_RGB (args, 0, &mapvals.lightsource.color);
+
+      mapvals.lightsource.position.x  = GIMP_VALUES_GET_DOUBLE  (args, 17);
+      mapvals.lightsource.position.y  = GIMP_VALUES_GET_DOUBLE  (args, 18);
+      mapvals.lightsource.position.z  = GIMP_VALUES_GET_DOUBLE  (args, 19);
+      mapvals.lightsource.direction.x = GIMP_VALUES_GET_DOUBLE  (args, 20);
+      mapvals.lightsource.direction.y = GIMP_VALUES_GET_DOUBLE  (args, 21);
+      mapvals.lightsource.direction.z = GIMP_VALUES_GET_DOUBLE  (args, 22);
+      mapvals.material.ambient_int    = GIMP_VALUES_GET_DOUBLE  (args, 23);
+      mapvals.material.diffuse_int    = GIMP_VALUES_GET_DOUBLE  (args, 24);
+      mapvals.material.diffuse_ref    = GIMP_VALUES_GET_DOUBLE  (args, 25);
+      mapvals.material.specular_ref   = GIMP_VALUES_GET_DOUBLE  (args, 26);
+      mapvals.material.highlight      = GIMP_VALUES_GET_DOUBLE  (args, 27);
+      mapvals.antialiasing            = GIMP_VALUES_GET_BOOLEAN (args, 28);
+      mapvals.tiled                   = GIMP_VALUES_GET_BOOLEAN (args, 29);
+      mapvals.create_new_image        = GIMP_VALUES_GET_BOOLEAN (args, 30);
+      mapvals.transparent_background  = GIMP_VALUES_GET_BOOLEAN (args, 31);
+      mapvals.radius                  = GIMP_VALUES_GET_DOUBLE  (args, 32);
+      mapvals.cylinder_radius         = GIMP_VALUES_GET_DOUBLE  (args, 33);
+      mapvals.scale.x                 = GIMP_VALUES_GET_DOUBLE  (args, 34);
+      mapvals.scale.y                 = GIMP_VALUES_GET_DOUBLE  (args, 35);
+      mapvals.scale.z                 = GIMP_VALUES_GET_DOUBLE  (args, 36);
+      mapvals.cylinder_length         = GIMP_VALUES_GET_DOUBLE  (args, 37);
+
+      for (i = 0; i < 6; i++)
+        {
+          side = GIMP_VALUES_GET_DRAWABLE (args, 38 + i);
+
+          mapvals.boxmap_id[i] = gimp_item_get_id (GIMP_ITEM (side));
+        }
+
+      for (i = 0; i < 2; i++)
+        {
+          side = GIMP_VALUES_GET_DRAWABLE (args, 44 + i);
+
+          mapvals.cylindermap_id[i] = gimp_item_get_id (GIMP_ITEM (side));
+        }
+
+      check_drawables (drawable);
+
+      if (! image_setup (drawable, FALSE))
+        {
+          return gimp_procedure_new_return_values (procedure,
+                                                   GIMP_PDB_SUCCESS,
+                                                   NULL);
+        }
+
+      compute_image ();
+      break;
     }
 
-  values[0].data.d_status = status;
-
   if (run_mode != GIMP_RUN_NONINTERACTIVE)
     gimp_displays_flush ();
-}
-
-const GimpPlugInInfo PLUG_IN_INFO =
-{
-  NULL,  /* init_proc  */
-  NULL,  /* quit_proc  */
-  query, /* query_proc */
-  run,   /* run_proc   */
-};
 
-MAIN ()
+  return gimp_procedure_new_return_values (procedure, GIMP_PDB_SUCCESS, NULL);
+}


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