void gimp_drawable_stroke_boundary (GimpDrawable *drawable, GimpStrokeOptions *options, const GimpBoundSeg *bound_segs, gint n_bound_segs, gint offset_x, gint offset_y, gboolean push_undo) { GimpScanConvert *scan_convert; g_return_if_fail (GIMP_IS_DRAWABLE (drawable)); g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable))); g_return_if_fail (GIMP_IS_STROKE_OPTIONS (options)); g_return_if_fail (bound_segs == NULL || n_bound_segs != 0); g_return_if_fail (gimp_fill_options_get_style (GIMP_FILL_OPTIONS (options)) != GIMP_FILL_STYLE_PATTERN || gimp_context_get_pattern (GIMP_CONTEXT (options)) != NULL); scan_convert = gimp_scan_convert_new_from_boundary (bound_segs, n_bound_segs, offset_x, offset_y); if (scan_convert) { gimp_drawable_stroke_scan_convert (drawable, options, scan_convert, push_undo); gimp_scan_convert_free (scan_convert); } }
static void gimp_display_shell_dnd_fill (GimpDisplayShell *shell, GimpFillOptions *options, const gchar *undo_desc) { GimpImage *image = gimp_display_get_image (shell->display); GimpDrawable *drawable; if (shell->display->gimp->busy) return; if (! image) return; drawable = gimp_image_get_active_drawable (image); if (! drawable) return; if (gimp_viewable_get_children (GIMP_VIEWABLE (drawable))) { gimp_message_literal (shell->display->gimp, G_OBJECT (shell->display), GIMP_MESSAGE_ERROR, _("Cannot modify the pixels of layer groups.")); return; } if (gimp_item_is_content_locked (GIMP_ITEM (drawable))) { gimp_message_literal (shell->display->gimp, G_OBJECT (shell->display), GIMP_MESSAGE_ERROR, _("The active layer's pixels are locked.")); return; } /* FIXME: there should be a virtual method for this that the * GimpTextLayer can override. */ if (gimp_fill_options_get_style (options) == GIMP_FILL_STYLE_SOLID && gimp_item_is_text_layer (GIMP_ITEM (drawable))) { GimpRGB color; gimp_context_get_foreground (GIMP_CONTEXT (options), &color); gimp_text_layer_set (GIMP_TEXT_LAYER (drawable), NULL, "color", &color, NULL); } else { gimp_edit_fill (image, drawable, options, undo_desc); } gimp_display_shell_dnd_flush (shell, image); }
static gboolean gimp_drawable_edit_can_fill_direct (GimpDrawable *drawable, GimpFillOptions *options) { GimpImage *image; GimpContext *context; gdouble opacity; GimpComponentMask affect; GimpLayerMode mode; GimpLayerCompositeMode composite_mode; GimpLayerCompositeRegion composite_region; image = gimp_item_get_image (GIMP_ITEM (drawable)); context = GIMP_CONTEXT (options); opacity = gimp_context_get_opacity (context); affect = gimp_drawable_get_active_mask (drawable); mode = gimp_context_get_paint_mode (context); composite_mode = gimp_layer_mode_get_paint_composite_mode (mode); composite_region = gimp_layer_mode_get_included_region (mode, composite_mode); if (gimp_channel_is_empty (gimp_image_get_mask (image)) && opacity == GIMP_OPACITY_OPAQUE && affect == GIMP_COMPONENT_MASK_ALL && gimp_layer_mode_is_trivial (mode) && (! gimp_layer_mode_is_subtractive (mode) ^ ! (composite_region & GIMP_LAYER_COMPOSITE_REGION_SOURCE))) { switch (gimp_fill_options_get_style (options)) { case GIMP_FILL_STYLE_SOLID: return TRUE; case GIMP_FILL_STYLE_PATTERN: { GimpPattern *pattern; GimpTempBuf *mask; const Babl *format; pattern = gimp_context_get_pattern (context); mask = gimp_pattern_get_mask (pattern); format = gimp_temp_buf_get_format (mask); return ! babl_format_has_alpha (format); } } } return FALSE; }
void gimp_drawable_stroke_scan_convert (GimpDrawable *drawable, GimpStrokeOptions *options, GimpScanConvert *scan_convert, gboolean push_undo) { gdouble width; GimpUnit unit; g_return_if_fail (GIMP_IS_DRAWABLE (drawable)); g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable))); g_return_if_fail (GIMP_IS_STROKE_OPTIONS (options)); g_return_if_fail (scan_convert != NULL); g_return_if_fail (gimp_fill_options_get_style (GIMP_FILL_OPTIONS (options)) != GIMP_FILL_STYLE_PATTERN || gimp_context_get_pattern (GIMP_CONTEXT (options)) != NULL); if (! gimp_item_mask_intersect (GIMP_ITEM (drawable), NULL, NULL, NULL, NULL)) return; width = gimp_stroke_options_get_width (options); unit = gimp_stroke_options_get_unit (options); if (unit != GIMP_UNIT_PIXEL) { GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable)); gdouble xres; gdouble yres; gimp_image_get_resolution (image, &xres, &yres); gimp_scan_convert_set_pixel_ratio (scan_convert, yres / xres); width = gimp_units_to_pixels (width, unit, yres); } gimp_scan_convert_stroke (scan_convert, width, gimp_stroke_options_get_join_style (options), gimp_stroke_options_get_cap_style (options), gimp_stroke_options_get_miter_limit (options), gimp_stroke_options_get_dash_offset (options), gimp_stroke_options_get_dash_info (options)); gimp_drawable_fill_scan_convert (drawable, GIMP_FILL_OPTIONS (options), scan_convert, push_undo); }
gboolean gimp_drawable_stroke_vectors (GimpDrawable *drawable, GimpStrokeOptions *options, GimpVectors *vectors, gboolean push_undo, GError **error) { const GimpBezierDesc *bezier; g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE); g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), FALSE); g_return_val_if_fail (GIMP_IS_STROKE_OPTIONS (options), FALSE); g_return_val_if_fail (GIMP_IS_VECTORS (vectors), FALSE); g_return_val_if_fail (gimp_fill_options_get_style (GIMP_FILL_OPTIONS (options)) != GIMP_FILL_STYLE_PATTERN || gimp_context_get_pattern (GIMP_CONTEXT (options)) != NULL, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); bezier = gimp_vectors_get_bezier (vectors); if (bezier && bezier->num_data >= 2) { GimpScanConvert *scan_convert = gimp_scan_convert_new (); gimp_scan_convert_add_bezier (scan_convert, bezier); gimp_drawable_stroke_scan_convert (drawable, options, scan_convert, push_undo); gimp_scan_convert_free (scan_convert); return TRUE; } g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED, _("Not enough points to stroke")); return FALSE; }
void gimp_edit_fill (GimpImage *image, GimpDrawable *drawable, GimpFillOptions *options, const gchar *undo_desc) { GeglBuffer *dest_buffer; GimpPattern *pattern = NULL; GimpRGB color; const Babl *format; gint x, y, width, height; g_return_if_fail (GIMP_IS_IMAGE (image)); g_return_if_fail (GIMP_IS_DRAWABLE (drawable)); g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable))); g_return_if_fail (GIMP_IS_FILL_OPTIONS (options)); if (! gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height)) return; /* nothing to do, but the fill succeeded */ switch (gimp_fill_options_get_style (options)) { case GIMP_FILL_STYLE_SOLID: gimp_context_get_foreground (GIMP_CONTEXT (options), &color); break; case GIMP_FILL_STYLE_PATTERN: pattern = gimp_context_get_pattern (GIMP_CONTEXT (options)); break; } if (pattern && babl_format_has_alpha (gimp_temp_buf_get_format (pattern->mask)) && ! gimp_drawable_has_alpha (drawable)) { format = gimp_drawable_get_format_with_alpha (drawable); } else { format = gimp_drawable_get_format (drawable); } dest_buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0, width, height), format); if (pattern) { GeglBuffer *src_buffer = gimp_pattern_create_buffer (pattern); gegl_buffer_set_pattern (dest_buffer, NULL, src_buffer, 0, 0); g_object_unref (src_buffer); } else { GeglColor *gegl_color = gimp_gegl_color_new (&color); gegl_buffer_set_color (dest_buffer, NULL, gegl_color); g_object_unref (gegl_color); } if (! undo_desc) undo_desc = gimp_fill_options_get_undo_desc (options); gimp_drawable_apply_buffer (drawable, dest_buffer, GEGL_RECTANGLE (0, 0, width, height), TRUE, undo_desc, gimp_context_get_opacity (GIMP_CONTEXT (options)), gimp_context_get_paint_mode (GIMP_CONTEXT (options)), NULL, x, y); g_object_unref (dest_buffer); gimp_drawable_update (drawable, x, y, width, height); }