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/.
32 #include "gtkdrawingarea.h"
34 #include "gtkmarshalers.h"
35 #include "gtkradiobutton.h"
39 #define RADIUS 3 /* radius of the control points */
40 #define MIN_DISTANCE 8 /* min distance between control points */
42 #define GRAPH_MASK (GDK_EXPOSURE_MASK | \
43 GDK_POINTER_MOTION_MASK | \
44 GDK_POINTER_MOTION_HINT_MASK | \
45 GDK_ENTER_NOTIFY_MASK | \
46 GDK_BUTTON_PRESS_MASK | \
47 GDK_BUTTON_RELEASE_MASK | \
48 GDK_BUTTON1_MOTION_MASK)
59 static GtkDrawingAreaClass *parent_class = NULL;
60 static guint curve_type_changed_signal = 0;
63 /* forward declarations: */
64 static void gtk_curve_class_init (GtkCurveClass *class);
65 static void gtk_curve_init (GtkCurve *curve);
66 static void gtk_curve_get_property (GObject *object,
70 static void gtk_curve_set_property (GObject *object,
74 static void gtk_curve_finalize (GObject *object);
75 static gint gtk_curve_graph_events (GtkWidget *widget,
78 static void gtk_curve_size_graph (GtkCurve *curve);
81 gtk_curve_get_type (void)
83 static GType curve_type = 0;
87 static const GTypeInfo curve_info =
89 sizeof (GtkCurveClass),
91 NULL, /* base_finalize */
92 (GClassInitFunc) gtk_curve_class_init,
93 NULL, /* class_finalize */
94 NULL, /* class_data */
97 (GInstanceInitFunc) gtk_curve_init,
100 curve_type = g_type_register_static (GTK_TYPE_DRAWING_AREA, "GtkCurve",
107 gtk_curve_class_init (GtkCurveClass *class)
109 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
111 parent_class = g_type_class_peek_parent (class);
113 gobject_class->finalize = gtk_curve_finalize;
115 gobject_class->set_property = gtk_curve_set_property;
116 gobject_class->get_property = gtk_curve_get_property;
118 g_object_class_install_property (gobject_class,
120 g_param_spec_enum ("curve_type",
122 _("Is this curve linear, spline interpolated, or free-form"),
124 GTK_CURVE_TYPE_LINEAR,
127 g_object_class_install_property (gobject_class,
129 g_param_spec_float ("min_x",
131 _("Minimum possible value for X"),
137 g_object_class_install_property (gobject_class,
139 g_param_spec_float ("max_x",
141 _("Maximum possible X value"),
147 g_object_class_install_property (gobject_class,
149 g_param_spec_float ("min_y",
151 _("Minimum possible value for Y"),
157 g_object_class_install_property (gobject_class,
159 g_param_spec_float ("max_y",
161 _("Maximum possible value for Y"),
168 curve_type_changed_signal =
169 g_signal_new ("curve_type_changed",
170 G_OBJECT_CLASS_TYPE (gobject_class),
172 G_STRUCT_OFFSET (GtkCurveClass, curve_type_changed),
174 _gtk_marshal_VOID__VOID,
179 gtk_curve_init (GtkCurve *curve)
183 curve->cursor_type = GDK_TOP_LEFT_ARROW;
184 curve->pixmap = NULL;
185 curve->curve_type = GTK_CURVE_TYPE_SPLINE;
187 curve->grab_point = -1;
189 curve->num_points = 0;
192 curve->num_ctlpoints = 0;
193 curve->ctlpoint = NULL;
200 old_mask = gtk_widget_get_events (GTK_WIDGET (curve));
201 gtk_widget_set_events (GTK_WIDGET (curve), old_mask | GRAPH_MASK);
202 g_signal_connect (curve, "event",
203 G_CALLBACK (gtk_curve_graph_events), curve);
204 gtk_curve_size_graph (curve);
208 gtk_curve_set_property (GObject *object,
213 GtkCurve *curve = GTK_CURVE (object);
217 case PROP_CURVE_TYPE:
218 gtk_curve_set_curve_type (curve, g_value_get_enum (value));
221 gtk_curve_set_range (curve, g_value_get_float (value), curve->max_x,
222 curve->min_y, curve->max_y);
225 gtk_curve_set_range (curve, curve->min_x, g_value_get_float (value),
226 curve->min_y, curve->max_y);
229 gtk_curve_set_range (curve, curve->min_x, curve->max_x,
230 g_value_get_float (value), curve->max_y);
233 gtk_curve_set_range (curve, curve->min_x, curve->max_x,
234 curve->min_y, g_value_get_float (value));
237 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
243 gtk_curve_get_property (GObject *object,
248 GtkCurve *curve = GTK_CURVE (object);
252 case PROP_CURVE_TYPE:
253 g_value_set_enum (value, curve->curve_type);
256 g_value_set_float (value, curve->min_x);
259 g_value_set_float (value, curve->max_x);
262 g_value_set_float (value, curve->min_y);
265 g_value_set_float (value, curve->max_y);
268 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
274 project (gfloat value, gfloat min, gfloat max, int norm)
276 return (norm - 1) * ((value - min) / (max - min)) + 0.5;
280 unproject (gint value, gfloat min, gfloat max, int norm)
282 return value / (gfloat) (norm - 1) * (max - min) + min;
285 /* Solve the tridiagonal equation system that determines the second
286 derivatives for the interpolation points. (Based on Numerical
287 Recipies 2nd Edition.) */
289 spline_solve (int n, gfloat x[], gfloat y[], gfloat y2[])
294 u = g_malloc ((n - 1) * sizeof (u[0]));
296 y2[0] = u[0] = 0.0; /* set lower boundary condition to "natural" */
298 for (i = 1; i < n - 1; ++i)
300 sig = (x[i] - x[i - 1]) / (x[i + 1] - x[i - 1]);
301 p = sig * y2[i - 1] + 2.0;
302 y2[i] = (sig - 1.0) / p;
303 u[i] = ((y[i + 1] - y[i])
304 / (x[i + 1] - x[i]) - (y[i] - y[i - 1]) / (x[i] - x[i - 1]));
305 u[i] = (6.0 * u[i] / (x[i + 1] - x[i - 1]) - sig * u[i - 1]) / p;
309 for (k = n - 2; k >= 0; --k)
310 y2[k] = y2[k] * y2[k + 1] + u[k];
316 spline_eval (int n, gfloat x[], gfloat y[], gfloat y2[], gfloat val)
321 /* do a binary search for the right interval: */
322 k_lo = 0; k_hi = n - 1;
323 while (k_hi - k_lo > 1)
325 k = (k_hi + k_lo) / 2;
332 h = x[k_hi] - x[k_lo];
335 a = (x[k_hi] - val) / h;
336 b = (val - x[k_lo]) / h;
337 return a*y[k_lo] + b*y[k_hi] +
338 ((a*a*a - a)*y2[k_lo] + (b*b*b - b)*y2[k_hi]) * (h*h)/6.0;
342 gtk_curve_interpolate (GtkCurve *c, gint width, gint height)
347 vector = g_malloc (width * sizeof (vector[0]));
349 gtk_curve_get_vector (c, width, vector);
352 if (c->num_points != width)
354 c->num_points = width;
357 c->point = g_malloc (c->num_points * sizeof (c->point[0]));
360 for (i = 0; i < width; ++i)
362 c->point[i].x = RADIUS + i;
363 c->point[i].y = RADIUS + height
364 - project (vector[i], c->min_y, c->max_y, height);
371 gtk_curve_draw (GtkCurve *c, gint width, gint height)
380 if (c->height != height || c->num_points != width)
381 gtk_curve_interpolate (c, width, height);
383 state = GTK_STATE_NORMAL;
384 if (!GTK_WIDGET_IS_SENSITIVE (GTK_WIDGET (c)))
385 state = GTK_STATE_INSENSITIVE;
387 style = GTK_WIDGET (c)->style;
389 /* clear the pixmap: */
390 gtk_paint_flat_box (style, c->pixmap, GTK_STATE_NORMAL, GTK_SHADOW_NONE,
391 NULL, GTK_WIDGET (c), "curve_bg",
392 0, 0, width + RADIUS * 2, height + RADIUS * 2);
393 /* draw the grid lines: (XXX make more meaningful) */
394 for (i = 0; i < 5; i++)
396 gdk_draw_line (c->pixmap, style->dark_gc[state],
397 RADIUS, i * (height / 4.0) + RADIUS,
398 width + RADIUS, i * (height / 4.0) + RADIUS);
399 gdk_draw_line (c->pixmap, style->dark_gc[state],
400 i * (width / 4.0) + RADIUS, RADIUS,
401 i * (width / 4.0) + RADIUS, height + RADIUS);
404 gdk_draw_points (c->pixmap, style->fg_gc[state], c->point, c->num_points);
405 if (c->curve_type != GTK_CURVE_TYPE_FREE)
406 for (i = 0; i < c->num_ctlpoints; ++i)
410 if (c->ctlpoint[i][0] < c->min_x)
413 x = project (c->ctlpoint[i][0], c->min_x, c->max_x,
416 project (c->ctlpoint[i][1], c->min_y, c->max_y,
420 gdk_draw_arc (c->pixmap, style->fg_gc[state], TRUE, x, y,
421 RADIUS * 2, RADIUS*2, 0, 360*64);
423 gdk_draw_drawable (GTK_WIDGET (c)->window, style->fg_gc[state], c->pixmap,
424 0, 0, 0, 0, width + RADIUS * 2, height + RADIUS * 2);
428 gtk_curve_graph_events (GtkWidget *widget, GdkEvent *event, GtkCurve *c)
430 GdkCursorType new_type = c->cursor_type;
431 gint i, src, dst, leftbound, rightbound;
432 GdkEventButton *bevent;
433 GdkEventMotion *mevent;
436 gint cx, x, y, width, height;
437 gint closest_point = 0;
438 gfloat rx, ry, min_x;
444 width = w->allocation.width - RADIUS * 2;
445 height = w->allocation.height - RADIUS * 2;
447 if ((width < 0) || (height < 0))
450 /* get the pointer position */
451 gdk_window_get_pointer (w->window, &tx, &ty, NULL);
452 x = CLAMP ((tx - RADIUS), 0, width-1);
453 y = CLAMP ((ty - RADIUS), 0, height-1);
458 for (i = 0; i < c->num_ctlpoints; ++i)
460 cx = project (c->ctlpoint[i][0], min_x, c->max_x, width);
461 if ((guint) abs (x - cx) < distance)
463 distance = abs (x - cx);
472 g_object_unref (c->pixmap);
477 c->pixmap = gdk_pixmap_new (w->window,
479 w->allocation.height, -1);
480 gtk_curve_draw (c, width, height);
483 case GDK_BUTTON_PRESS:
484 gtk_grab_add (widget);
486 bevent = (GdkEventButton *) event;
487 new_type = GDK_TCROSS;
489 switch (c->curve_type)
491 case GTK_CURVE_TYPE_LINEAR:
492 case GTK_CURVE_TYPE_SPLINE:
493 if (distance > MIN_DISTANCE)
495 /* insert a new control point */
496 if (c->num_ctlpoints > 0)
498 cx = project (c->ctlpoint[closest_point][0], min_x,
505 g_realloc (c->ctlpoint,
506 c->num_ctlpoints * sizeof (*c->ctlpoint));
507 for (i = c->num_ctlpoints - 1; i > closest_point; --i)
508 memcpy (c->ctlpoint + i, c->ctlpoint + i - 1,
509 sizeof (*c->ctlpoint));
511 c->grab_point = closest_point;
512 c->ctlpoint[c->grab_point][0] =
513 unproject (x, min_x, c->max_x, width);
514 c->ctlpoint[c->grab_point][1] =
515 unproject (height - y, c->min_y, c->max_y, height);
517 gtk_curve_interpolate (c, width, height);
520 case GTK_CURVE_TYPE_FREE:
521 c->point[x].x = RADIUS + x;
522 c->point[x].y = RADIUS + y;
527 gtk_curve_draw (c, width, height);
531 case GDK_BUTTON_RELEASE:
532 gtk_grab_remove (widget);
534 /* delete inactive points: */
535 if (c->curve_type != GTK_CURVE_TYPE_FREE)
537 for (src = dst = 0; src < c->num_ctlpoints; ++src)
539 if (c->ctlpoint[src][0] >= min_x)
541 memcpy (c->ctlpoint + dst, c->ctlpoint + src,
542 sizeof (*c->ctlpoint));
548 c->num_ctlpoints -= (src - dst);
549 if (c->num_ctlpoints <= 0)
551 c->num_ctlpoints = 1;
552 c->ctlpoint[0][0] = min_x;
553 c->ctlpoint[0][1] = c->min_y;
554 gtk_curve_interpolate (c, width, height);
555 gtk_curve_draw (c, width, height);
558 g_realloc (c->ctlpoint,
559 c->num_ctlpoints * sizeof (*c->ctlpoint));
562 new_type = GDK_FLEUR;
567 case GDK_MOTION_NOTIFY:
568 mevent = (GdkEventMotion *) event;
570 switch (c->curve_type)
572 case GTK_CURVE_TYPE_LINEAR:
573 case GTK_CURVE_TYPE_SPLINE:
574 if (c->grab_point == -1)
576 /* if no point is grabbed... */
577 if (distance <= MIN_DISTANCE)
578 new_type = GDK_FLEUR;
580 new_type = GDK_TCROSS;
584 /* drag the grabbed point */
585 new_type = GDK_TCROSS;
587 leftbound = -MIN_DISTANCE;
588 if (c->grab_point > 0)
589 leftbound = project (c->ctlpoint[c->grab_point - 1][0],
590 min_x, c->max_x, width);
592 rightbound = width + RADIUS * 2 + MIN_DISTANCE;
593 if (c->grab_point + 1 < c->num_ctlpoints)
594 rightbound = project (c->ctlpoint[c->grab_point + 1][0],
595 min_x, c->max_x, width);
597 if (tx <= leftbound || tx >= rightbound
598 || ty > height + RADIUS * 2 + MIN_DISTANCE
599 || ty < -MIN_DISTANCE)
600 c->ctlpoint[c->grab_point][0] = min_x - 1.0;
603 rx = unproject (x, min_x, c->max_x, width);
604 ry = unproject (height - y, c->min_y, c->max_y, height);
605 c->ctlpoint[c->grab_point][0] = rx;
606 c->ctlpoint[c->grab_point][1] = ry;
608 gtk_curve_interpolate (c, width, height);
609 gtk_curve_draw (c, width, height);
613 case GTK_CURVE_TYPE_FREE:
614 if (c->grab_point != -1)
616 if (c->grab_point > x)
632 for (i = x1; i <= x2; i++)
634 c->point[i].x = RADIUS + i;
635 c->point[i].y = RADIUS +
636 (y1 + ((y2 - y1) * (i - x1)) / (x2 - x1));
640 c->point[x].x = RADIUS + x;
641 c->point[x].y = RADIUS + y;
645 gtk_curve_draw (c, width, height);
647 if (mevent->state & GDK_BUTTON1_MASK)
648 new_type = GDK_TCROSS;
650 new_type = GDK_PENCIL;
653 if (new_type != (GdkCursorType) c->cursor_type)
657 c->cursor_type = new_type;
659 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (w),
661 gdk_window_set_cursor (w->window, cursor);
662 gdk_cursor_unref (cursor);
675 gtk_curve_set_curve_type (GtkCurve *c, GtkCurveType new_type)
680 if (new_type != c->curve_type)
684 width = GTK_WIDGET (c)->allocation.width - RADIUS * 2;
685 height = GTK_WIDGET (c)->allocation.height - RADIUS * 2;
687 if (new_type == GTK_CURVE_TYPE_FREE)
689 gtk_curve_interpolate (c, width, height);
690 c->curve_type = new_type;
692 else if (c->curve_type == GTK_CURVE_TYPE_FREE)
695 g_free (c->ctlpoint);
696 c->num_ctlpoints = 9;
697 c->ctlpoint = g_malloc (c->num_ctlpoints * sizeof (*c->ctlpoint));
700 dx = (width - 1) / (gfloat) (c->num_ctlpoints - 1);
702 for (i = 0; i < c->num_ctlpoints; ++i, rx += dx)
704 x = (int) (rx + 0.5);
706 unproject (x, c->min_x, c->max_x, width);
708 unproject (RADIUS + height - c->point[x].y,
709 c->min_y, c->max_y, height);
711 c->curve_type = new_type;
712 gtk_curve_interpolate (c, width, height);
716 c->curve_type = new_type;
717 gtk_curve_interpolate (c, width, height);
719 g_signal_emit (c, curve_type_changed_signal, 0);
720 g_object_notify (G_OBJECT (c), "curve_type");
721 gtk_curve_draw (c, width, height);
726 gtk_curve_size_graph (GtkCurve *curve)
730 GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (curve));
732 width = (curve->max_x - curve->min_x) + 1;
733 height = (curve->max_y - curve->min_y) + 1;
734 aspect = width / (gfloat) height;
735 if (width > gdk_screen_get_width (screen) / 4)
736 width = gdk_screen_get_width (screen) / 4;
737 if (height > gdk_screen_get_height (screen) / 4)
738 height = gdk_screen_get_height (screen) / 4;
741 width = height * aspect;
743 height = width / aspect;
745 gtk_widget_set_size_request (GTK_WIDGET (curve),
747 height + RADIUS * 2);
751 gtk_curve_reset_vector (GtkCurve *curve)
754 g_free (curve->ctlpoint);
756 curve->num_ctlpoints = 2;
757 curve->ctlpoint = g_malloc (2 * sizeof (curve->ctlpoint[0]));
758 curve->ctlpoint[0][0] = curve->min_x;
759 curve->ctlpoint[0][1] = curve->min_y;
760 curve->ctlpoint[1][0] = curve->max_x;
761 curve->ctlpoint[1][1] = curve->max_y;
767 width = GTK_WIDGET (curve)->allocation.width - RADIUS * 2;
768 height = GTK_WIDGET (curve)->allocation.height - RADIUS * 2;
770 if (curve->curve_type == GTK_CURVE_TYPE_FREE)
772 curve->curve_type = GTK_CURVE_TYPE_LINEAR;
773 gtk_curve_interpolate (curve, width, height);
774 curve->curve_type = GTK_CURVE_TYPE_FREE;
777 gtk_curve_interpolate (curve, width, height);
778 gtk_curve_draw (curve, width, height);
783 gtk_curve_reset (GtkCurve *c)
785 GtkCurveType old_type;
787 old_type = c->curve_type;
788 c->curve_type = GTK_CURVE_TYPE_SPLINE;
789 gtk_curve_reset_vector (c);
791 if (old_type != GTK_CURVE_TYPE_SPLINE)
793 g_signal_emit (c, curve_type_changed_signal, 0);
794 g_object_notify (G_OBJECT (c), "curve_type");
799 gtk_curve_set_gamma (GtkCurve *c, gfloat gamma)
801 gfloat x, one_over_gamma, height, one_over_width;
802 GtkCurveType old_type;
805 if (c->num_points < 2)
808 old_type = c->curve_type;
809 c->curve_type = GTK_CURVE_TYPE_FREE;
812 one_over_gamma = 1.0;
814 one_over_gamma = 1.0 / gamma;
815 one_over_width = 1.0 / (c->num_points - 1);
817 for (i = 0; i < c->num_points; ++i)
819 x = (gfloat) i / (c->num_points - 1);
820 c->point[i].x = RADIUS + i;
822 RADIUS + (height * (1.0 - pow (x, one_over_gamma)) + 0.5);
825 if (old_type != GTK_CURVE_TYPE_FREE)
826 g_signal_emit (c, curve_type_changed_signal, 0);
828 gtk_curve_draw (c, c->num_points, c->height);
832 gtk_curve_set_range (GtkCurve *curve,
838 g_object_freeze_notify (G_OBJECT (curve));
839 if (curve->min_x != min_x) {
840 curve->min_x = min_x;
841 g_object_notify (G_OBJECT (curve), "min_x");
843 if (curve->max_x != max_x) {
844 curve->max_x = max_x;
845 g_object_notify (G_OBJECT (curve), "max_x");
847 if (curve->min_y != min_y) {
848 curve->min_y = min_y;
849 g_object_notify (G_OBJECT (curve), "min_y");
851 if (curve->max_y != max_y) {
852 curve->max_y = max_y;
853 g_object_notify (G_OBJECT (curve), "max_y");
855 g_object_thaw_notify (G_OBJECT (curve));
857 gtk_curve_size_graph (curve);
858 gtk_curve_reset_vector (curve);
862 gtk_curve_set_vector (GtkCurve *c, int veclen, gfloat vector[])
864 GtkCurveType old_type;
867 GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (c));
869 old_type = c->curve_type;
870 c->curve_type = GTK_CURVE_TYPE_FREE;
873 height = GTK_WIDGET (c)->allocation.height - RADIUS * 2;
876 height = (c->max_y - c->min_y);
877 if (height > gdk_screen_get_height (screen) / 4)
878 height = gdk_screen_get_height (screen) / 4;
881 c->num_points = veclen;
882 c->point = g_malloc (c->num_points * sizeof (c->point[0]));
885 dx = (veclen - 1.0) / (c->num_points - 1.0);
887 for (i = 0; i < c->num_points; ++i, rx += dx)
889 ry = vector[(int) (rx + 0.5)];
890 if (ry > c->max_y) ry = c->max_y;
891 if (ry < c->min_y) ry = c->min_y;
892 c->point[i].x = RADIUS + i;
894 RADIUS + height - project (ry, c->min_y, c->max_y, height);
896 if (old_type != GTK_CURVE_TYPE_FREE)
898 g_signal_emit (c, curve_type_changed_signal, 0);
899 g_object_notify (G_OBJECT (c), "curve_type");
902 gtk_curve_draw (c, c->num_points, height);
906 gtk_curve_get_vector (GtkCurve *c, int veclen, gfloat vector[])
908 gfloat rx, ry, dx, dy, min_x, delta_x, *mem, *xv, *yv, *y2v, prev;
909 gint dst, i, x, next, num_active_ctlpoints = 0, first_active = -1;
913 if (c->curve_type != GTK_CURVE_TYPE_FREE)
915 /* count active points: */
917 for (i = num_active_ctlpoints = 0; i < c->num_ctlpoints; ++i)
918 if (c->ctlpoint[i][0] > prev)
920 if (first_active < 0)
922 prev = c->ctlpoint[i][0];
923 ++num_active_ctlpoints;
926 /* handle degenerate case: */
927 if (num_active_ctlpoints < 2)
929 if (num_active_ctlpoints > 0)
930 ry = c->ctlpoint[first_active][1];
933 if (ry < c->min_y) ry = c->min_y;
934 if (ry > c->max_y) ry = c->max_y;
935 for (x = 0; x < veclen; ++x)
941 switch (c->curve_type)
943 case GTK_CURVE_TYPE_SPLINE:
944 mem = g_malloc (3 * num_active_ctlpoints * sizeof (gfloat));
946 yv = mem + num_active_ctlpoints;
947 y2v = mem + 2*num_active_ctlpoints;
950 for (i = dst = 0; i < c->num_ctlpoints; ++i)
951 if (c->ctlpoint[i][0] > prev)
953 prev = c->ctlpoint[i][0];
954 xv[dst] = c->ctlpoint[i][0];
955 yv[dst] = c->ctlpoint[i][1];
959 spline_solve (num_active_ctlpoints, xv, yv, y2v);
962 dx = (c->max_x - min_x) / (veclen - 1);
963 for (x = 0; x < veclen; ++x, rx += dx)
965 ry = spline_eval (num_active_ctlpoints, xv, yv, y2v, rx);
966 if (ry < c->min_y) ry = c->min_y;
967 if (ry > c->max_y) ry = c->max_y;
974 case GTK_CURVE_TYPE_LINEAR:
975 dx = (c->max_x - min_x) / (veclen - 1);
980 for (x = 0; x < veclen; ++x, rx += dx)
982 if (rx >= c->ctlpoint[i][0])
984 if (rx > c->ctlpoint[i][0])
988 while (next < c->num_ctlpoints
989 && c->ctlpoint[next][0] <= c->ctlpoint[i][0])
991 if (next < c->num_ctlpoints)
993 delta_x = c->ctlpoint[next][0] - c->ctlpoint[i][0];
994 dy = ((c->ctlpoint[next][1] - c->ctlpoint[i][1])
997 ry = c->ctlpoint[i][1];
1006 case GTK_CURVE_TYPE_FREE:
1010 dx = c->num_points / (double) veclen;
1011 for (x = 0; x < veclen; ++x, rx += dx)
1012 vector[x] = unproject (RADIUS + c->height - c->point[(int) rx].y,
1017 memset (vector, 0, veclen * sizeof (vector[0]));
1023 gtk_curve_new (void)
1025 return g_object_new (GTK_TYPE_CURVE, NULL);
1029 gtk_curve_finalize (GObject *object)
1033 g_return_if_fail (GTK_IS_CURVE (object));
1035 curve = GTK_CURVE (object);
1037 g_object_unref (curve->pixmap);
1039 g_free (curve->point);
1040 if (curve->ctlpoint)
1041 g_free (curve->ctlpoint);
1043 G_OBJECT_CLASS (parent_class)->finalize (object);