static void gimp_operation_tool_finalize (GObject *object) { GimpOperationTool *tool = GIMP_OPERATION_TOOL (object); if (tool->operation) { g_free (tool->operation); tool->operation = NULL; } if (tool->config) { g_object_unref (tool->config); tool->config = NULL; } if (tool->undo_desc) { g_free (tool->undo_desc); tool->undo_desc = NULL; } G_OBJECT_CLASS (parent_class)->finalize (object); }
static void gimp_operation_tool_dialog (GimpImageMapTool *image_map_tool) { GimpOperationTool *tool = GIMP_OPERATION_TOOL (image_map_tool); GtkWidget *main_vbox; main_vbox = gimp_image_map_tool_dialog_get_vbox (image_map_tool); /* The options vbox */ tool->options_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_box_pack_start (GTK_BOX (main_vbox), tool->options_box, FALSE, FALSE, 0); gtk_widget_show (tool->options_box); if (tool->options_table) { gtk_container_add (GTK_CONTAINER (tool->options_box), tool->options_table); gtk_widget_show (tool->options_table); } if (tool->undo_desc) g_object_set (GIMP_IMAGE_MAP_TOOL (tool)->dialog, "description", tool->undo_desc, NULL); }
static void gimp_operation_tool_options_notify (GimpTool *tool, GimpToolOptions *options, const GParamSpec *pspec) { GimpOperationTool *op_tool = GIMP_OPERATION_TOOL (tool); GIMP_TOOL_CLASS (parent_class)->options_notify (tool, options, pspec); if (! strcmp (pspec->name, "region")) { GimpFilterTool *filter_tool = GIMP_FILTER_TOOL (tool); /* when the region changes, do we want the operation's on-canvas * controller to move to a new position, or the operation to * change its properties to match the on-canvas controller? * * decided to leave the on-canvas controller where it is and * pretend it has changed, so the operation is updated * accordingly... */ if (filter_tool->widget) g_signal_emit_by_name (filter_tool->widget, "changed"); if (filter_tool->config && tool->drawable) gimp_operation_tool_sync_op (op_tool, FALSE); } }
static void gimp_operation_tool_finalize (GObject *object) { GimpOperationTool *tool = GIMP_OPERATION_TOOL (object); if (tool->operation) { g_free (tool->operation); tool->operation = NULL; } if (tool->undo_desc) { g_free (tool->undo_desc); tool->undo_desc = NULL; } if (tool->icon_name) { g_free (tool->icon_name); tool->icon_name = NULL; } g_list_free_full (tool->aux_inputs, (GDestroyNotify) gimp_operation_tool_aux_input_free); tool->aux_inputs = NULL; G_OBJECT_CLASS (parent_class)->finalize (object); }
static void gimp_operation_tool_control (GimpTool *tool, GimpToolAction action, GimpDisplay *display) { GimpOperationTool *op_tool = GIMP_OPERATION_TOOL (tool); switch (action) { case GIMP_TOOL_ACTION_PAUSE: case GIMP_TOOL_ACTION_RESUME: break; case GIMP_TOOL_ACTION_HALT: if (op_tool->aux_input_button) gimp_pickable_button_set_pickable (GIMP_PICKABLE_BUTTON (op_tool->aux_input_button), NULL); if (op_tool->aux2_input_button) gimp_pickable_button_set_pickable (GIMP_PICKABLE_BUTTON (op_tool->aux2_input_button), NULL); break; case GIMP_TOOL_ACTION_COMMIT: break; } GIMP_TOOL_CLASS (parent_class)->control (tool, action, display); }
static gboolean gimp_operation_tool_initialize (GimpTool *tool, GimpDisplay *display, GError **error) { if (GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error)) { GimpFilterTool *filter_tool = GIMP_FILTER_TOOL (tool); GimpOperationTool *op_tool = GIMP_OPERATION_TOOL (tool); if (filter_tool->config) { GtkWidget *options_gui; gimp_operation_tool_sync_op (op_tool, TRUE); options_gui = g_weak_ref_get (&op_tool->options_gui_ref); if (! options_gui) { gimp_operation_tool_create_gui (op_tool); gimp_operation_tool_add_gui (op_tool); } else { g_object_unref (options_gui); } } return TRUE; } return FALSE; }
static void gimp_operation_tool_reset (GimpImageMapTool *image_map_tool) { GimpOperationTool *tool = GIMP_OPERATION_TOOL (image_map_tool); if (tool->config) gimp_config_reset (GIMP_CONFIG (tool->config)); }
static void gimp_operation_tool_map (GimpImageMapTool *image_map_tool) { GimpOperationTool *tool = GIMP_OPERATION_TOOL (image_map_tool); if (tool->config) gimp_gegl_config_proxy_sync (tool->config, image_map_tool->operation); }
static void gimp_operation_tool_reset (GimpImageMapTool *im_tool) { GimpOperationTool *tool = GIMP_OPERATION_TOOL (im_tool); GIMP_IMAGE_MAP_TOOL_CLASS (parent_class)->reset (im_tool); if (im_tool->config && GIMP_TOOL (tool)->drawable) gimp_operation_tool_sync_op (tool, GIMP_TOOL (tool)->drawable); }
static gchar * gimp_operation_tool_get_operation (GimpFilterTool *filter_tool, gchar **description) { GimpOperationTool *op_tool = GIMP_OPERATION_TOOL (filter_tool); *description = g_strdup (op_tool->description); return g_strdup (op_tool->operation); }
static void gimp_operation_tool_color_picked (GimpImageMapTool *im_tool, gpointer identifier, const Babl *sample_format, const GimpRGB *color) { GimpOperationTool *tool = GIMP_OPERATION_TOOL (im_tool); g_object_set (tool->config, identifier, color, NULL); }
static void gimp_operation_tool_finalize (GObject *object) { GimpOperationTool *op_tool = GIMP_OPERATION_TOOL (object); g_clear_pointer (&op_tool->operation, g_free); g_clear_pointer (&op_tool->description, g_free); g_list_free_full (op_tool->aux_inputs, (GDestroyNotify) gimp_operation_tool_aux_input_free); op_tool->aux_inputs = NULL; G_OBJECT_CLASS (parent_class)->finalize (object); }
static void gimp_operation_tool_reset (GimpFilterTool *filter_tool) { GimpOperationTool *op_tool = GIMP_OPERATION_TOOL (filter_tool); gimp_operation_tool_unlink_chains (op_tool); GIMP_FILTER_TOOL_CLASS (parent_class)->reset (filter_tool); if (filter_tool->config && GIMP_TOOL (op_tool)->drawable) gimp_operation_tool_sync_op (op_tool, TRUE); gimp_operation_tool_relink_chains (op_tool); }
static GtkWidget * gimp_operation_tool_get_settings_ui (GimpImageMapTool *im_tool, GimpContainer *settings, GFile *settings_file, const gchar *import_dialog_title, const gchar *export_dialog_title, const gchar *file_dialog_help_id, GFile *default_folder, GtkWidget **settings_box) { GimpOperationTool *tool = GIMP_OPERATION_TOOL (im_tool); GType type = G_TYPE_FROM_INSTANCE (im_tool->config); GtkWidget *widget; gchar *basename; GFile *file; gchar *import_title; gchar *export_title; settings = gimp_gegl_get_config_container (type); if (! gimp_list_get_sort_func (GIMP_LIST (settings))) gimp_list_set_sort_func (GIMP_LIST (settings), (GCompareFunc) gimp_settings_compare); basename = g_strconcat (G_OBJECT_TYPE_NAME (im_tool->config), ".settings", NULL); file = gimp_directory_file ("filters", basename, NULL); g_free (basename); import_title = g_strdup_printf (_("Import '%s' Settings"), tool->undo_desc); export_title = g_strdup_printf (_("Export '%s' Settings"), tool->undo_desc); widget = GIMP_IMAGE_MAP_TOOL_CLASS (parent_class)->get_settings_ui (im_tool, settings, file, import_title, export_title, "help-foo", NULL, /* sic */ settings_box); g_free (import_title); g_free (export_title); g_object_unref (file); return widget; }
static void gimp_operation_tool_dialog (GimpImageMapTool *im_tool) { GimpOperationTool *tool = GIMP_OPERATION_TOOL (im_tool); GtkWidget *main_vbox; main_vbox = gimp_image_map_tool_dialog_get_vbox (im_tool); /* The options vbox */ tool->options_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2); gtk_box_pack_start (GTK_BOX (main_vbox), tool->options_box, FALSE, FALSE, 0); gtk_widget_show (tool->options_box); if (tool->aux_input_box) { gtk_box_pack_start (GTK_BOX (tool->options_box), tool->aux_input_box, FALSE, FALSE, 0); gtk_widget_show (tool->aux_input_box); } if (tool->aux2_input_box) { gtk_box_pack_start (GTK_BOX (tool->options_box), tool->aux2_input_box, FALSE, FALSE, 0); gtk_widget_show (tool->aux2_input_box); } if (tool->options_gui) { gtk_box_pack_start (GTK_BOX (tool->options_box), tool->options_gui, FALSE, FALSE, 0); gtk_widget_show (tool->options_gui); } if (tool->undo_desc) gimp_tool_gui_set_description (GIMP_IMAGE_MAP_TOOL (tool)->gui, tool->undo_desc); if (tool->icon_name) gimp_tool_gui_set_icon_name (GIMP_IMAGE_MAP_TOOL (tool)->gui, tool->icon_name); }
static gboolean gimp_operation_tool_initialize (GimpTool *tool, GimpDisplay *display, GError **error) { if (GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error)) { GimpOperationTool *op_tool = GIMP_OPERATION_TOOL (tool); GimpImage *image = gimp_display_get_image (display); GimpDrawable *drawable = gimp_image_get_active_drawable (image); if (op_tool->config) gimp_operation_tool_sync_op (op_tool, drawable); return TRUE; } return FALSE; }
static GeglNode * gimp_operation_tool_get_operation (GimpImageMapTool *im_tool, GObject **config, gchar **undo_desc) { GimpOperationTool *tool = GIMP_OPERATION_TOOL (im_tool); if (tool->config) *config = g_object_ref (tool->config); if (tool->undo_desc) *undo_desc = g_strdup (tool->undo_desc); if (tool->operation) return gegl_node_new_child (NULL, "operation", tool->operation, NULL); return g_object_new (GEGL_TYPE_NODE, NULL); }
static void gimp_gegl_tool_operation_changed (GtkWidget *widget, GimpGeglTool *tool) { GtkTreeModel *model; GtkTreeIter iter; gchar *operation; if (! gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter)) return; model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget)); gtk_tree_model_get (model, &iter, COLUMN_NAME, &operation, -1); if (operation) { const gchar *description; description = gegl_operation_get_key (operation, "description"); if (description) { gtk_label_set_text (GTK_LABEL (tool->description_label), description); gtk_widget_show (tool->description_label); } else { gtk_widget_hide (tool->description_label); } gimp_operation_tool_set_operation (GIMP_OPERATION_TOOL (tool), operation, NULL); g_free (operation); } }
static GeglNode * gimp_operation_tool_get_operation (GimpImageMapTool *im_tool, GObject **config, gchar **undo_desc) { GimpOperationTool *tool = GIMP_OPERATION_TOOL (im_tool); if (tool->operation) *config = G_OBJECT (gimp_gegl_get_config_proxy (tool->operation, GIMP_TYPE_SETTINGS)); if (tool->undo_desc) *undo_desc = g_strdup (tool->undo_desc); if (tool->operation) return gegl_node_new_child (NULL, "operation", tool->operation, NULL); return gegl_node_new_child (NULL, "operation", "gegl:nop", NULL); }
static void gimp_operation_tool_dialog (GimpFilterTool *filter_tool) { GimpOperationTool *op_tool = GIMP_OPERATION_TOOL (filter_tool); GtkWidget *main_vbox; GtkWidget *options_sw; GtkWidget *options_gui; GtkWidget *options_box; main_vbox = gimp_filter_tool_dialog_get_vbox (filter_tool); /* The options scrolled window */ options_sw = gtk_scrolled_window_new (NULL, NULL); g_weak_ref_set (&op_tool->options_sw_ref, options_sw); gtk_scrolled_window_set_overlay_scrolling (GTK_SCROLLED_WINDOW (options_sw), FALSE); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (options_sw), GTK_SHADOW_NONE); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (options_sw), GTK_POLICY_NEVER, GTK_POLICY_NEVER); gtk_box_pack_start (GTK_BOX (main_vbox), options_sw, TRUE, TRUE, 0); gtk_widget_show (options_sw); /* The options vbox */ options_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2); g_weak_ref_set (&op_tool->options_box_ref, options_box); gtk_container_add (GTK_CONTAINER (options_sw), options_box); gtk_widget_show (options_box); options_gui = g_weak_ref_get (&op_tool->options_gui_ref); if (options_gui) { gimp_operation_tool_add_gui (op_tool); g_object_unref (options_gui); } }
static void gimp_operation_tool_control (GimpTool *tool, GimpToolAction action, GimpDisplay *display) { GimpOperationTool *op_tool = GIMP_OPERATION_TOOL (tool); switch (action) { case GIMP_TOOL_ACTION_PAUSE: case GIMP_TOOL_ACTION_RESUME: break; case GIMP_TOOL_ACTION_HALT: gimp_operation_tool_halt (op_tool); break; case GIMP_TOOL_ACTION_COMMIT: gimp_operation_tool_commit (op_tool); break; } GIMP_TOOL_CLASS (parent_class)->control (tool, action, display); }
static void gimp_operation_tool_control (GimpTool *tool, GimpToolAction action, GimpDisplay *display) { GimpOperationTool *op_tool = GIMP_OPERATION_TOOL (tool); switch (action) { case GIMP_TOOL_ACTION_PAUSE: case GIMP_TOOL_ACTION_RESUME: break; case GIMP_TOOL_ACTION_HALT: g_list_foreach (op_tool->aux_inputs, (GFunc) gimp_operation_tool_aux_input_clear, NULL); break; case GIMP_TOOL_ACTION_COMMIT: break; } GIMP_TOOL_CLASS (parent_class)->control (tool, action, display); }
static void gimp_gegl_tool_operation_changed (GtkWidget *widget, GimpGeglTool *tool) { GtkTreeModel *model; GtkTreeIter iter; gchar *operation; if (! gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter)) return; model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget)); gtk_tree_model_get (model, &iter, COLUMN_NAME, &operation, -1); if (operation) { gimp_operation_tool_set_operation (GIMP_OPERATION_TOOL (tool), operation, NULL); g_free (operation); } }
static void gimp_operation_tool_color_picked (GimpImageMapTool *im_tool, gpointer identifier, gdouble x, gdouble y, const Babl *sample_format, const GimpRGB *color) { GimpOperationTool *tool = GIMP_OPERATION_TOOL (im_tool); gchar **pspecs; pspecs = g_strsplit (identifier, ":", 2); if (pspecs[1]) { GimpImageMapOptions *options = GIMP_IMAGE_MAP_TOOL_GET_OPTIONS (tool); GimpDrawable *drawable = GIMP_TOOL (im_tool)->drawable; GObjectClass *object_class = G_OBJECT_GET_CLASS (im_tool->config); GParamSpec *pspec_x; GParamSpec *pspec_y; gint width = 1; gint height = 1; if (drawable) { gint off_x, off_y; gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y); x -= off_x; y -= off_y; switch (options->region) { case GIMP_IMAGE_MAP_REGION_SELECTION: if (gimp_item_mask_intersect (GIMP_ITEM (drawable), &off_x, &off_y, &width, &height)) { x -= off_x; y -= off_y; } break; case GIMP_IMAGE_MAP_REGION_DRAWABLE: width = gimp_item_get_width (GIMP_ITEM (drawable)); height = gimp_item_get_height (GIMP_ITEM (drawable)); break; } } pspec_x = g_object_class_find_property (object_class, pspecs[0]); pspec_y = g_object_class_find_property (object_class, pspecs[1]); if (pspec_x && pspec_y && G_PARAM_SPEC_TYPE (pspec_x) == G_PARAM_SPEC_TYPE (pspec_y)) { GValue value_x = G_VALUE_INIT; GValue value_y = G_VALUE_INIT; g_value_init (&value_x, G_PARAM_SPEC_VALUE_TYPE (pspec_x)); g_value_init (&value_y, G_PARAM_SPEC_VALUE_TYPE (pspec_y)); #define HAS_KEY(p,k,v) gimp_gegl_param_spec_has_key (p, k, v) if (HAS_KEY (pspec_x, "unit", "relative-coordinate") && HAS_KEY (pspec_y, "unit", "relative-coordinate")) { x /= (gdouble) width; y /= (gdouble) height; } if (G_IS_PARAM_SPEC_INT (pspec_x)) { g_value_set_int (&value_x, x); g_value_set_int (&value_y, y); g_param_value_validate (pspec_x, &value_x); g_param_value_validate (pspec_y, &value_y); g_object_set (im_tool->config, pspecs[0], g_value_get_int (&value_x), pspecs[1], g_value_get_int (&value_y), NULL); } else if (G_IS_PARAM_SPEC_DOUBLE (pspec_x)) { g_value_set_double (&value_x, x); g_value_set_double (&value_y, y); g_param_value_validate (pspec_x, &value_x); g_param_value_validate (pspec_y, &value_y); g_object_set (im_tool->config, pspecs[0], g_value_get_double (&value_x), pspecs[1], g_value_get_double (&value_y), NULL); } else { g_warning ("%s: unhandled param spec of type %s", G_STRFUNC, G_PARAM_SPEC_TYPE_NAME (pspec_x)); } g_value_unset (&value_x); g_value_unset (&value_y); } } else { g_object_set (im_tool->config, pspecs[0], color, NULL); } g_strfreev (pspecs); }
static void gimp_gegl_tool_dialog (GimpImageMapTool *image_map_tool) { GimpGeglTool *tool = GIMP_GEGL_TOOL (image_map_tool); GimpOperationTool *o_tool = GIMP_OPERATION_TOOL (image_map_tool); GtkListStore *store; GtkCellRenderer *cell; GtkWidget *main_vbox; GtkWidget *hbox; GtkWidget *combo; GList *opclasses; GList *iter; GIMP_IMAGE_MAP_TOOL_CLASS (parent_class)->dialog (image_map_tool); main_vbox = gimp_image_map_tool_dialog_get_vbox (image_map_tool); /* The operation combo box */ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0); gtk_box_reorder_child (GTK_BOX (main_vbox), hbox, 0); gtk_widget_show (hbox); store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); opclasses = gimp_get_geglopclasses (); for (iter = opclasses; iter; iter = iter->next) { GeglOperationClass *opclass = GEGL_OPERATION_CLASS (iter->data); const gchar *stock_id; const gchar *label; if (g_str_has_prefix (opclass->name, "gegl:")) { label = opclass->name + strlen ("gegl:"); stock_id = GIMP_STOCK_GEGL; } else { label = opclass->name; stock_id = NULL; } gtk_list_store_insert_with_values (store, NULL, -1, COLUMN_NAME, opclass->name, COLUMN_LABEL, label, COLUMN_STOCK_ID, stock_id, -1); } g_list_free (opclasses); combo = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store)); g_object_unref (store); gtk_box_pack_start (GTK_BOX (hbox), combo, TRUE, TRUE, 0); gtk_widget_show (combo); cell = gtk_cell_renderer_pixbuf_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), cell, FALSE); gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo), cell, "stock-id", COLUMN_STOCK_ID); cell = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), cell, TRUE); gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo), cell, "text", COLUMN_LABEL); g_signal_connect (combo, "changed", G_CALLBACK (gimp_gegl_tool_operation_changed), tool); tool->operation_combo = combo; tool->description_label = gtk_label_new (""); gtk_label_set_line_wrap (GTK_LABEL (tool->description_label), TRUE); gtk_misc_set_alignment (GTK_MISC (tool->description_label), 0.0, 0.0); gtk_box_pack_start (GTK_BOX (main_vbox), tool->description_label, FALSE, FALSE, 0); gtk_box_reorder_child (GTK_BOX (main_vbox), tool->description_label, 1); /* The options vbox */ o_tool->options_table = gtk_label_new (_("Select an operation from the list above")); gimp_label_set_attributes (GTK_LABEL (o_tool->options_table), PANGO_ATTR_STYLE, PANGO_STYLE_ITALIC, -1); gtk_misc_set_padding (GTK_MISC (o_tool->options_table), 0, 4); gtk_container_add (GTK_CONTAINER (o_tool->options_box), o_tool->options_table); gtk_widget_show (o_tool->options_table); }