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/.
34 #include "gtkdrawingarea.h"
36 #include "gtkmarshalers.h"
37 #include "gtkradiobutton.h"
41 #define RADIUS 3 /* radius of the control points */
42 #define MIN_DISTANCE 8 /* min distance between control points */
44 #define GRAPH_MASK (GDK_EXPOSURE_MASK | \
45 GDK_POINTER_MOTION_MASK | \
46 GDK_POINTER_MOTION_HINT_MASK | \
47 GDK_ENTER_NOTIFY_MASK | \
48 GDK_BUTTON_PRESS_MASK | \
49 GDK_BUTTON_RELEASE_MASK | \
50 GDK_BUTTON1_MOTION_MASK)
61 static GtkDrawingAreaClass *parent_class = NULL;
62 static guint curve_type_changed_signal = 0;
65 /* forward declarations: */
66 static void gtk_curve_class_init (GtkCurveClass *class);
67 static void gtk_curve_init (GtkCurve *curve);
68 static void gtk_curve_get_property (GObject *object,
72 static void gtk_curve_set_property (GObject *object,
76 static void gtk_curve_finalize (GObject *object);
77 static gint gtk_curve_graph_events (GtkWidget *widget,
80 static void gtk_curve_size_graph (GtkCurve *curve);
83 gtk_curve_get_type (void)
85 static GType curve_type = 0;
89 static const GTypeInfo curve_info =
91 sizeof (GtkCurveClass),
93 NULL, /* base_finalize */
94 (GClassInitFunc) gtk_curve_class_init,
95 NULL, /* class_finalize */
96 NULL, /* class_data */
99 (GInstanceInitFunc) gtk_curve_init,
102 curve_type = g_type_register_static (GTK_TYPE_DRAWING_AREA, "GtkCurve",
109 gtk_curve_class_init (GtkCurveClass *class)
111 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
113 parent_class = g_type_class_peek_parent (class);
115 gobject_class->finalize = gtk_curve_finalize;
117 gobject_class->set_property = gtk_curve_set_property;
118 gobject_class->get_property = gtk_curve_get_property;
120 g_object_class_install_property (gobject_class,
122 g_param_spec_enum ("curve_type",
124 P_("Is this curve linear, spline interpolated, or free-form"),
126 GTK_CURVE_TYPE_LINEAR,
129 g_object_class_install_property (gobject_class,
131 g_param_spec_float ("min_x",
133 P_("Minimum possible value for X"),
139 g_object_class_install_property (gobject_class,
141 g_param_spec_float ("max_x",
143 P_("Maximum possible X value"),
149 g_object_class_install_property (gobject_class,
151 g_param_spec_float ("min_y",
153 P_("Minimum possible value for Y"),
159 g_object_class_install_property (gobject_class,
161 g_param_spec_float ("max_y",
163 P_("Maximum possible value for Y"),
170 curve_type_changed_signal =
171 g_signal_new ("curve_type_changed",
172 G_OBJECT_CLASS_TYPE (gobject_class),
174 G_STRUCT_OFFSET (GtkCurveClass, curve_type_changed),
176 _gtk_marshal_VOID__VOID,
181 gtk_curve_init (GtkCurve *curve)
185 curve->cursor_type = GDK_TOP_LEFT_ARROW;
186 curve->pixmap = NULL;
187 curve->curve_type = GTK_CURVE_TYPE_SPLINE;
189 curve->grab_point = -1;
191 curve->num_points = 0;
194 curve->num_ctlpoints = 0;
195 curve->ctlpoint = NULL;
202 old_mask = gtk_widget_get_events (GTK_WIDGET (curve));
203 gtk_widget_set_events (GTK_WIDGET (curve), old_mask | GRAPH_MASK);
204 g_signal_connect (curve, "event",
205 G_CALLBACK (gtk_curve_graph_events), curve);
206 gtk_curve_size_graph (curve);
210 gtk_curve_set_property (GObject *object,
215 GtkCurve *curve = GTK_CURVE (object);
219 case PROP_CURVE_TYPE:
220 gtk_curve_set_curve_type (curve, g_value_get_enum (value));
223 gtk_curve_set_range (curve, g_value_get_float (value), curve->max_x,
224 curve->min_y, curve->max_y);
227 gtk_curve_set_range (curve, curve->min_x, g_value_get_float (value),
228 curve->min_y, curve->max_y);
231 gtk_curve_set_range (curve, curve->min_x, curve->max_x,
232 g_value_get_float (value), curve->max_y);
235 gtk_curve_set_range (curve, curve->min_x, curve->max_x,
236 curve->min_y, g_value_get_float (value));
239 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
245 gtk_curve_get_property (GObject *object,
250 GtkCurve *curve = GTK_CURVE (object);
254 case PROP_CURVE_TYPE:
255 g_value_set_enum (value, curve->curve_type);
258 g_value_set_float (value, curve->min_x);
261 g_value_set_float (value, curve->max_x);
264 g_value_set_float (value, curve->min_y);
267 g_value_set_float (value, curve->max_y);
270 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
276 project (gfloat value, gfloat min, gfloat max, int norm)
278 return (norm - 1) * ((value - min) / (max - min)) + 0.5;
282 unproject (gint value, gfloat min, gfloat max, int norm)
284 return value / (gfloat) (norm - 1) * (max - min) + min;
287 /* Solve the tridiagonal equation system that determines the second
288 derivatives for the interpolation points. (Based on Numerical
289 Recipies 2nd Edition.) */
291 spline_solve (int n, gfloat x[], gfloat y[], gfloat y2[])
296 u = g_malloc ((n - 1) * sizeof (u[0]));
298 y2[0] = u[0] = 0.0; /* set lower boundary condition to "natural" */
300 for (i = 1; i < n - 1; ++i)
302 sig = (x[i] - x[i - 1]) / (x[i + 1] - x[i - 1]);
303 p = sig * y2[i - 1] + 2.0;
304 y2[i] = (sig - 1.0) / p;
305 u[i] = ((y[i + 1] - y[i])
306 / (x[i + 1] - x[i]) - (y[i] - y[i - 1]) / (x[i] - x[i - 1]));
307 u[i] = (6.0 * u[i] / (x[i + 1] - x[i - 1]) - sig * u[i - 1]) / p;
311 for (k = n - 2; k >= 0; --k)
312 y2[k] = y2[k] * y2[k + 1] + u[k];
318 spline_eval (int n, gfloat x[], gfloat y[], gfloat y2[], gfloat val)
323 /* do a binary search for the right interval: */
324 k_lo = 0; k_hi = n - 1;
325 while (k_hi - k_lo > 1)
327 k = (k_hi + k_lo) / 2;
334 h = x[k_hi] - x[k_lo];
337 a = (x[k_hi] - val) / h;
338 b = (val - x[k_lo]) / h;
339 return a*y[k_lo] + b*y[k_hi] +
340 ((a*a*a - a)*y2[k_lo] + (b*b*b - b)*y2[k_hi]) * (h*h)/6.0;
344 gtk_curve_interpolate (GtkCurve *c, gint width, gint height)
349 vector = g_malloc (width * sizeof (vector[0]));
351 gtk_curve_get_vector (c, width, vector);
354 if (c->num_points != width)
356 c->num_points = width;
359 c->point = g_malloc (c->num_points * sizeof (c->point[0]));
362 for (i = 0; i < width; ++i)
364 c->point[i].x = RADIUS + i;
365 c->point[i].y = RADIUS + height
366 - project (vector[i], c->min_y, c->max_y, height);
373 gtk_curve_draw (GtkCurve *c, gint width, gint height)
382 if (c->height != height || c->num_points != width)
383 gtk_curve_interpolate (c, width, height);
385 state = GTK_STATE_NORMAL;
386 if (!GTK_WIDGET_IS_SENSITIVE (GTK_WIDGET (c)))
387 state = GTK_STATE_INSENSITIVE;
389 style = GTK_WIDGET (c)->style;
391 /* clear the pixmap: */
392 gtk_paint_flat_box (style, c->pixmap, GTK_STATE_NORMAL, GTK_SHADOW_NONE,
393 NULL, GTK_WIDGET (c), "curve_bg",
394 0, 0, width + RADIUS * 2, height + RADIUS * 2);
395 /* draw the grid lines: (XXX make more meaningful) */
396 for (i = 0; i < 5; i++)
398 gdk_draw_line (c->pixmap, style->dark_gc[state],
399 RADIUS, i * (height / 4.0) + RADIUS,
400 width + RADIUS, i * (height / 4.0) + RADIUS);
401 gdk_draw_line (c->pixmap, style->dark_gc[state],
402 i * (width / 4.0) + RADIUS, RADIUS,
403 i * (width / 4.0) + RADIUS, height + RADIUS);
406 gdk_draw_points (c->pixmap, style->fg_gc[state], c->point, c->num_points);
407 if (c->curve_type != GTK_CURVE_TYPE_FREE)
408 for (i = 0; i < c->num_ctlpoints; ++i)
412 if (c->ctlpoint[i][0] < c->min_x)
415 x = project (c->ctlpoint[i][0], c->min_x, c->max_x,
418 project (c->ctlpoint[i][1], c->min_y, c->max_y,
422 gdk_draw_arc (c->pixmap, style->fg_gc[state], TRUE, x, y,
423 RADIUS * 2, RADIUS*2, 0, 360*64);
425 gdk_draw_drawable (GTK_WIDGET (c)->window, style->fg_gc[state], c->pixmap,
426 0, 0, 0, 0, width + RADIUS * 2, height + RADIUS * 2);
430 gtk_curve_graph_events (GtkWidget *widget, GdkEvent *event, GtkCurve *c)
432 GdkCursorType new_type = c->cursor_type;
433 gint i, src, dst, leftbound, rightbound;
434 GdkEventButton *bevent;
435 GdkEventMotion *mevent;
438 gint cx, x, y, width, height;
439 gint closest_point = 0;
440 gfloat rx, ry, min_x;
446 width = w->allocation.width - RADIUS * 2;
447 height = w->allocation.height - RADIUS * 2;
449 if ((width < 0) || (height < 0))
452 /* get the pointer position */
453 gdk_window_get_pointer (w->window, &tx, &ty, NULL);
454 x = CLAMP ((tx - RADIUS), 0, width-1);
455 y = CLAMP ((ty - RADIUS), 0, height-1);
460 for (i = 0; i < c->num_ctlpoints; ++i)
462 cx = project (c->ctlpoint[i][0], min_x, c->max_x, width);
463 if ((guint) abs (x - cx) < distance)
465 distance = abs (x - cx);
474 g_object_unref (c->pixmap);
479 c->pixmap = gdk_pixmap_new (w->window,
481 w->allocation.height, -1);
482 gtk_curve_draw (c, width, height);
485 case GDK_BUTTON_PRESS:
486 gtk_grab_add (widget);
488 bevent = (GdkEventButton *) event;
489 new_type = GDK_TCROSS;
491 switch (c->curve_type)
493 case GTK_CURVE_TYPE_LINEAR:
494 case GTK_CURVE_TYPE_SPLINE:
495 if (distance > MIN_DISTANCE)
497 /* insert a new control point */
498 if (c->num_ctlpoints > 0)
500 cx = project (c->ctlpoint[closest_point][0], min_x,
507 g_realloc (c->ctlpoint,
508 c->num_ctlpoints * sizeof (*c->ctlpoint));
509 for (i = c->num_ctlpoints - 1; i > closest_point; --i)
510 memcpy (c->ctlpoint + i, c->ctlpoint + i - 1,
511 sizeof (*c->ctlpoint));
513 c->grab_point = closest_point;
514 c->ctlpoint[c->grab_point][0] =
515 unproject (x, min_x, c->max_x, width);
516 c->ctlpoint[c->grab_point][1] =
517 unproject (height - y, c->min_y, c->max_y, height);
519 gtk_curve_interpolate (c, width, height);
522 case GTK_CURVE_TYPE_FREE:
523 c->point[x].x = RADIUS + x;
524 c->point[x].y = RADIUS + y;
529 gtk_curve_draw (c, width, height);
533 case GDK_BUTTON_RELEASE:
534 gtk_grab_remove (widget);
536 /* delete inactive points: */
537 if (c->curve_type != GTK_CURVE_TYPE_FREE)
539 for (src = dst = 0; src < c->num_ctlpoints; ++src)
541 if (c->ctlpoint[src][0] >= min_x)
543 memcpy (c->ctlpoint + dst, c->ctlpoint + src,
544 sizeof (*c->ctlpoint));
550 c->num_ctlpoints -= (src - dst);
551 if (c->num_ctlpoints <= 0)
553 c->num_ctlpoints = 1;
554 c->ctlpoint[0][0] = min_x;
555 c->ctlpoint[0][1] = c->min_y;
556 gtk_curve_interpolate (c, width, height);
557 gtk_curve_draw (c, width, height);
560 g_realloc (c->ctlpoint,
561 c->num_ctlpoints * sizeof (*c->ctlpoint));
564 new_type = GDK_FLEUR;
569 case GDK_MOTION_NOTIFY:
570 mevent = (GdkEventMotion *) event;
572 switch (c->curve_type)
574 case GTK_CURVE_TYPE_LINEAR:
575 case GTK_CURVE_TYPE_SPLINE:
576 if (c->grab_point == -1)
578 /* if no point is grabbed... */
579 if (distance <= MIN_DISTANCE)
580 new_type = GDK_FLEUR;
582 new_type = GDK_TCROSS;
586 /* drag the grabbed point */
587 new_type = GDK_TCROSS;
589 leftbound = -MIN_DISTANCE;
590 if (c->grab_point > 0)
591 leftbound = project (c->ctlpoint[c->grab_point - 1][0],
592 min_x, c->max_x, width);
594 rightbound = width + RADIUS * 2 + MIN_DISTANCE;
595 if (c->grab_point + 1 < c->num_ctlpoints)
596 rightbound = project (c->ctlpoint[c->grab_point + 1][0],
597 min_x, c->max_x, width);
599 if (tx <= leftbound || tx >= rightbound
600 || ty > height + RADIUS * 2 + MIN_DISTANCE
601 || ty < -MIN_DISTANCE)
602 c->ctlpoint[c->grab_point][0] = min_x - 1.0;
605 rx = unproject (x, min_x, c->max_x, width);
606 ry = unproject (height - y, c->min_y, c->max_y, height);
607 c->ctlpoint[c->grab_point][0] = rx;
608 c->ctlpoint[c->grab_point][1] = ry;
610 gtk_curve_interpolate (c, width, height);
611 gtk_curve_draw (c, width, height);
615 case GTK_CURVE_TYPE_FREE:
616 if (c->grab_point != -1)
618 if (c->grab_point > x)
634 for (i = x1; i <= x2; i++)
636 c->point[i].x = RADIUS + i;
637 c->point[i].y = RADIUS +
638 (y1 + ((y2 - y1) * (i - x1)) / (x2 - x1));
642 c->point[x].x = RADIUS + x;
643 c->point[x].y = RADIUS + y;
647 gtk_curve_draw (c, width, height);
649 if (mevent->state & GDK_BUTTON1_MASK)
650 new_type = GDK_TCROSS;
652 new_type = GDK_PENCIL;
655 if (new_type != (GdkCursorType) c->cursor_type)
659 c->cursor_type = new_type;
661 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (w),
663 gdk_window_set_cursor (w->window, cursor);
664 gdk_cursor_unref (cursor);
677 gtk_curve_set_curve_type (GtkCurve *c, GtkCurveType new_type)
682 if (new_type != c->curve_type)
686 width = GTK_WIDGET (c)->allocation.width - RADIUS * 2;
687 height = GTK_WIDGET (c)->allocation.height - RADIUS * 2;
689 if (new_type == GTK_CURVE_TYPE_FREE)
691 gtk_curve_interpolate (c, width, height);
692 c->curve_type = new_type;
694 else if (c->curve_type == GTK_CURVE_TYPE_FREE)
697 g_free (c->ctlpoint);
698 c->num_ctlpoints = 9;
699 c->ctlpoint = g_malloc (c->num_ctlpoints * sizeof (*c->ctlpoint));
702 dx = (width - 1) / (gfloat) (c->num_ctlpoints - 1);
704 for (i = 0; i < c->num_ctlpoints; ++i, rx += dx)
706 x = (int) (rx + 0.5);
708 unproject (x, c->min_x, c->max_x, width);
710 unproject (RADIUS + height - c->point[x].y,
711 c->min_y, c->max_y, height);
713 c->curve_type = new_type;
714 gtk_curve_interpolate (c, width, height);
718 c->curve_type = new_type;
719 gtk_curve_interpolate (c, width, height);
721 g_signal_emit (c, curve_type_changed_signal, 0);
722 g_object_notify (G_OBJECT (c), "curve_type");
723 gtk_curve_draw (c, width, height);
728 gtk_curve_size_graph (GtkCurve *curve)
732 GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (curve));
734 width = (curve->max_x - curve->min_x) + 1;
735 height = (curve->max_y - curve->min_y) + 1;
736 aspect = width / (gfloat) height;
737 if (width > gdk_screen_get_width (screen) / 4)
738 width = gdk_screen_get_width (screen) / 4;
739 if (height > gdk_screen_get_height (screen) / 4)
740 height = gdk_screen_get_height (screen) / 4;
743 width = height * aspect;
745 height = width / aspect;
747 gtk_widget_set_size_request (GTK_WIDGET (curve),
749 height + RADIUS * 2);
753 gtk_curve_reset_vector (GtkCurve *curve)
756 g_free (curve->ctlpoint);
758 curve->num_ctlpoints = 2;
759 curve->ctlpoint = g_malloc (2 * sizeof (curve->ctlpoint[0]));
760 curve->ctlpoint[0][0] = curve->min_x;
761 curve->ctlpoint[0][1] = curve->min_y;
762 curve->ctlpoint[1][0] = curve->max_x;
763 curve->ctlpoint[1][1] = curve->max_y;
769 width = GTK_WIDGET (curve)->allocation.width - RADIUS * 2;
770 height = GTK_WIDGET (curve)->allocation.height - RADIUS * 2;
772 if (curve->curve_type == GTK_CURVE_TYPE_FREE)
774 curve->curve_type = GTK_CURVE_TYPE_LINEAR;
775 gtk_curve_interpolate (curve, width, height);
776 curve->curve_type = GTK_CURVE_TYPE_FREE;
779 gtk_curve_interpolate (curve, width, height);
780 gtk_curve_draw (curve, width, height);
785 gtk_curve_reset (GtkCurve *c)
787 GtkCurveType old_type;
789 old_type = c->curve_type;
790 c->curve_type = GTK_CURVE_TYPE_SPLINE;
791 gtk_curve_reset_vector (c);
793 if (old_type != GTK_CURVE_TYPE_SPLINE)
795 g_signal_emit (c, curve_type_changed_signal, 0);
796 g_object_notify (G_OBJECT (c), "curve_type");
801 gtk_curve_set_gamma (GtkCurve *c, gfloat gamma)
803 gfloat x, one_over_gamma, height, one_over_width;
804 GtkCurveType old_type;
807 if (c->num_points < 2)
810 old_type = c->curve_type;
811 c->curve_type = GTK_CURVE_TYPE_FREE;
814 one_over_gamma = 1.0;
816 one_over_gamma = 1.0 / gamma;
817 one_over_width = 1.0 / (c->num_points - 1);
819 for (i = 0; i < c->num_points; ++i)
821 x = (gfloat) i / (c->num_points - 1);
822 c->point[i].x = RADIUS + i;
824 RADIUS + (height * (1.0 - pow (x, one_over_gamma)) + 0.5);
827 if (old_type != GTK_CURVE_TYPE_FREE)
828 g_signal_emit (c, curve_type_changed_signal, 0);
830 gtk_curve_draw (c, c->num_points, c->height);
834 gtk_curve_set_range (GtkCurve *curve,
840 g_object_freeze_notify (G_OBJECT (curve));
841 if (curve->min_x != min_x) {
842 curve->min_x = min_x;
843 g_object_notify (G_OBJECT (curve), "min_x");
845 if (curve->max_x != max_x) {
846 curve->max_x = max_x;
847 g_object_notify (G_OBJECT (curve), "max_x");
849 if (curve->min_y != min_y) {
850 curve->min_y = min_y;
851 g_object_notify (G_OBJECT (curve), "min_y");
853 if (curve->max_y != max_y) {
854 curve->max_y = max_y;
855 g_object_notify (G_OBJECT (curve), "max_y");
857 g_object_thaw_notify (G_OBJECT (curve));
859 gtk_curve_size_graph (curve);
860 gtk_curve_reset_vector (curve);
864 gtk_curve_set_vector (GtkCurve *c, int veclen, gfloat vector[])
866 GtkCurveType old_type;
869 GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (c));
871 old_type = c->curve_type;
872 c->curve_type = GTK_CURVE_TYPE_FREE;
875 height = GTK_WIDGET (c)->allocation.height - RADIUS * 2;
878 height = (c->max_y - c->min_y);
879 if (height > gdk_screen_get_height (screen) / 4)
880 height = gdk_screen_get_height (screen) / 4;
883 c->num_points = veclen;
884 c->point = g_malloc (c->num_points * sizeof (c->point[0]));
887 dx = (veclen - 1.0) / (c->num_points - 1.0);
889 for (i = 0; i < c->num_points; ++i, rx += dx)
891 ry = vector[(int) (rx + 0.5)];
892 if (ry > c->max_y) ry = c->max_y;
893 if (ry < c->min_y) ry = c->min_y;
894 c->point[i].x = RADIUS + i;
896 RADIUS + height - project (ry, c->min_y, c->max_y, height);
898 if (old_type != GTK_CURVE_TYPE_FREE)
900 g_signal_emit (c, curve_type_changed_signal, 0);
901 g_object_notify (G_OBJECT (c), "curve_type");
904 gtk_curve_draw (c, c->num_points, height);
908 gtk_curve_get_vector (GtkCurve *c, int veclen, gfloat vector[])
910 gfloat rx, ry, dx, dy, min_x, delta_x, *mem, *xv, *yv, *y2v, prev;
911 gint dst, i, x, next, num_active_ctlpoints = 0, first_active = -1;
915 if (c->curve_type != GTK_CURVE_TYPE_FREE)
917 /* count active points: */
919 for (i = num_active_ctlpoints = 0; i < c->num_ctlpoints; ++i)
920 if (c->ctlpoint[i][0] > prev)
922 if (first_active < 0)
924 prev = c->ctlpoint[i][0];
925 ++num_active_ctlpoints;
928 /* handle degenerate case: */
929 if (num_active_ctlpoints < 2)
931 if (num_active_ctlpoints > 0)
932 ry = c->ctlpoint[first_active][1];
935 if (ry < c->min_y) ry = c->min_y;
936 if (ry > c->max_y) ry = c->max_y;
937 for (x = 0; x < veclen; ++x)
943 switch (c->curve_type)
945 case GTK_CURVE_TYPE_SPLINE:
946 mem = g_malloc (3 * num_active_ctlpoints * sizeof (gfloat));
948 yv = mem + num_active_ctlpoints;
949 y2v = mem + 2*num_active_ctlpoints;
952 for (i = dst = 0; i < c->num_ctlpoints; ++i)
953 if (c->ctlpoint[i][0] > prev)
955 prev = c->ctlpoint[i][0];
956 xv[dst] = c->ctlpoint[i][0];
957 yv[dst] = c->ctlpoint[i][1];
961 spline_solve (num_active_ctlpoints, xv, yv, y2v);
964 dx = (c->max_x - min_x) / (veclen - 1);
965 for (x = 0; x < veclen; ++x, rx += dx)
967 ry = spline_eval (num_active_ctlpoints, xv, yv, y2v, rx);
968 if (ry < c->min_y) ry = c->min_y;
969 if (ry > c->max_y) ry = c->max_y;
976 case GTK_CURVE_TYPE_LINEAR:
977 dx = (c->max_x - min_x) / (veclen - 1);
982 for (x = 0; x < veclen; ++x, rx += dx)
984 if (rx >= c->ctlpoint[i][0])
986 if (rx > c->ctlpoint[i][0])
990 while (next < c->num_ctlpoints
991 && c->ctlpoint[next][0] <= c->ctlpoint[i][0])
993 if (next < c->num_ctlpoints)
995 delta_x = c->ctlpoint[next][0] - c->ctlpoint[i][0];
996 dy = ((c->ctlpoint[next][1] - c->ctlpoint[i][1])
999 ry = c->ctlpoint[i][1];
1008 case GTK_CURVE_TYPE_FREE:
1012 dx = c->num_points / (double) veclen;
1013 for (x = 0; x < veclen; ++x, rx += dx)
1014 vector[x] = unproject (RADIUS + c->height - c->point[(int) rx].y,
1019 memset (vector, 0, veclen * sizeof (vector[0]));
1025 gtk_curve_new (void)
1027 return g_object_new (GTK_TYPE_CURVE, NULL);
1031 gtk_curve_finalize (GObject *object)
1035 g_return_if_fail (GTK_IS_CURVE (object));
1037 curve = GTK_CURVE (object);
1039 g_object_unref (curve->pixmap);
1041 g_free (curve->point);
1042 if (curve->ctlpoint)
1043 g_free (curve->ctlpoint);
1045 G_OBJECT_CLASS (parent_class)->finalize (object);