1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1997 David Mosberger
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
33 #include "gtkdrawingarea.h"
35 #include "gtkmarshalers.h"
36 #include "gtkradiobutton.h"
38 #include "gtkprivate.h"
42 #define RADIUS 3 /* radius of the control points */
43 #define MIN_DISTANCE 8 /* min distance between control points */
45 #define GRAPH_MASK (GDK_EXPOSURE_MASK | \
46 GDK_POINTER_MOTION_MASK | \
47 GDK_POINTER_MOTION_HINT_MASK | \
48 GDK_ENTER_NOTIFY_MASK | \
49 GDK_BUTTON_PRESS_MASK | \
50 GDK_BUTTON_RELEASE_MASK | \
51 GDK_BUTTON1_MOTION_MASK)
62 static GtkDrawingAreaClass *parent_class = NULL;
63 static guint curve_type_changed_signal = 0;
66 /* forward declarations: */
67 static void gtk_curve_class_init (GtkCurveClass *class);
68 static void gtk_curve_init (GtkCurve *curve);
69 static void gtk_curve_get_property (GObject *object,
73 static void gtk_curve_set_property (GObject *object,
77 static void gtk_curve_finalize (GObject *object);
78 static gint gtk_curve_graph_events (GtkWidget *widget,
81 static void gtk_curve_size_graph (GtkCurve *curve);
84 gtk_curve_get_type (void)
86 static GType curve_type = 0;
90 const GTypeInfo curve_info =
92 sizeof (GtkCurveClass),
94 NULL, /* base_finalize */
95 (GClassInitFunc) gtk_curve_class_init,
96 NULL, /* class_finalize */
97 NULL, /* class_data */
100 (GInstanceInitFunc) gtk_curve_init,
103 curve_type = g_type_register_static (GTK_TYPE_DRAWING_AREA, I_("GtkCurve"),
110 gtk_curve_class_init (GtkCurveClass *class)
112 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
114 parent_class = g_type_class_peek_parent (class);
116 gobject_class->finalize = gtk_curve_finalize;
118 gobject_class->set_property = gtk_curve_set_property;
119 gobject_class->get_property = gtk_curve_get_property;
121 g_object_class_install_property (gobject_class,
123 g_param_spec_enum ("curve-type",
125 P_("Is this curve linear, spline interpolated, or free-form"),
127 GTK_CURVE_TYPE_LINEAR,
128 GTK_PARAM_READWRITE));
129 g_object_class_install_property (gobject_class,
131 g_param_spec_float ("min-x",
133 P_("Minimum possible value for X"),
137 GTK_PARAM_READWRITE));
138 g_object_class_install_property (gobject_class,
140 g_param_spec_float ("max-x",
142 P_("Maximum possible X value"),
146 GTK_PARAM_READWRITE));
147 g_object_class_install_property (gobject_class,
149 g_param_spec_float ("min-y",
151 P_("Minimum possible value for Y"),
155 GTK_PARAM_READWRITE));
156 g_object_class_install_property (gobject_class,
158 g_param_spec_float ("max-y",
160 P_("Maximum possible value for Y"),
164 GTK_PARAM_READWRITE));
166 curve_type_changed_signal =
167 g_signal_new (I_("curve_type_changed"),
168 G_OBJECT_CLASS_TYPE (gobject_class),
170 G_STRUCT_OFFSET (GtkCurveClass, curve_type_changed),
172 _gtk_marshal_VOID__VOID,
177 gtk_curve_init (GtkCurve *curve)
181 curve->cursor_type = GDK_TOP_LEFT_ARROW;
182 curve->pixmap = NULL;
183 curve->curve_type = GTK_CURVE_TYPE_SPLINE;
185 curve->grab_point = -1;
187 curve->num_points = 0;
190 curve->num_ctlpoints = 0;
191 curve->ctlpoint = NULL;
198 old_mask = gtk_widget_get_events (GTK_WIDGET (curve));
199 gtk_widget_set_events (GTK_WIDGET (curve), old_mask | GRAPH_MASK);
200 g_signal_connect (curve, "event",
201 G_CALLBACK (gtk_curve_graph_events), curve);
202 gtk_curve_size_graph (curve);
206 gtk_curve_set_property (GObject *object,
211 GtkCurve *curve = GTK_CURVE (object);
215 case PROP_CURVE_TYPE:
216 gtk_curve_set_curve_type (curve, g_value_get_enum (value));
219 gtk_curve_set_range (curve, g_value_get_float (value), curve->max_x,
220 curve->min_y, curve->max_y);
223 gtk_curve_set_range (curve, curve->min_x, g_value_get_float (value),
224 curve->min_y, curve->max_y);
227 gtk_curve_set_range (curve, curve->min_x, curve->max_x,
228 g_value_get_float (value), curve->max_y);
231 gtk_curve_set_range (curve, curve->min_x, curve->max_x,
232 curve->min_y, g_value_get_float (value));
235 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
241 gtk_curve_get_property (GObject *object,
246 GtkCurve *curve = GTK_CURVE (object);
250 case PROP_CURVE_TYPE:
251 g_value_set_enum (value, curve->curve_type);
254 g_value_set_float (value, curve->min_x);
257 g_value_set_float (value, curve->max_x);
260 g_value_set_float (value, curve->min_y);
263 g_value_set_float (value, curve->max_y);
266 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
272 project (gfloat value, gfloat min, gfloat max, int norm)
274 return (norm - 1) * ((value - min) / (max - min)) + 0.5;
278 unproject (gint value, gfloat min, gfloat max, int norm)
280 return value / (gfloat) (norm - 1) * (max - min) + min;
283 /* Solve the tridiagonal equation system that determines the second
284 derivatives for the interpolation points. (Based on Numerical
285 Recipies 2nd Edition.) */
287 spline_solve (int n, gfloat x[], gfloat y[], gfloat y2[])
292 u = g_malloc ((n - 1) * sizeof (u[0]));
294 y2[0] = u[0] = 0.0; /* set lower boundary condition to "natural" */
296 for (i = 1; i < n - 1; ++i)
298 sig = (x[i] - x[i - 1]) / (x[i + 1] - x[i - 1]);
299 p = sig * y2[i - 1] + 2.0;
300 y2[i] = (sig - 1.0) / p;
301 u[i] = ((y[i + 1] - y[i])
302 / (x[i + 1] - x[i]) - (y[i] - y[i - 1]) / (x[i] - x[i - 1]));
303 u[i] = (6.0 * u[i] / (x[i + 1] - x[i - 1]) - sig * u[i - 1]) / p;
307 for (k = n - 2; k >= 0; --k)
308 y2[k] = y2[k] * y2[k + 1] + u[k];
314 spline_eval (int n, gfloat x[], gfloat y[], gfloat y2[], gfloat val)
319 /* do a binary search for the right interval: */
320 k_lo = 0; k_hi = n - 1;
321 while (k_hi - k_lo > 1)
323 k = (k_hi + k_lo) / 2;
330 h = x[k_hi] - x[k_lo];
333 a = (x[k_hi] - val) / h;
334 b = (val - x[k_lo]) / h;
335 return a*y[k_lo] + b*y[k_hi] +
336 ((a*a*a - a)*y2[k_lo] + (b*b*b - b)*y2[k_hi]) * (h*h)/6.0;
340 gtk_curve_interpolate (GtkCurve *c, gint width, gint height)
345 vector = g_malloc (width * sizeof (vector[0]));
347 gtk_curve_get_vector (c, width, vector);
350 if (c->num_points != width)
352 c->num_points = width;
355 c->point = g_malloc (c->num_points * sizeof (c->point[0]));
358 for (i = 0; i < width; ++i)
360 c->point[i].x = RADIUS + i;
361 c->point[i].y = RADIUS + height
362 - project (vector[i], c->min_y, c->max_y, height);
369 gtk_curve_draw (GtkCurve *c, gint width, gint height)
378 if (c->height != height || c->num_points != width)
379 gtk_curve_interpolate (c, width, height);
381 state = GTK_STATE_NORMAL;
382 if (!GTK_WIDGET_IS_SENSITIVE (GTK_WIDGET (c)))
383 state = GTK_STATE_INSENSITIVE;
385 style = GTK_WIDGET (c)->style;
387 /* clear the pixmap: */
388 gtk_paint_flat_box (style, c->pixmap, GTK_STATE_NORMAL, GTK_SHADOW_NONE,
389 NULL, GTK_WIDGET (c), "curve_bg",
390 0, 0, width + RADIUS * 2, height + RADIUS * 2);
391 /* draw the grid lines: (XXX make more meaningful) */
392 for (i = 0; i < 5; i++)
394 gdk_draw_line (c->pixmap, style->dark_gc[state],
395 RADIUS, i * (height / 4.0) + RADIUS,
396 width + RADIUS, i * (height / 4.0) + RADIUS);
397 gdk_draw_line (c->pixmap, style->dark_gc[state],
398 i * (width / 4.0) + RADIUS, RADIUS,
399 i * (width / 4.0) + RADIUS, height + RADIUS);
402 gdk_draw_points (c->pixmap, style->fg_gc[state], c->point, c->num_points);
403 if (c->curve_type != GTK_CURVE_TYPE_FREE)
404 for (i = 0; i < c->num_ctlpoints; ++i)
408 if (c->ctlpoint[i][0] < c->min_x)
411 x = project (c->ctlpoint[i][0], c->min_x, c->max_x,
414 project (c->ctlpoint[i][1], c->min_y, c->max_y,
418 gdk_draw_arc (c->pixmap, style->fg_gc[state], TRUE, x, y,
419 RADIUS * 2, RADIUS*2, 0, 360*64);
421 gdk_draw_drawable (GTK_WIDGET (c)->window, style->fg_gc[state], c->pixmap,
422 0, 0, 0, 0, width + RADIUS * 2, height + RADIUS * 2);
426 gtk_curve_graph_events (GtkWidget *widget, GdkEvent *event, GtkCurve *c)
428 GdkCursorType new_type = c->cursor_type;
429 gint i, src, dst, leftbound, rightbound;
430 GdkEventMotion *mevent;
433 gint cx, x, y, width, height;
434 gint closest_point = 0;
435 gfloat rx, ry, min_x;
441 width = w->allocation.width - RADIUS * 2;
442 height = w->allocation.height - RADIUS * 2;
444 if ((width < 0) || (height < 0))
447 /* get the pointer position */
448 gdk_window_get_pointer (w->window, &tx, &ty, NULL);
449 x = CLAMP ((tx - RADIUS), 0, width-1);
450 y = CLAMP ((ty - RADIUS), 0, height-1);
455 for (i = 0; i < c->num_ctlpoints; ++i)
457 cx = project (c->ctlpoint[i][0], min_x, c->max_x, width);
458 if ((guint) abs (x - cx) < distance)
460 distance = abs (x - cx);
469 g_object_unref (c->pixmap);
474 c->pixmap = gdk_pixmap_new (w->window,
476 w->allocation.height, -1);
477 gtk_curve_draw (c, width, height);
480 case GDK_BUTTON_PRESS:
481 gtk_grab_add (widget);
483 new_type = GDK_TCROSS;
485 switch (c->curve_type)
487 case GTK_CURVE_TYPE_LINEAR:
488 case GTK_CURVE_TYPE_SPLINE:
489 if (distance > MIN_DISTANCE)
491 /* insert a new control point */
492 if (c->num_ctlpoints > 0)
494 cx = project (c->ctlpoint[closest_point][0], min_x,
501 g_realloc (c->ctlpoint,
502 c->num_ctlpoints * sizeof (*c->ctlpoint));
503 for (i = c->num_ctlpoints - 1; i > closest_point; --i)
504 memcpy (c->ctlpoint + i, c->ctlpoint + i - 1,
505 sizeof (*c->ctlpoint));
507 c->grab_point = closest_point;
508 c->ctlpoint[c->grab_point][0] =
509 unproject (x, min_x, c->max_x, width);
510 c->ctlpoint[c->grab_point][1] =
511 unproject (height - y, c->min_y, c->max_y, height);
513 gtk_curve_interpolate (c, width, height);
516 case GTK_CURVE_TYPE_FREE:
517 c->point[x].x = RADIUS + x;
518 c->point[x].y = RADIUS + y;
523 gtk_curve_draw (c, width, height);
527 case GDK_BUTTON_RELEASE:
528 gtk_grab_remove (widget);
530 /* delete inactive points: */
531 if (c->curve_type != GTK_CURVE_TYPE_FREE)
533 for (src = dst = 0; src < c->num_ctlpoints; ++src)
535 if (c->ctlpoint[src][0] >= min_x)
537 memcpy (c->ctlpoint + dst, c->ctlpoint + src,
538 sizeof (*c->ctlpoint));
544 c->num_ctlpoints -= (src - dst);
545 if (c->num_ctlpoints <= 0)
547 c->num_ctlpoints = 1;
548 c->ctlpoint[0][0] = min_x;
549 c->ctlpoint[0][1] = c->min_y;
550 gtk_curve_interpolate (c, width, height);
551 gtk_curve_draw (c, width, height);
554 g_realloc (c->ctlpoint,
555 c->num_ctlpoints * sizeof (*c->ctlpoint));
558 new_type = GDK_FLEUR;
563 case GDK_MOTION_NOTIFY:
564 mevent = (GdkEventMotion *) event;
566 switch (c->curve_type)
568 case GTK_CURVE_TYPE_LINEAR:
569 case GTK_CURVE_TYPE_SPLINE:
570 if (c->grab_point == -1)
572 /* if no point is grabbed... */
573 if (distance <= MIN_DISTANCE)
574 new_type = GDK_FLEUR;
576 new_type = GDK_TCROSS;
580 /* drag the grabbed point */
581 new_type = GDK_TCROSS;
583 leftbound = -MIN_DISTANCE;
584 if (c->grab_point > 0)
585 leftbound = project (c->ctlpoint[c->grab_point - 1][0],
586 min_x, c->max_x, width);
588 rightbound = width + RADIUS * 2 + MIN_DISTANCE;
589 if (c->grab_point + 1 < c->num_ctlpoints)
590 rightbound = project (c->ctlpoint[c->grab_point + 1][0],
591 min_x, c->max_x, width);
593 if (tx <= leftbound || tx >= rightbound
594 || ty > height + RADIUS * 2 + MIN_DISTANCE
595 || ty < -MIN_DISTANCE)
596 c->ctlpoint[c->grab_point][0] = min_x - 1.0;
599 rx = unproject (x, min_x, c->max_x, width);
600 ry = unproject (height - y, c->min_y, c->max_y, height);
601 c->ctlpoint[c->grab_point][0] = rx;
602 c->ctlpoint[c->grab_point][1] = ry;
604 gtk_curve_interpolate (c, width, height);
605 gtk_curve_draw (c, width, height);
609 case GTK_CURVE_TYPE_FREE:
610 if (c->grab_point != -1)
612 if (c->grab_point > x)
628 for (i = x1; i <= x2; i++)
630 c->point[i].x = RADIUS + i;
631 c->point[i].y = RADIUS +
632 (y1 + ((y2 - y1) * (i - x1)) / (x2 - x1));
636 c->point[x].x = RADIUS + x;
637 c->point[x].y = RADIUS + y;
641 gtk_curve_draw (c, width, height);
643 if (mevent->state & GDK_BUTTON1_MASK)
644 new_type = GDK_TCROSS;
646 new_type = GDK_PENCIL;
649 if (new_type != (GdkCursorType) c->cursor_type)
653 c->cursor_type = new_type;
655 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (w),
657 gdk_window_set_cursor (w->window, cursor);
658 gdk_cursor_unref (cursor);
671 gtk_curve_set_curve_type (GtkCurve *c, GtkCurveType new_type)
676 if (new_type != c->curve_type)
680 width = GTK_WIDGET (c)->allocation.width - RADIUS * 2;
681 height = GTK_WIDGET (c)->allocation.height - RADIUS * 2;
683 if (new_type == GTK_CURVE_TYPE_FREE)
685 gtk_curve_interpolate (c, width, height);
686 c->curve_type = new_type;
688 else if (c->curve_type == GTK_CURVE_TYPE_FREE)
691 g_free (c->ctlpoint);
692 c->num_ctlpoints = 9;
693 c->ctlpoint = g_malloc (c->num_ctlpoints * sizeof (*c->ctlpoint));
696 dx = (width - 1) / (gfloat) (c->num_ctlpoints - 1);
698 for (i = 0; i < c->num_ctlpoints; ++i, rx += dx)
700 x = (int) (rx + 0.5);
702 unproject (x, c->min_x, c->max_x, width);
704 unproject (RADIUS + height - c->point[x].y,
705 c->min_y, c->max_y, height);
707 c->curve_type = new_type;
708 gtk_curve_interpolate (c, width, height);
712 c->curve_type = new_type;
713 gtk_curve_interpolate (c, width, height);
715 g_signal_emit (c, curve_type_changed_signal, 0);
716 g_object_notify (G_OBJECT (c), "curve-type");
717 gtk_curve_draw (c, width, height);
722 gtk_curve_size_graph (GtkCurve *curve)
726 GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (curve));
728 width = (curve->max_x - curve->min_x) + 1;
729 height = (curve->max_y - curve->min_y) + 1;
730 aspect = width / (gfloat) height;
731 if (width > gdk_screen_get_width (screen) / 4)
732 width = gdk_screen_get_width (screen) / 4;
733 if (height > gdk_screen_get_height (screen) / 4)
734 height = gdk_screen_get_height (screen) / 4;
737 width = height * aspect;
739 height = width / aspect;
741 gtk_widget_set_size_request (GTK_WIDGET (curve),
743 height + RADIUS * 2);
747 gtk_curve_reset_vector (GtkCurve *curve)
750 g_free (curve->ctlpoint);
752 curve->num_ctlpoints = 2;
753 curve->ctlpoint = g_malloc (2 * sizeof (curve->ctlpoint[0]));
754 curve->ctlpoint[0][0] = curve->min_x;
755 curve->ctlpoint[0][1] = curve->min_y;
756 curve->ctlpoint[1][0] = curve->max_x;
757 curve->ctlpoint[1][1] = curve->max_y;
763 width = GTK_WIDGET (curve)->allocation.width - RADIUS * 2;
764 height = GTK_WIDGET (curve)->allocation.height - RADIUS * 2;
766 if (curve->curve_type == GTK_CURVE_TYPE_FREE)
768 curve->curve_type = GTK_CURVE_TYPE_LINEAR;
769 gtk_curve_interpolate (curve, width, height);
770 curve->curve_type = GTK_CURVE_TYPE_FREE;
773 gtk_curve_interpolate (curve, width, height);
774 gtk_curve_draw (curve, width, height);
779 gtk_curve_reset (GtkCurve *c)
781 GtkCurveType old_type;
783 old_type = c->curve_type;
784 c->curve_type = GTK_CURVE_TYPE_SPLINE;
785 gtk_curve_reset_vector (c);
787 if (old_type != GTK_CURVE_TYPE_SPLINE)
789 g_signal_emit (c, curve_type_changed_signal, 0);
790 g_object_notify (G_OBJECT (c), "curve-type");
795 gtk_curve_set_gamma (GtkCurve *c, gfloat gamma)
797 gfloat x, one_over_gamma, height;
798 GtkCurveType old_type;
801 if (c->num_points < 2)
804 old_type = c->curve_type;
805 c->curve_type = GTK_CURVE_TYPE_FREE;
808 one_over_gamma = 1.0;
810 one_over_gamma = 1.0 / gamma;
812 for (i = 0; i < c->num_points; ++i)
814 x = (gfloat) i / (c->num_points - 1);
815 c->point[i].x = RADIUS + i;
817 RADIUS + (height * (1.0 - pow (x, one_over_gamma)) + 0.5);
820 if (old_type != GTK_CURVE_TYPE_FREE)
821 g_signal_emit (c, curve_type_changed_signal, 0);
823 gtk_curve_draw (c, c->num_points, c->height);
827 gtk_curve_set_range (GtkCurve *curve,
833 g_object_freeze_notify (G_OBJECT (curve));
834 if (curve->min_x != min_x) {
835 curve->min_x = min_x;
836 g_object_notify (G_OBJECT (curve), "min-x");
838 if (curve->max_x != max_x) {
839 curve->max_x = max_x;
840 g_object_notify (G_OBJECT (curve), "max-x");
842 if (curve->min_y != min_y) {
843 curve->min_y = min_y;
844 g_object_notify (G_OBJECT (curve), "min-y");
846 if (curve->max_y != max_y) {
847 curve->max_y = max_y;
848 g_object_notify (G_OBJECT (curve), "max-y");
850 g_object_thaw_notify (G_OBJECT (curve));
852 gtk_curve_size_graph (curve);
853 gtk_curve_reset_vector (curve);
857 gtk_curve_set_vector (GtkCurve *c, int veclen, gfloat vector[])
859 GtkCurveType old_type;
862 GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (c));
864 old_type = c->curve_type;
865 c->curve_type = GTK_CURVE_TYPE_FREE;
868 height = GTK_WIDGET (c)->allocation.height - RADIUS * 2;
871 height = (c->max_y - c->min_y);
872 if (height > gdk_screen_get_height (screen) / 4)
873 height = gdk_screen_get_height (screen) / 4;
876 c->num_points = veclen;
877 c->point = g_malloc (c->num_points * sizeof (c->point[0]));
880 dx = (veclen - 1.0) / (c->num_points - 1.0);
882 for (i = 0; i < c->num_points; ++i, rx += dx)
884 ry = vector[(int) (rx + 0.5)];
885 if (ry > c->max_y) ry = c->max_y;
886 if (ry < c->min_y) ry = c->min_y;
887 c->point[i].x = RADIUS + i;
889 RADIUS + height - project (ry, c->min_y, c->max_y, height);
891 if (old_type != GTK_CURVE_TYPE_FREE)
893 g_signal_emit (c, curve_type_changed_signal, 0);
894 g_object_notify (G_OBJECT (c), "curve-type");
897 gtk_curve_draw (c, c->num_points, height);
901 gtk_curve_get_vector (GtkCurve *c, int veclen, gfloat vector[])
903 gfloat rx, ry, dx, dy, min_x, delta_x, *mem, *xv, *yv, *y2v, prev;
904 gint dst, i, x, next, num_active_ctlpoints = 0, first_active = -1;
908 if (c->curve_type != GTK_CURVE_TYPE_FREE)
910 /* count active points: */
912 for (i = num_active_ctlpoints = 0; i < c->num_ctlpoints; ++i)
913 if (c->ctlpoint[i][0] > prev)
915 if (first_active < 0)
917 prev = c->ctlpoint[i][0];
918 ++num_active_ctlpoints;
921 /* handle degenerate case: */
922 if (num_active_ctlpoints < 2)
924 if (num_active_ctlpoints > 0)
925 ry = c->ctlpoint[first_active][1];
928 if (ry < c->min_y) ry = c->min_y;
929 if (ry > c->max_y) ry = c->max_y;
930 for (x = 0; x < veclen; ++x)
936 switch (c->curve_type)
938 case GTK_CURVE_TYPE_SPLINE:
939 mem = g_malloc (3 * num_active_ctlpoints * sizeof (gfloat));
941 yv = mem + num_active_ctlpoints;
942 y2v = mem + 2*num_active_ctlpoints;
945 for (i = dst = 0; i < c->num_ctlpoints; ++i)
946 if (c->ctlpoint[i][0] > prev)
948 prev = c->ctlpoint[i][0];
949 xv[dst] = c->ctlpoint[i][0];
950 yv[dst] = c->ctlpoint[i][1];
954 spline_solve (num_active_ctlpoints, xv, yv, y2v);
957 dx = (c->max_x - min_x) / (veclen - 1);
958 for (x = 0; x < veclen; ++x, rx += dx)
960 ry = spline_eval (num_active_ctlpoints, xv, yv, y2v, rx);
961 if (ry < c->min_y) ry = c->min_y;
962 if (ry > c->max_y) ry = c->max_y;
969 case GTK_CURVE_TYPE_LINEAR:
970 dx = (c->max_x - min_x) / (veclen - 1);
975 for (x = 0; x < veclen; ++x, rx += dx)
977 if (rx >= c->ctlpoint[i][0])
979 if (rx > c->ctlpoint[i][0])
983 while (next < c->num_ctlpoints
984 && c->ctlpoint[next][0] <= c->ctlpoint[i][0])
986 if (next < c->num_ctlpoints)
988 delta_x = c->ctlpoint[next][0] - c->ctlpoint[i][0];
989 dy = ((c->ctlpoint[next][1] - c->ctlpoint[i][1])
992 ry = c->ctlpoint[i][1];
1001 case GTK_CURVE_TYPE_FREE:
1005 dx = c->num_points / (double) veclen;
1006 for (x = 0; x < veclen; ++x, rx += dx)
1007 vector[x] = unproject (RADIUS + c->height - c->point[(int) rx].y,
1012 memset (vector, 0, veclen * sizeof (vector[0]));
1018 gtk_curve_new (void)
1020 return g_object_new (GTK_TYPE_CURVE, NULL);
1024 gtk_curve_finalize (GObject *object)
1028 g_return_if_fail (GTK_IS_CURVE (object));
1030 curve = GTK_CURVE (object);
1032 g_object_unref (curve->pixmap);
1034 g_free (curve->point);
1035 if (curve->ctlpoint)
1036 g_free (curve->ctlpoint);
1038 G_OBJECT_CLASS (parent_class)->finalize (object);
1041 #define __GTK_CURVE_C__
1042 #include "gtkaliasdef.c"