コード例 #1
0
ファイル: gimpimageeditor.c プロジェクト: jiapei100/gimp
static void
gimp_image_editor_set_context (GimpDocked  *docked,
                               GimpContext *context)
{
  GimpImageEditor *editor = GIMP_IMAGE_EDITOR (docked);
  GimpImage       *image  = NULL;

  if (editor->context)
    {
      g_signal_handlers_disconnect_by_func (editor->context,
                                            gimp_image_editor_set_image,
                                            editor);

      g_object_unref (editor->context);
    }

  editor->context = context;

  if (context)
    {
      g_object_ref (editor->context);

      g_signal_connect_swapped (context, "image-changed",
                                G_CALLBACK (gimp_image_editor_set_image),
                                editor);

      image = gimp_context_get_image (context);
    }

  gimp_image_editor_set_image (editor, image);
}
コード例 #2
0
ファイル: images-commands.c プロジェクト: 1ynx/gimp
void
images_raise_views_cmd_callback (GtkAction *action,
                                 gpointer   data)
{
  GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (data);
  GimpContainer       *container;
  GimpContext         *context;
  GimpImage           *image;

  container = gimp_container_view_get_container (editor->view);
  context   = gimp_container_view_get_context (editor->view);

  image = gimp_context_get_image (context);

  if (image && gimp_container_have (container, GIMP_OBJECT (image)))
    {
      GList *list;

      for (list = gimp_get_display_iter (image->gimp);
           list;
           list = g_list_next (list))
        {
          GimpDisplay *display = list->data;

          if (gimp_display_get_image (display) == image)
            gimp_display_shell_present (gimp_display_get_shell (display));
        }
    }
}
コード例 #3
0
ファイル: buffers-commands.c プロジェクト: 1ynx/gimp
void
buffers_paste_as_new_cmd_callback (GtkAction *action,
                                   gpointer   data)
{
  GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (data);
  GimpContainer       *container;
  GimpContext         *context;
  GimpBuffer          *buffer;

  container = gimp_container_view_get_container (editor->view);
  context   = gimp_container_view_get_context (editor->view);

  buffer = gimp_context_get_buffer (context);

  if (buffer && gimp_container_have (container, GIMP_OBJECT (buffer)))
    {
      GimpImage *image = gimp_context_get_image (context);

      if (image)
        {
          GimpImage *new_image;

          new_image = gimp_image_new_from_buffer (image->gimp, image, buffer);
          gimp_create_display (image->gimp, new_image,
                               GIMP_UNIT_PIXEL, 1.0);
          g_object_unref (new_image);
        }
    }
}
コード例 #4
0
GtkWidget *
gimp_toolbox_image_area_create (GimpToolbox *toolbox,
                                gint         width,
                                gint         height)
{
  GimpContext *context;
  GtkWidget   *image_view;
  gchar       *tooltip;

  g_return_val_if_fail (GIMP_IS_TOOLBOX (toolbox), NULL);

  context = gimp_toolbox_get_context (toolbox);

  image_view = gimp_view_new_full_by_types (context,
                                            GIMP_TYPE_VIEW, GIMP_TYPE_IMAGE,
                                            width, height, 0,
                                            FALSE, TRUE, TRUE);

  g_signal_connect (image_view, "set-viewable",
                    G_CALLBACK (image_preview_set_viewable),
                    NULL);

  gimp_view_set_viewable (GIMP_VIEW (image_view),
                          GIMP_VIEWABLE (gimp_context_get_image (context)));

  gtk_widget_show (image_view);

#ifdef GDK_WINDOWING_X11
  tooltip = g_strdup_printf ("%s\n%s",
                             _("The active image.\n"
                               "Click to open the Image Dialog."),
                             _("Drag to an XDS enabled file-manager to "
                               "save the image."));
#else
  tooltip = g_strdup (_("The active image.\n"
                        "Click to open the Image Dialog."));
#endif

  gimp_help_set_help_data (image_view, tooltip,
                           GIMP_HELP_TOOLBOX_IMAGE_AREA);
  g_free (tooltip);

  g_signal_connect_object (context, "image-changed",
                           G_CALLBACK (gimp_view_set_viewable),
                           image_view, G_CONNECT_SWAPPED);

  g_signal_connect (image_view, "clicked",
                    G_CALLBACK (image_preview_clicked),
                    toolbox);

  gimp_dnd_viewable_dest_add (image_view,
                              GIMP_TYPE_IMAGE,
                              image_preview_drop_image,
                              context);

  return image_view;
}
コード例 #5
0
ファイル: plug-in-actions.c プロジェクト: jiapei100/gimp
static void
plug_in_actions_add_proc (GimpActionGroup     *group,
                          GimpPlugInProcedure *proc)
{
  GimpProcedureActionEntry  entry;
  const gchar              *locale_domain;
  GList                    *list;

  locale_domain = gimp_plug_in_procedure_get_locale_domain (proc);

  entry.name        = gimp_object_get_name (proc);
  entry.icon_name   = gimp_viewable_get_icon_name (GIMP_VIEWABLE (proc));
  entry.label       = gimp_procedure_get_menu_label (GIMP_PROCEDURE (proc));
  entry.accelerator = NULL;
  entry.tooltip     = gimp_procedure_get_blurb (GIMP_PROCEDURE (proc));
  entry.procedure   = GIMP_PROCEDURE (proc);
  entry.help_id     = gimp_procedure_get_help_id (GIMP_PROCEDURE (proc));

  gimp_action_group_add_procedure_actions (group, &entry, 1,
                                           G_CALLBACK (plug_in_run_cmd_callback));

  for (list = proc->menu_paths; list; list = g_list_next (list))
    {
      const gchar *original   = list->data;
      const gchar *translated = dgettext (locale_domain, original);

      if (plug_in_actions_check_translation (original, translated))
        plug_in_actions_build_path (group, original, translated);
      else
        plug_in_actions_build_path (group, original, original);
    }

  if (proc->image_types_val)
    {
      GimpContext  *context  = gimp_get_user_context (group->gimp);
      GimpImage    *image    = gimp_context_get_image (context);
      GimpDrawable *drawable = NULL;
      gboolean      sensitive;
      const gchar  *tooltip;

      if (image)
        drawable = gimp_image_get_active_drawable (image);

      sensitive = gimp_procedure_get_sensitive (GIMP_PROCEDURE (proc),
                                                GIMP_OBJECT (drawable),
                                                &tooltip);

      gimp_action_group_set_action_sensitive (group,
                                              gimp_object_get_name (proc),
                                              sensitive);

      if (! sensitive && drawable && tooltip)
        gimp_action_group_set_action_tooltip (group,
                                              gimp_object_get_name (proc),
                                              tooltip);
    }
}
コード例 #6
0
GtkWidget *
dialogs_vectors_list_view_new (GimpDialogFactory *factory,
                               GimpContext       *context,
                               GimpUIManager     *ui_manager,
                               gint               view_size)
{
  if (view_size < 1)
    view_size = context->gimp->config->layer_preview_size;

  return gimp_item_tree_view_new (GIMP_TYPE_VECTORS_TREE_VIEW,
                                  view_size, 1,
                                  gimp_context_get_image (context),
                                  gimp_dialog_factory_get_menu_factory (factory),
                                  "<Vectors>",
                                  "/vectors-popup");
}
コード例 #7
0
ファイル: buffers-commands.c プロジェクト: 1ynx/gimp
static void
buffers_paste (GimpBufferView *view,
               gboolean        paste_into)
{
  GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (view);
  GimpContainer       *container;
  GimpContext         *context;
  GimpBuffer          *buffer;

  container = gimp_container_view_get_container (editor->view);
  context   = gimp_container_view_get_context (editor->view);

  buffer = gimp_context_get_buffer (context);

  if (buffer && gimp_container_have (container, GIMP_OBJECT (buffer)))
    {
      GimpDisplay *display = gimp_context_get_display (context);
      GimpImage   *image   = NULL;
      gint         x       = -1;
      gint         y       = -1;
      gint         width   = -1;
      gint         height  = -1;

      if (display)
        {
          GimpDisplayShell *shell = gimp_display_get_shell (display);

          gimp_display_shell_untransform_viewport (shell,
                                                   &x, &y, &width, &height);

          image = gimp_display_get_image (display);
        }
      else
        {
          image = gimp_context_get_image (context);
        }

      if (image)
        {
          gimp_edit_paste (image, gimp_image_get_active_drawable (image),
                           buffer, paste_into, x, y, width, height);

          gimp_image_flush (image);
        }
    }
}
コード例 #8
0
ファイル: gimpcroptool.c プロジェクト: AjayRamanathan/gimp
static void
gimp_crop_tool_constructed (GObject *object)
{
  GimpCropTool    *crop_tool = GIMP_CROP_TOOL (object);
  GimpCropOptions *options;
  GimpContext     *gimp_context;
  GimpToolInfo    *tool_info;

  G_OBJECT_CLASS (parent_class)->constructed (object);

  gimp_rectangle_tool_constructor (object);

  tool_info = GIMP_TOOL (crop_tool)->tool_info;

  gimp_context = gimp_get_user_context (tool_info->gimp);

  g_signal_connect_object (gimp_context, "image-changed",
                           G_CALLBACK (gimp_crop_tool_image_changed),
                           crop_tool,
                           G_CONNECT_SWAPPED);

  /* Make sure we are connected to "size-changed" for the initial
   * image.
   */
  gimp_crop_tool_image_changed (crop_tool,
                                gimp_context_get_image (gimp_context),
                                gimp_context);


  options = GIMP_CROP_TOOL_GET_OPTIONS (object);

  g_signal_connect_object (options, "notify::layer-only",
                           G_CALLBACK (gimp_crop_tool_options_notify),
                           object, 0);

  g_signal_connect_object (options, "notify::allow-growing",
                           G_CALLBACK (gimp_crop_tool_options_notify),
                           object, 0);

  gimp_rectangle_tool_set_constraint (GIMP_RECTANGLE_TOOL (object),
                                      gimp_crop_tool_get_constraint (crop_tool));

  gimp_crop_tool_update_option_defaults (crop_tool, FALSE);
}
コード例 #9
0
ファイル: images-commands.c プロジェクト: 1ynx/gimp
void
images_new_view_cmd_callback (GtkAction *action,
                              gpointer   data)
{
  GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (data);
  GimpContainer       *container;
  GimpContext         *context;
  GimpImage           *image;

  container = gimp_container_view_get_container (editor->view);
  context   = gimp_container_view_get_context (editor->view);

  image = gimp_context_get_image (context);

  if (image && gimp_container_have (container, GIMP_OBJECT (image)))
    {
      gimp_create_display (image->gimp, image, GIMP_UNIT_PIXEL, 1.0);
    }
}
コード例 #10
0
ファイル: images-commands.c プロジェクト: 1ynx/gimp
void
images_delete_image_cmd_callback (GtkAction *action,
                                  gpointer   data)
{
  GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (data);
  GimpContainer       *container;
  GimpContext         *context;
  GimpImage           *image;

  container = gimp_container_view_get_container (editor->view);
  context   = gimp_container_view_get_context (editor->view);

  image = gimp_context_get_image (context);

  if (image && gimp_container_have (container, GIMP_OBJECT (image)))
    {
      if (gimp_image_get_display_count (image) == 0)
        g_object_unref (image);
    }
}
コード例 #11
0
static void
gui_display_changed (GimpContext *context,
                     GimpDisplay *display,
                     Gimp        *gimp)
{
  if (! display)
    {
      GimpImage *image = gimp_context_get_image (context);

      if (image)
        {
          GList *list;

          for (list = gimp_get_display_iter (gimp);
               list;
               list = g_list_next (list))
            {
              GimpDisplay *display2 = list->data;

              if (gimp_display_get_image (display2) == image)
                {
                  gimp_context_set_display (context, display2);

                  /* stop the emission of the original signal
                   * (the emission of the recursive signal is finished)
                   */
                  g_signal_stop_emission_by_name (context, "display-changed");
                  return;
                }
            }

          gimp_context_set_image (context, NULL);
        }
    }

  gimp_ui_manager_update (image_ui_manager, display);
}
コード例 #12
0
ファイル: actions.c プロジェクト: jiapei100/gimp
GimpImage *
action_data_get_image (gpointer data)
{
  GimpImage       *result    = NULL;
  static gboolean  recursion = FALSE;

  if (! data || recursion)
    return NULL;

  recursion = TRUE;

  if (GIMP_IS_ITEM_TREE_VIEW (data))
    result = gimp_item_tree_view_get_image ((GimpItemTreeView *) data);
  else if (GIMP_IS_IMAGE_EDITOR (data))
    result = ((GimpImageEditor *) data)->image;

  if (! result)
    {
      GimpDisplay *display = action_data_get_display (data);

      if (display)
        result = gimp_display_get_image (display);
    }

  if (! result)
    {
      GimpContext *context = action_data_get_context (data);

      if (context)
        result = gimp_context_get_image (context);
    }

  recursion = FALSE;

  return result;
}
コード例 #13
0
static void
palette_import_image_callback (GtkWidget    *widget,
                               ImportDialog *dialog)
{
  GimpImage *image;

  if (! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
    return;

  dialog->import_type = IMAGE_IMPORT;

  image = gimp_context_get_image (dialog->context);

  if (! image)
    {
      GimpContainer *images = dialog->context->gimp->images;

      image = GIMP_IMAGE (gimp_container_get_first_child (images));
    }

  palette_import_set_sensitive (dialog);

  palette_import_image_changed (dialog->context, image, dialog);
}
コード例 #14
0
static void
palette_import_make_palette (ImportDialog *dialog)
{
  GimpPalette  *palette = NULL;
  const gchar  *palette_name;
  gint          n_colors;
  gint          n_columns;
  gint          threshold;

  palette_name = gtk_entry_get_text (GTK_ENTRY (dialog->entry));

  if (! palette_name || ! strlen (palette_name))
    palette_name = _("Untitled");

  n_colors  = ROUND (gtk_adjustment_get_value (dialog->num_colors));
  n_columns = ROUND (gtk_adjustment_get_value (dialog->columns));
  threshold = ROUND (gtk_adjustment_get_value (dialog->threshold));

  switch (dialog->import_type)
    {
    case GRADIENT_IMPORT:
      {
        GimpGradient *gradient;

        gradient = gimp_context_get_gradient (dialog->context);

        palette = gimp_palette_import_from_gradient (gradient,
                                                     dialog->context,
                                                     FALSE,
                                                     palette_name,
                                                     n_colors);
      }
      break;

    case IMAGE_IMPORT:
      {
        GimpImage *image = gimp_context_get_image (dialog->context);
        gboolean   sample_merged;
        gboolean   selection_only;

        sample_merged =
          gtk_toggle_button_get_active
          (GTK_TOGGLE_BUTTON (dialog->sample_merged_toggle));

        selection_only =
          gtk_toggle_button_get_active
          (GTK_TOGGLE_BUTTON (dialog->selection_only_toggle));

        if (gimp_image_get_base_type (image) == GIMP_INDEXED)
          {
            palette = gimp_palette_import_from_indexed_image (image,
                                                              dialog->context,
                                                              palette_name);
          }
        else if (sample_merged)
          {
            palette = gimp_palette_import_from_image (image,
                                                      dialog->context,
                                                      palette_name,
                                                      n_colors,
                                                      threshold,
                                                      selection_only);
          }
        else
          {
            GimpDrawable *drawable;

            drawable = GIMP_DRAWABLE (gimp_image_get_active_layer (image));

            palette = gimp_palette_import_from_drawable (drawable,
                                                         dialog->context,
                                                         palette_name,
                                                         n_colors,
                                                         threshold,
                                                         selection_only);
          }
      }
      break;

    case FILE_IMPORT:
      {
        GFile  *file;
        GError *error = NULL;

        file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog->file_chooser));

        palette = gimp_palette_import_from_file (dialog->context,
                                                 file,
                                                 palette_name, &error);
        g_object_unref (file);

        if (! palette)
          {
            gimp_message_literal (dialog->context->gimp,
                                  G_OBJECT (dialog->dialog), GIMP_MESSAGE_ERROR,
                                  error->message);
            g_error_free (error);
          }
      }
      break;
    }

  if (palette)
    {
      if (dialog->palette)
        g_object_unref (dialog->palette);

      gimp_palette_set_columns (palette, n_columns);

      gimp_view_set_viewable (GIMP_VIEW (dialog->preview),
                              GIMP_VIEWABLE (palette));

      dialog->palette = palette;
    }

  gtk_widget_set_visible (dialog->no_colors_label,
                          dialog->palette &&
                          gimp_palette_get_n_colors (dialog->palette) > 0);
}