static void gimp_blend_tool_cursor_update (GimpTool *tool, const GimpCoords *coords, GdkModifierType state, GimpDisplay *display) { GimpBlendTool *blend_tool = GIMP_BLEND_TOOL (tool); GimpImage *image = gimp_display_get_image (display); GimpDrawable *drawable = gimp_image_get_active_drawable (image); GimpCursorModifier modifier = GIMP_CURSOR_MODIFIER_NONE; blend_tool->mouse_x = coords->x; blend_tool->mouse_y = coords->y; if (gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) || gimp_item_is_content_locked (GIMP_ITEM (drawable)) || ! gimp_item_is_visible (GIMP_ITEM (drawable))) { modifier = GIMP_CURSOR_MODIFIER_BAD; } else if (gimp_blend_tool_is_shapeburst (blend_tool)) { modifier = GIMP_CURSOR_MODIFIER_PLUS; } else if (gimp_blend_tool_get_point_under_cursor (blend_tool)) { modifier = GIMP_CURSOR_MODIFIER_MOVE; } gimp_tool_control_set_cursor_modifier (tool->control, modifier); GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, display); }
static void gimp_paint_tool_cursor_update (GimpTool *tool, const GimpCoords *coords, GdkModifierType state, GimpDisplay *display) { GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (tool); GimpCursorModifier modifier; GimpCursorModifier toggle_modifier; GimpCursorModifier old_modifier; GimpCursorModifier old_toggle_modifier; modifier = tool->control->cursor_modifier; toggle_modifier = tool->control->toggle_cursor_modifier; old_modifier = modifier; old_toggle_modifier = toggle_modifier; if (! gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool))) { GimpImage *image = gimp_display_get_image (display); GimpDrawable *drawable = gimp_image_get_active_drawable (image); if (gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) || gimp_item_is_content_locked (GIMP_ITEM (drawable)) || ! gimp_item_is_visible (GIMP_ITEM (drawable))) { modifier = GIMP_CURSOR_MODIFIER_BAD; toggle_modifier = GIMP_CURSOR_MODIFIER_BAD; } if (! paint_tool->show_cursor && modifier != GIMP_CURSOR_MODIFIER_BAD) { gimp_tool_set_cursor (tool, display, GIMP_CURSOR_NONE, GIMP_TOOL_CURSOR_NONE, GIMP_CURSOR_MODIFIER_NONE); return; } gimp_tool_control_set_cursor_modifier (tool->control, modifier); gimp_tool_control_set_toggle_cursor_modifier (tool->control, toggle_modifier); } GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, display); /* reset old stuff here so we are not interferring with the modifiers * set by our subclasses */ gimp_tool_control_set_cursor_modifier (tool->control, old_modifier); gimp_tool_control_set_toggle_cursor_modifier (tool->control, old_toggle_modifier); }
static gboolean gimp_blend_tool_initialize (GimpTool *tool, GimpDisplay *display, GError **error) { GimpImage *image = gimp_display_get_image (display); GimpDrawable *drawable = gimp_image_get_active_drawable (image); GimpBlendOptions *options = GIMP_BLEND_TOOL_GET_OPTIONS (tool); if (! GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error)) { return FALSE; } if (gimp_viewable_get_children (GIMP_VIEWABLE (drawable))) { g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED, _("Cannot modify the pixels of layer groups.")); return FALSE; } if (gimp_item_is_content_locked (GIMP_ITEM (drawable))) { g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED, _("The active layer's pixels are locked.")); return FALSE; } if (! gimp_item_is_visible (GIMP_ITEM (drawable))) { g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED, _("The active layer is not visible.")); return FALSE; } if (! gimp_context_get_gradient (GIMP_CONTEXT (options))) { g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED, _("No gradient available for use with this tool.")); return FALSE; } return TRUE; }
static void gimp_warp_tool_cursor_update (GimpTool *tool, const GimpCoords *coords, GdkModifierType state, GimpDisplay *display) { GimpWarpOptions *options = GIMP_WARP_TOOL_GET_OPTIONS (tool); GimpCursorModifier modifier = GIMP_CURSOR_MODIFIER_PLUS; if (display == tool->display) { /* FIXME have better cursors */ switch (options->behavior) { case GIMP_WARP_BEHAVIOR_MOVE: case GEGL_WARP_BEHAVIOR_GROW: case GEGL_WARP_BEHAVIOR_SHRINK: case GEGL_WARP_BEHAVIOR_SWIRL_CW: case GEGL_WARP_BEHAVIOR_SWIRL_CCW: case GEGL_WARP_BEHAVIOR_ERASE: case GEGL_WARP_BEHAVIOR_SMOOTH: modifier = GIMP_CURSOR_MODIFIER_MOVE; break; } } else { GimpImage *image = gimp_display_get_image (display); GimpDrawable *drawable = gimp_image_get_active_drawable (image); if (gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) || gimp_item_is_content_locked (GIMP_ITEM (drawable)) || ! gimp_item_is_visible (GIMP_ITEM (drawable))) { modifier = GIMP_CURSOR_MODIFIER_BAD; } } gimp_tool_control_set_cursor_modifier (tool->control, modifier); GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, display); }
static void gimp_bucket_fill_tool_cursor_update (GimpTool *tool, const GimpCoords *coords, GdkModifierType state, GimpDisplay *display) { GimpBucketFillOptions *options = GIMP_BUCKET_FILL_TOOL_GET_OPTIONS (tool); GimpCursorModifier modifier = GIMP_CURSOR_MODIFIER_BAD; GimpImage *image = gimp_display_get_image (display); if (gimp_image_coords_in_active_pickable (image, coords, options->sample_merged, TRUE)) { GimpDrawable *drawable = gimp_image_get_active_drawable (image); if (! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) && ! gimp_item_is_content_locked (GIMP_ITEM (drawable)) && gimp_item_is_visible (GIMP_ITEM (drawable))) { switch (options->fill_mode) { case GIMP_BUCKET_FILL_FG: modifier = GIMP_CURSOR_MODIFIER_FOREGROUND; break; case GIMP_BUCKET_FILL_BG: modifier = GIMP_CURSOR_MODIFIER_BACKGROUND; break; case GIMP_BUCKET_FILL_PATTERN: modifier = GIMP_CURSOR_MODIFIER_PATTERN; break; } } } gimp_tool_control_set_cursor_modifier (tool->control, modifier); GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, display); }
static gboolean gimp_bucket_fill_tool_initialize (GimpTool *tool, GimpDisplay *display, GError **error) { GimpImage *image = gimp_display_get_image (display); GimpDrawable *drawable = gimp_image_get_active_drawable (image); if (! GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error)) { return FALSE; } if (gimp_viewable_get_children (GIMP_VIEWABLE (drawable))) { g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED, _("Cannot modify the pixels of layer groups.")); return FALSE; } if (gimp_item_is_content_locked (GIMP_ITEM (drawable))) { g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED, _("The active layer's pixels are locked.")); return FALSE; } if (! gimp_item_is_visible (GIMP_ITEM (drawable))) { g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED, _("The active layer is not visible.")); return FALSE; } return TRUE; }
static void gimp_paint_tool_button_press (GimpTool *tool, const GimpCoords *coords, guint32 time, GdkModifierType state, GimpButtonPressType press_type, GimpDisplay *display) { GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool); GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (tool); GimpPaintOptions *paint_options = GIMP_PAINT_TOOL_GET_OPTIONS (tool); GimpPaintCore *core = paint_tool->core; GimpDisplayShell *shell = gimp_display_get_shell (display); GimpImage *image = gimp_display_get_image (display); GimpDrawable *drawable = gimp_image_get_active_drawable (image); GimpCoords curr_coords; gint off_x, off_y; GError *error = NULL; if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool))) { GIMP_TOOL_CLASS (parent_class)->button_press (tool, coords, time, state, press_type, display); return; } if (gimp_viewable_get_children (GIMP_VIEWABLE (drawable))) { gimp_tool_message_literal (tool, display, _("Cannot paint on layer groups.")); return; } if (gimp_item_is_content_locked (GIMP_ITEM (drawable))) { gimp_tool_message_literal (tool, display, _("The active layer's pixels are locked.")); return; } if (! gimp_item_is_visible (GIMP_ITEM (drawable))) { gimp_tool_message_literal (tool, display, _("The active layer is not visible.")); return; } curr_coords = *coords; gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y); curr_coords.x -= off_x; curr_coords.y -= off_y; if (gimp_draw_tool_is_active (draw_tool)) gimp_draw_tool_stop (draw_tool); if (tool->display && tool->display != display && gimp_display_get_image (tool->display) == image) { /* if this is a different display, but the same image, HACK around * in tool internals AFTER stopping the current draw_tool, so * straight line drawing works across different views of the * same image. */ tool->display = display; } if (! gimp_paint_core_start (core, drawable, paint_options, &curr_coords, &error)) { gimp_tool_message_literal (tool, display, error->message); g_clear_error (&error); return; } if ((display != tool->display) || ! paint_tool->draw_line) { /* if this is a new display, resest the "last stroke's endpoint" * because there is none */ if (display != tool->display) core->start_coords = core->cur_coords; core->last_coords = core->cur_coords; core->distance = 0.0; core->pixel_dist = 0.0; } else if (paint_tool->draw_line) { gboolean constrain = (state & gimp_get_constrain_behavior_mask ()) != 0; /* If shift is down and this is not the first paint * stroke, then draw a line from the last coords to the pointer */ gimp_paint_core_round_line (core, paint_options, constrain); } /* chain up to activate the tool */ GIMP_TOOL_CLASS (parent_class)->button_press (tool, coords, time, state, press_type, display); /* pause the current selection */ gimp_display_shell_selection_pause (shell); /* Let the specific painting function initialize itself */ gimp_paint_core_paint (core, drawable, paint_options, GIMP_PAINT_STATE_INIT, time); /* Paint to the image */ if (paint_tool->draw_line) { gimp_paint_core_interpolate (core, drawable, paint_options, &core->cur_coords, time); } else { gimp_paint_core_paint (core, drawable, paint_options, GIMP_PAINT_STATE_MOTION, time); } gimp_projection_flush_now (gimp_image_get_projection (image)); gimp_display_flush_now (display); gimp_draw_tool_start (draw_tool, display); }
static gboolean gimp_image_map_tool_initialize (GimpTool *tool, GimpDisplay *display, GError **error) { GimpImageMapTool *im_tool = GIMP_IMAGE_MAP_TOOL (tool); GimpToolInfo *tool_info = tool->tool_info; GimpImage *image = gimp_display_get_image (display); GimpDrawable *drawable = gimp_image_get_active_drawable (image); GimpDisplayShell *shell = gimp_display_get_shell (display); if (! drawable) return FALSE; if (gimp_viewable_get_children (GIMP_VIEWABLE (drawable))) { g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED, _("Cannot modify the pixels of layer groups.")); return FALSE; } if (gimp_item_is_content_locked (GIMP_ITEM (drawable))) { g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED, _("The active layer's pixels are locked.")); return FALSE; } if (! gimp_item_is_visible (GIMP_ITEM (drawable))) { g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED, _("The active layer is not visible.")); return FALSE; } if (im_tool->active_picker) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (im_tool->active_picker), FALSE); /* set display so the dialog can be hidden on display destruction */ tool->display = display; if (im_tool->config) gimp_config_reset (GIMP_CONFIG (im_tool->config)); if (! im_tool->gui) { GimpImageMapToolClass *klass = GIMP_IMAGE_MAP_TOOL_GET_CLASS (im_tool); GtkWidget *vbox; GtkWidget *hbox; GtkWidget *toggle; gchar *operation_name; /* disabled for at least GIMP 2.8 */ im_tool->overlay = FALSE; im_tool->gui = gimp_tool_gui_new (tool_info, im_tool->title, im_tool->description, im_tool->icon_name, im_tool->help_id, gtk_widget_get_screen (GTK_WIDGET (shell)), gimp_widget_get_monitor (GTK_WIDGET (shell)), im_tool->overlay, GIMP_STOCK_RESET, RESPONSE_RESET, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); gimp_tool_gui_set_default_response (im_tool->gui, GTK_RESPONSE_OK); gimp_tool_gui_set_alternative_button_order (im_tool->gui, RESPONSE_RESET, GTK_RESPONSE_OK, GTK_RESPONSE_CANCEL, -1); vbox = gimp_tool_gui_get_vbox (im_tool->gui); g_signal_connect_object (im_tool->gui, "response", G_CALLBACK (gimp_image_map_tool_response), G_OBJECT (im_tool), 0); if (im_tool->config && klass->settings_name) { GType type = G_TYPE_FROM_INSTANCE (im_tool->config); GimpContainer *settings; GFile *settings_file; GFile *default_folder; GtkWidget *settings_ui; settings = gimp_gegl_config_get_container (type); if (! gimp_list_get_sort_func (GIMP_LIST (settings))) gimp_list_set_sort_func (GIMP_LIST (settings), (GCompareFunc) gimp_settings_compare); settings_file = gimp_tool_info_get_options_file (tool_info, ".settings"); default_folder = gimp_directory_file (klass->settings_name, NULL); settings_ui = klass->get_settings_ui (im_tool, settings, settings_file, klass->import_dialog_title, klass->export_dialog_title, im_tool->help_id, default_folder, &im_tool->settings_box); g_object_unref (default_folder); g_object_unref (settings_file); gtk_box_pack_start (GTK_BOX (vbox), settings_ui, FALSE, FALSE, 0); gtk_widget_show (settings_ui); } /* The gamma hack toggle */ toggle = gtk_check_button_new_with_label ("Gamma hack (temp hack, please ignore)"); gtk_box_pack_end (GTK_BOX (vbox), toggle, FALSE, FALSE, 0); gtk_widget_show (toggle); g_signal_connect (toggle, "toggled", G_CALLBACK (gamma_hack), im_tool); /* The preview and split view toggles */ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4); gtk_box_pack_end (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); gtk_widget_show (hbox); toggle = gimp_prop_check_button_new (G_OBJECT (tool_info->tool_options), "preview", NULL); gtk_box_pack_start (GTK_BOX (hbox), toggle, TRUE, TRUE, 0); gtk_widget_show (toggle); toggle = gimp_prop_check_button_new (G_OBJECT (tool_info->tool_options), "preview-split", NULL); gtk_box_pack_start (GTK_BOX (hbox), toggle, FALSE, FALSE, 0); gtk_widget_show (toggle); g_object_bind_property (G_OBJECT (tool_info->tool_options), "preview", toggle, "sensitive", G_BINDING_SYNC_CREATE); /* The area combo */ gegl_node_get (im_tool->operation, "operation", &operation_name, NULL); im_tool->region_combo = gimp_prop_enum_combo_box_new (G_OBJECT (tool_info->tool_options), "region", 0, 0); gtk_box_pack_end (GTK_BOX (vbox), im_tool->region_combo, FALSE, FALSE, 0); if (operation_name && gegl_operation_get_key (operation_name, "position-dependent")) { gtk_widget_show (im_tool->region_combo); } g_free (operation_name); /* Fill in subclass widgets */ gimp_image_map_tool_dialog (im_tool); } else { gimp_tool_gui_set_title (im_tool->gui, im_tool->title); gimp_tool_gui_set_description (im_tool->gui, im_tool->description); gimp_tool_gui_set_icon_name (im_tool->gui, im_tool->icon_name); gimp_tool_gui_set_help_id (im_tool->gui, im_tool->help_id); } gimp_tool_gui_set_shell (im_tool->gui, shell); gimp_tool_gui_set_viewable (im_tool->gui, GIMP_VIEWABLE (drawable)); gimp_tool_gui_show (im_tool->gui); im_tool->drawable = drawable; gimp_image_map_tool_create_map (im_tool); gimp_image_map_tool_preview (im_tool); return TRUE; }
static gboolean gimp_warp_tool_start (GimpWarpTool *wt, GimpDisplay *display) { GimpTool *tool = GIMP_TOOL (wt); GimpWarpOptions *options = GIMP_WARP_TOOL_GET_OPTIONS (wt); GimpImage *image = gimp_display_get_image (display); GimpDrawable *drawable = gimp_image_get_active_drawable (image); const Babl *format; GeglRectangle bbox; if (gimp_viewable_get_children (GIMP_VIEWABLE (drawable))) { gimp_tool_message_literal (tool, display, _("Cannot warp layer groups.")); return FALSE; } if (gimp_item_is_content_locked (GIMP_ITEM (drawable))) { gimp_tool_message_literal (tool, display, _("The active layer's pixels are locked.")); return FALSE; } if (! gimp_item_is_visible (GIMP_ITEM (drawable))) { gimp_tool_message_literal (tool, display, _("The active layer is not visible.")); return FALSE; } tool->display = display; tool->drawable = drawable; /* Create the coords buffer, with the size of the selection */ format = babl_format_n (babl_type ("float"), 2); gimp_item_mask_intersect (GIMP_ITEM (drawable), &bbox.x, &bbox.y, &bbox.width, &bbox.height); #ifdef WARP_DEBUG g_printerr ("Initialize coordinate buffer (%d,%d) at %d,%d\n", bbox.width, bbox.height, bbox.x, bbox.y); #endif wt->coords_buffer = gegl_buffer_new (&bbox, format); gimp_warp_tool_create_filter (wt, drawable); if (! gimp_draw_tool_is_active (GIMP_DRAW_TOOL (wt))) gimp_draw_tool_start (GIMP_DRAW_TOOL (wt), display); if (options->animate_button) { g_signal_connect_swapped (options->animate_button, "clicked", G_CALLBACK (gimp_warp_tool_animate), wt); gtk_widget_set_sensitive (options->animate_button, TRUE); } return TRUE; }