void drawable_flip_cmd_callback (GtkAction *action, gint value, gpointer data) { GimpImage *image; GimpDrawable *drawable; GimpItem *item; GimpContext *context; gint off_x, off_y; gdouble axis = 0.0; return_if_no_drawable (image, drawable, data); return_if_no_context (context, data); item = GIMP_ITEM (drawable); gimp_item_get_offset (item, &off_x, &off_y); switch ((GimpOrientationType) value) { case GIMP_ORIENTATION_HORIZONTAL: axis = ((gdouble) off_x + (gdouble) gimp_item_get_width (item) / 2.0); break; case GIMP_ORIENTATION_VERTICAL: axis = ((gdouble) off_y + (gdouble) gimp_item_get_height (item) / 2.0); break; default: break; } if (gimp_item_get_linked (item)) { gimp_item_linked_flip (item, context, (GimpOrientationType) value, axis, FALSE); } else { gimp_item_flip (item, context, (GimpOrientationType) value, axis, FALSE); } gimp_image_flush (image); }
static GeglBuffer * gimp_flip_tool_transform (GimpTransformTool *tr_tool, GimpItem *active_item, GeglBuffer *orig_buffer, gint orig_offset_x, gint orig_offset_y, GimpColorProfile **buffer_profile, gint *new_offset_x, gint *new_offset_y) { GimpFlipTool *flip = GIMP_FLIP_TOOL (tr_tool); GimpFlipOptions *options = GIMP_FLIP_TOOL_GET_OPTIONS (tr_tool); GimpTransformOptions *tr_options = GIMP_TRANSFORM_TOOL_GET_OPTIONS (tr_tool); GimpContext *context = GIMP_CONTEXT (options); GimpOrientationType flip_type = GIMP_ORIENTATION_UNKNOWN; gdouble axis = 0.0; gboolean clip_result = FALSE; GeglBuffer *ret = NULL; flip_type = gimp_flip_tool_get_flip_type (flip); if (flip->guide) { axis = gimp_guide_get_position (flip->guide); } else { switch (flip_type) { case GIMP_ORIENTATION_HORIZONTAL: axis = ((gdouble) tr_tool->x1 + (gdouble) (tr_tool->x2 - tr_tool->x1) / 2.0); break; case GIMP_ORIENTATION_VERTICAL: axis = ((gdouble) tr_tool->y1 + (gdouble) (tr_tool->y2 - tr_tool->y1) / 2.0); break; default: break; } } switch (tr_options->clip) { case GIMP_TRANSFORM_RESIZE_ADJUST: clip_result = FALSE; break; case GIMP_TRANSFORM_RESIZE_CLIP: clip_result = TRUE; break; default: g_return_val_if_reached (NULL); } if (orig_buffer) { /* this happens when transforming a selection cut out of a * normal drawable, or the selection */ /* always clip the selection and unfloated channels * so they keep their size */ if (GIMP_IS_CHANNEL (active_item) && ! babl_format_has_alpha (gegl_buffer_get_format (orig_buffer))) clip_result = TRUE; ret = gimp_drawable_transform_buffer_flip (GIMP_DRAWABLE (active_item), context, orig_buffer, orig_offset_x, orig_offset_y, flip_type, axis, clip_result, buffer_profile, new_offset_x, new_offset_y); } else { /* this happens for entire drawables, paths and layer groups */ /* always clip layer masks so they keep their size */ if (GIMP_IS_CHANNEL (active_item)) clip_result = TRUE; if (gimp_item_get_linked (active_item)) { gimp_item_linked_flip (active_item, context, flip_type, axis, clip_result); } else { gimp_item_flip (active_item, context, flip_type, axis, clip_result); } } return ret; }
static TileManager * gimp_flip_tool_transform (GimpTransformTool *trans_tool, GimpItem *active_item, gboolean mask_empty, GimpDisplay *display) { GimpFlipOptions *options = GIMP_FLIP_TOOL_GET_OPTIONS (trans_tool); GimpTransformOptions *tr_options = GIMP_TRANSFORM_OPTIONS (options); GimpContext *context = GIMP_CONTEXT (options); gdouble axis = 0.0; TileManager *ret = NULL; switch (options->flip_type) { case GIMP_ORIENTATION_HORIZONTAL: axis = ((gdouble) trans_tool->x1 + (gdouble) (trans_tool->x2 - trans_tool->x1) / 2.0); break; case GIMP_ORIENTATION_VERTICAL: axis = ((gdouble) trans_tool->y1 + (gdouble) (trans_tool->y2 - trans_tool->y1) / 2.0); break; default: break; } if (gimp_item_get_linked (active_item)) gimp_item_linked_flip (active_item, context, options->flip_type, axis, FALSE); if (GIMP_IS_LAYER (active_item) && gimp_layer_get_mask (GIMP_LAYER (active_item)) && mask_empty) { GimpLayerMask *mask = gimp_layer_get_mask (GIMP_LAYER (active_item)); gimp_item_flip (GIMP_ITEM (mask), context, options->flip_type, axis, FALSE); } switch (tr_options->type) { case GIMP_TRANSFORM_TYPE_LAYER: case GIMP_TRANSFORM_TYPE_SELECTION: if (trans_tool->original) ret = gimp_drawable_transform_tiles_flip (GIMP_DRAWABLE (active_item), context, trans_tool->original, options->flip_type, axis, FALSE); break; case GIMP_TRANSFORM_TYPE_PATH: gimp_item_flip (active_item, context, options->flip_type, axis, FALSE); break; } return ret; }