void gimp_display_shell_set_layer_style (GimpDisplayShell *shell, cairo_t *cr, GimpLayer *layer) { cairo_pattern_t *pattern; g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell)); g_return_if_fail (cr != NULL); g_return_if_fail (GIMP_IS_LAYER (layer)); cairo_set_line_width (cr, 1.0); cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE); if (gimp_layer_get_mask (layer) && gimp_layer_mask_get_edit (gimp_layer_get_mask (layer))) { pattern = gimp_cairo_stipple_pattern_create (&layer_mask_fg, &layer_mask_bg, 0); } else if (gimp_viewable_get_children (GIMP_VIEWABLE (layer))) { pattern = gimp_cairo_stipple_pattern_create (&layer_group_fg, &layer_group_bg, 0); } else { pattern = gimp_cairo_stipple_pattern_create (&layer_fg, &layer_bg, 0); } cairo_set_source (cr, pattern); cairo_pattern_destroy (pattern); }
void layers_actions_update (GimpActionGroup *group, gpointer data) { GimpImage *image = action_data_get_image (data); GimpLayer *layer = NULL; GimpLayerMask *mask = NULL; /* layer mask */ gboolean fs = FALSE; /* floating sel */ gboolean ac = FALSE; /* active channel */ gboolean sel = FALSE; gboolean alpha = FALSE; /* alpha channel present */ gboolean indexed = FALSE; /* is indexed */ gboolean lock_alpha = FALSE; gboolean text_layer = FALSE; GList *next = NULL; GList *prev = NULL; if (image) { fs = (gimp_image_floating_sel (image) != NULL); ac = (gimp_image_get_active_channel (image) != NULL); sel = ! gimp_channel_is_empty (gimp_image_get_mask (image)); indexed = (gimp_image_base_type (image) == GIMP_INDEXED); layer = gimp_image_get_active_layer (image); if (layer) { GList *list; mask = gimp_layer_get_mask (layer); lock_alpha = gimp_layer_get_lock_alpha (layer); alpha = gimp_drawable_has_alpha (GIMP_DRAWABLE (layer)); list = g_list_find (GIMP_LIST (image->layers)->list, layer); if (list) { prev = g_list_previous (list); next = g_list_next (list); } if (layer) text_layer = gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)); } } #define SET_VISIBLE(action,condition) \ gimp_action_group_set_action_visible (group, action, (condition) != 0) #define SET_SENSITIVE(action,condition) \ gimp_action_group_set_action_sensitive (group, action, (condition) != 0) #define SET_ACTIVE(action,condition) \ gimp_action_group_set_action_active (group, action, (condition) != 0) SET_VISIBLE ("layers-text-tool", text_layer && !ac); SET_SENSITIVE ("layers-edit-attributes", layer && !fs && !ac); SET_SENSITIVE ("layers-new", image); SET_SENSITIVE ("layers-new-last-values", image); SET_SENSITIVE ("layers-duplicate", layer && !fs && !ac); SET_SENSITIVE ("layers-delete", layer && !ac); SET_SENSITIVE ("layers-select-top", layer && !fs && !ac && prev); SET_SENSITIVE ("layers-select-bottom", layer && !fs && !ac && next); SET_SENSITIVE ("layers-select-previous", layer && !fs && !ac && prev); SET_SENSITIVE ("layers-select-next", layer && !fs && !ac && next); SET_SENSITIVE ("layers-raise", layer && !fs && !ac && prev); SET_SENSITIVE ("layers-raise-to-top", layer && !fs && !ac && prev); SET_SENSITIVE ("layers-lower", layer && !fs && !ac && next); SET_SENSITIVE ("layers-lower-to-bottom", layer && !fs && !ac && next); SET_SENSITIVE ("layers-anchor", layer && fs && !ac); SET_SENSITIVE ("layers-merge-down", layer && !fs && !ac && next); SET_SENSITIVE ("layers-merge-layers", layer && !fs && !ac); SET_SENSITIVE ("layers-flatten-image", layer && !fs && !ac); SET_VISIBLE ("layers-text-discard", text_layer && !ac); SET_VISIBLE ("layers-text-to-vectors", text_layer && !ac); SET_VISIBLE ("layers-text-along-vectors", text_layer && !ac); SET_VISIBLE ("layers-text-selection-replace", text_layer && !ac); SET_VISIBLE ("layers-text-selection-add", text_layer && !ac); SET_VISIBLE ("layers-text-selection-subtract", text_layer && !ac); SET_VISIBLE ("layers-text-selection-intersect", text_layer && !ac); SET_SENSITIVE ("layers-resize", layer && !ac); SET_SENSITIVE ("layers-resize-to-image", layer && !ac); SET_SENSITIVE ("layers-scale", layer && !ac); SET_SENSITIVE ("layers-crop", layer && sel); SET_SENSITIVE ("layers-alpha-add", layer && !fs && !alpha); SET_SENSITIVE ("layers-alpha-remove", layer && !fs && alpha); SET_SENSITIVE ("layers-lock-alpha", layer); SET_ACTIVE ("layers-lock-alpha", lock_alpha); SET_SENSITIVE ("layers-mask-add", layer && !fs && !ac && !mask); SET_SENSITIVE ("layers-mask-apply", layer && !fs && !ac && mask); SET_SENSITIVE ("layers-mask-delete", layer && !fs && !ac && mask); SET_SENSITIVE ("layers-mask-edit", layer && !fs && !ac && mask); SET_SENSITIVE ("layers-mask-show", layer && !fs && !ac && mask); SET_SENSITIVE ("layers-mask-disable", layer && !fs && !ac && mask); SET_ACTIVE ("layers-mask-edit", mask && gimp_layer_mask_get_edit (mask)); SET_ACTIVE ("layers-mask-show", mask && gimp_layer_mask_get_show (mask)); SET_ACTIVE ("layers-mask-disable", mask && !gimp_layer_mask_get_apply (mask)); SET_SENSITIVE ("layers-mask-selection-replace", layer && !fs && !ac && mask); SET_SENSITIVE ("layers-mask-selection-add", layer && !fs && !ac && mask); SET_SENSITIVE ("layers-mask-selection-subtract", layer && !fs && !ac && mask); SET_SENSITIVE ("layers-mask-selection-intersect", layer && !fs && !ac && mask); SET_SENSITIVE ("layers-alpha-selection-replace", layer && !fs && !ac); SET_SENSITIVE ("layers-alpha-selection-add", layer && !fs && !ac); SET_SENSITIVE ("layers-alpha-selection-subtract", layer && !fs && !ac); SET_SENSITIVE ("layers-alpha-selection-intersect", layer && !fs && !ac); #undef SET_VISIBLE #undef SET_SENSITIVE #undef SET_ACTIVE }
void layers_actions_update (GimpActionGroup *group, gpointer data) { GimpImage *image = action_data_get_image (data); GimpLayer *layer = NULL; GimpLayerMask *mask = NULL; /* layer mask */ gboolean fs = FALSE; /* floating sel */ gboolean ac = FALSE; /* active channel */ gboolean sel = FALSE; gboolean alpha = FALSE; /* alpha channel present */ gboolean indexed = FALSE; /* is indexed */ gboolean lock_alpha = FALSE; gboolean can_lock_alpha = FALSE; gboolean text_layer = FALSE; gboolean writable = FALSE; gboolean children = FALSE; GList *next = NULL; GList *next_visible = NULL; GList *prev = NULL; if (image) { fs = (gimp_image_get_floating_selection (image) != NULL); ac = (gimp_image_get_active_channel (image) != NULL); sel = ! gimp_channel_is_empty (gimp_image_get_mask (image)); indexed = (gimp_image_base_type (image) == GIMP_INDEXED); layer = gimp_image_get_active_layer (image); if (layer) { GList *layer_list; GList *list; mask = gimp_layer_get_mask (layer); lock_alpha = gimp_layer_get_lock_alpha (layer); can_lock_alpha = gimp_layer_can_lock_alpha (layer); alpha = gimp_drawable_has_alpha (GIMP_DRAWABLE (layer)); writable = ! gimp_item_is_content_locked (GIMP_ITEM (layer)); if (gimp_viewable_get_children (GIMP_VIEWABLE (layer))) children = TRUE; layer_list = gimp_item_get_container_iter (GIMP_ITEM (layer)); list = g_list_find (layer_list, layer); if (list) { prev = g_list_previous (list); next = g_list_next (list); for (next_visible = next; next_visible; next_visible = g_list_next (next_visible)) { if (gimp_item_get_visible (next_visible->data)) { /* "next_visible" is actually "next_visible" and * "writable" and "not group" */ if (gimp_item_is_content_locked (next_visible->data) || gimp_viewable_get_children (next_visible->data)) next_visible = NULL; break; } } } text_layer = gimp_item_is_text_layer (GIMP_ITEM (layer)); } } #define SET_VISIBLE(action,condition) \ gimp_action_group_set_action_visible (group, action, (condition) != 0) #define SET_SENSITIVE(action,condition) \ gimp_action_group_set_action_sensitive (group, action, (condition) != 0) #define SET_ACTIVE(action,condition) \ gimp_action_group_set_action_active (group, action, (condition) != 0) #define SET_LABEL(action,label) \ gimp_action_group_set_action_label (group, action, label) SET_VISIBLE ("layers-text-tool", text_layer && !ac); SET_SENSITIVE ("layers-edit-attributes", layer && !fs && !ac); if (layer && gimp_layer_is_floating_sel (layer)) { SET_LABEL ("layers-new", C_("layers-action", "To _New Layer")); SET_LABEL ("layers-new-last-values", C_("layers-action", "To _New Layer")); } else { SET_LABEL ("layers-new", C_("layers-action", "_New Layer...")); SET_LABEL ("layers-new-last-values", C_("layers-action", "_New Layer")); } SET_SENSITIVE ("layers-new", image); SET_SENSITIVE ("layers-new-last-values", image); SET_SENSITIVE ("layers-new-from-visible", image); SET_SENSITIVE ("layers-new-group", image && !indexed); SET_SENSITIVE ("layers-duplicate", layer && !fs && !ac); SET_SENSITIVE ("layers-delete", layer && !ac); SET_SENSITIVE ("layers-select-top", layer && !fs && !ac && prev); SET_SENSITIVE ("layers-select-bottom", layer && !fs && !ac && next); SET_SENSITIVE ("layers-select-previous", layer && !fs && !ac && prev); SET_SENSITIVE ("layers-select-next", layer && !fs && !ac && next); SET_SENSITIVE ("layers-raise", layer && !fs && !ac && prev); SET_SENSITIVE ("layers-raise-to-top", layer && !fs && !ac && prev); SET_SENSITIVE ("layers-lower", layer && !fs && !ac && next); SET_SENSITIVE ("layers-lower-to-bottom", layer && !fs && !ac && next); SET_SENSITIVE ("layers-anchor", layer && fs && !ac); SET_SENSITIVE ("layers-merge-down", layer && !fs && !ac && next_visible); SET_VISIBLE ("layers-merge-group", children); SET_SENSITIVE ("layers-merge-group", layer && !fs && !ac && children); SET_SENSITIVE ("layers-merge-layers", layer && !fs && !ac); SET_SENSITIVE ("layers-flatten-image", layer && !fs && !ac); SET_VISIBLE ("layers-text-discard", text_layer && !ac); SET_VISIBLE ("layers-text-to-vectors", text_layer && !ac); SET_VISIBLE ("layers-text-along-vectors", text_layer && !ac); SET_SENSITIVE ("layers-resize", writable && !ac); SET_SENSITIVE ("layers-resize-to-image", writable && !ac); SET_SENSITIVE ("layers-scale", writable && !ac); SET_SENSITIVE ("layers-crop", writable && sel); SET_SENSITIVE ("layers-alpha-add", writable && !children && !fs && !alpha); SET_SENSITIVE ("layers-alpha-remove", writable && !children && !fs && alpha); SET_SENSITIVE ("layers-lock-alpha", can_lock_alpha); SET_ACTIVE ("layers-lock-alpha", lock_alpha); SET_SENSITIVE ("layers-mask-add", layer && !fs && !ac && !mask && !children); SET_SENSITIVE ("layers-mask-apply", writable && !fs && !ac && mask && !children); SET_SENSITIVE ("layers-mask-delete", layer && !fs && !ac && mask); SET_SENSITIVE ("layers-mask-edit", layer && !fs && !ac && mask); SET_SENSITIVE ("layers-mask-show", layer && !fs && !ac && mask); SET_SENSITIVE ("layers-mask-disable", layer && !fs && !ac && mask); SET_ACTIVE ("layers-mask-edit", mask && gimp_layer_mask_get_edit (mask)); SET_ACTIVE ("layers-mask-show", mask && gimp_layer_mask_get_show (mask)); SET_ACTIVE ("layers-mask-disable", mask && !gimp_layer_mask_get_apply (mask)); SET_SENSITIVE ("layers-mask-selection-replace", layer && !fs && !ac && mask); SET_SENSITIVE ("layers-mask-selection-add", layer && !fs && !ac && mask); SET_SENSITIVE ("layers-mask-selection-subtract", layer && !fs && !ac && mask); SET_SENSITIVE ("layers-mask-selection-intersect", layer && !fs && !ac && mask); SET_SENSITIVE ("layers-alpha-selection-replace", layer && !fs && !ac); SET_SENSITIVE ("layers-alpha-selection-add", layer && !fs && !ac); SET_SENSITIVE ("layers-alpha-selection-subtract", layer && !fs && !ac); SET_SENSITIVE ("layers-alpha-selection-intersect", layer && !fs && !ac); #undef SET_VISIBLE #undef SET_SENSITIVE #undef SET_ACTIVE #undef SET_LABEL }