コード例 #1
0
static void
tool_manager_preset_changed (GimpContext     *user_context,
                             GimpToolPreset  *preset,
                             GimpToolManager *tool_manager)
{
  GimpToolInfo *preset_tool;
  gboolean      tool_change = FALSE;

  if (! preset || user_context->gimp->busy)
    return;

  preset_tool = gimp_context_get_tool (GIMP_CONTEXT (preset->tool_options));

  if (preset_tool != gimp_context_get_tool (user_context))
    tool_change = TRUE;

  if (! tool_change)
    tool_manager_disconnect_options (user_context, preset_tool);

  gimp_config_copy (GIMP_CONFIG (preset->tool_options),
                    GIMP_CONFIG (preset_tool->tool_options), 0);

  if (tool_change)
    gimp_context_set_tool (user_context, preset_tool);
  else
    tool_manager_connect_options (user_context, preset_tool);

  gimp_context_copy_properties (GIMP_CONTEXT (preset->tool_options),
                                user_context,
                                gimp_tool_preset_get_prop_mask (preset));
}
コード例 #2
0
ファイル: tool_manager.c プロジェクト: jiapei100/gimp
static void
tool_manager_preset_changed (GimpContext     *user_context,
                             GimpToolPreset  *preset,
                             GimpToolManager *tool_manager)
{
  GimpToolInfo *preset_tool;
  gchar        *options_name;
  gboolean      tool_change = FALSE;

  if (! preset || user_context->gimp->busy)
    return;

  preset_tool = gimp_context_get_tool (GIMP_CONTEXT (preset->tool_options));

  if (preset_tool != gimp_context_get_tool (user_context))
    tool_change = TRUE;

  /*  save the name, we don't want to overwrite it  */
  options_name = g_strdup (gimp_object_get_name (preset_tool->tool_options));

  gimp_config_copy (GIMP_CONFIG (preset->tool_options),
                    GIMP_CONFIG (preset_tool->tool_options), 0);

  /*  restore the saved name  */
  gimp_object_take_name (GIMP_OBJECT (preset_tool->tool_options), options_name);

  if (tool_change)
    gimp_context_set_tool (user_context, preset_tool);

  gimp_context_copy_properties (GIMP_CONTEXT (preset->tool_options),
                                user_context,
                                gimp_tool_preset_get_prop_mask (preset));

  if (GIMP_IS_PAINT_OPTIONS (preset->tool_options))
    {
      GimpToolOptions     *src;
      GimpToolOptions     *dest;
      GimpContextPropMask  prop_mask = 0;

      src  = preset->tool_options;
      dest = tool_manager->active_tool->tool_info->tool_options;

      /*  copy various data objects' additional tool options again
       *  manually, they might have been overwritten by e.g. the "link
       *  brush stuff to brush defaults" logic in gimptooloptions.c
       */
      if (preset->use_brush)
        prop_mask |= GIMP_CONTEXT_PROP_MASK_BRUSH;

      if (preset->use_dynamics)
        prop_mask |= GIMP_CONTEXT_PROP_MASK_DYNAMICS;

      if (preset->use_gradient)
        prop_mask |= GIMP_CONTEXT_PROP_MASK_GRADIENT;

      gimp_paint_options_copy_props (GIMP_PAINT_OPTIONS (src),
                                     GIMP_PAINT_OPTIONS (dest),
                                     prop_mask);
    }
}
コード例 #3
0
void
tool_presets_save_cmd_callback (GtkAction *action,
                                gpointer   data)
{
  GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (data);
  GimpContext         *context;
  GimpToolPreset      *preset;
  GimpToolInfo        *tool_info;

  context = gimp_container_view_get_context (editor->view);

  preset    = gimp_context_get_tool_preset (context);
  tool_info = gimp_context_get_tool (gimp_get_user_context (context->gimp));

  if (tool_info && preset)
    {
      GimpToolInfo *preset_tool;

      preset_tool =  gimp_context_get_tool (GIMP_CONTEXT (preset->tool_options));

      if (tool_info != preset_tool)
        {
          gimp_message (context->gimp,
                        G_OBJECT (editor), GIMP_MESSAGE_WARNING,
                        _("Can't save '%s' tool options to an "
                          "existing '%s' tool preset."),
                        tool_info->blurb,
                        preset_tool->blurb);
          return;
        }

      gimp_config_sync (G_OBJECT (tool_info->tool_options),
                        G_OBJECT (preset->tool_options), 0);
    }
}
コード例 #4
0
void
tool_options_actions_update (GimpActionGroup *group,
                             gpointer         data)
{
  GimpContext  *context   = gimp_get_user_context (group->gimp);
  GimpToolInfo *tool_info = gimp_context_get_tool (context);

  SET_VISIBLE ("tool-options-save-preset-menu",    tool_info->presets);
  SET_VISIBLE ("tool-options-restore-preset-menu", tool_info->presets);
  SET_VISIBLE ("tool-options-edit-preset-menu",    tool_info->presets);
  SET_VISIBLE ("tool-options-delete-preset-menu",  tool_info->presets);

  tool_options_actions_update_presets (group, "tool-options-save-preset",
                                       G_CALLBACK (tool_options_save_preset_cmd_callback),
                                       GIMP_HELP_TOOL_OPTIONS_SAVE,
                                       tool_info->presets);

  tool_options_actions_update_presets (group, "tool-options-restore-preset",
                                       G_CALLBACK (tool_options_restore_preset_cmd_callback),
                                       GIMP_HELP_TOOL_OPTIONS_RESTORE,
                                       tool_info->presets);

  tool_options_actions_update_presets (group, "tool-options-edit-preset",
                                       G_CALLBACK (tool_options_edit_preset_cmd_callback),
                                       GIMP_HELP_TOOL_OPTIONS_EDIT,
                                       tool_info->presets);

  tool_options_actions_update_presets (group, "tool-options-delete-preset",
                                       G_CALLBACK (tool_options_delete_preset_cmd_callback),
                                       GIMP_HELP_TOOL_OPTIONS_DELETE,
                                       tool_info->presets);
}
コード例 #5
0
void
tool_options_reset_cmd_callback (GtkAction *action,
                                 gpointer   data)
{
    GimpEditor   *editor    = GIMP_EDITOR (data);
    GimpContext  *context   = gimp_get_user_context (gimp_editor_get_ui_manager (editor)->gimp);
    GimpToolInfo *tool_info = gimp_context_get_tool (context);

    gimp_config_reset (GIMP_CONFIG (tool_info->tool_options));
}
コード例 #6
0
ファイル: tools-commands.c プロジェクト: Distrotech/gimp
void
tools_select_cmd_callback (GtkAction   *action,
                           const gchar *value,
                           gpointer     data)
{
  Gimp         *gimp;
  GimpToolInfo *tool_info;
  GimpContext  *context;
  GimpDisplay  *display;
  gboolean      rotate_layer = FALSE;
  return_if_no_gimp (gimp, data);

  /*  special case gimp-rotate-tool being called from the Layer menu  */
  if (strcmp (value, "gimp-rotate-layer") == 0)
    {
      rotate_layer = TRUE;
      value = "gimp-rotate-tool";
    }

  tool_info = gimp_get_tool_info (gimp, value);

  context = gimp_get_user_context (gimp);

  /*  always allocate a new tool when selected from the image menu
   */
  if (gimp_context_get_tool (context) != tool_info)
    {
      gimp_context_set_tool (context, tool_info);

      if (rotate_layer)
        g_object_set (tool_info->tool_options,
                      "type", GIMP_TRANSFORM_TYPE_LAYER,
                      NULL);
    }
  else
    {
      gimp_context_tool_changed (context);
    }

  display = gimp_context_get_display (context);

  if (display && gimp_display_get_image (display))
    tool_manager_initialize_active (gimp, display);
}
コード例 #7
0
void
tool_options_edit_preset_cmd_callback (GtkAction *action,
                                       gint       value,
                                       gpointer   data)
{
    GimpEditor     *editor    = GIMP_EDITOR (data);
    Gimp           *gimp      = gimp_editor_get_ui_manager (editor)->gimp;
    GimpContext    *context   = gimp_get_user_context (gimp);
    GimpToolInfo   *tool_info = gimp_context_get_tool (context);
    GimpToolPreset *preset;

    preset = (GimpToolPreset *)
             gimp_container_get_child_by_index (tool_info->presets, value);

    if (preset)
    {
        tool_options_show_preset_editor (gimp, editor, preset);
    }
}
コード例 #8
0
ファイル: tools-commands.c プロジェクト: Amerekanets/gimp
void
tools_fg_select_brush_size_cmd_callback (GtkAction *action,
                                         gint       value,
                                         gpointer   data)
{
  GimpContext  *context;
  GimpToolInfo *tool_info;
  return_if_no_context (context, data);

  tool_info = gimp_context_get_tool (context);

  if (tool_info && GIMP_IS_FOREGROUND_SELECT_OPTIONS (tool_info->tool_options))
    {
      action_select_property ((GimpActionSelectType) value,
                              G_OBJECT (tool_info->tool_options),
                              "stroke-width",
                              1.0, 4.0, 16.0, FALSE);
    }
}
コード例 #9
0
ファイル: tools-commands.c プロジェクト: Amerekanets/gimp
void
tools_ink_blob_angle_cmd_callback (GtkAction *action,
                                   gint       value,
                                   gpointer   data)
{
  GimpContext  *context;
  GimpToolInfo *tool_info;
  return_if_no_context (context, data);

  tool_info = gimp_context_get_tool (context);

  if (tool_info && GIMP_IS_INK_OPTIONS (tool_info->tool_options))
    {
      action_select_property ((GimpActionSelectType) value,
                              G_OBJECT (tool_info->tool_options),
                              "blob-angle",
                              1.0, 1.0, 15.0, TRUE);
    }
}
コード例 #10
0
ファイル: tools-commands.c プロジェクト: Amerekanets/gimp
void
tools_paint_brush_scale_cmd_callback (GtkAction *action,
                                      gint       value,
                                      gpointer   data)
{
  GimpContext  *context;
  GimpToolInfo *tool_info;
  return_if_no_context (context, data);

  tool_info = gimp_context_get_tool (context);

  if (tool_info && GIMP_IS_PAINT_OPTIONS (tool_info->tool_options))
    {
      action_select_property ((GimpActionSelectType) value,
                              G_OBJECT (tool_info->tool_options),
                              "brush-scale",
                              0.01, 0.1, 1.0, FALSE);
    }
}
コード例 #11
0
ファイル: tools-commands.c プロジェクト: Amerekanets/gimp
void
tools_color_average_radius_cmd_callback (GtkAction *action,
                                         gint       value,
                                         gpointer   data)
{
  GimpContext  *context;
  GimpToolInfo *tool_info;
  return_if_no_context (context, data);

  tool_info = gimp_context_get_tool (context);

  if (tool_info && GIMP_IS_COLOR_OPTIONS (tool_info->tool_options))
    {
      action_select_property ((GimpActionSelectType) value,
                              G_OBJECT (tool_info->tool_options),
                              "average-radius",
                              1.0, 1.0, 10.0, FALSE);
    }
}
コード例 #12
0
ファイル: tools-commands.c プロジェクト: Amerekanets/gimp
void
tools_toggle_visibility_cmd_callback (GtkAction *action,
                                      gpointer   data)
{
  GimpContext  *context;
  GimpToolInfo *tool_info;
  return_if_no_context (context, data);

  tool_info = gimp_context_get_tool (context);

  if (tool_info)
    {
      gboolean active =
        gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));

      if (active != tool_info->visible)
        g_object_set (tool_info, "visible", active, NULL);
    }
}
コード例 #13
0
ファイル: tool_manager.c プロジェクト: jiapei100/gimp
void
tool_manager_init (Gimp *gimp)
{
  GimpToolManager *tool_manager;
  GimpContext     *user_context;

  g_return_if_fail (GIMP_IS_GIMP (gimp));
  g_return_if_fail (tool_manager_quark == 0);

  tool_manager_quark = g_quark_from_static_string ("gimp-tool-manager");

  tool_manager = g_slice_new0 (GimpToolManager);

  g_object_set_qdata (G_OBJECT (gimp), tool_manager_quark, tool_manager);

  tool_manager->image_clean_handler_id =
    gimp_container_add_handler (gimp->images, "clean",
                                G_CALLBACK (tool_manager_image_clean_dirty),
                                tool_manager);

  tool_manager->image_dirty_handler_id =
    gimp_container_add_handler (gimp->images, "dirty",
                                G_CALLBACK (tool_manager_image_clean_dirty),
                                tool_manager);

  tool_manager->image_saving_handler_id =
    gimp_container_add_handler (gimp->images, "saving",
                                G_CALLBACK (tool_manager_image_saving),
                                tool_manager);

  user_context = gimp_get_user_context (gimp);

  g_signal_connect (user_context, "tool-changed",
                    G_CALLBACK (tool_manager_tool_changed),
                    tool_manager);
  g_signal_connect (user_context, "tool-preset-changed",
                    G_CALLBACK (tool_manager_preset_changed),
                    tool_manager);

  tool_manager_tool_changed (user_context,
                             gimp_context_get_tool (user_context),
                             tool_manager);
}
コード例 #14
0
ファイル: tools-commands.c プロジェクト: Distrotech/gimp
void
tools_warp_effect_size_cmd_callback (GtkAction *action,
                                     gint       value,
                                     gpointer   data)
{
  GimpContext  *context;
  GimpToolInfo *tool_info;
  return_if_no_context (context, data);

  tool_info = gimp_context_get_tool (context);

  if (tool_info && GIMP_IS_WARP_OPTIONS (tool_info->tool_options))
    {
      action_select_property ((GimpActionSelectType) value,
                              action_data_get_display (data),
                              G_OBJECT (tool_info->tool_options),
                              "effect-size",
                              1.0, 4.0, 16.0, 0.1, FALSE);
    }
}
コード例 #15
0
ファイル: tools-commands.c プロジェクト: Distrotech/gimp
void
tools_transform_preview_opacity_cmd_callback (GtkAction *action,
                                              gint       value,
                                              gpointer   data)
{
  GimpContext  *context;
  GimpToolInfo *tool_info;
  return_if_no_context (context, data);

  tool_info = gimp_context_get_tool (context);

  if (tool_info && GIMP_IS_TRANSFORM_OPTIONS (tool_info->tool_options))
    {
      action_select_property ((GimpActionSelectType) value,
                              action_data_get_display (data),
                              G_OBJECT (tool_info->tool_options),
                              "preview-opacity",
                              0.01, 0.1, 0.5, 0.1, FALSE);
    }
}
コード例 #16
0
ファイル: tools-commands.c プロジェクト: Distrotech/gimp
void
tools_mybrush_radius_cmd_callback (GtkAction *action,
                                   gint       value,
                                   gpointer   data)
{
  GimpContext  *context;
  GimpToolInfo *tool_info;
  return_if_no_context (context, data);

  tool_info = gimp_context_get_tool (context);

  if (tool_info && GIMP_IS_MYBRUSH_OPTIONS (tool_info->tool_options))
    {
      action_select_property ((GimpActionSelectType) value,
                              action_data_get_display (data),
                              G_OBJECT (tool_info->tool_options),
                              "radius",
                              0.1, 0.1, 0.5, 1.0, FALSE);
    }
}
コード例 #17
0
ファイル: tools-commands.c プロジェクト: Distrotech/gimp
void
tools_paintbrush_aspect_ratio_cmd_callback (GtkAction *action,
                                            gint       value,
                                            gpointer   data)
{
  GimpContext  *context;
  GimpToolInfo *tool_info;
  return_if_no_context (context, data);

  tool_info = gimp_context_get_tool (context);

  if (tool_info && GIMP_IS_PAINT_OPTIONS (tool_info->tool_options))
    {
      action_select_property ((GimpActionSelectType) value,
                              action_data_get_display (data),
                              G_OBJECT (tool_info->tool_options),
                              "brush-aspect-ratio",
                              0.01, 0.1, 1.0, 0.1, TRUE);
    }
}
コード例 #18
0
ファイル: gimptoolpreset.c プロジェクト: Distrotech/gimp
GimpData *
gimp_tool_preset_new (GimpContext *context,
                      const gchar *unused)
{
  GimpToolInfo *tool_info;
  const gchar  *icon_name;

  g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);

  tool_info = gimp_context_get_tool (context);

  g_return_val_if_fail (tool_info != NULL, NULL);

  icon_name = gimp_viewable_get_icon_name (GIMP_VIEWABLE (tool_info));

  return g_object_new (GIMP_TYPE_TOOL_PRESET,
                       "name",         tool_info->blurb,
                       "icon-name",    icon_name,
                       "gimp",         context->gimp,
                       "tool-options", tool_info->tool_options,
                       NULL);
}
コード例 #19
0
void
context_paint_mode_cmd_callback (GtkAction *action,
                                 gint       value,
                                 gpointer   data)
{
  GimpContext          *context;
  GimpToolInfo         *tool_info;
  GimpLayerModeEffects  paint_mode;
  gint                  index;
  return_if_no_context (context, data);

  paint_mode = gimp_context_get_paint_mode (context);

  index = action_select_value ((GimpActionSelectType) value,
                               context_paint_mode_index (paint_mode),
                               0, G_N_ELEMENTS (paint_modes) - 1, 0,
                               0.0, 1.0, 1.0, 0.0, FALSE);
  gimp_context_set_paint_mode (context, paint_modes[index]);

  tool_info = gimp_context_get_tool (context);

  if (tool_info && GIMP_IS_TOOL_OPTIONS (tool_info->tool_options))
    {
      GimpDisplay *display;
      const char  *value_desc;

      gimp_enum_get_value (GIMP_TYPE_LAYER_MODE_EFFECTS, index,
                           NULL, NULL, &value_desc, NULL);

      display = action_data_get_display (data);

      if (value_desc && display)
        {
          action_message (display, G_OBJECT (tool_info->tool_options),
                          _("Paint Mode: %s"), value_desc);
        }
    }
}
コード例 #20
0
ファイル: tools-commands.c プロジェクト: Amerekanets/gimp
void
tools_lower_to_bottom_cmd_callback (GtkAction *action,
                                    gpointer   data)
{
  GimpContext  *context;
  GimpToolInfo *tool_info;
  return_if_no_context (context, data);

  tool_info = gimp_context_get_tool (context);

  if (tool_info)
    {
      GimpContainer *container;
      gint           index;

      container = context->gimp->tool_info_list;
      index     = gimp_container_num_children (container) - 1;

      index = index >= 0 ? index : 0;

      gimp_container_reorder (container, GIMP_OBJECT (tool_info), index);
    }
}
コード例 #21
0
ファイル: tools-commands.c プロジェクト: Amerekanets/gimp
void
tools_raise_to_top_cmd_callback (GtkAction *action,
                                 gpointer   data)
{
  GimpContext  *context;
  GimpToolInfo *tool_info;
  return_if_no_context (context, data);

  tool_info = gimp_context_get_tool (context);

  if (tool_info)
    {
      GimpContainer *container;
      gint           index;

      container = context->gimp->tool_info_list;
      index     = gimp_container_get_child_index (container,
                                                  GIMP_OBJECT (tool_info));

      if (index > 0)
        gimp_container_reorder (container, GIMP_OBJECT (tool_info), 0);
    }
}
コード例 #22
0
void
tool_options_delete_preset_cmd_callback (GtkAction *action,
        gint       value,
        gpointer   data)
{
    GimpEditor     *editor    = GIMP_EDITOR (data);
    GimpContext    *context   = gimp_get_user_context (gimp_editor_get_ui_manager (editor)->gimp);
    GimpToolInfo   *tool_info = gimp_context_get_tool (context);
    GimpToolPreset *preset;

    preset = (GimpToolPreset *)
             gimp_container_get_child_by_index (tool_info->presets, value);

    if (preset &&
            gimp_data_is_deletable (GIMP_DATA (preset)))
    {
        GimpDataFactory *factory = context->gimp->tool_preset_factory;
        GtkWidget       *dialog;

        dialog = data_delete_dialog_new (factory, GIMP_DATA (preset), NULL,
                                         GTK_WIDGET (editor));
        gtk_widget_show (dialog);
    }
}
コード例 #23
0
ファイル: gimp-tools.c プロジェクト: AdamGrzonkowski/gimp-1
void
gimp_tools_restore (Gimp *gimp)
{
  GimpContainer *gimp_list;
  GimpObject    *object;
  GFile         *file;
  GList         *list;
  GError        *error = NULL;

  g_return_if_fail (GIMP_IS_GIMP (gimp));

  gimp_list = gimp_list_new (GIMP_TYPE_TOOL_INFO, FALSE);

  file = gimp_directory_file ("toolrc", NULL);

  if (gimp->be_verbose)
    g_print ("Parsing '%s'\n", gimp_file_get_utf8_name (file));

  if (gimp_config_deserialize_gfile (GIMP_CONFIG (gimp_list), file,
                                     NULL, NULL))
    {
      gint n = gimp_container_get_n_children (gimp->tool_info_list);
      gint i;

      gimp_list_reverse (GIMP_LIST (gimp_list));

      for (list = GIMP_LIST (gimp_list)->list, i = 0;
           list;
           list = g_list_next (list), i++)
        {
          const gchar *name;

          name = gimp_object_get_name (list->data);

          object = gimp_container_get_child_by_name (gimp->tool_info_list,
                                                     name);

          if (object)
            {
              g_object_set (object,
                            "visible", GIMP_TOOL_INFO (list->data)->visible,
                            NULL);

              gimp_container_reorder (gimp->tool_info_list,
                                      object, MIN (i, n - 1));
            }
        }
    }

  g_object_unref (file);
  g_object_unref (gimp_list);

  /* make the generic operation tool invisible by default */
  object = gimp_container_get_child_by_name (gimp->tool_info_list,
                                             "gimp-operation-tool");
  if (object)
    g_object_set (object, "visible", FALSE, NULL);

  for (list = gimp_get_tool_info_iter (gimp);
       list;
       list = g_list_next (list))
    {
      GimpToolInfo *tool_info = GIMP_TOOL_INFO (list->data);

      /*  get default values from prefs (see bug #120832)  */
      gimp_config_reset (GIMP_CONFIG (tool_info->tool_options));
    }

  if (! gimp_contexts_load (gimp, &error))
    {
      gimp_message_literal (gimp, NULL, GIMP_MESSAGE_WARNING, error->message);
      g_clear_error (&error);
    }

  /*  make sure there is always a tool active, so broken config files
   *  can't leave us with no initial tool
   */
  if (! gimp_context_get_tool (gimp_get_user_context (gimp)))
    {
      gimp_context_set_tool (gimp_get_user_context (gimp),
                             gimp_get_tool_info_iter (gimp)->data);
    }

  for (list = gimp_get_tool_info_iter (gimp);
       list;
       list = g_list_next (list))
    {
      GimpToolInfo           *tool_info = GIMP_TOOL_INFO (list->data);
      GimpToolOptionsGUIFunc  options_gui_func;
      GtkWidget              *options_gui;

      /*  copy all context properties except those the tool actually
       *  uses, because the subsequent deserialize() on the tool
       *  options will only set the properties that were set to
       *  non-default values at the time of saving, and we want to
       *  keep these default values as if they have been saved.
       * (see bug #541586).
       */
      gimp_context_copy_properties (gimp_get_user_context (gimp),
                                    GIMP_CONTEXT (tool_info->tool_options),
                                    GIMP_CONTEXT_PROP_MASK_ALL &~
                                    (tool_info->context_props    |
                                     GIMP_CONTEXT_PROP_MASK_TOOL |
                                     GIMP_CONTEXT_PROP_MASK_PAINT_INFO));

      gimp_tool_options_deserialize (tool_info->tool_options, NULL);

      options_gui_func = g_object_get_data (G_OBJECT (tool_info),
                                            "gimp-tool-options-gui-func");

      if (options_gui_func)
        {
          options_gui = (* options_gui_func) (tool_info->tool_options);
        }
      else
        {
          GtkWidget *label;

          options_gui = gimp_tool_options_gui (tool_info->tool_options);

          label = gtk_label_new (_("This tool has\nno options."));
          gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_CENTER);
          gimp_label_set_attributes (GTK_LABEL (label),
                                     PANGO_ATTR_STYLE, PANGO_STYLE_ITALIC,
                                     -1);
          gtk_box_pack_start (GTK_BOX (options_gui), label, FALSE, FALSE, 6);
          gtk_widget_show (label);
        }

      gimp_tools_set_tool_options_gui (tool_info->tool_options,
                                       g_object_ref_sink (options_gui));
    }
}
コード例 #24
0
ファイル: gimptoolpreset.c プロジェクト: Distrotech/gimp
static gboolean
gimp_tool_preset_deserialize_property (GimpConfig *config,
                                       guint       property_id,
                                       GValue     *value,
                                       GParamSpec *pspec,
                                       GScanner   *scanner,
                                       GTokenType *expected)
{
  GimpToolPreset *tool_preset = GIMP_TOOL_PRESET (config);

  switch (property_id)
    {
    case PROP_TOOL_OPTIONS:
      {
        GObject             *options;
        gchar               *type_name;
        GType                type;
        GimpContextPropMask  serialize_props;

        if (! gimp_scanner_parse_string (scanner, &type_name))
          {
            *expected = G_TOKEN_STRING;
            break;
          }

        type = g_type_from_name (type_name);

        if (! type)
          {
            g_scanner_error (scanner,
                             "unable to determine type of '%s'",
                             type_name);
            *expected = G_TOKEN_STRING;
            g_free (type_name);
            break;
          }

        if (! g_type_is_a (type, GIMP_TYPE_TOOL_OPTIONS))
          {
            g_scanner_error (scanner,
                             "'%s' is not a subclass of GimpToolOptions",
                             type_name);
            *expected = G_TOKEN_STRING;
            g_free (type_name);
            break;
          }

        g_free (type_name);

        options = g_object_new (type,
                                "gimp", tool_preset->gimp,
                                NULL);

        /*  Initialize all GimpContext object properties that can be
         *  used by presets with some non-NULL object, so loading a
         *  broken preset won't leave us with NULL objects that have
         *  bad effects. See bug #742159.
         */
        gimp_context_copy_properties (gimp_get_user_context (tool_preset->gimp),
                                      GIMP_CONTEXT (options),
                                      GIMP_CONTEXT_BRUSH_MASK    |
                                      GIMP_CONTEXT_DYNAMICS_MASK |
                                      GIMP_CONTEXT_PATTERN_MASK  |
                                      GIMP_CONTEXT_GRADIENT_MASK |
                                      GIMP_CONTEXT_PALETTE_MASK  |
                                      GIMP_CONTEXT_FONT_MASK);

        if (! GIMP_CONFIG_GET_INTERFACE (options)->deserialize (GIMP_CONFIG (options),
                                                                scanner, 1,
                                                                NULL))
          {
            g_object_unref (options);
            break;
          }

        /* we need both tool and tool-info on the options */
        if (gimp_context_get_tool (GIMP_CONTEXT (options)))
          {
            g_object_set (options,
                          "tool-info",
                          gimp_context_get_tool (GIMP_CONTEXT (options)),
                          NULL);
          }
        else if (GIMP_TOOL_OPTIONS (options)->tool_info)
          {
            g_object_set (options,
                          "tool", GIMP_TOOL_OPTIONS (options)->tool_info,
                          NULL);
          }
        else
          {
            /* if we have none, the options set_property() logic will
             * replace the NULL with its best guess
             */
            g_object_set (options,
                          "tool",      NULL,
                          "tool-info", NULL,
                          NULL);
          }

        serialize_props =
          gimp_context_get_serialize_properties (GIMP_CONTEXT (options));

        gimp_context_set_serialize_properties (GIMP_CONTEXT (options),
                                               serialize_props |
                                               GIMP_CONTEXT_TOOL_MASK);

        g_value_take_object (value, options);
      }
      break;

    default:
      return FALSE;
    }

  return TRUE;
}
コード例 #25
0
ファイル: stroke-dialog.c プロジェクト: jdburton/gimp-osx
static void
stroke_dialog_response (GtkWidget  *widget,
                        gint        response_id,
                        GtkWidget  *dialog)
{
  GimpStrokeDesc *desc;
  GimpItem       *item;
  GimpImage      *image;
  GimpContext    *context;

  item = g_object_get_data (G_OBJECT (dialog), "gimp-item");
  desc = g_object_get_data (G_OBJECT (dialog), "gimp-stroke-desc");

  image   = gimp_item_get_image (item);
  context = GIMP_VIEWABLE_DIALOG (dialog)->context;

  switch (response_id)
    {
    case RESPONSE_RESET:
      {
        GimpToolInfo *tool_info = gimp_context_get_tool (context);
        GtkWidget    *combo     = g_object_get_data (G_OBJECT (dialog),
                                                     "gimp-tool-menu");;

        gimp_config_reset (GIMP_CONFIG (desc));

        gimp_container_view_select_item (GIMP_CONTAINER_VIEW (combo),
                                         GIMP_VIEWABLE (tool_info->paint_info));

      }
      break;

    case GTK_RESPONSE_OK:
      {
        GimpDrawable   *drawable = gimp_image_get_active_drawable (image);
        GimpStrokeDesc *saved_desc;
        GError         *error    = NULL;

        if (! drawable)
          {
            gimp_message (context->gimp, G_OBJECT (widget),
                          GIMP_MESSAGE_WARNING,
                          _("There is no active layer or channel "
                            "to stroke to."));
            return;
          }

        saved_desc = g_object_get_data (G_OBJECT (context->gimp),
                                        "saved-stroke-desc");

        if (saved_desc)
          g_object_ref (saved_desc);
        else
          saved_desc = gimp_stroke_desc_new (context->gimp, context);

        gimp_config_sync (G_OBJECT (desc), G_OBJECT (saved_desc), 0);

        g_object_set_data_full (G_OBJECT (context->gimp), "saved-stroke-desc",
                                saved_desc,
                                (GDestroyNotify) g_object_unref);

        if (! gimp_item_stroke (item, drawable, context, desc, FALSE, NULL,
                                &error))
          {
            gimp_message (context->gimp,
                          G_OBJECT (widget),
                          GIMP_MESSAGE_WARNING,
                          "%s",
                          error ? error->message : "NULL");
            g_clear_error (&error);
            return;
          }

        gimp_image_flush (image);
      }
      /* fallthrough */

    default:
      gtk_widget_destroy (dialog);
      break;
    }
}
コード例 #26
0
ファイル: tool_manager.c プロジェクト: davidyang5405/gimp
static void
tool_manager_preset_changed (GimpContext     *user_context,
                             GimpToolPreset  *preset,
                             GimpToolManager *tool_manager)
{
  GimpToolInfo *preset_tool;
  gchar        *options_name;
  gboolean      tool_change = FALSE;

  if (! preset || user_context->gimp->busy)
    return;

  preset_tool = gimp_context_get_tool (GIMP_CONTEXT (preset->tool_options));

  if (preset_tool != gimp_context_get_tool (user_context))
    tool_change = TRUE;

  if (! tool_change)
    tool_manager_disconnect_options (tool_manager, user_context, preset_tool);

  /*  save the name, we don't want to overwrite it  */
  options_name = g_strdup (gimp_object_get_name (preset_tool->tool_options));

  gimp_config_copy (GIMP_CONFIG (preset->tool_options),
                    GIMP_CONFIG (preset_tool->tool_options), 0);

  /*  restore the saved name  */
  gimp_object_take_name (GIMP_OBJECT (preset_tool->tool_options), options_name);

  if (tool_change)
    gimp_context_set_tool (user_context, preset_tool);
  else
    tool_manager_connect_options (tool_manager, user_context, preset_tool);

  gimp_context_copy_properties (GIMP_CONTEXT (preset->tool_options),
                                user_context,
                                gimp_tool_preset_get_prop_mask (preset));

  if (GIMP_IS_PAINT_OPTIONS (preset->tool_options))
    {
      GimpCoreConfig  *config = user_context->gimp->config;
      GimpToolOptions *src    = preset->tool_options;
      GimpToolOptions *dest   = tool_manager->active_tool->tool_info->tool_options;

      /* if connect_options() did overwrite the brush options and the
       * preset contains a brush, use the brush options from the
       * preset
       */
      if (config->global_brush && preset->use_brush)
        gimp_paint_options_copy_brush_props (GIMP_PAINT_OPTIONS (src),
                                             GIMP_PAINT_OPTIONS (dest));

      if (config->global_dynamics && preset->use_dynamics)
        gimp_paint_options_copy_dynamics_props (GIMP_PAINT_OPTIONS (src),
                                                GIMP_PAINT_OPTIONS (dest));

      if (config->global_gradient && preset->use_gradient)
        gimp_paint_options_copy_gradient_props (GIMP_PAINT_OPTIONS (src),
                                                GIMP_PAINT_OPTIONS (dest));
    }
}