From 6852fc8068a3a194c363df05750c1d33487f1db4 Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Tue, 27 Feb 2007 11:03:18 +0000 Subject: [PATCH] allow the parent progress to be NULL. Documented the API. 2007-02-27 Sven Neumann * app/core/gimpsubprogress.[ch]: allow the parent progress to be NULL. Documented the API. * app/core/gimpimage-scale.c: use the sub-progress unconditionally. svn path=/trunk/; revision=22010 --- ChangeLog | 7 ++++++ app/core/gimpimage-scale.c | 49 ++++++++++++++++---------------------- app/core/gimpsubprogress.c | 44 +++++++++++++++++++++++++++------- app/core/gimpsubprogress.h | 6 ++--- 4 files changed, 67 insertions(+), 39 deletions(-) diff --git a/ChangeLog b/ChangeLog index baf0851354..ac3206da0c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2007-02-27 Sven Neumann + + * app/core/gimpsubprogress.[ch]: allow the parent progress to be NULL. + Documented the API. + + * app/core/gimpimage-scale.c: use the sub-progress unconditionally. + 2007-02-27 Sven Neumann * app/core/Makefile.am diff --git a/app/core/gimpimage-scale.c b/app/core/gimpimage-scale.c index a98644ab29..a7442f20b8 100644 --- a/app/core/gimpimage-scale.c +++ b/app/core/gimpimage-scale.c @@ -49,15 +49,15 @@ gimp_image_scale (GimpImage *image, GimpProgress *progress) { GimpItem *item; - GimpProgress *sub_progress = NULL; + GimpProgress *sub_progress; GList *list; - GList *remove = NULL; + GList *remove = NULL; gint old_width; gint old_height; - gdouble img_scale_w = 1.0; - gdouble img_scale_h = 1.0; - gint progress_steps = 1; - gint progress_current = 0; + gdouble img_scale_w = 1.0; + gdouble img_scale_h = 1.0; + gint progress_steps; + gint progress_current; g_return_if_fail (GIMP_IS_IMAGE (image)); g_return_if_fail (new_width > 0 && new_height > 0); @@ -65,15 +65,12 @@ gimp_image_scale (GimpImage *image, gimp_set_busy (image->gimp); - if (progress) - { - sub_progress = gimp_sub_progress_new (progress); + sub_progress = gimp_sub_progress_new (progress); - progress_steps = (image->channels->num_children + - image->layers->num_children + - image->vectors->num_children + - 1 /* selection */); - } + progress_steps = (image->channels->num_children + + image->layers->num_children + + image->vectors->num_children + + 1 /* selection */); g_object_freeze_notify (G_OBJECT (image)); @@ -101,9 +98,8 @@ gimp_image_scale (GimpImage *image, { item = list->data; - if (sub_progress) - gimp_sub_progress_set_steps (GIMP_SUB_PROGRESS (sub_progress), - progress_current++, progress_steps); + gimp_sub_progress_set_steps (GIMP_SUB_PROGRESS (sub_progress), + progress_current++, progress_steps); gimp_item_scale (item, new_width, new_height, 0, 0, @@ -117,18 +113,17 @@ gimp_image_scale (GimpImage *image, { item = list->data; - if (sub_progress) - gimp_sub_progress_set_steps (GIMP_SUB_PROGRESS (sub_progress), - progress_current++, progress_steps); + gimp_sub_progress_set_steps (GIMP_SUB_PROGRESS (sub_progress), + progress_current++, progress_steps); + gimp_item_scale (item, new_width, new_height, 0, 0, interpolation_type, sub_progress); } /* Don't forget the selection mask! */ - if (sub_progress) - gimp_sub_progress_set_steps (GIMP_SUB_PROGRESS (sub_progress), - progress_current++, progress_steps); + gimp_sub_progress_set_steps (GIMP_SUB_PROGRESS (sub_progress), + progress_current++, progress_steps); gimp_item_scale (GIMP_ITEM (gimp_image_get_mask (image)), new_width, new_height, 0, 0, @@ -141,9 +136,8 @@ gimp_image_scale (GimpImage *image, { item = list->data; - if (sub_progress) - gimp_sub_progress_set_steps (GIMP_SUB_PROGRESS (sub_progress), - progress_current++, progress_steps); + gimp_sub_progress_set_steps (GIMP_SUB_PROGRESS (sub_progress), + progress_current++, progress_steps); if (! gimp_item_scale_by_factors (item, img_scale_w, img_scale_h, @@ -207,8 +201,7 @@ gimp_image_scale (GimpImage *image, gimp_image_undo_group_end (image); - if (sub_progress) - g_object_unref (sub_progress); + g_object_unref (sub_progress); gimp_viewable_size_changed (GIMP_VIEWABLE (image)); g_object_thaw_notify (G_OBJECT (image)); diff --git a/app/core/gimpsubprogress.c b/app/core/gimpsubprogress.c index 5bf0fdd9d2..4703430fb1 100644 --- a/app/core/gimpsubprogress.c +++ b/app/core/gimpsubprogress.c @@ -190,20 +190,41 @@ gimp_sub_progress_message (GimpProgress *progress, return FALSE; } +/** + * gimp_sub_progress_new: + * @progress: parent progress or %NULL + * + * GimpSubProgress implements the GimpProgress interface and can be + * used whereever a GimpProgress is needed. It maps progress + * information to a sub-range of its parent @progress. This is useful + * when an action breaks down into multiple sub-actions that itself + * need a #GimpProgress pointer. See gimp_image_scale() for an example. + * + * Return value: a new #GimpProgress object + */ GimpProgress * gimp_sub_progress_new (GimpProgress *progress) { GimpSubProgress *sub; - g_return_val_if_fail (GIMP_IS_PROGRESS (progress), NULL); + g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), NULL); sub = g_object_new (GIMP_TYPE_SUB_PROGRESS, NULL); - sub->progress = g_object_ref (progress); + if (progress) + sub->progress = g_object_ref (progress); return GIMP_PROGRESS (sub); } +/** + * gimp_sub_progress_set_range: + * @start: start value of range on the parent process + * @end: end value of range on the parent process + * + * Sets a range on the parent progress that this @progress should be + * mapped to. + */ void gimp_sub_progress_set_range (GimpSubProgress *progress, gdouble start, @@ -216,14 +237,21 @@ gimp_sub_progress_set_range (GimpSubProgress *progress, progress->end = end; } +/** + * gimp_sub_progress_set_step: + * @index: step index + * @num_steps: number of steps + * + * A more convenient form of gimp_sub_progress_set_range(). + */ void -gimp_sub_progress_set_steps (GimpSubProgress *progress, - gint num, - gint steps) +gimp_sub_progress_set_step (GimpSubProgress *progress, + gint index, + gint num_steps) { g_return_if_fail (GIMP_IS_SUB_PROGRESS (progress)); - g_return_if_fail (num < steps && steps > 0); + g_return_if_fail (index < num_steps && num_steps > 0); - progress->start = (gdouble) num / steps; - progress->end = (gdouble) (num + 1) / steps; + progress->start = (gdouble) index / num_steps; + progress->end = (gdouble) (index + 1) / num_steps; } diff --git a/app/core/gimpsubprogress.h b/app/core/gimpsubprogress.h index a1e8d0ca8a..8da12bd7f3 100644 --- a/app/core/gimpsubprogress.h +++ b/app/core/gimpsubprogress.h @@ -51,9 +51,9 @@ GimpProgress * gimp_sub_progress_new (GimpProgress *progress); void gimp_sub_progress_set_range (GimpSubProgress *progress, gdouble start, gdouble end); -void gimp_sub_progress_set_steps (GimpSubProgress *progress, - gint num, - gint steps); +void gimp_sub_progress_set_step (GimpSubProgress *progress, + gint index, + gint num_steps);