From 72bcb72c44a8c14b5ee6a7bdd4043ac0a3613523 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Sat, 5 Jun 2010 22:42:00 +0200 Subject: [PATCH] app: rename gimp_template_create_image() to gimp_image_new_from_template() and move it from gimptemplate.c to gimpimage-new.c --- app/actions/templates-commands.c | 2 +- app/core/gimpimage-new.c | 72 +++++++++++++++++++++++++++++ app/core/gimpimage-new.h | 3 ++ app/core/gimptemplate.c | 77 -------------------------------- app/core/gimptemplate.h | 12 ++--- app/dialogs/image-new-dialog.c | 2 +- 6 files changed, 81 insertions(+), 87 deletions(-) diff --git a/app/actions/templates-commands.c b/app/actions/templates-commands.c index 57d413a61e..cfd327421d 100644 --- a/app/actions/templates-commands.c +++ b/app/actions/templates-commands.c @@ -91,7 +91,7 @@ templates_create_image_cmd_callback (GtkAction *action, if (template && gimp_container_have (container, GIMP_OBJECT (template))) { - gimp_template_create_image (gimp, template, context); + gimp_image_new_from_template (gimp, template, context); gimp_image_new_set_last_template (gimp, template); } } diff --git a/app/core/gimpimage-new.c b/app/core/gimpimage-new.c index 9c46a8f673..a1addfd00e 100644 --- a/app/core/gimpimage-new.c +++ b/app/core/gimpimage-new.c @@ -31,6 +31,7 @@ #include "gimp.h" #include "gimpbuffer.h" #include "gimpchannel.h" +#include "gimpcontext.h" #include "gimpimage.h" #include "gimpimage-colormap.h" #include "gimpimage-new.h" @@ -78,6 +79,77 @@ gimp_image_new_set_last_template (Gimp *gimp, G_OBJECT (gimp->image_new_last_template), 0); } +GimpImage * +gimp_image_new_from_template (Gimp *gimp, + GimpTemplate *template, + GimpContext *context) +{ + GimpImage *image; + GimpLayer *layer; + GimpImageType type; + gint width, height; + + g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL); + g_return_val_if_fail (GIMP_IS_TEMPLATE (template), NULL); + g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL); + + image = gimp_create_image (gimp, + template->width, template->height, + template->image_type, + FALSE); + + gimp_image_undo_disable (image); + + if (template->comment) + { + GimpParasite *parasite; + + parasite = gimp_parasite_new ("gimp-comment", + GIMP_PARASITE_PERSISTENT, + strlen (template->comment) + 1, + template->comment); + gimp_image_parasite_attach (image, parasite); + gimp_parasite_free (parasite); + } + + gimp_image_set_resolution (image, + template->xresolution, template->yresolution); + gimp_image_set_unit (image, template->resolution_unit); + + width = gimp_image_get_width (image); + height = gimp_image_get_height (image); + + switch (template->fill_type) + { + case GIMP_TRANSPARENT_FILL: + type = ((template->image_type == GIMP_RGB) ? + GIMP_RGBA_IMAGE : GIMP_GRAYA_IMAGE); + break; + default: + type = ((template->image_type == GIMP_RGB) ? + GIMP_RGB_IMAGE : GIMP_GRAY_IMAGE); + break; + } + + layer = gimp_layer_new (image, width, height, type, + _("Background"), + GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE); + + gimp_drawable_fill_by_type (GIMP_DRAWABLE (layer), + context, template->fill_type); + + gimp_image_add_layer (image, layer, NULL, 0, FALSE); + + gimp_image_undo_enable (image); + gimp_image_clean_all (image); + + gimp_create_display (gimp, image, template->unit, 1.0); + + g_object_unref (image); + + return image; +} + GimpImage * gimp_image_new_from_drawable (Gimp *gimp, GimpDrawable *drawable) diff --git a/app/core/gimpimage-new.h b/app/core/gimpimage-new.h index 178615789e..d07e780b97 100644 --- a/app/core/gimpimage-new.h +++ b/app/core/gimpimage-new.h @@ -24,6 +24,9 @@ GimpTemplate * gimp_image_new_get_last_template (Gimp *gimp, void gimp_image_new_set_last_template (Gimp *gimp, GimpTemplate *template); +GimpImage * gimp_image_new_from_template (Gimp *gimp, + GimpTemplate *template, + GimpContext *context); GimpImage * gimp_image_new_from_drawable (Gimp *gimp, GimpDrawable *drawable); GimpImage * gimp_image_new_from_component (Gimp *gimp, diff --git a/app/core/gimptemplate.c b/app/core/gimptemplate.c index fe45ede989..250a1a6045 100644 --- a/app/core/gimptemplate.c +++ b/app/core/gimptemplate.c @@ -20,8 +20,6 @@ #include "config.h" -#include - #include #include "libgimpbase/gimpbase.h" @@ -29,11 +27,7 @@ #include "core-types.h" -#include "gimp.h" -#include "gimpcontext.h" #include "gimpimage.h" -#include "gimpimage-undo.h" -#include "gimplayer.h" #include "gimpprojection.h" #include "gimptemplate.h" @@ -348,74 +342,3 @@ gimp_template_set_from_image (GimpTemplate *template, if (comment) g_free (comment); } - -GimpImage * -gimp_template_create_image (Gimp *gimp, - GimpTemplate *template, - GimpContext *context) -{ - GimpImage *image; - GimpLayer *layer; - GimpImageType type; - gint width, height; - - g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL); - g_return_val_if_fail (GIMP_IS_TEMPLATE (template), NULL); - g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL); - - image = gimp_create_image (gimp, - template->width, template->height, - template->image_type, - FALSE); - - gimp_image_undo_disable (image); - - if (template->comment) - { - GimpParasite *parasite; - - parasite = gimp_parasite_new ("gimp-comment", - GIMP_PARASITE_PERSISTENT, - strlen (template->comment) + 1, - template->comment); - gimp_image_parasite_attach (image, parasite); - gimp_parasite_free (parasite); - } - - gimp_image_set_resolution (image, - template->xresolution, template->yresolution); - gimp_image_set_unit (image, template->resolution_unit); - - width = gimp_image_get_width (image); - height = gimp_image_get_height (image); - - switch (template->fill_type) - { - case GIMP_TRANSPARENT_FILL: - type = ((template->image_type == GIMP_RGB) ? - GIMP_RGBA_IMAGE : GIMP_GRAYA_IMAGE); - break; - default: - type = ((template->image_type == GIMP_RGB) ? - GIMP_RGB_IMAGE : GIMP_GRAY_IMAGE); - break; - } - - layer = gimp_layer_new (image, width, height, type, - _("Background"), - GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE); - - gimp_drawable_fill_by_type (GIMP_DRAWABLE (layer), - context, template->fill_type); - - gimp_image_add_layer (image, layer, NULL, 0, FALSE); - - gimp_image_undo_enable (image); - gimp_image_clean_all (image); - - gimp_create_display (gimp, image, template->unit, 1.0); - - g_object_unref (image); - - return image; -} diff --git a/app/core/gimptemplate.h b/app/core/gimptemplate.h index ffc1598cb1..1a68c38231 100644 --- a/app/core/gimptemplate.h +++ b/app/core/gimptemplate.h @@ -78,16 +78,12 @@ struct _GimpTemplateClass }; -GType gimp_template_get_type (void) G_GNUC_CONST; +GType gimp_template_get_type (void) G_GNUC_CONST; -GimpTemplate * gimp_template_new (const gchar *name); +GimpTemplate * gimp_template_new (const gchar *name); -void gimp_template_set_from_image (GimpTemplate *template, - GimpImage *image); - -GimpImage * gimp_template_create_image (Gimp *gimp, - GimpTemplate *template, - GimpContext *context); +void gimp_template_set_from_image (GimpTemplate *template, + GimpImage *image); #endif /* __GIMP_TEMPLATE__ */ diff --git a/app/dialogs/image-new-dialog.c b/app/dialogs/image-new-dialog.c index 28ad571f9f..0fc0375324 100644 --- a/app/dialogs/image-new-dialog.c +++ b/app/dialogs/image-new-dialog.c @@ -344,7 +344,7 @@ image_new_create_image (ImageNewDialog *dialog) gtk_widget_destroy (dialog->dialog); - gimp_template_create_image (gimp, template, gimp_get_user_context (gimp)); + gimp_image_new_from_template (gimp, template, gimp_get_user_context (gimp)); gimp_image_new_set_last_template (gimp, template); g_object_unref (template);