static void gimp_warp_tool_update_stroke (GimpWarpTool *wt, GeglNode *node) { GeglPath *stroke; gdouble size; gegl_node_get (node, "stroke", &stroke, "size", &size, NULL); if (stroke) { gdouble min_x; gdouble max_x; gdouble min_y; gdouble max_y; GeglRectangle bbox; gegl_path_get_bounds (stroke, &min_x, &max_x, &min_y, &max_y); g_object_unref (stroke); bbox.x = min_x - size * 0.5; bbox.y = min_y - size * 0.5; bbox.width = max_x - min_x + size; bbox.height = max_y - min_y + size; gimp_image_map_apply (wt->image_map, &bbox); } }
static void gimp_image_map_tool_map (GimpImageMapTool *tool) { GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (GIMP_TOOL (tool)->display->shell); GimpItem *item = GIMP_ITEM (tool->drawable); gint x, y; gint w, h; gint off_x, off_y; GeglRectangle visible; GIMP_IMAGE_MAP_TOOL_GET_CLASS (tool)->map (tool); gimp_display_shell_untransform_viewport (shell, &x, &y, &w, &h); gimp_item_offsets (item, &off_x, &off_y); gimp_rectangle_intersect (x, y, w, h, off_x, off_y, gimp_item_width (item), gimp_item_height (item), &visible.x, &visible.y, &visible.width, &visible.height); visible.x -= off_x; visible.y -= off_y; gimp_image_map_apply (tool->image_map, &visible); }
static void gimp_cage_tool_image_map_update (GimpCageTool *ct) { GimpTool *tool = GIMP_TOOL (ct); GimpDisplayShell *shell = gimp_display_get_shell (tool->display); GimpItem *item = GIMP_ITEM (tool->drawable); gint x, y; gint w, h; gint off_x, off_y; GeglRectangle visible; gimp_display_shell_untransform_viewport (shell, &x, &y, &w, &h); gimp_item_get_offset (item, &off_x, &off_y); gimp_rectangle_intersect (x, y, w, h, off_x, off_y, gimp_item_get_width (item), gimp_item_get_height (item), &visible.x, &visible.y, &visible.width, &visible.height); visible.x -= off_x; visible.y -= off_y; gimp_image_map_apply (ct->image_map, &visible); }
static void gimp_blend_tool_active_modifier_key (GimpTool *tool, GdkModifierType key, gboolean press, GdkModifierType state, GimpDisplay *display) { GimpBlendTool *blend_tool = GIMP_BLEND_TOOL (tool); GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool); if (key == gimp_get_constrain_behavior_mask ()) { gimp_draw_tool_pause (draw_tool); gimp_blend_tool_point_motion (blend_tool, press); gimp_draw_tool_resume (draw_tool); gimp_tool_pop_status (tool, display); gimp_blend_tool_push_status (blend_tool, state, display); gimp_blend_tool_update_preview_coords (blend_tool); gimp_image_map_apply (blend_tool->image_map, NULL); } else if (key == GDK_MOD1_MASK) { gimp_tool_pop_status (tool, display); gimp_blend_tool_push_status (blend_tool, state, display); } }
static void gimp_image_map_tool_map (GimpImageMapTool *tool) { if (GIMP_IMAGE_MAP_TOOL_GET_CLASS (tool)->map) GIMP_IMAGE_MAP_TOOL_GET_CLASS (tool)->map (tool); gimp_image_map_apply (tool->image_map, NULL); }
static void gimp_levels_tool_map (GimpImageMapTool *image_map_tool) { GimpLevelsTool *tool = GIMP_LEVELS_TOOL (image_map_tool); gimp_image_map_apply (image_map_tool->image_map, (GimpImageMapApplyFunc) gimp_lut_process, tool->lut); }
static void gimp_blend_tool_options_notify (GimpTool *tool, GimpToolOptions *options, const GParamSpec *pspec) { GimpContext *context = GIMP_CONTEXT (options); GimpBlendTool *blend_tool = GIMP_BLEND_TOOL (tool); if (! strcmp (pspec->name, "gradient")) { gimp_blend_tool_set_gradient (blend_tool, context->gradient); if (blend_tool->image_map) gimp_image_map_apply (blend_tool->image_map, NULL); } else if (blend_tool->render_node && gegl_node_find_property (blend_tool->render_node, pspec->name)) { /* Sync any property changes on the config object that match the op */ GValue value = G_VALUE_INIT; g_value_init (&value, pspec->value_type); g_object_get_property (G_OBJECT (options), pspec->name, &value); gegl_node_set_property (blend_tool->render_node, pspec->name, &value); g_value_unset (&value); gimp_image_map_apply (blend_tool->image_map, NULL); } else if (blend_tool->image_map && (! strcmp (pspec->name, "opacity") || ! strcmp (pspec->name, "paint-mode"))) { gimp_image_map_set_mode (blend_tool->image_map, gimp_context_get_opacity (context), gimp_context_get_paint_mode (context)); gimp_image_map_apply (blend_tool->image_map, NULL); } }
static void gimp_blend_tool_motion (GimpTool *tool, const GimpCoords *coords, guint32 time, GdkModifierType state, GimpDisplay *display) { GimpBlendTool *blend_tool = GIMP_BLEND_TOOL (tool); /* Save the mouse coordinates from last call */ gdouble last_x = blend_tool->mouse_x; gdouble last_y = blend_tool->mouse_y; blend_tool->mouse_x = coords->x; blend_tool->mouse_y = coords->y; if (blend_tool->grabbed_point == POINT_INIT_MODE) { GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (blend_tool); gimp_draw_tool_pause (draw_tool); blend_tool->grabbed_point = POINT_END; gimp_draw_tool_resume (draw_tool); } /* Move the whole line if alt is pressed */ if (state & GDK_MOD1_MASK) { gdouble dx = last_x - coords->x; gdouble dy = last_y - coords->y; blend_tool->start_x -= dx; blend_tool->start_y -= dy; blend_tool->end_x -= dx; blend_tool->end_y -= dy; } else { gimp_blend_tool_point_motion (blend_tool, state & gimp_get_constrain_behavior_mask ()); } gimp_tool_pop_status (tool, display); gimp_blend_tool_push_status (blend_tool, state, display); if (GIMP_IS_CANVAS_LINE (blend_tool->line)) gimp_blend_tool_update_items (blend_tool); gimp_blend_tool_update_preview_coords (blend_tool); gimp_image_map_apply (blend_tool->image_map, NULL); }
static void gimp_blend_tool_gradient_dirty (GimpBlendTool *blend_tool) { if (!blend_tool->image_map) return; /* Set a property on the node. Otherwise it will cache and refuse to update */ gegl_node_set (blend_tool->render_node, "gradient", blend_tool->gradient, NULL); /* Update the image_map */ gimp_image_map_apply (blend_tool->image_map, NULL); }
void gimp_image_map_tool_preview (GimpImageMapTool *im_tool) { GimpTool *tool; GimpImageMapOptions *options; g_return_if_fail (GIMP_IS_IMAGE_MAP_TOOL (im_tool)); tool = GIMP_TOOL (im_tool); options = GIMP_IMAGE_MAP_TOOL_GET_OPTIONS (tool); if (im_tool->image_map && options->preview) { gimp_tool_control_push_preserve (tool->control, TRUE); gimp_image_map_apply (im_tool->image_map, NULL); gimp_tool_control_pop_preserve (tool->control); } }
static void gimp_warp_tool_stroke_changed (GeglPath *path, const GeglRectangle *roi, GimpWarpTool *wt) { GimpWarpOptions *options = GIMP_WARP_TOOL_GET_OPTIONS (wt); GeglRectangle update_region = *roi; update_region.x -= options->effect_size * 0.5; update_region.y -= options->effect_size * 0.5; update_region.width += options->effect_size; update_region.height += options->effect_size; #ifdef WARP_DEBUG g_printerr ("update rect: (%d,%d), %dx%d\n", update_region.x, update_region.y, update_region.width, update_region.height); #endif gimp_image_map_apply (wt->image_map, &update_region); }
static void gimp_image_map_tool_commit (GimpImageMapTool *im_tool) { GimpTool *tool = GIMP_TOOL (im_tool); if (im_tool->gui) gimp_tool_gui_hide (im_tool->gui); if (im_tool->image_map) { GimpImageMapOptions *options = GIMP_IMAGE_MAP_TOOL_GET_OPTIONS (tool); gimp_tool_control_push_preserve (tool->control, TRUE); if (! options->preview) gimp_image_map_apply (im_tool->image_map, NULL); gimp_image_map_commit (im_tool->image_map, GIMP_PROGRESS (tool), TRUE); g_object_unref (im_tool->image_map); im_tool->image_map = NULL; gimp_tool_control_pop_preserve (tool->control); gimp_image_map_tool_remove_guide (im_tool); gimp_image_flush (gimp_display_get_image (tool->display)); if (im_tool->config && im_tool->settings_box) { GimpGuiConfig *config = GIMP_GUI_CONFIG (tool->tool_info->gimp->config); gimp_settings_box_add_current (GIMP_SETTINGS_BOX (im_tool->settings_box), config->image_map_tool_max_recent); } } tool->display = NULL; tool->drawable = NULL; }
static void gimp_cage_tool_image_map_update (GimpCageTool *ct) { gimp_image_map_apply (ct->image_map, NULL); }
static void gimp_blend_tool_button_press (GimpTool *tool, const GimpCoords *coords, guint32 time, GdkModifierType state, GimpButtonPressType press_type, GimpDisplay *display) { GimpBlendTool *blend_tool = GIMP_BLEND_TOOL (tool); GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool); blend_tool->mouse_x = coords->x; blend_tool->mouse_y = coords->y; if (tool->display && display != tool->display) { gimp_tool_pop_status (tool, tool->display); gimp_blend_tool_halt_preview (blend_tool); } gimp_draw_tool_pause (draw_tool); blend_tool->grabbed_point = gimp_blend_tool_get_point_under_cursor (blend_tool); if (blend_tool->grabbed_point == POINT_NONE) { if (gimp_draw_tool_is_active (draw_tool)) { gimp_tool_control (tool, GIMP_TOOL_ACTION_COMMIT, display); gimp_tool_control (tool, GIMP_TOOL_ACTION_HALT, display); } if (gimp_blend_tool_is_shapeburst (blend_tool)) { blend_tool->grabbed_point = POINT_FILL_MODE; } else { blend_tool->grabbed_point = POINT_INIT_MODE; blend_tool->start_x = coords->x; blend_tool->start_y = coords->y; } } gimp_blend_tool_point_motion (blend_tool, state & gimp_get_constrain_behavior_mask ()); tool->display = display; gimp_draw_tool_resume (draw_tool); if (blend_tool->grabbed_point != POINT_FILL_MODE && blend_tool->grabbed_point != POINT_INIT_MODE) { gimp_blend_tool_update_preview_coords (blend_tool); gimp_image_map_apply (blend_tool->image_map, NULL); } gimp_tool_control_activate (tool->control); gimp_blend_tool_push_status (blend_tool, state, display); }
static void gimp_warp_tool_animate (GimpWarpTool *wt) { GimpTool *tool = GIMP_TOOL (wt); GimpWarpOptions *options = GIMP_WARP_TOOL_GET_OPTIONS (wt); GimpImage *orig_image; GimpImage *image; GimpLayer *layer; GimpLayer *first_layer; GeglNode *scale_node; GimpProgress *progress; GtkWidget *widget; gint i; if (! gimp_warp_tool_get_undo_desc (tool, tool->display)) { gimp_tool_message_literal (tool, tool->display, _("Please add some warp strokes first.")); return; } /* get rid of the image map so we can use wt->graph */ if (wt->image_map) { gimp_image_map_abort (wt->image_map); g_object_unref (wt->image_map); wt->image_map = NULL; } gimp_progress_start (GIMP_PROGRESS (tool), FALSE, _("Rendering Frame %d"), 1); orig_image = gimp_item_get_image (GIMP_ITEM (tool->drawable)); image = gimp_create_image (orig_image->gimp, gimp_item_get_width (GIMP_ITEM (tool->drawable)), gimp_item_get_height (GIMP_ITEM (tool->drawable)), gimp_drawable_get_base_type (tool->drawable), gimp_drawable_get_precision (tool->drawable), TRUE); /* the first frame is always the unwarped image */ layer = GIMP_LAYER (gimp_item_convert (GIMP_ITEM (tool->drawable), image, GIMP_TYPE_LAYER)); gimp_object_take_name (GIMP_OBJECT (layer), g_strdup_printf (_("Frame %d"), 1)); gimp_item_set_offset (GIMP_ITEM (layer), 0, 0); gimp_item_set_visible (GIMP_ITEM (layer), TRUE, FALSE); gimp_layer_set_mode (layer, GIMP_NORMAL_MODE, FALSE); gimp_layer_set_opacity (layer, GIMP_OPACITY_OPAQUE, FALSE); gimp_image_add_layer (image, layer, NULL, 0, FALSE); first_layer = layer; scale_node = gegl_node_new_child (NULL, "operation", "gimp:scalar-multiply", "n-components", 2, NULL); gimp_warp_tool_add_op (wt, scale_node); progress = gimp_sub_progress_new (GIMP_PROGRESS (tool)); for (i = 1; i < options->n_animation_frames; i++) { gimp_progress_set_text (GIMP_PROGRESS (tool), _("Rendering Frame %d"), i + 1); gimp_sub_progress_set_step (GIMP_SUB_PROGRESS (progress), i, options->n_animation_frames); layer = GIMP_LAYER (gimp_item_duplicate (GIMP_ITEM (first_layer), GIMP_TYPE_LAYER)); gimp_object_take_name (GIMP_OBJECT (layer), g_strdup_printf (_("Frame %d"), i + 1)); gegl_node_set (scale_node, "factor", (gdouble) i / (gdouble) (options->n_animation_frames - 1), NULL); gimp_gegl_apply_operation (gimp_drawable_get_buffer (GIMP_DRAWABLE (first_layer)), progress, _("Frame"), wt->graph, gimp_drawable_get_buffer (GIMP_DRAWABLE (layer)), NULL); gimp_image_add_layer (image, layer, NULL, 0, FALSE); } g_object_unref (progress); gimp_warp_tool_remove_op (wt, scale_node); gimp_progress_end (GIMP_PROGRESS (tool)); /* recreate the image map */ gimp_warp_tool_create_image_map (wt, tool->drawable); gimp_image_map_apply (wt->image_map, NULL); widget = GTK_WIDGET (gimp_display_get_shell (tool->display)); gimp_create_display (orig_image->gimp, image, GIMP_UNIT_PIXEL, 1.0, G_OBJECT (gtk_widget_get_screen (widget)), gimp_widget_get_monitor (widget)); g_object_unref (image); }
static void gimp_image_map_tool_options_notify (GimpTool *tool, GimpToolOptions *options, const GParamSpec *pspec) { GimpImageMapTool *im_tool = GIMP_IMAGE_MAP_TOOL (tool); GimpImageMapOptions *im_options = GIMP_IMAGE_MAP_OPTIONS (options); if (! strcmp (pspec->name, "preview") && im_tool->image_map) { if (im_options->preview) { gimp_tool_control_push_preserve (tool->control, TRUE); gimp_image_map_apply (im_tool->image_map, NULL); gimp_tool_control_pop_preserve (tool->control); if (im_options->preview_split) gimp_image_map_tool_add_guide (im_tool); } else { gimp_tool_control_push_preserve (tool->control, TRUE); gimp_image_map_abort (im_tool->image_map); gimp_tool_control_pop_preserve (tool->control); if (im_options->preview_split) gimp_image_map_tool_remove_guide (im_tool); } } else if (! strcmp (pspec->name, "preview-split") && im_tool->image_map) { if (im_options->preview_split) { GimpDisplayShell *shell = gimp_display_get_shell (tool->display); GimpItem *item = GIMP_ITEM (im_tool->drawable); gint x, y, width, height; gimp_display_shell_untransform_viewport (shell, &x, &y, &width, &height); if (gimp_rectangle_intersect (gimp_item_get_offset_x (item), gimp_item_get_offset_y (item), gimp_item_get_width (item), gimp_item_get_height (item), x, y, width, height, &x, &y, &width, &height)) { gdouble position; if (im_options->preview_alignment == GIMP_ALIGN_LEFT || im_options->preview_alignment == GIMP_ALIGN_RIGHT) { position = ((gdouble) ((x + width / 2) - gimp_item_get_offset_x (item)) / (gdouble) gimp_item_get_width (item)); } else { position = ((gdouble) ((y + height / 2) - gimp_item_get_offset_y (item)) / (gdouble) gimp_item_get_height (item)); } g_object_set (options, "preview-position", CLAMP (position, 0.0, 1.0), NULL); } } gimp_image_map_set_preview (im_tool->image_map, im_options->preview_split, im_options->preview_alignment, im_options->preview_position); if (im_options->preview_split) gimp_image_map_tool_add_guide (im_tool); else gimp_image_map_tool_remove_guide (im_tool); } else if (! strcmp (pspec->name, "preview-alignment") && im_tool->image_map) { gimp_image_map_set_preview (im_tool->image_map, im_options->preview_split, im_options->preview_alignment, im_options->preview_position); if (im_options->preview_split) gimp_image_map_tool_move_guide (im_tool); } else if (! strcmp (pspec->name, "preview-position") && im_tool->image_map) { gimp_image_map_set_preview (im_tool->image_map, im_options->preview_split, im_options->preview_alignment, im_options->preview_position); if (im_options->preview_split) gimp_image_map_tool_move_guide (im_tool); } else if (! strcmp (pspec->name, "region") && im_tool->image_map) { gimp_image_map_set_region (im_tool->image_map, im_options->region); gimp_image_map_tool_preview (im_tool); } }
static void gimp_seamless_clone_tool_image_map_update (GimpSeamlessCloneTool *sc) { GimpTool *tool = GIMP_TOOL (sc); GimpDisplayShell *shell = gimp_display_get_shell (tool->display); GimpItem *item = GIMP_ITEM (tool->drawable); gint x, y; gint w, h; gint off_x, off_y; GeglRectangle visible; GeglOperation *op = NULL; GimpProgress *progress; GeglNode *output; GeglProcessor *processor; gdouble value; progress = gimp_progress_start (GIMP_PROGRESS (sc), _("Cloning the foreground object..."), FALSE); /* Find out at which x,y is the top left corner of the currently * displayed part */ gimp_display_shell_untransform_viewport (shell, &x, &y, &w, &h); /* Find out where is our drawable positioned */ gimp_item_get_offset (item, &off_x, &off_y); /* Create a rectangle from the intersection of the currently displayed * part with the drawable */ gimp_rectangle_intersect (x, y, w, h, off_x, off_y, gimp_item_get_width (item), gimp_item_get_height (item), &visible.x, &visible.y, &visible.width, &visible.height); /* Since the image_map_apply function receives a rectangle describing * where it should update the preview, and since that rectangle should * be relative to the drawable's location, we now offset back by the * drawable's offsetts. */ visible.x -= off_x; visible.y -= off_y; g_object_get (sc->sc_node, "gegl-operation", &op, NULL); /* If any cache of the visible area was present, clear it! * We need to clear the cache in the sc_node, since that is * where the previous paste was located */ gegl_operation_invalidate (op, &visible, TRUE); g_object_unref (op); /* Now update the image map and show this area */ gimp_image_map_apply (sc->image_map, NULL); /* Show update progress. */ output = gegl_node_get_output_proxy (sc->render_node, "output"); processor = gegl_node_new_processor (output, NULL); while (gegl_processor_work (processor, &value)) { if (progress) gimp_progress_set_value (progress, value); } if (progress) gimp_progress_end (progress); g_object_unref (processor); }