Hi!

This is a patch that adds a gradient segment left/right endpoint
color+opacity set/get routines. Please don't apply it yet, because I'm not
sure if it's philosophy is correct. I'll welcome any comments.

What I decided to do was specify the gradient name and segment index as
parameters to each of the function. However, since the segments in a
gradient are stored as a linked list, it means that accessing segment No.
i is O(i), and on average O(n) where n is the number of segments in the
gradient. This is sub-optimal.

Should we use cursors or the selection instead?

Regards,

        Shlomi Fish

----------------------------------------------------------------------
Shlomi Fish        [EMAIL PROTECTED]
Home Page:         http://t2.technion.ac.il/~shlomif/

An apple a day will keep a doctor away. Two apples a day will keep two
doctors away.

        Falk Fish
--- ../gimp-1.3.23/tools/pdbgen/Makefile.am     2003-10-05 15:16:51.000000000 +0200
+++ gimp/tools/pdbgen/Makefile.am       2003-12-12 21:00:22.000000000 +0200
@@ -15,6 +15,7 @@
        pdb/font_select.pdb     \
        pdb/fonts.pdb           \
        pdb/gimprc.pdb          \
+       pdb/gradient_edit.pdb   \
        pdb/gradient_select.pdb \
        pdb/gradients.pdb       \
        pdb/guides.pdb          \
--- ../gimp-1.3.23/app/pdb/Makefile.am  2003-10-05 15:16:14.000000000 +0200
+++ gimp/app/pdb/Makefile.am    2003-12-12 20:57:07.000000000 +0200
@@ -20,6 +20,7 @@
        font_select_cmds.c      \
        fonts_cmds.c            \
        gimprc_cmds.c           \
+       gradient_edit_cmds.c \
        gradient_select_cmds.c  \
        gradients_cmds.c        \
        guides_cmds.c           \
--- ../gimp-1.3.23/tools/pdbgen/groups.pl       2003-09-07 22:57:12.000000000 +0300
+++ gimp/tools/pdbgen/groups.pl 2003-12-12 20:45:20.000000000 +0200
@@ -13,6 +13,7 @@
     font_select
     fonts
     gimprc
+    gradient_edit
     gradient_select
     gradients
     guides
--- ../gimp-1.3.23/tools/pdbgen/pdb/gradient_edit.pdb   1970-01-01 02:00:00.000000000 
+0200
+++ gimp/tools/pdbgen/pdb/gradient_edit.pdb     2003-12-17 20:53:44.000000000 +0200
@@ -0,0 +1,225 @@
+# The GIMP -- an image manipulation program
+# Copyright (C) 1995 Spencer Kimball and Peter Mattis
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+sub pdb_misc {
+    $author = $copyright = 'Shlomi Fish';
+    $date = '2003';
+}
+
+sub _gen_gradient_search_for_segment_code
+{
+    my $action_on_success = shift;
+
+    return <<"CODE";
+{
+  if (strlen (name))
+    {
+      gradient = (GimpGradient *)
+        gimp_container_get_child_by_name (gimp->gradient_factory->container,
+                                          name);
+    }
+  else
+    {
+      gradient = gimp_context_get_gradient (gimp_get_current_context (gimp));;
+    }
+
+  if (gradient)
+    {
+      GimpGradientSegment * seg;
+      int i;
+      seg = gradient->segments;
+      i = 0;
+      while (seg && (i < segment))
+        {
+          seg = seg->next;
+          i++;
+        }
+      if (seg && (i == segment))
+        {
+          /* Success */
+          $action_on_success
+        }
+      else
+        {
+          success = FALSE;
+        }
+    }
+  else
+    {
+      success = FALSE;
+    }
+}
+    
+CODE
+}
+
+sub other_side
+{
+    my $side = shift;
+
+    return ($side eq "left") ? "right" : "left";
+}
+
+sub _gen_gradient_set_side_end_color
+{
+    my $side = shift;
+
+    my $other_side = other_side($side);
+
+    $blurb = "Retrieves the $side endpoint color of the specified gradient and 
segment";
+
+    $help = <<"HELP";
+This procedure retrieves the $side endpoint color of the specified segment of
+the specified gradient.
+HELP
+
+    &pdb_misc;
+
+    @inargs = (
+        {
+            name => 'name',
+            type => 'string',
+            desc => 'The name of the gradient to get the color from',
+        },
+        {
+            name => 'segment',
+            type => '0 <= int32',
+            desc => 'The index of the segment from to which the endpoint belongs',
+        },
+        {
+            name => 'color',
+            type => 'color',
+            desc => "The color to set",
+        },
+        {
+            name => "opacity",
+            type => '0 <= float <= 100.0',
+            desc => "The opacity to set for the endpoint",
+        },
+        
+    );
+
+    @outargs = (
+    );
+
+    my @blend_params = ("&color","&(seg->${other_side}_color)");
+    if ($side eq "right")
+    {
+        @blend_params = reverse(@blend_params);
+    }
+    
+    %invoke = (
+        vars => [ 'GimpGradient *gradient = NULL' ],
+        code => &_gen_gradient_search_for_segment_code(<<"CODE"),
+          color.a = opacity / 100.0;
+          gimp_gradient_segments_blend_endpoints (seg, seg, 
+                                                  $blend_params[0], 
+                                                  $blend_params[1],
+                                                  TRUE,TRUE);
+          /* seg->${side}_color = color;
+          seg->${side}_color.a = opacity/100.0; */
+          gimp_data_dirty (GIMP_DATA (gradient));
+CODE
+    );
+}
+
+
+sub _gen_gradient_get_side_end_color
+{
+    my $side = shift;
+
+    $blurb = "Retrieves the $side endpoint color of the specified gradient and 
segment";
+
+    $help = <<"HELP";
+This procedure retrieves the $side endpoint color of the specified segment of
+the specified gradient.
+HELP
+
+    &pdb_misc;
+
+    @inargs = (
+        {
+            name => 'name',
+            type => 'string',
+            desc => 'The name of the gradient to get the color from',
+        },
+        {
+            name => 'segment',
+            type => '0 <= int32',
+            desc => 'The index of the segment from to which the endpoint belongs',
+        },
+    );
+
+    @outargs = (
+        {
+            name => 'color',
+            type => 'color',
+            desc => "The return color",
+            void_ret => 1,
+            init => 1,
+        },
+        {
+            name => "opacity",
+            type => 'float',
+            desc => "The opacity of the endpoint",
+        },
+    );
+    
+    %invoke = (
+        vars => [ 'GimpGradient *gradient = NULL' ],
+        code => &_gen_gradient_search_for_segment_code(<<"CODE"),
+          color = seg->${side}_color;
+          opacity = color.a * 100.0;
+CODE
+    );
+}
+
+sub gradient_get_left_end_color
+{
+    &_gen_gradient_get_side_end_color("left");
+}
+
+sub gradient_get_right_end_color
+{
+    &_gen_gradient_get_side_end_color("right");
+}
+
+sub gradient_set_left_end_color
+{
+    &_gen_gradient_set_side_end_color("left");
+}
+
+sub gradient_set_right_end_color
+{
+    &_gen_gradient_set_side_end_color("right");
+}
+
[EMAIL PROTECTED] = qw(<string.h> "core/gimp.h" "core/gimpcontext.h" 
+    "core/gimpgradient.h" "core/gimpcontainer.h" 
+    "core/gimpdatafactory.h" "core/gimplist.h");
+
[EMAIL PROTECTED] = (qw(gradient_get_left_end_color gradient_get_right_end_color),
+    qw(gradient_set_left_end_color gradient_set_right_end_color)
+    );
+
+# %exports = (app => [EMAIL PROTECTED], lib => [EMAIL PROTECTED]);
+%exports = (app => [EMAIL PROTECTED]);
+
+$desc = 'Gradient';
+
+1;
+
_______________________________________________
Gimp-developer mailing list
[EMAIL PROTECTED]
http://lists.xcf.berkeley.edu/mailman/listinfo/gimp-developer

Reply via email to