Exemplo n.º 1
0
static gint
plug_in_collect_display_args (GtkAction       *action,
                              GimpDisplay     *display,
                              GParamSpec     **pspecs,
                              GimpValueArray  *args,
                              gint             n_args)
{
  if (gimp_value_array_length (args) > n_args &&
      GIMP_IS_PARAM_SPEC_DISPLAY_ID (pspecs[n_args]))
    {
      if (display)
        {
          gimp_value_set_display (gimp_value_array_index (args, n_args),
                                  GIMP_OBJECT (display));
          n_args++;
        }
      else
        {
          g_warning ("Uh-oh, no active display for the plug-in!");
          return -1;
        }
    }

  if (gimp_value_array_length (args) > n_args &&
      GIMP_IS_PARAM_SPEC_IMAGE_ID (pspecs[n_args]))
    {
      GimpImage *image = display ? gimp_display_get_image (display) : NULL;

      if (image)
        {
          gimp_value_set_image (gimp_value_array_index (args, n_args),
                                image);
          n_args++;

          if (gimp_value_array_length (args) > n_args &&
              GIMP_IS_PARAM_SPEC_DRAWABLE_ID (pspecs[n_args]))
            {
              GimpDrawable *drawable = gimp_image_get_active_drawable (image);

              if (drawable)
                {
                  gimp_value_set_drawable (gimp_value_array_index (args, n_args),
                                           drawable);
                  n_args++;
                }
              else
                {
                  g_warning ("Uh-oh, no active drawable for the plug-in!");
                  return -1;
                }
            }
        }
    }

  return n_args;
}
Exemplo n.º 2
0
static GValueArray *
display_new_invoker (GimpProcedure      *procedure,
                     Gimp               *gimp,
                     GimpContext        *context,
                     GimpProgress       *progress,
                     const GValueArray  *args,
                     GError            **error)
{
  gboolean success = TRUE;
  GValueArray *return_vals;
  GimpImage *image;
  GimpObject *display = NULL;

  image = gimp_value_get_image (&args->values[0], gimp);

  if (success)
    {
      gimp_image_flush (image);

      display = gimp_create_display (gimp, image, GIMP_UNIT_PIXEL, 1.0);

      if (display)
        {
          /* the first display takes ownership of the image */
          if (image->disp_count == 1)
            g_object_unref (image);
        }
      else
        {
          success = FALSE;
        }
    }

  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);

  if (success)
    gimp_value_set_display (&return_vals->values[1], display);

  return return_vals;
}
Exemplo n.º 3
0
GimpValueArray *
procedure_commands_get_display_args (GimpProcedure *procedure,
                                     GimpDisplay   *display)
{
  GimpValueArray *args;
  gint            n_args = 0;

  args = gimp_procedure_get_arguments (procedure);

  /* initialize the first argument  */
  g_value_set_int (gimp_value_array_index (args, n_args),
                   GIMP_RUN_INTERACTIVE);
  n_args++;

  if (gimp_value_array_length (args) > n_args &&
      GIMP_IS_PARAM_SPEC_DISPLAY_ID (procedure->args[n_args]))
    {
      if (display)
        {
          gimp_value_set_display (gimp_value_array_index (args, n_args),
                                  GIMP_OBJECT (display));
          n_args++;
        }
      else
        {
          g_warning ("Uh-oh, no active display for the plug-in!");
          gimp_value_array_unref (args);
          return NULL;
        }
    }

  if (gimp_value_array_length (args) > n_args &&
      GIMP_IS_PARAM_SPEC_IMAGE_ID (procedure->args[n_args]))
    {
      GimpImage *image = display ? gimp_display_get_image (display) : NULL;

      if (image)
        {
          gimp_value_set_image (gimp_value_array_index (args, n_args),
                                image);
          n_args++;

          if (gimp_value_array_length (args) > n_args &&
              GIMP_IS_PARAM_SPEC_DRAWABLE_ID (procedure->args[n_args]))
            {
              GimpDrawable *drawable = gimp_image_get_active_drawable (image);

              if (drawable)
                {
                  gimp_value_set_drawable (gimp_value_array_index (args, n_args),
                                           drawable);
                  n_args++;
                }
              else
                {
                  g_warning ("Uh-oh, no active drawable for the plug-in!");
                  gimp_value_array_unref (args);
                  return NULL;
                }
            }
        }
    }

  gimp_value_array_truncate (args, n_args);

  return args;
}