[gimp/wip/gradient-edit: 201/225] app: add gimp_gradient_segment_range_merge()
- From: N/A <ell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/wip/gradient-edit: 201/225] app: add gimp_gradient_segment_range_merge()
- Date: Fri, 6 Oct 2017 17:07:21 +0000 (UTC)
commit 84544c1fea57f2141620370dbe8bcbea5dc02c8f
Author: Ell <ell_se yahoo com>
Date: Sun Jul 30 15:11:02 2017 -0400
app: add gimp_gradient_segment_range_merge()
... which merges a segment range into a single segment, that spans
the entire range, and has the same endpoint colors. The merged
segment's midpoint is at its center, and its blend function and
coloring type are those of the range's segments if they're uniform,
or the default ones otherwise.
app/core/gimpgradient.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++
app/core/gimpgradient.h | 6 ++++
2 files changed, 70 insertions(+), 0 deletions(-)
---
diff --git a/app/core/gimpgradient.c b/app/core/gimpgradient.c
index 15a40b0..4d99a8e 100644
--- a/app/core/gimpgradient.c
+++ b/app/core/gimpgradient.c
@@ -1792,6 +1792,70 @@ gimp_gradient_segment_range_delete (GimpGradient *gradient,
}
void
+gimp_gradient_segment_range_merge (GimpGradient *gradient,
+ GimpGradientSegment *start_seg,
+ GimpGradientSegment *end_seg,
+ GimpGradientSegment **final_start_seg,
+ GimpGradientSegment **final_end_seg)
+{
+ GimpGradientSegment *seg;
+
+ g_return_if_fail (GIMP_IS_GRADIENT (gradient));
+
+ if (! end_seg)
+ end_seg = gimp_gradient_segment_get_last (start_seg);
+
+ gimp_data_freeze (GIMP_DATA (gradient));
+
+ /* Copy the end segment's right position and color to the start segment */
+
+ start_seg->right = end_seg->right;
+ start_seg->right_color_type = end_seg->right_color_type;
+ start_seg->right_color = end_seg->right_color;
+
+ /* Center the start segment's midpoint */
+
+ start_seg->middle = (start_seg->left + start_seg->right) / 2.0;
+
+ /* Remove range segments past the start segment from the segment list */
+
+ start_seg->next = end_seg->next;
+
+ if (start_seg->next)
+ start_seg->next->prev = start_seg;
+
+ /* Merge the range's blend function and coloring type, and free the rest of
+ * the segments.
+ */
+
+ seg = end_seg;
+
+ while (seg != start_seg)
+ {
+ GimpGradientSegment *prev = seg->prev;
+
+ /* If the blend function and/or coloring type aren't uniform, reset them. */
+
+ if (seg->type != start_seg->type)
+ start_seg->type = GIMP_GRADIENT_SEGMENT_LINEAR;
+
+ if (seg->color != start_seg->color)
+ start_seg->color = GIMP_GRADIENT_SEGMENT_RGB;
+
+ gimp_gradient_segment_free (seg);
+
+ seg = prev;
+ }
+
+ if (final_start_seg)
+ *final_start_seg = start_seg;
+ if (final_end_seg)
+ *final_end_seg = start_seg;
+
+ gimp_data_thaw (GIMP_DATA (gradient));
+}
+
+void
gimp_gradient_segment_range_recenter_handles (GimpGradient *gradient,
GimpGradientSegment *start_seg,
GimpGradientSegment *end_seg)
diff --git a/app/core/gimpgradient.h b/app/core/gimpgradient.h
index f9f9987..c550ba1 100644
--- a/app/core/gimpgradient.h
+++ b/app/core/gimpgradient.h
@@ -265,6 +265,12 @@ void gimp_gradient_segment_range_delete (GimpGradient *gradient,
GimpGradientSegment **final_start_seg,
GimpGradientSegment **final_end_seg);
+void gimp_gradient_segment_range_merge (GimpGradient *gradient,
+ GimpGradientSegment *start_seg,
+ GimpGradientSegment *end_seg,
+ GimpGradientSegment **final_start_seg,
+ GimpGradientSegment **final_end_seg);
+
void gimp_gradient_segment_range_recenter_handles
(GimpGradient *gradient,
GimpGradientSegment *start_seg,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]