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/.
27 #undef GTK_DISABLE_DEPRECATED
35 #include "gtkdrawingarea.h"
37 #include "gtkmarshalers.h"
38 #include "gtkradiobutton.h"
40 #include "gtkprivate.h"
44 #define RADIUS 3 /* radius of the control points */
45 #define MIN_DISTANCE 8 /* min distance between control points */
47 #define GRAPH_MASK (GDK_EXPOSURE_MASK | \
48 GDK_POINTER_MOTION_MASK | \
49 GDK_POINTER_MOTION_HINT_MASK | \
50 GDK_ENTER_NOTIFY_MASK | \
51 GDK_BUTTON_PRESS_MASK | \
52 GDK_BUTTON_RELEASE_MASK | \
53 GDK_BUTTON1_MOTION_MASK)
64 static GtkDrawingAreaClass *parent_class = NULL;
65 static guint curve_type_changed_signal = 0;
68 /* forward declarations: */
69 static void gtk_curve_class_init (GtkCurveClass *class);
70 static void gtk_curve_init (GtkCurve *curve);
71 static void gtk_curve_get_property (GObject *object,
75 static void gtk_curve_set_property (GObject *object,
79 static void gtk_curve_finalize (GObject *object);
80 static gint gtk_curve_graph_events (GtkWidget *widget,
83 static void gtk_curve_size_graph (GtkCurve *curve);
86 gtk_curve_get_type (void)
88 static GType curve_type = 0;
92 const GTypeInfo curve_info =
94 sizeof (GtkCurveClass),
96 NULL, /* base_finalize */
97 (GClassInitFunc) gtk_curve_class_init,
98 NULL, /* class_finalize */
99 NULL, /* class_data */
102 (GInstanceInitFunc) gtk_curve_init,
105 curve_type = g_type_register_static (GTK_TYPE_DRAWING_AREA, I_("GtkCurve"),
112 gtk_curve_class_init (GtkCurveClass *class)
114 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
116 parent_class = g_type_class_peek_parent (class);
118 gobject_class->finalize = gtk_curve_finalize;
120 gobject_class->set_property = gtk_curve_set_property;
121 gobject_class->get_property = gtk_curve_get_property;
123 g_object_class_install_property (gobject_class,
125 g_param_spec_enum ("curve-type",
127 P_("Is this curve linear, spline interpolated, or free-form"),
129 GTK_CURVE_TYPE_SPLINE,
130 GTK_PARAM_READWRITE));
131 g_object_class_install_property (gobject_class,
133 g_param_spec_float ("min-x",
135 P_("Minimum possible value for X"),
139 GTK_PARAM_READWRITE));
140 g_object_class_install_property (gobject_class,
142 g_param_spec_float ("max-x",
144 P_("Maximum possible X value"),
148 GTK_PARAM_READWRITE));
149 g_object_class_install_property (gobject_class,
151 g_param_spec_float ("min-y",
153 P_("Minimum possible value for Y"),
157 GTK_PARAM_READWRITE));
158 g_object_class_install_property (gobject_class,
160 g_param_spec_float ("max-y",
162 P_("Maximum possible value for Y"),
166 GTK_PARAM_READWRITE));
168 curve_type_changed_signal =
169 g_signal_new (I_("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;
356 c->point = g_malloc (c->num_points * sizeof (c->point[0]));
359 for (i = 0; i < width; ++i)
361 c->point[i].x = RADIUS + i;
362 c->point[i].y = RADIUS + height
363 - project (vector[i], c->min_y, c->max_y, height);
370 gtk_curve_draw (GtkCurve *c, gint width, gint height)
379 if (c->height != height || c->num_points != width)
380 gtk_curve_interpolate (c, width, height);
382 state = GTK_STATE_NORMAL;
383 if (!gtk_widget_is_sensitive (GTK_WIDGET (c)))
384 state = GTK_STATE_INSENSITIVE;
386 style = GTK_WIDGET (c)->style;
388 /* clear the pixmap: */
389 gtk_paint_flat_box (style, c->pixmap, GTK_STATE_NORMAL, GTK_SHADOW_NONE,
390 NULL, GTK_WIDGET (c), "curve_bg",
391 0, 0, width + RADIUS * 2, height + RADIUS * 2);
392 /* draw the grid lines: (XXX make more meaningful) */
393 for (i = 0; i < 5; i++)
395 gdk_draw_line (c->pixmap, style->dark_gc[state],
396 RADIUS, i * (height / 4.0) + RADIUS,
397 width + RADIUS, i * (height / 4.0) + RADIUS);
398 gdk_draw_line (c->pixmap, style->dark_gc[state],
399 i * (width / 4.0) + RADIUS, RADIUS,
400 i * (width / 4.0) + RADIUS, height + RADIUS);
403 gdk_draw_points (c->pixmap, style->fg_gc[state], c->point, c->num_points);
404 if (c->curve_type != GTK_CURVE_TYPE_FREE)
405 for (i = 0; i < c->num_ctlpoints; ++i)
409 if (c->ctlpoint[i][0] < c->min_x)
412 x = project (c->ctlpoint[i][0], c->min_x, c->max_x,
415 project (c->ctlpoint[i][1], c->min_y, c->max_y,
419 gdk_draw_arc (c->pixmap, style->fg_gc[state], TRUE, x, y,
420 RADIUS * 2, RADIUS*2, 0, 360*64);
422 gdk_draw_drawable (GTK_WIDGET (c)->window, style->fg_gc[state], c->pixmap,
423 0, 0, 0, 0, width + RADIUS * 2, height + RADIUS * 2);
427 gtk_curve_graph_events (GtkWidget *widget, GdkEvent *event, GtkCurve *c)
429 GdkCursorType new_type = c->cursor_type;
430 gint i, src, dst, leftbound, rightbound;
431 GdkEventMotion *mevent;
434 gint cx, x, y, width, height;
435 gint closest_point = 0;
436 gfloat rx, ry, min_x;
442 width = w->allocation.width - RADIUS * 2;
443 height = w->allocation.height - RADIUS * 2;
445 if ((width < 0) || (height < 0))
448 /* get the pointer position */
449 gdk_window_get_pointer (w->window, &tx, &ty, NULL);
450 x = CLAMP ((tx - RADIUS), 0, width-1);
451 y = CLAMP ((ty - RADIUS), 0, height-1);
456 for (i = 0; i < c->num_ctlpoints; ++i)
458 cx = project (c->ctlpoint[i][0], min_x, c->max_x, width);
459 if ((guint) abs (x - cx) < distance)
461 distance = abs (x - cx);
470 g_object_unref (c->pixmap);
475 c->pixmap = gdk_pixmap_new (w->window,
477 w->allocation.height, -1);
478 gtk_curve_draw (c, width, height);
481 case GDK_BUTTON_PRESS:
482 gtk_grab_add (widget);
484 new_type = GDK_TCROSS;
486 switch (c->curve_type)
488 case GTK_CURVE_TYPE_LINEAR:
489 case GTK_CURVE_TYPE_SPLINE:
490 if (distance > MIN_DISTANCE)
492 /* insert a new control point */
493 if (c->num_ctlpoints > 0)
495 cx = project (c->ctlpoint[closest_point][0], min_x,
502 g_realloc (c->ctlpoint,
503 c->num_ctlpoints * sizeof (*c->ctlpoint));
504 for (i = c->num_ctlpoints - 1; i > closest_point; --i)
505 memcpy (c->ctlpoint + i, c->ctlpoint + i - 1,
506 sizeof (*c->ctlpoint));
508 c->grab_point = closest_point;
509 c->ctlpoint[c->grab_point][0] =
510 unproject (x, min_x, c->max_x, width);
511 c->ctlpoint[c->grab_point][1] =
512 unproject (height - y, c->min_y, c->max_y, height);
514 gtk_curve_interpolate (c, width, height);
517 case GTK_CURVE_TYPE_FREE:
518 c->point[x].x = RADIUS + x;
519 c->point[x].y = RADIUS + y;
524 gtk_curve_draw (c, width, height);
528 case GDK_BUTTON_RELEASE:
529 gtk_grab_remove (widget);
531 /* delete inactive points: */
532 if (c->curve_type != GTK_CURVE_TYPE_FREE)
534 for (src = dst = 0; src < c->num_ctlpoints; ++src)
536 if (c->ctlpoint[src][0] >= min_x)
538 memcpy (c->ctlpoint + dst, c->ctlpoint + src,
539 sizeof (*c->ctlpoint));
545 c->num_ctlpoints -= (src - dst);
546 if (c->num_ctlpoints <= 0)
548 c->num_ctlpoints = 1;
549 c->ctlpoint[0][0] = min_x;
550 c->ctlpoint[0][1] = c->min_y;
551 gtk_curve_interpolate (c, width, height);
552 gtk_curve_draw (c, width, height);
555 g_realloc (c->ctlpoint,
556 c->num_ctlpoints * sizeof (*c->ctlpoint));
559 new_type = GDK_FLEUR;
564 case GDK_MOTION_NOTIFY:
565 mevent = (GdkEventMotion *) event;
567 switch (c->curve_type)
569 case GTK_CURVE_TYPE_LINEAR:
570 case GTK_CURVE_TYPE_SPLINE:
571 if (c->grab_point == -1)
573 /* if no point is grabbed... */
574 if (distance <= MIN_DISTANCE)
575 new_type = GDK_FLEUR;
577 new_type = GDK_TCROSS;
581 /* drag the grabbed point */
582 new_type = GDK_TCROSS;
584 leftbound = -MIN_DISTANCE;
585 if (c->grab_point > 0)
586 leftbound = project (c->ctlpoint[c->grab_point - 1][0],
587 min_x, c->max_x, width);
589 rightbound = width + RADIUS * 2 + MIN_DISTANCE;
590 if (c->grab_point + 1 < c->num_ctlpoints)
591 rightbound = project (c->ctlpoint[c->grab_point + 1][0],
592 min_x, c->max_x, width);
594 if (tx <= leftbound || tx >= rightbound
595 || ty > height + RADIUS * 2 + MIN_DISTANCE
596 || ty < -MIN_DISTANCE)
597 c->ctlpoint[c->grab_point][0] = min_x - 1.0;
600 rx = unproject (x, min_x, c->max_x, width);
601 ry = unproject (height - y, c->min_y, c->max_y, height);
602 c->ctlpoint[c->grab_point][0] = rx;
603 c->ctlpoint[c->grab_point][1] = ry;
605 gtk_curve_interpolate (c, width, height);
606 gtk_curve_draw (c, width, height);
610 case GTK_CURVE_TYPE_FREE:
611 if (c->grab_point != -1)
613 if (c->grab_point > x)
629 for (i = x1; i <= x2; i++)
631 c->point[i].x = RADIUS + i;
632 c->point[i].y = RADIUS +
633 (y1 + ((y2 - y1) * (i - x1)) / (x2 - x1));
637 c->point[x].x = RADIUS + x;
638 c->point[x].y = RADIUS + y;
642 gtk_curve_draw (c, width, height);
644 if (mevent->state & GDK_BUTTON1_MASK)
645 new_type = GDK_TCROSS;
647 new_type = GDK_PENCIL;
650 if (new_type != (GdkCursorType) c->cursor_type)
654 c->cursor_type = new_type;
656 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (w),
658 gdk_window_set_cursor (w->window, cursor);
659 gdk_cursor_unref (cursor);
672 gtk_curve_set_curve_type (GtkCurve *c, GtkCurveType new_type)
677 if (new_type != c->curve_type)
681 width = GTK_WIDGET (c)->allocation.width - RADIUS * 2;
682 height = GTK_WIDGET (c)->allocation.height - RADIUS * 2;
684 if (new_type == GTK_CURVE_TYPE_FREE)
686 gtk_curve_interpolate (c, width, height);
687 c->curve_type = new_type;
689 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)
749 g_free (curve->ctlpoint);
751 curve->num_ctlpoints = 2;
752 curve->ctlpoint = g_malloc (2 * sizeof (curve->ctlpoint[0]));
753 curve->ctlpoint[0][0] = curve->min_x;
754 curve->ctlpoint[0][1] = curve->min_y;
755 curve->ctlpoint[1][0] = curve->max_x;
756 curve->ctlpoint[1][1] = curve->max_y;
762 width = GTK_WIDGET (curve)->allocation.width - RADIUS * 2;
763 height = GTK_WIDGET (curve)->allocation.height - RADIUS * 2;
765 if (curve->curve_type == GTK_CURVE_TYPE_FREE)
767 curve->curve_type = GTK_CURVE_TYPE_LINEAR;
768 gtk_curve_interpolate (curve, width, height);
769 curve->curve_type = GTK_CURVE_TYPE_FREE;
772 gtk_curve_interpolate (curve, width, height);
773 gtk_curve_draw (curve, width, height);
778 gtk_curve_reset (GtkCurve *c)
780 GtkCurveType old_type;
782 old_type = c->curve_type;
783 c->curve_type = GTK_CURVE_TYPE_SPLINE;
784 gtk_curve_reset_vector (c);
786 if (old_type != GTK_CURVE_TYPE_SPLINE)
788 g_signal_emit (c, curve_type_changed_signal, 0);
789 g_object_notify (G_OBJECT (c), "curve-type");
794 gtk_curve_set_gamma (GtkCurve *c, gfloat gamma)
796 gfloat x, one_over_gamma, height;
797 GtkCurveType old_type;
800 if (c->num_points < 2)
803 old_type = c->curve_type;
804 c->curve_type = GTK_CURVE_TYPE_FREE;
807 one_over_gamma = 1.0;
809 one_over_gamma = 1.0 / gamma;
811 for (i = 0; i < c->num_points; ++i)
813 x = (gfloat) i / (c->num_points - 1);
814 c->point[i].x = RADIUS + i;
816 RADIUS + (height * (1.0 - pow (x, one_over_gamma)) + 0.5);
819 if (old_type != GTK_CURVE_TYPE_FREE)
820 g_signal_emit (c, curve_type_changed_signal, 0);
822 gtk_curve_draw (c, c->num_points, c->height);
826 gtk_curve_set_range (GtkCurve *curve,
832 g_object_freeze_notify (G_OBJECT (curve));
833 if (curve->min_x != min_x) {
834 curve->min_x = min_x;
835 g_object_notify (G_OBJECT (curve), "min-x");
837 if (curve->max_x != max_x) {
838 curve->max_x = max_x;
839 g_object_notify (G_OBJECT (curve), "max-x");
841 if (curve->min_y != min_y) {
842 curve->min_y = min_y;
843 g_object_notify (G_OBJECT (curve), "min-y");
845 if (curve->max_y != max_y) {
846 curve->max_y = max_y;
847 g_object_notify (G_OBJECT (curve), "max-y");
849 g_object_thaw_notify (G_OBJECT (curve));
851 gtk_curve_size_graph (curve);
852 gtk_curve_reset_vector (curve);
856 gtk_curve_set_vector (GtkCurve *c, int veclen, gfloat vector[])
858 GtkCurveType old_type;
861 GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (c));
863 old_type = c->curve_type;
864 c->curve_type = GTK_CURVE_TYPE_FREE;
867 height = GTK_WIDGET (c)->allocation.height - RADIUS * 2;
870 height = (c->max_y - c->min_y);
871 if (height > gdk_screen_get_height (screen) / 4)
872 height = gdk_screen_get_height (screen) / 4;
875 c->num_points = veclen;
876 c->point = g_malloc (c->num_points * sizeof (c->point[0]));
879 dx = (veclen - 1.0) / (c->num_points - 1.0);
881 for (i = 0; i < c->num_points; ++i, rx += dx)
883 ry = vector[(int) (rx + 0.5)];
884 if (ry > c->max_y) ry = c->max_y;
885 if (ry < c->min_y) ry = c->min_y;
886 c->point[i].x = RADIUS + i;
888 RADIUS + height - project (ry, c->min_y, c->max_y, height);
890 if (old_type != GTK_CURVE_TYPE_FREE)
892 g_signal_emit (c, curve_type_changed_signal, 0);
893 g_object_notify (G_OBJECT (c), "curve-type");
896 gtk_curve_draw (c, c->num_points, height);
900 gtk_curve_get_vector (GtkCurve *c, int veclen, gfloat vector[])
902 gfloat rx, ry, dx, dy, min_x, delta_x, *mem, *xv, *yv, *y2v, prev;
903 gint dst, i, x, next, num_active_ctlpoints = 0, first_active = -1;
907 if (c->curve_type != GTK_CURVE_TYPE_FREE)
909 /* count active points: */
911 for (i = num_active_ctlpoints = 0; i < c->num_ctlpoints; ++i)
912 if (c->ctlpoint[i][0] > prev)
914 if (first_active < 0)
916 prev = c->ctlpoint[i][0];
917 ++num_active_ctlpoints;
920 /* handle degenerate case: */
921 if (num_active_ctlpoints < 2)
923 if (num_active_ctlpoints > 0)
924 ry = c->ctlpoint[first_active][1];
927 if (ry < c->min_y) ry = c->min_y;
928 if (ry > c->max_y) ry = c->max_y;
929 for (x = 0; x < veclen; ++x)
935 switch (c->curve_type)
937 case GTK_CURVE_TYPE_SPLINE:
938 mem = g_malloc (3 * num_active_ctlpoints * sizeof (gfloat));
940 yv = mem + num_active_ctlpoints;
941 y2v = mem + 2*num_active_ctlpoints;
944 for (i = dst = 0; i < c->num_ctlpoints; ++i)
945 if (c->ctlpoint[i][0] > prev)
947 prev = c->ctlpoint[i][0];
948 xv[dst] = c->ctlpoint[i][0];
949 yv[dst] = c->ctlpoint[i][1];
953 spline_solve (num_active_ctlpoints, xv, yv, y2v);
956 dx = (c->max_x - min_x) / (veclen - 1);
957 for (x = 0; x < veclen; ++x, rx += dx)
959 ry = spline_eval (num_active_ctlpoints, xv, yv, y2v, rx);
960 if (ry < c->min_y) ry = c->min_y;
961 if (ry > c->max_y) ry = c->max_y;
968 case GTK_CURVE_TYPE_LINEAR:
969 dx = (c->max_x - min_x) / (veclen - 1);
974 for (x = 0; x < veclen; ++x, rx += dx)
976 if (rx >= c->ctlpoint[i][0])
978 if (rx > c->ctlpoint[i][0])
982 while (next < c->num_ctlpoints
983 && c->ctlpoint[next][0] <= c->ctlpoint[i][0])
985 if (next < c->num_ctlpoints)
987 delta_x = c->ctlpoint[next][0] - c->ctlpoint[i][0];
988 dy = ((c->ctlpoint[next][1] - c->ctlpoint[i][1])
991 ry = c->ctlpoint[i][1];
1000 case GTK_CURVE_TYPE_FREE:
1004 dx = c->num_points / (double) veclen;
1005 for (x = 0; x < veclen; ++x, rx += dx)
1006 vector[x] = unproject (RADIUS + c->height - c->point[(int) rx].y,
1011 memset (vector, 0, veclen * sizeof (vector[0]));
1017 gtk_curve_new (void)
1019 return g_object_new (GTK_TYPE_CURVE, NULL);
1023 gtk_curve_finalize (GObject *object)
1027 g_return_if_fail (GTK_IS_CURVE (object));
1029 curve = GTK_CURVE (object);
1031 g_object_unref (curve->pixmap);
1032 g_free (curve->point);
1033 g_free (curve->ctlpoint);
1035 G_OBJECT_CLASS (parent_class)->finalize (object);
1038 #define __GTK_CURVE_C__
1039 #include "gtkaliasdef.c"