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 "gtkradiobutton.h"
35 #include "gtksignal.h"
38 #define RADIUS 3 /* radius of the control points */
39 #define MIN_DISTANCE 8 /* min distance between control points */
41 #define GRAPH_MASK (GDK_EXPOSURE_MASK | \
42 GDK_POINTER_MOTION_MASK | \
43 GDK_POINTER_MOTION_HINT_MASK | \
44 GDK_ENTER_NOTIFY_MASK | \
45 GDK_BUTTON_PRESS_MASK | \
46 GDK_BUTTON_RELEASE_MASK | \
47 GDK_BUTTON1_MOTION_MASK)
58 static GtkDrawingAreaClass *parent_class = NULL;
59 static guint curve_type_changed_signal = 0;
62 /* forward declarations: */
63 static void gtk_curve_class_init (GtkCurveClass *class);
64 static void gtk_curve_init (GtkCurve *curve);
65 static void gtk_curve_set_arg (GtkObject *object,
68 static void gtk_curve_get_arg (GtkObject *object,
71 static void gtk_curve_finalize (GObject *object);
72 static gint gtk_curve_graph_events (GtkWidget *widget,
75 static void gtk_curve_size_graph (GtkCurve *curve);
78 gtk_curve_get_type (void)
80 static GtkType curve_type = 0;
84 static const GtkTypeInfo curve_info =
88 sizeof (GtkCurveClass),
89 (GtkClassInitFunc) gtk_curve_class_init,
90 (GtkObjectInitFunc) gtk_curve_init,
91 /* reserved_1 */ NULL,
92 /* reserved_2 */ NULL,
93 (GtkClassInitFunc) NULL,
96 curve_type = gtk_type_unique (GTK_TYPE_DRAWING_AREA, &curve_info);
102 gtk_curve_class_init (GtkCurveClass *class)
104 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
105 GtkObjectClass *object_class = GTK_OBJECT_CLASS (class);
107 parent_class = gtk_type_class (GTK_TYPE_DRAWING_AREA);
109 gobject_class->finalize = gtk_curve_finalize;
111 object_class->set_arg = gtk_curve_set_arg;
112 object_class->get_arg = gtk_curve_get_arg;
114 curve_type_changed_signal =
115 gtk_signal_new ("curve_type_changed", GTK_RUN_FIRST, GTK_CLASS_TYPE (object_class),
116 GTK_SIGNAL_OFFSET (GtkCurveClass, curve_type_changed),
117 gtk_marshal_VOID__VOID, GTK_TYPE_NONE, 0);
118 gtk_object_class_add_signals (object_class, &curve_type_changed_signal, 1);
120 gtk_object_add_arg_type ("GtkCurve::curve_type", GTK_TYPE_CURVE_TYPE,
121 GTK_ARG_READWRITE, ARG_CURVE_TYPE);
122 gtk_object_add_arg_type ("GtkCurve::min_x", GTK_TYPE_FLOAT,
123 GTK_ARG_READWRITE, ARG_MIN_X);
124 gtk_object_add_arg_type ("GtkCurve::max_x", GTK_TYPE_FLOAT,
125 GTK_ARG_READWRITE, ARG_MAX_X);
126 gtk_object_add_arg_type ("GtkCurve::min_y", GTK_TYPE_FLOAT,
127 GTK_ARG_READWRITE, ARG_MIN_Y);
128 gtk_object_add_arg_type ("GtkCurve::max_y", GTK_TYPE_FLOAT,
129 GTK_ARG_READWRITE, ARG_MAX_Y);
133 gtk_curve_init (GtkCurve *curve)
137 curve->cursor_type = GDK_TOP_LEFT_ARROW;
138 curve->pixmap = NULL;
139 curve->curve_type = GTK_CURVE_TYPE_SPLINE;
141 curve->grab_point = -1;
143 curve->num_points = 0;
146 curve->num_ctlpoints = 0;
147 curve->ctlpoint = NULL;
154 old_mask = gtk_widget_get_events (GTK_WIDGET (curve));
155 gtk_widget_set_events (GTK_WIDGET (curve), old_mask | GRAPH_MASK);
156 gtk_signal_connect (GTK_OBJECT (curve), "event",
157 (GtkSignalFunc) gtk_curve_graph_events, curve);
158 gtk_curve_size_graph (curve);
162 gtk_curve_set_arg (GtkObject *object,
166 GtkCurve *curve = GTK_CURVE (object);
171 gtk_curve_set_curve_type (curve, GTK_VALUE_ENUM (*arg));
174 gtk_curve_set_range (curve, GTK_VALUE_FLOAT (*arg), curve->max_x,
175 curve->min_y, curve->max_y);
178 gtk_curve_set_range (curve, curve->min_x, GTK_VALUE_FLOAT (*arg),
179 curve->min_y, curve->max_y);
182 gtk_curve_set_range (curve, curve->min_x, curve->max_x,
183 GTK_VALUE_FLOAT (*arg), curve->max_y);
186 gtk_curve_set_range (curve, curve->min_x, curve->max_x,
187 curve->min_y, GTK_VALUE_FLOAT (*arg));
193 gtk_curve_get_arg (GtkObject *object,
197 GtkCurve *curve = GTK_CURVE (object);
202 GTK_VALUE_ENUM (*arg) = curve->curve_type;
205 GTK_VALUE_FLOAT (*arg) = curve->min_x;
208 GTK_VALUE_FLOAT (*arg) = curve->max_x;
211 GTK_VALUE_FLOAT (*arg) = curve->min_y;
214 GTK_VALUE_FLOAT (*arg) = curve->max_y;
217 arg->type = GTK_TYPE_INVALID;
223 project (gfloat value, gfloat min, gfloat max, int norm)
225 return (norm - 1) * ((value - min) / (max - min)) + 0.5;
229 unproject (gint value, gfloat min, gfloat max, int norm)
231 return value / (gfloat) (norm - 1) * (max - min) + min;
234 /* Solve the tridiagonal equation system that determines the second
235 derivatives for the interpolation points. (Based on Numerical
236 Recipies 2nd Edition.) */
238 spline_solve (int n, gfloat x[], gfloat y[], gfloat y2[])
243 u = g_malloc ((n - 1) * sizeof (u[0]));
245 y2[0] = u[0] = 0.0; /* set lower boundary condition to "natural" */
247 for (i = 1; i < n - 1; ++i)
249 sig = (x[i] - x[i - 1]) / (x[i + 1] - x[i - 1]);
250 p = sig * y2[i - 1] + 2.0;
251 y2[i] = (sig - 1.0) / p;
252 u[i] = ((y[i + 1] - y[i])
253 / (x[i + 1] - x[i]) - (y[i] - y[i - 1]) / (x[i] - x[i - 1]));
254 u[i] = (6.0 * u[i] / (x[i + 1] - x[i - 1]) - sig * u[i - 1]) / p;
258 for (k = n - 2; k >= 0; --k)
259 y2[k] = y2[k] * y2[k + 1] + u[k];
265 spline_eval (int n, gfloat x[], gfloat y[], gfloat y2[], gfloat val)
270 /* do a binary search for the right interval: */
271 k_lo = 0; k_hi = n - 1;
272 while (k_hi - k_lo > 1)
274 k = (k_hi + k_lo) / 2;
281 h = x[k_hi] - x[k_lo];
284 a = (x[k_hi] - val) / h;
285 b = (val - x[k_lo]) / h;
286 return a*y[k_lo] + b*y[k_hi] +
287 ((a*a*a - a)*y2[k_lo] + (b*b*b - b)*y2[k_hi]) * (h*h)/6.0;
291 gtk_curve_interpolate (GtkCurve *c, gint width, gint height)
296 vector = g_malloc (width * sizeof (vector[0]));
298 gtk_curve_get_vector (c, width, vector);
301 if (c->num_points != width)
303 c->num_points = width;
306 c->point = g_malloc (c->num_points * sizeof (c->point[0]));
309 for (i = 0; i < width; ++i)
311 c->point[i].x = RADIUS + i;
312 c->point[i].y = RADIUS + height
313 - project (vector[i], c->min_y, c->max_y, height);
320 gtk_curve_draw (GtkCurve *c, gint width, gint height)
329 if (c->height != height || c->num_points != width)
330 gtk_curve_interpolate (c, width, height);
332 state = GTK_STATE_NORMAL;
333 if (!GTK_WIDGET_IS_SENSITIVE (GTK_WIDGET (c)))
334 state = GTK_STATE_INSENSITIVE;
336 style = GTK_WIDGET (c)->style;
338 /* clear the pixmap: */
339 gtk_paint_flat_box (style, c->pixmap, GTK_STATE_NORMAL, GTK_SHADOW_NONE,
340 NULL, GTK_WIDGET(c), "curve_bg",
341 0, 0, width + RADIUS * 2, height + RADIUS * 2);
342 /* draw the grid lines: (XXX make more meaningful) */
343 for (i = 0; i < 5; i++)
345 gdk_draw_line (c->pixmap, style->dark_gc[state],
346 RADIUS, i * (height / 4.0) + RADIUS,
347 width + RADIUS, i * (height / 4.0) + RADIUS);
348 gdk_draw_line (c->pixmap, style->dark_gc[state],
349 i * (width / 4.0) + RADIUS, RADIUS,
350 i * (width / 4.0) + RADIUS, height + RADIUS);
353 gdk_draw_points (c->pixmap, style->fg_gc[state], c->point, c->num_points);
354 if (c->curve_type != GTK_CURVE_TYPE_FREE)
355 for (i = 0; i < c->num_ctlpoints; ++i)
359 if (c->ctlpoint[i][0] < c->min_x)
362 x = project (c->ctlpoint[i][0], c->min_x, c->max_x,
365 project (c->ctlpoint[i][1], c->min_y, c->max_y,
369 gdk_draw_arc (c->pixmap, style->fg_gc[state], TRUE, x, y,
370 RADIUS * 2, RADIUS*2, 0, 360*64);
372 gdk_draw_pixmap (GTK_WIDGET (c)->window, style->fg_gc[state], c->pixmap,
373 0, 0, 0, 0, width + RADIUS * 2, height + RADIUS * 2);
377 gtk_curve_graph_events (GtkWidget *widget, GdkEvent *event, GtkCurve *c)
379 GdkCursorType new_type = c->cursor_type;
380 gint i, src, dst, leftbound, rightbound;
381 GdkEventButton *bevent;
382 GdkEventMotion *mevent;
385 gint cx, x, y, width, height;
386 gint closest_point = 0;
387 gfloat rx, ry, min_x;
392 width = w->allocation.width - RADIUS * 2;
393 height = w->allocation.height - RADIUS * 2;
395 if ((width < 0) || (height < 0))
398 /* get the pointer position */
399 gdk_window_get_pointer (w->window, &tx, &ty, NULL);
400 x = CLAMP ((tx - RADIUS), 0, width-1);
401 y = CLAMP ((ty - RADIUS), 0, height-1);
406 for (i = 0; i < c->num_ctlpoints; ++i)
408 cx = project (c->ctlpoint[i][0], min_x, c->max_x, width);
409 if ((guint) abs (x - cx) < distance)
411 distance = abs (x - cx);
420 gdk_pixmap_unref (c->pixmap);
425 c->pixmap = gdk_pixmap_new (w->window,
427 w->allocation.height, -1);
428 gtk_curve_draw (c, width, height);
431 case GDK_BUTTON_PRESS:
432 gtk_grab_add (widget);
434 bevent = (GdkEventButton *) event;
435 new_type = GDK_TCROSS;
437 switch (c->curve_type)
439 case GTK_CURVE_TYPE_LINEAR:
440 case GTK_CURVE_TYPE_SPLINE:
441 if (distance > MIN_DISTANCE)
443 /* insert a new control point */
444 if (c->num_ctlpoints > 0)
446 cx = project (c->ctlpoint[closest_point][0], min_x,
453 g_realloc (c->ctlpoint,
454 c->num_ctlpoints * sizeof (*c->ctlpoint));
455 for (i = c->num_ctlpoints - 1; i > closest_point; --i)
456 memcpy (c->ctlpoint + i, c->ctlpoint + i - 1,
457 sizeof (*c->ctlpoint));
459 c->grab_point = closest_point;
460 c->ctlpoint[c->grab_point][0] =
461 unproject (x, min_x, c->max_x, width);
462 c->ctlpoint[c->grab_point][1] =
463 unproject (height - y, c->min_y, c->max_y, height);
465 gtk_curve_interpolate (c, width, height);
468 case GTK_CURVE_TYPE_FREE:
469 c->point[x].x = RADIUS + x;
470 c->point[x].y = RADIUS + y;
475 gtk_curve_draw (c, width, height);
478 case GDK_BUTTON_RELEASE:
479 gtk_grab_remove (widget);
481 /* delete inactive points: */
482 if (c->curve_type != GTK_CURVE_TYPE_FREE)
484 for (src = dst = 0; src < c->num_ctlpoints; ++src)
486 if (c->ctlpoint[src][0] >= min_x)
488 memcpy (c->ctlpoint + dst, c->ctlpoint + src,
489 sizeof (*c->ctlpoint));
495 c->num_ctlpoints -= (src - dst);
496 if (c->num_ctlpoints <= 0)
498 c->num_ctlpoints = 1;
499 c->ctlpoint[0][0] = min_x;
500 c->ctlpoint[0][1] = c->min_y;
501 gtk_curve_interpolate (c, width, height);
502 gtk_curve_draw (c, width, height);
505 g_realloc (c->ctlpoint,
506 c->num_ctlpoints * sizeof (*c->ctlpoint));
509 new_type = GDK_FLEUR;
513 case GDK_MOTION_NOTIFY:
514 mevent = (GdkEventMotion *) event;
516 switch (c->curve_type)
518 case GTK_CURVE_TYPE_LINEAR:
519 case GTK_CURVE_TYPE_SPLINE:
520 if (c->grab_point == -1)
522 /* if no point is grabbed... */
523 if (distance <= MIN_DISTANCE)
524 new_type = GDK_FLEUR;
526 new_type = GDK_TCROSS;
530 /* drag the grabbed point */
531 new_type = GDK_TCROSS;
533 leftbound = -MIN_DISTANCE;
534 if (c->grab_point > 0)
535 leftbound = project (c->ctlpoint[c->grab_point - 1][0],
536 min_x, c->max_x, width);
538 rightbound = width + RADIUS * 2 + MIN_DISTANCE;
539 if (c->grab_point + 1 < c->num_ctlpoints)
540 rightbound = project (c->ctlpoint[c->grab_point + 1][0],
541 min_x, c->max_x, width);
543 if (tx <= leftbound || tx >= rightbound
544 || ty > height + RADIUS * 2 + MIN_DISTANCE
545 || ty < -MIN_DISTANCE)
546 c->ctlpoint[c->grab_point][0] = min_x - 1.0;
549 rx = unproject (x, min_x, c->max_x, width);
550 ry = unproject (height - y, c->min_y, c->max_y, height);
551 c->ctlpoint[c->grab_point][0] = rx;
552 c->ctlpoint[c->grab_point][1] = ry;
554 gtk_curve_interpolate (c, width, height);
555 gtk_curve_draw (c, width, height);
559 case GTK_CURVE_TYPE_FREE:
560 if (c->grab_point != -1)
562 if (c->grab_point > x)
578 for (i = x1; i <= x2; i++)
580 c->point[i].x = RADIUS + i;
581 c->point[i].y = RADIUS +
582 (y1 + ((y2 - y1) * (i - x1)) / (x2 - x1));
586 c->point[x].x = RADIUS + x;
587 c->point[x].y = RADIUS + y;
591 gtk_curve_draw (c, width, height);
593 if (mevent->state & GDK_BUTTON1_MASK)
594 new_type = GDK_TCROSS;
596 new_type = GDK_PENCIL;
599 if (new_type != (GdkCursorType) c->cursor_type)
603 c->cursor_type = new_type;
605 cursor = gdk_cursor_new (c->cursor_type);
606 gdk_window_set_cursor (w->window, cursor);
607 gdk_cursor_destroy (cursor);
618 gtk_curve_set_curve_type (GtkCurve *c, GtkCurveType new_type)
623 if (new_type != c->curve_type)
627 width = GTK_WIDGET(c)->allocation.width - RADIUS * 2;
628 height = GTK_WIDGET(c)->allocation.height - RADIUS * 2;
630 if (new_type == GTK_CURVE_TYPE_FREE)
632 gtk_curve_interpolate (c, width, height);
633 c->curve_type = new_type;
635 else if (c->curve_type == GTK_CURVE_TYPE_FREE)
638 g_free (c->ctlpoint);
639 c->num_ctlpoints = 9;
640 c->ctlpoint = g_malloc (c->num_ctlpoints * sizeof (*c->ctlpoint));
643 dx = (width - 1) / (gfloat) (c->num_ctlpoints - 1);
645 for (i = 0; i < c->num_ctlpoints; ++i, rx += dx)
647 x = (int) (rx + 0.5);
649 unproject (x, c->min_x, c->max_x, width);
651 unproject (RADIUS + height - c->point[x].y,
652 c->min_y, c->max_y, height);
654 c->curve_type = new_type;
655 gtk_curve_interpolate (c, width, height);
659 c->curve_type = new_type;
660 gtk_curve_interpolate (c, width, height);
662 gtk_signal_emit (GTK_OBJECT (c), curve_type_changed_signal);
663 gtk_curve_draw (c, width, height);
668 gtk_curve_size_graph (GtkCurve *curve)
673 width = (curve->max_x - curve->min_x) + 1;
674 height = (curve->max_y - curve->min_y) + 1;
675 aspect = width / (gfloat) height;
676 if (width > gdk_screen_width () / 4)
677 width = gdk_screen_width () / 4;
678 if (height > gdk_screen_height () / 4)
679 height = gdk_screen_height () / 4;
682 width = height * aspect;
684 height = width / aspect;
686 gtk_drawing_area_size (GTK_DRAWING_AREA (curve),
687 width + RADIUS * 2, height + RADIUS * 2);
691 gtk_curve_reset_vector (GtkCurve *curve)
694 g_free (curve->ctlpoint);
696 curve->num_ctlpoints = 2;
697 curve->ctlpoint = g_malloc (2 * sizeof (curve->ctlpoint[0]));
698 curve->ctlpoint[0][0] = curve->min_x;
699 curve->ctlpoint[0][1] = curve->min_y;
700 curve->ctlpoint[1][0] = curve->max_x;
701 curve->ctlpoint[1][1] = curve->max_y;
707 width = GTK_WIDGET (curve)->allocation.width - RADIUS * 2;
708 height = GTK_WIDGET (curve)->allocation.height - RADIUS * 2;
710 if (curve->curve_type == GTK_CURVE_TYPE_FREE)
712 curve->curve_type = GTK_CURVE_TYPE_LINEAR;
713 gtk_curve_interpolate (curve, width, height);
714 curve->curve_type = GTK_CURVE_TYPE_FREE;
717 gtk_curve_interpolate (curve, width, height);
718 gtk_curve_draw (curve, width, height);
723 gtk_curve_reset (GtkCurve *c)
725 GtkCurveType old_type;
727 old_type = c->curve_type;
728 c->curve_type = GTK_CURVE_TYPE_SPLINE;
729 gtk_curve_reset_vector (c);
731 if (old_type != GTK_CURVE_TYPE_SPLINE)
732 gtk_signal_emit (GTK_OBJECT (c), curve_type_changed_signal);
736 gtk_curve_set_gamma (GtkCurve *c, gfloat gamma)
738 gfloat x, one_over_gamma, height, one_over_width;
739 GtkCurveType old_type;
742 if (c->num_points < 2)
745 old_type = c->curve_type;
746 c->curve_type = GTK_CURVE_TYPE_FREE;
749 one_over_gamma = 1.0;
751 one_over_gamma = 1.0 / gamma;
752 one_over_width = 1.0 / (c->num_points - 1);
754 for (i = 0; i < c->num_points; ++i)
756 x = (gfloat) i / (c->num_points - 1);
757 c->point[i].x = RADIUS + i;
759 RADIUS + (height * (1.0 - pow (x, one_over_gamma)) + 0.5);
762 if (old_type != GTK_CURVE_TYPE_FREE)
763 gtk_signal_emit (GTK_OBJECT (c), curve_type_changed_signal);
765 gtk_curve_draw (c, c->num_points, c->height);
769 gtk_curve_set_range (GtkCurve *curve,
770 gfloat min_x, gfloat max_x, gfloat min_y, gfloat max_y)
772 curve->min_x = min_x;
773 curve->max_x = max_x;
774 curve->min_y = min_y;
775 curve->max_y = max_y;
777 gtk_curve_size_graph (curve);
778 gtk_curve_reset_vector (curve);
782 gtk_curve_set_vector (GtkCurve *c, int veclen, gfloat vector[])
784 GtkCurveType old_type;
788 old_type = c->curve_type;
789 c->curve_type = GTK_CURVE_TYPE_FREE;
792 height = GTK_WIDGET (c)->allocation.height - RADIUS * 2;
795 height = (c->max_y - c->min_y);
796 if (height > gdk_screen_height () / 4)
797 height = gdk_screen_height () / 4;
800 c->num_points = veclen;
801 c->point = g_malloc (c->num_points * sizeof (c->point[0]));
804 dx = (veclen - 1.0) / (c->num_points - 1.0);
806 for (i = 0; i < c->num_points; ++i, rx += dx)
808 ry = vector[(int) (rx + 0.5)];
809 if (ry > c->max_y) ry = c->max_y;
810 if (ry < c->min_y) ry = c->min_y;
811 c->point[i].x = RADIUS + i;
813 RADIUS + height - project (ry, c->min_y, c->max_y, height);
815 if (old_type != GTK_CURVE_TYPE_FREE)
816 gtk_signal_emit (GTK_OBJECT (c), curve_type_changed_signal);
818 gtk_curve_draw (c, c->num_points, height);
822 gtk_curve_get_vector (GtkCurve *c, int veclen, gfloat vector[])
824 gfloat rx, ry, dx, dy, min_x, delta_x, *mem, *xv, *yv, *y2v, prev;
825 gint dst, i, x, next, num_active_ctlpoints = 0, first_active = -1;
829 if (c->curve_type != GTK_CURVE_TYPE_FREE)
831 /* count active points: */
833 for (i = num_active_ctlpoints = 0; i < c->num_ctlpoints; ++i)
834 if (c->ctlpoint[i][0] > prev)
836 if (first_active < 0)
838 prev = c->ctlpoint[i][0];
839 ++num_active_ctlpoints;
842 /* handle degenerate case: */
843 if (num_active_ctlpoints < 2)
845 if (num_active_ctlpoints > 0)
846 ry = c->ctlpoint[first_active][1];
849 if (ry < c->min_y) ry = c->min_y;
850 if (ry > c->max_y) ry = c->max_y;
851 for (x = 0; x < veclen; ++x)
857 switch (c->curve_type)
859 case GTK_CURVE_TYPE_SPLINE:
860 mem = g_malloc (3 * num_active_ctlpoints * sizeof (gfloat));
862 yv = mem + num_active_ctlpoints;
863 y2v = mem + 2*num_active_ctlpoints;
866 for (i = dst = 0; i < c->num_ctlpoints; ++i)
867 if (c->ctlpoint[i][0] > prev)
869 prev = c->ctlpoint[i][0];
870 xv[dst] = c->ctlpoint[i][0];
871 yv[dst] = c->ctlpoint[i][1];
875 spline_solve (num_active_ctlpoints, xv, yv, y2v);
878 dx = (c->max_x - min_x) / (veclen - 1);
879 for (x = 0; x < veclen; ++x, rx += dx)
881 ry = spline_eval (num_active_ctlpoints, xv, yv, y2v, rx);
882 if (ry < c->min_y) ry = c->min_y;
883 if (ry > c->max_y) ry = c->max_y;
890 case GTK_CURVE_TYPE_LINEAR:
891 dx = (c->max_x - min_x) / (veclen - 1);
896 for (x = 0; x < veclen; ++x, rx += dx)
898 if (rx >= c->ctlpoint[i][0])
900 if (rx > c->ctlpoint[i][0])
904 while (next < c->num_ctlpoints
905 && c->ctlpoint[next][0] <= c->ctlpoint[i][0])
907 if (next < c->num_ctlpoints)
909 delta_x = c->ctlpoint[next][0] - c->ctlpoint[i][0];
910 dy = ((c->ctlpoint[next][1] - c->ctlpoint[i][1])
913 ry = c->ctlpoint[i][1];
922 case GTK_CURVE_TYPE_FREE:
926 dx = c->num_points / (double) veclen;
927 for (x = 0; x < veclen; ++x, rx += dx)
928 vector[x] = unproject (RADIUS + c->height - c->point[(int) rx].y,
933 memset (vector, 0, veclen * sizeof (vector[0]));
941 return gtk_type_new (gtk_curve_get_type ());
945 gtk_curve_finalize (GObject *object)
949 g_return_if_fail (object != NULL);
950 g_return_if_fail (GTK_IS_CURVE (object));
952 curve = GTK_CURVE (object);
954 gdk_pixmap_unref (curve->pixmap);
956 g_free (curve->point);
958 g_free (curve->ctlpoint);
960 G_OBJECT_CLASS (parent_class)->finalize (object);