1
1
mirror of https://gitlab.gnome.org/GNOME/gimp.git synced 2025-10-05 21:02:42 +02:00

app: add ability to choose new layers' position.

This commit is contained in:
Jehan
2024-08-14 18:39:14 +02:00
parent 308963c271
commit cf8c306f6d
8 changed files with 337 additions and 109 deletions

View File

@@ -97,89 +97,93 @@
/* local function prototypes */
static void layers_new_callback (GtkWidget *dialog,
GimpImage *image,
GimpLayer *layer,
GimpContext *context,
const gchar *layer_name,
GimpLayerMode layer_mode,
GimpLayerColorSpace layer_blend_space,
GimpLayerColorSpace layer_composite_space,
GimpLayerCompositeMode layer_composite_mode,
gdouble layer_opacity,
GimpFillType layer_fill_type,
GimpLink *link,
gint layer_width,
gint layer_height,
gint layer_offset_x,
gint layer_offset_y,
gboolean layer_visible,
GimpColorTag layer_color_tag,
gboolean layer_lock_pixels,
gboolean layer_lock_position,
gboolean layer_lock_visibility,
gboolean layer_lock_alpha,
gboolean rename_text_layer,
gpointer user_data);
static void layers_edit_attributes_callback (GtkWidget *dialog,
GimpImage *image,
GimpLayer *layer,
GimpContext *context,
const gchar *layer_name,
GimpLayerMode layer_mode,
GimpLayerColorSpace layer_blend_space,
GimpLayerColorSpace layer_composite_space,
GimpLayerCompositeMode layer_composite_mode,
gdouble layer_opacity,
GimpFillType layer_fill_type,
GimpLink *link,
gint layer_width,
gint layer_height,
gint layer_offset_x,
gint layer_offset_y,
gboolean layer_visible,
GimpColorTag layer_color_tag,
gboolean layer_lock_pixels,
gboolean layer_lock_position,
gboolean layer_lock_visibility,
gboolean layer_lock_alpha,
gboolean rename_text_layer,
gpointer user_data);
static void layers_add_mask_callback (GtkWidget *dialog,
GList *layers,
GimpAddMaskType add_mask_type,
GimpChannel *channel,
gboolean invert,
gpointer user_data);
static void layers_scale_callback (GtkWidget *dialog,
GimpViewable *viewable,
gint width,
gint height,
GimpUnit *unit,
GimpInterpolationType interpolation,
gdouble xresolution,
gdouble yresolution,
GimpUnit *resolution_unit,
gpointer user_data);
static void layers_resize_callback (GtkWidget *dialog,
GimpViewable *viewable,
GimpContext *context,
gint width,
gint height,
GimpUnit *unit,
gint offset_x,
gint offset_y,
gdouble unused0,
gdouble unused1,
GimpUnit *unused2,
GimpFillType fill_type,
GimpItemSet unused3,
gboolean unused4,
gpointer data);
static void layers_new_callback (GtkWidget *dialog,
GimpImage *image,
GimpLayer *layer,
GimpContext *context,
const gchar *layer_name,
GimpLayerMode layer_mode,
GimpLayerColorSpace layer_blend_space,
GimpLayerColorSpace layer_composite_space,
GimpLayerCompositeMode layer_composite_mode,
gdouble layer_opacity,
GimpFillType layer_fill_type,
GimpInsertPosition insert_position,
GimpInsertGroupPosition insert_group_position,
GimpLink *link,
gint layer_width,
gint layer_height,
gint layer_offset_x,
gint layer_offset_y,
gboolean layer_visible,
GimpColorTag layer_color_tag,
gboolean layer_lock_pixels,
gboolean layer_lock_position,
gboolean layer_lock_visibility,
gboolean layer_lock_alpha,
gboolean rename_text_layer,
gpointer user_data);
static void layers_edit_attributes_callback (GtkWidget *dialog,
GimpImage *image,
GimpLayer *layer,
GimpContext *context,
const gchar *layer_name,
GimpLayerMode layer_mode,
GimpLayerColorSpace layer_blend_space,
GimpLayerColorSpace layer_composite_space,
GimpLayerCompositeMode layer_composite_mode,
gdouble layer_opacity,
GimpFillType unused,
GimpInsertPosition unused2,
GimpInsertGroupPosition unused3,
GimpLink *link,
gint layer_width,
gint layer_height,
gint layer_offset_x,
gint layer_offset_y,
gboolean layer_visible,
GimpColorTag layer_color_tag,
gboolean layer_lock_pixels,
gboolean layer_lock_position,
gboolean layer_lock_visibility,
gboolean layer_lock_alpha,
gboolean rename_text_layer,
gpointer user_data);
static void layers_add_mask_callback (GtkWidget *dialog,
GList *layers,
GimpAddMaskType add_mask_type,
GimpChannel *channel,
gboolean invert,
gpointer user_data);
static void layers_scale_callback (GtkWidget *dialog,
GimpViewable *viewable,
gint width,
gint height,
GimpUnit *unit,
GimpInterpolationType interpolation,
gdouble xresolution,
gdouble yresolution,
GimpUnit *resolution_unit,
gpointer user_data);
static void layers_resize_callback (GtkWidget *dialog,
GimpViewable *viewable,
GimpContext *context,
gint width,
gint height,
GimpUnit *unit,
gint offset_x,
gint offset_y,
gdouble unused0,
gdouble unused1,
GimpUnit *unused2,
GimpFillType fill_type,
GimpItemSet unused3,
gboolean unused4,
gpointer data);
static gint layers_mode_index (GimpLayerMode layer_mode,
const GimpLayerMode *modes,
gint n_modes);
static gint layers_mode_index (GimpLayerMode layer_mode,
const GimpLayerMode *modes,
gint n_modes);
/* private variables */
@@ -355,6 +359,8 @@ layers_edit_attributes_cmd_callback (GimpAction *action,
gimp_layer_get_composite_mode (layer),
gimp_layer_get_opacity (layer),
0 /* unused */,
0 /* unused */,
0 /* unused */,
gimp_item_get_visible (item),
gimp_item_get_color_tag (item),
gimp_item_get_lock_content (item),
@@ -440,6 +446,8 @@ layers_new_cmd_callback (GimpAction *action,
config->layer_new_composite_mode,
config->layer_new_opacity,
config->layer_new_fill_type,
config->layer_new_insert_position,
config->layer_new_insert_group_position,
TRUE,
GIMP_COLOR_TAG_NONE,
FALSE,
@@ -513,15 +521,38 @@ layers_new_last_vals_cmd_callback (GimpAction *action,
run_once = FALSE;
if (iter)
{
if (gimp_viewable_get_children (GIMP_VIEWABLE (iter->data)))
GimpContainer *container;
if ((container = gimp_viewable_get_children (GIMP_VIEWABLE (iter->data))))
{
parent = iter->data;
position = 0;
if (config->layer_new_insert_group_position == GIMP_INSERT_GROUP_TOP ||
config->layer_new_insert_group_position == GIMP_INSERT_GROUP_BOTTOM)
{
parent = iter->data;
if (config->layer_new_insert_group_position == GIMP_INSERT_GROUP_TOP)
position = 0;
else
position = gimp_container_get_n_children (container);
}
else
{
parent = GIMP_LAYER (gimp_item_get_parent (iter->data));
if (config->layer_new_insert_group_position == GIMP_INSERT_GROUP_ABOVE)
position = gimp_item_get_index (iter->data);
else
position = gimp_item_get_index (iter->data) + 1;
}
}
else
{
parent = GIMP_LAYER (gimp_item_get_parent (iter->data));
position = gimp_item_get_index (iter->data);
parent = GIMP_LAYER (gimp_item_get_parent (iter->data));
if (config->layer_new_insert_position == GIMP_INSERT_ABOVE)
position = gimp_item_get_index (iter->data);
else
position = gimp_item_get_index (iter->data) + 1;
}
}
else /* run_once */
@@ -2358,6 +2389,8 @@ layers_new_callback (GtkWidget *dialog,
GimpLayerCompositeMode layer_composite_mode,
gdouble layer_opacity,
GimpFillType layer_fill_type,
GimpInsertPosition layer_insert_position,
GimpInsertGroupPosition layer_insert_group_position,
GimpLink *link,
gint layer_width,
gint layer_height,
@@ -2389,6 +2422,8 @@ layers_new_callback (GtkWidget *dialog,
"layer-new-composite-mode", layer_composite_mode,
"layer-new-opacity", layer_opacity,
"layer-new-fill-type", layer_fill_type,
"layer-new-insert-position", layer_insert_position,
"layer-new-insert-group-position", layer_insert_group_position,
NULL);
layers = g_list_copy (layers);
@@ -2405,15 +2440,38 @@ layers_new_callback (GtkWidget *dialog,
run_once = FALSE;
if (iter)
{
if (gimp_viewable_get_children (GIMP_VIEWABLE (iter->data)))
GimpContainer *container;
if ((container = gimp_viewable_get_children (GIMP_VIEWABLE (iter->data))))
{
parent = iter->data;
position = 0;
if (layer_insert_group_position == GIMP_INSERT_GROUP_TOP ||
layer_insert_group_position == GIMP_INSERT_GROUP_BOTTOM)
{
parent = iter->data;
if (layer_insert_group_position == GIMP_INSERT_GROUP_TOP)
position = 0;
else
position = gimp_container_get_n_children (container);
}
else
{
parent = GIMP_LAYER (gimp_item_get_parent (iter->data));
if (layer_insert_group_position == GIMP_INSERT_GROUP_ABOVE)
position = gimp_item_get_index (iter->data);
else
position = gimp_item_get_index (iter->data) + 1;
}
}
else
{
parent = GIMP_LAYER (gimp_item_get_parent (iter->data));
position = gimp_item_get_index (iter->data);
parent = GIMP_LAYER (gimp_item_get_parent (iter->data));
if (layer_insert_position == GIMP_INSERT_ABOVE)
position = gimp_item_get_index (iter->data);
else
position = gimp_item_get_index (iter->data) + 1;
}
}
else /* run_once */
@@ -2477,9 +2535,11 @@ layers_edit_attributes_callback (GtkWidget *dialog,
GimpLayerCompositeMode layer_composite_mode,
gdouble layer_opacity,
GimpFillType unused1,
GimpInsertPosition unused2,
GimpInsertGroupPosition unused3,
GimpLink *link,
gint unused2,
gint unused3,
gint unused4,
gint unused5,
gint layer_offset_x,
gint layer_offset_y,
gboolean layer_visible,

View File

@@ -420,6 +420,68 @@ gimp_theme_scheme_get_type (void)
return type;
}
GType
gimp_insert_position_get_type (void)
{
static const GEnumValue values[] =
{
{ GIMP_INSERT_ABOVE, "GIMP_INSERT_ABOVE", "above" },
{ GIMP_INSERT_BELOW, "GIMP_INSERT_BELOW", "below" },
{ 0, NULL, NULL }
};
static const GimpEnumDesc descs[] =
{
{ GIMP_INSERT_ABOVE, NC_("insert-position", "Above selected"), NULL },
{ GIMP_INSERT_BELOW, NC_("insert-position", "Below selected"), NULL },
{ 0, NULL, NULL }
};
static GType type = 0;
if (G_UNLIKELY (! type))
{
type = g_enum_register_static ("GimpInsertPosition", values);
gimp_type_set_translation_context (type, "insert-position");
gimp_enum_set_value_descriptions (type, descs);
}
return type;
}
GType
gimp_insert_group_position_get_type (void)
{
static const GEnumValue values[] =
{
{ GIMP_INSERT_GROUP_TOP, "GIMP_INSERT_GROUP_TOP", "top" },
{ GIMP_INSERT_GROUP_BOTTOM, "GIMP_INSERT_GROUP_BOTTOM", "bottom" },
{ GIMP_INSERT_GROUP_ABOVE, "GIMP_INSERT_GROUP_ABOVE", "above" },
{ GIMP_INSERT_GROUP_BELOW, "GIMP_INSERT_GROUP_BELOW", "below" },
{ 0, NULL, NULL }
};
static const GimpEnumDesc descs[] =
{
{ GIMP_INSERT_GROUP_TOP, NC_("insert-group-position", "As top child"), NULL },
{ GIMP_INSERT_GROUP_BOTTOM, NC_("insert-group-position", "As bottom child"), NULL },
{ GIMP_INSERT_GROUP_ABOVE, NC_("insert-group-position", "Above the group"), NULL },
{ GIMP_INSERT_GROUP_BELOW, NC_("insert-group-position", "Below the group"), NULL },
{ 0, NULL, NULL }
};
static GType type = 0;
if (G_UNLIKELY (! type))
{
type = g_enum_register_static ("GimpInsertGroupPosition", values);
gimp_type_set_translation_context (type, "insert-group-position");
gimp_enum_set_value_descriptions (type, descs);
}
return type;
}
/* Generated data ends here */

View File

@@ -174,3 +174,41 @@ typedef enum
GIMP_THEME_DARK, /*< desc="Dark Colors" >*/
GIMP_THEME_SYSTEM, /*< desc="System Colors" >*/
} GimpThemeScheme;
/**
* GimpInsertPosition:
* @GIMP_INSERT_ABOVE: Insert above selected item
* @GIMP_INSERT_BELOW: Insert below selected item
*
* Position for item insertion.
**/
#define GIMP_TYPE_INSERT_POSITION (gimp_insert_position_get_type ())
GType gimp_insert_position_get_type (void) G_GNUC_CONST;
typedef enum
{
GIMP_INSERT_ABOVE, /*< desc="Above selected" >*/
GIMP_INSERT_BELOW, /*< desc="Below selected" >*/
} GimpInsertPosition;
/**
* GimpInsertGroupPosition:
* @GIMP_INSERT_GROUP_TOP: Insert as top child
* @GIMP_INSERT_GROUP_BOTTOM: Insert as bottom child
* @GIMP_INSERT_GROUP_ABOVE: Insert above selected group
* @GIMP_INSERT_GROUP_BELOW: Insert below selected group
*
* Position for item insertion in an item group.
**/
#define GIMP_TYPE_INSERT_GROUP_POSITION (gimp_insert_group_position_get_type ())
GType gimp_insert_group_position_get_type (void) G_GNUC_CONST;
typedef enum
{
GIMP_INSERT_GROUP_TOP, /*< desc="As top child" >*/
GIMP_INSERT_GROUP_BOTTOM, /*< desc="As bottom child" >*/
GIMP_INSERT_GROUP_ABOVE, /*< desc="Above the group" >*/
GIMP_INSERT_GROUP_BELOW, /*< desc="Below the group" >*/
} GimpInsertGroupPosition;

View File

@@ -76,6 +76,8 @@ enum
PROP_LAYER_NEW_COMPOSITE_MODE,
PROP_LAYER_NEW_OPACITY,
PROP_LAYER_NEW_FILL_TYPE,
PROP_LAYER_NEW_INSERT_POSITION,
PROP_LAYER_NEW_INSERT_GROUP_POSITION,
PROP_LAYER_RESIZE_FILL_TYPE,
@@ -366,6 +368,22 @@ gimp_dialog_config_class_init (GimpDialogConfigClass *klass)
GIMP_FILL_TRANSPARENT,
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_PROP_ENUM (object_class, PROP_LAYER_NEW_INSERT_POSITION,
"layer-new-insert-position",
"Default new layer position",
LAYER_NEW_INSERT_POSITION_BLURB,
GIMP_TYPE_INSERT_POSITION,
GIMP_INSERT_ABOVE,
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_PROP_ENUM (object_class, PROP_LAYER_NEW_INSERT_GROUP_POSITION,
"layer-new-insert-group-position",
"Default new layer position in group",
LAYER_NEW_INSERT_GROUP_POSITION_BLURB,
GIMP_TYPE_INSERT_GROUP_POSITION,
GIMP_INSERT_GROUP_TOP,
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_PROP_ENUM (object_class, PROP_LAYER_RESIZE_FILL_TYPE,
"layer-resize-fill-type",
"Default layer resize fill type",
@@ -705,6 +723,12 @@ gimp_dialog_config_set_property (GObject *object,
case PROP_LAYER_NEW_FILL_TYPE:
config->layer_new_fill_type = g_value_get_enum (value);
break;
case PROP_LAYER_NEW_INSERT_POSITION:
config->layer_new_insert_position = g_value_get_enum (value);
break;
case PROP_LAYER_NEW_INSERT_GROUP_POSITION:
config->layer_new_insert_group_position = g_value_get_enum (value);
break;
case PROP_LAYER_RESIZE_FILL_TYPE:
config->layer_resize_fill_type = g_value_get_enum (value);
@@ -897,6 +921,12 @@ gimp_dialog_config_get_property (GObject *object,
case PROP_LAYER_NEW_FILL_TYPE:
g_value_set_enum (value, config->layer_new_fill_type);
break;
case PROP_LAYER_NEW_INSERT_POSITION:
g_value_set_enum (value, config->layer_new_insert_position);
break;
case PROP_LAYER_NEW_INSERT_GROUP_POSITION:
g_value_set_enum (value, config->layer_new_insert_group_position);
break;
case PROP_LAYER_RESIZE_FILL_TYPE:
g_value_set_enum (value, config->layer_resize_fill_type);

View File

@@ -73,6 +73,8 @@ struct _GimpDialogConfig
GimpLayerCompositeMode layer_new_composite_mode;
gdouble layer_new_opacity;
GimpFillType layer_new_fill_type;
GimpInsertPosition layer_new_insert_position;
GimpInsertGroupPosition layer_new_insert_group_position;
GimpFillType layer_resize_fill_type;

View File

@@ -650,6 +650,12 @@ _("Sets the default opacity for the 'New Layer' dialog.")
#define LAYER_NEW_FILL_TYPE_BLURB \
_("Sets the default fill type for the 'New Layer' dialog.")
#define LAYER_NEW_INSERT_POSITION_BLURB \
_("Sets the default insert position for the 'New Layer' dialog.")
#define LAYER_NEW_INSERT_GROUP_POSITION_BLURB \
_("Sets the default insert position in layer groups for the 'New Layer' dialog.")
#define LAYER_RESIZE_FILL_TYPE_BLURB \
_("Sets the default fill type for the 'Layer Boundary Size' dialog.")

View File

@@ -61,6 +61,8 @@ struct _LayerOptionsDialog
GimpLayerCompositeMode composite_mode;
gdouble opacity;
GimpFillType fill_type;
GimpInsertPosition insert_position;
GimpInsertGroupPosition insert_group_position;
gboolean lock_alpha;
gboolean rename_text_layers;
GimpLayerOptionsCallback callback;
@@ -122,6 +124,8 @@ layer_options_dialog_new (GimpImage *image,
GimpLayerCompositeMode layer_composite_mode,
gdouble layer_opacity,
GimpFillType layer_fill_type,
GimpInsertPosition insert_position,
GimpInsertGroupPosition insert_group_position,
gboolean layer_visible,
GimpColorTag layer_color_tag,
gboolean layer_lock_content,
@@ -154,20 +158,21 @@ layer_options_dialog_new (GimpImage *image,
private = g_slice_new0 (LayerOptionsDialog);
private->gimp = image->gimp;
private->layer = layer;
private->mode = layer_mode;
private->blend_space = layer_blend_space;
private->composite_space = layer_composite_space;
private->composite_mode = layer_composite_mode;
private->opacity = layer_opacity * 100.0;
private->fill_type = layer_fill_type;
private->lock_alpha = layer_lock_alpha;
private->rename_text_layers = FALSE;
private->callback = callback;
private->user_data = user_data;
private->link = NULL;
private->gimp = image->gimp;
private->layer = layer;
private->mode = layer_mode;
private->blend_space = layer_blend_space;
private->composite_space = layer_composite_space;
private->composite_mode = layer_composite_mode;
private->opacity = layer_opacity * 100.0;
private->fill_type = layer_fill_type;
private->insert_position = insert_position;
private->insert_group_position = insert_group_position;
private->lock_alpha = layer_lock_alpha;
private->rename_text_layers = FALSE;
private->callback = callback;
private->user_data = user_data;
private->link = NULL;
if (layer && gimp_item_is_text_layer (GIMP_ITEM (layer)))
private->rename_text_layers = GIMP_TEXT_LAYER (layer)->auto_rename;
@@ -446,13 +451,32 @@ layer_options_dialog_new (GimpImage *image,
{
/* The fill type */
combo = gimp_enum_combo_box_new (GIMP_TYPE_FILL_TYPE);
gimp_grid_attach_aligned (GTK_GRID (grid), 0, row,
gimp_grid_attach_aligned (GTK_GRID (grid), 0, row++,
_("_Fill with:"), 0.0, 0.5,
combo, 1);
gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo),
private->fill_type,
G_CALLBACK (gimp_int_combo_box_get_active),
&private->fill_type, NULL);
/* The insert position */
combo = gimp_enum_combo_box_new (GIMP_TYPE_INSERT_POSITION);
gimp_grid_attach_aligned (GTK_GRID (grid), 0, row++,
_("Insert position:"), 0.0, 0.5,
combo, 1);
gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo),
private->insert_position,
G_CALLBACK (gimp_int_combo_box_get_active),
&private->insert_position, NULL);
combo = gimp_enum_combo_box_new (GIMP_TYPE_INSERT_GROUP_POSITION);
gimp_grid_attach_aligned (GTK_GRID (grid), 0, row++,
_("Insert position in layer group:"), 0.0, 0.5,
combo, 1);
gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo),
private->insert_group_position,
G_CALLBACK (gimp_int_combo_box_get_active),
&private->insert_group_position, NULL);
}
button = item_options_dialog_get_lock_position (dialog);
@@ -553,6 +577,8 @@ layer_options_dialog_callback (GtkWidget *dialog,
private->composite_mode,
private->opacity / 100.0,
private->fill_type,
private->insert_position,
private->insert_group_position,
private->link,
width,
height,

View File

@@ -29,6 +29,8 @@ typedef void (* GimpLayerOptionsCallback) (GtkWidget *dialog,
GimpLayerCompositeMode layer_composite_mode,
gdouble layer_opacity,
GimpFillType layer_fill_type,
GimpInsertPosition insert_position,
GimpInsertGroupPosition insert_group_position,
GimpLink *link,
gint layer_width,
gint layer_height,
@@ -60,6 +62,8 @@ GtkWidget * layer_options_dialog_new (GimpImage *image,
GimpLayerCompositeMode layer_composite_mode,
gdouble layer_opacity,
GimpFillType layer_fill_type,
GimpInsertPosition insert_position,
GimpInsertGroupPosition insert_group_position,
gboolean layer_visible,
GimpColorTag layer_color_tag,
gboolean layer_lock_content,