annotate src/xs_curve.c @ 370:df6f12a00305

Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 09 Nov 2005 05:52:01 +0000
parents b1a858b8cb1a
children 58079c6180a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /* GTK - The GIMP Toolkit
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * Copyright (C) 1997 David Mosberger
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 *
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 * This library is free software; you can redistribute it and/or
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 * modify it under the terms of the GNU Library General Public
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 * License as published by the Free Software Foundation; either
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 * version 2 of the License, or (at your option) any later version.
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 *
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 * This library is distributed in the hope that it will be useful,
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 * Library General Public License for more details.
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 *
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 * You should have received a copy of the GNU Library General Public
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 * License along with this library; if not, write to the
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 * Boston, MA 02111-1307, USA.
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 */
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 /*
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 * file for a list of people on the GTK+ Team. See the ChangeLog
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 * files for a list of changes. These files are distributed with
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 */
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 #include <stdlib.h>
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 #include <string.h>
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 #include <math.h>
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 #include "xs_curve.h"
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 #include <gtk/gtkdrawingarea.h>
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 #include <gtk/gtkmain.h>
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 #include <gtk/gtksignal.h>
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
35
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 #define RADIUS 3 /* radius of the control points */
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 #define MIN_DISTANCE 8 /* min distance between control points */
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 #define GRAPH_MASK (GDK_EXPOSURE_MASK | \
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 GDK_POINTER_MOTION_MASK | \
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 GDK_POINTER_MOTION_HINT_MASK | \
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 GDK_ENTER_NOTIFY_MASK | \
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 GDK_BUTTON_PRESS_MASK | \
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 GDK_BUTTON_RELEASE_MASK | \
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 GDK_BUTTON1_MOTION_MASK)
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
48 enum
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
49 {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
50 ARG_0,
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
51 ARG_CURVE_TYPE,
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
52 ARG_MIN_X,
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
53 ARG_MAX_X,
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
54 ARG_MIN_Y,
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
55 ARG_MAX_Y
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 };
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 static GtkDrawingAreaClass *parent_class = NULL;
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 static guint curve_type_changed_signal = 0;
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 /* forward declarations: */
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
63 static void xs_curve_class_init(XSCurveClass * class);
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
64 static void xs_curve_init(XSCurve * curve);
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
65 static void xs_curve_set_arg(GtkObject * object, GtkArg * arg, guint arg_id);
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
66 static void xs_curve_get_arg(GtkObject * object, GtkArg * arg, guint arg_id);
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
67 static void xs_curve_finalize(GtkObject * object);
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
68 static gint xs_curve_graph_events(GtkWidget * widget, GdkEvent * event, XSCurve * c);
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
69 static void xs_curve_size_graph(XSCurve * curve);
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
71 GtkType xs_curve_get_type(void)
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 {
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
73 static GtkType curve_type = 0;
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
75 if (!curve_type) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
76 static const GtkTypeInfo curve_info = {
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
77 "XSCurve",
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
78 sizeof(XSCurve),
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
79 sizeof(XSCurveClass),
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
80 (GtkClassInitFunc) xs_curve_class_init,
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
81 (GtkObjectInitFunc) xs_curve_init,
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
82 /* reserved_1 */ NULL,
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
83 /* reserved_2 */ NULL,
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
84 (GtkClassInitFunc) NULL,
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
85 };
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
87 curve_type = gtk_type_unique(GTK_TYPE_DRAWING_AREA, &curve_info);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
88 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
89 return curve_type;
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 }
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
92 static void xs_curve_class_init(XSCurveClass * class)
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 {
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
94 GtkObjectClass *object_class;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
95
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
96 parent_class = gtk_type_class(GTK_TYPE_DRAWING_AREA);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
97
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
98 object_class = (GtkObjectClass *) class;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
99
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
100 object_class->set_arg = xs_curve_set_arg;
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
101 object_class->get_arg = xs_curve_get_arg;
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
102 object_class->finalize = xs_curve_finalize;
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
103
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
104 curve_type_changed_signal =
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
105 gtk_signal_new("curve_type_changed", GTK_RUN_FIRST, object_class->type,
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
106 GTK_SIGNAL_OFFSET(XSCurveClass, curve_type_changed),
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
107 gtk_marshal_NONE__NONE, GTK_TYPE_NONE, 0);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
108 gtk_object_class_add_signals(object_class, &curve_type_changed_signal, 1);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
109
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
110 gtk_object_add_arg_type("XSCurve::curve_type", GTK_TYPE_CURVE_TYPE, GTK_ARG_READWRITE, ARG_CURVE_TYPE);
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
111 gtk_object_add_arg_type("XSCurve::min_x", GTK_TYPE_FLOAT, GTK_ARG_READWRITE, ARG_MIN_X);
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
112 gtk_object_add_arg_type("XSCurve::max_x", GTK_TYPE_FLOAT, GTK_ARG_READWRITE, ARG_MAX_X);
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
113 gtk_object_add_arg_type("XSCurve::min_y", GTK_TYPE_FLOAT, GTK_ARG_READWRITE, ARG_MIN_Y);
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
114 gtk_object_add_arg_type("XSCurve::max_y", GTK_TYPE_FLOAT, GTK_ARG_READWRITE, ARG_MAX_Y);
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115 }
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
117 static void xs_curve_init(XSCurve * curve)
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 {
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
119 gint old_mask;
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
121 curve->cursor_type = GDK_TOP_LEFT_ARROW;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
122 curve->pixmap = NULL;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
123 curve->curve_type = GTK_CURVE_TYPE_SPLINE;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
124 curve->height = 0;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
125 curve->grab_point = -1;
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
127 curve->num_points = 0;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
128 curve->point = 0;
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
130 curve->num_ctlpoints = 0;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
131 curve->ctlpoint = NULL;
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
133 curve->min_x = 0.0;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
134 curve->max_x = 1.0;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
135 curve->min_y = 0.0;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
136 curve->max_y = 1.0;
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
138 old_mask = gtk_widget_get_events(GTK_WIDGET(curve));
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
139 gtk_widget_set_events(GTK_WIDGET(curve), old_mask | GRAPH_MASK);
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
140 gtk_signal_connect(GTK_OBJECT(curve), "event", (GtkSignalFunc) xs_curve_graph_events, curve);
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
141 xs_curve_size_graph(curve);
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 }
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
144 static void xs_curve_set_arg(GtkObject * object, GtkArg * arg, guint arg_id)
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145 {
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
146 XSCurve *curve = XS_CURVE(object);
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
147
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
148 switch (arg_id) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
149 case ARG_CURVE_TYPE:
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
150 xs_curve_set_curve_type(curve, GTK_VALUE_ENUM(*arg));
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
151 break;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
152 case ARG_MIN_X:
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
153 xs_curve_set_range(curve, GTK_VALUE_FLOAT(*arg), curve->max_x, curve->min_y, curve->max_y);
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
154 break;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
155 case ARG_MAX_X:
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
156 xs_curve_set_range(curve, curve->min_x, GTK_VALUE_FLOAT(*arg), curve->min_y, curve->max_y);
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
157 break;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
158 case ARG_MIN_Y:
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
159 xs_curve_set_range(curve, curve->min_x, curve->max_x, GTK_VALUE_FLOAT(*arg), curve->max_y);
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
160 break;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
161 case ARG_MAX_Y:
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
162 xs_curve_set_range(curve, curve->min_x, curve->max_x, curve->min_y, GTK_VALUE_FLOAT(*arg));
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
163 break;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
164 }
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165 }
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
167 static void xs_curve_get_arg(GtkObject * object, GtkArg * arg, guint arg_id)
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 {
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
169 XSCurve *curve = XS_CURVE(object);
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
171 switch (arg_id) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
172 case ARG_CURVE_TYPE:
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
173 GTK_VALUE_ENUM(*arg) = curve->curve_type;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
174 break;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
175 case ARG_MIN_X:
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
176 GTK_VALUE_FLOAT(*arg) = curve->min_x;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
177 break;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
178 case ARG_MAX_X:
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
179 GTK_VALUE_FLOAT(*arg) = curve->max_x;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
180 break;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
181 case ARG_MIN_Y:
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
182 GTK_VALUE_FLOAT(*arg) = curve->min_y;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
183 break;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
184 case ARG_MAX_Y:
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
185 GTK_VALUE_FLOAT(*arg) = curve->max_y;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
186 break;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
187 default:
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
188 arg->type = GTK_TYPE_INVALID;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
189 break;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
190 }
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191 }
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
193 static int project(gfloat value, gfloat min, gfloat max, int norm)
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194 {
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
195 return (norm - 1) * ((value - min) / (max - min)) + 0.5;
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
196 }
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
198 static gfloat unproject(gint value, gfloat min, gfloat max, int norm)
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199 {
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
200 return value / (gfloat) (norm - 1) * (max - min) + min;
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
201 }
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203 /* Solve the tridiagonal equation system that determines the second
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204 derivatives for the interpolation points. (Based on Numerical
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205 Recipies 2nd Edition.) */
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
206 static void spline_solve(int n, gfloat x[], gfloat y[], gfloat y2[])
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
207 {
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
208 gfloat p, sig, *u;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
209 gint i, k;
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
210
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
211 u = g_malloc((n - 1) * sizeof(u[0]));
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
212
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
213 y2[0] = u[0] = 0.0; /* set lower boundary condition to "natural" */
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
214
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
215 for (i = 1; i < n - 1; ++i) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
216 sig = (x[i] - x[i - 1]) / (x[i + 1] - x[i - 1]);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
217 p = sig * y2[i - 1] + 2.0;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
218 y2[i] = (sig - 1.0) / p;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
219 u[i] = ((y[i + 1] - y[i])
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
220 / (x[i + 1] - x[i]) - (y[i] - y[i - 1]) / (x[i] - x[i - 1]));
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
221 u[i] = (6.0 * u[i] / (x[i + 1] - x[i - 1]) - sig * u[i - 1]) / p;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
222 }
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
224 y2[n - 1] = 0.0;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
225 for (k = n - 2; k >= 0; --k)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
226 y2[k] = y2[k] * y2[k + 1] + u[k];
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
227
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
228 g_free(u);
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229 }
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
230
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
231 static gfloat spline_eval(int n, gfloat x[], gfloat y[], gfloat y2[], gfloat val)
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232 {
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
233 gint k_lo, k_hi, k;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
234 gfloat h, b, a;
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
236 /* do a binary search for the right interval: */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
237 k_lo = 0;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
238 k_hi = n - 1;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
239 while (k_hi - k_lo > 1) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
240 k = (k_hi + k_lo) / 2;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
241 if (x[k] > val)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
242 k_hi = k;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
243 else
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
244 k_lo = k;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
245 }
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
246
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
247 h = x[k_hi] - x[k_lo];
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
248 g_assert(h > 0.0);
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
249
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
250 a = (x[k_hi] - val) / h;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
251 b = (val - x[k_lo]) / h;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
252 return a * y[k_lo] + b * y[k_hi] + ((a * a * a - a) * y2[k_lo] + (b * b * b - b) * y2[k_hi]) * (h * h) / 6.0;
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
253 }
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
254
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
255 static void xs_curve_interpolate(XSCurve * c, gint width, gint height)
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
256 {
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
257 gfloat *vector;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
258 int i;
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
259
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
260 vector = g_malloc(width * sizeof(vector[0]));
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
261
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
262 xs_curve_get_vector(c, width, vector);
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
263
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
264 c->height = height;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
265 if (c->num_points != width) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
266 c->num_points = width;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
267 if (c->point)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
268 g_free(c->point);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
269 c->point = g_malloc(c->num_points * sizeof(c->point[0]));
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
270 }
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
271
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
272 for (i = 0; i < width; ++i) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
273 c->point[i].x = RADIUS + i;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
274 c->point[i].y = RADIUS + height - project(vector[i], c->min_y, c->max_y, height);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
275 }
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
276
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
277 g_free(vector);
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
278 }
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
279
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
280 static void xs_curve_draw(XSCurve * c, gint width, gint height)
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
281 {
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
282 GtkStateType state;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
283 GtkStyle *style;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
284 gint i;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
285
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
286 if (!c->pixmap)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
287 return;
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
288
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
289 if (c->height != height || c->num_points != width)
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
290 xs_curve_interpolate(c, width, height);
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
291
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
292 state = GTK_STATE_NORMAL;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
293 if (!GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(c)))
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
294 state = GTK_STATE_INSENSITIVE;
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
295
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
296 style = GTK_WIDGET(c)->style;
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
297
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
298 /* clear the pixmap: */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
299 gtk_paint_flat_box(style, c->pixmap, GTK_STATE_NORMAL, GTK_SHADOW_NONE,
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
300 NULL, GTK_WIDGET(c), "curve_bg", 0, 0, width + RADIUS * 2, height + RADIUS * 2);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
301 /* draw the grid lines: (XXX make more meaningful) */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
302 for (i = 0; i < 5; i++) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
303 gdk_draw_line(c->pixmap, style->dark_gc[state],
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
304 RADIUS, i * (height / 4.0) + RADIUS, width + RADIUS, i * (height / 4.0) + RADIUS);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
305 gdk_draw_line(c->pixmap, style->dark_gc[state],
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
306 i * (width / 4.0) + RADIUS, RADIUS, i * (width / 4.0) + RADIUS, height + RADIUS);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
307 }
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
308
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
309 gdk_draw_points(c->pixmap, style->fg_gc[state], c->point, c->num_points);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
310 if (c->curve_type != GTK_CURVE_TYPE_FREE)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
311 for (i = 0; i < c->num_ctlpoints; ++i) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
312 gint x, y;
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
313
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
314 if (c->ctlpoint[i][0] < c->min_x)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
315 continue;
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
316
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
317 x = project(c->ctlpoint[i][0], c->min_x, c->max_x, width);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
318 y = height - project(c->ctlpoint[i][1], c->min_y, c->max_y, height);
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
319
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
320 /* draw a bullet: */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
321 gdk_draw_arc(c->pixmap, style->fg_gc[state], TRUE, x, y, RADIUS * 2, RADIUS * 2, 0, 360 * 64);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
322 }
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
323
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
324 gdk_draw_pixmap(GTK_WIDGET(c)->window, style->fg_gc[state], c->pixmap,
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
325 0, 0, 0, 0, width + RADIUS * 2, height + RADIUS * 2);
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
326 }
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
327
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
328 static gint xs_curve_graph_events(GtkWidget * widget, GdkEvent * event, XSCurve * c)
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
329 {
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
330 GdkCursorType new_type = c->cursor_type;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
331 gint i, src, dst, leftbound, rightbound;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
332 GdkEventButton *bevent;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
333 GdkEventMotion *mevent;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
334 GtkWidget *w;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
335 gint tx, ty;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
336 gint cx, x, y, width, height;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
337 gint closest_point = 0;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
338 gfloat rx, ry, min_x;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
339 guint distance;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
340 gint x1, x2, y1, y2;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
341
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
342 w = GTK_WIDGET(c);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
343 width = w->allocation.width - RADIUS * 2;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
344 height = w->allocation.height - RADIUS * 2;
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
345
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
346 if ((width < 0) || (height < 0))
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
347 return FALSE;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
348
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
349 /* get the pointer position */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
350 gdk_window_get_pointer(w->window, &tx, &ty, NULL);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
351 x = CLAMP((tx - RADIUS), 0, width - 1);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
352 y = CLAMP((ty - RADIUS), 0, height - 1);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
353
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
354 min_x = c->min_x;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
355
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
356 distance = ~0U;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
357 for (i = 0; i < c->num_ctlpoints; ++i) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
358 cx = project(c->ctlpoint[i][0], min_x, c->max_x, width);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
359 if ((guint) abs(x - cx) < distance) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
360 distance = abs(x - cx);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
361 closest_point = i;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
362 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
363 }
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
364
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
365 switch (event->type) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
366 case GDK_CONFIGURE:
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
367 if (c->pixmap)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
368 gdk_pixmap_unref(c->pixmap);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
369 c->pixmap = 0;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
370 /* fall through */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
371 case GDK_EXPOSE:
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
372 if (!c->pixmap)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
373 c->pixmap = gdk_pixmap_new(w->window, w->allocation.width, w->allocation.height, -1);
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
374 xs_curve_draw(c, width, height);
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
375 break;
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
376
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
377 case GDK_BUTTON_PRESS:
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
378 gtk_grab_add(widget);
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
379
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
380 bevent = (GdkEventButton *) event;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
381 new_type = GDK_TCROSS;
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
382
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
383 switch (c->curve_type) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
384 case GTK_CURVE_TYPE_LINEAR:
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
385 case GTK_CURVE_TYPE_SPLINE:
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
386 if (distance > MIN_DISTANCE) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
387 /* insert a new control point */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
388 if (c->num_ctlpoints > 0) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
389 cx = project(c->ctlpoint[closest_point][0], min_x, c->max_x, width);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
390 if (x > cx)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
391 ++closest_point;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
392 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
393 ++c->num_ctlpoints;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
394 c->ctlpoint = g_realloc(c->ctlpoint, c->num_ctlpoints * sizeof(*c->ctlpoint));
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
395 for (i = c->num_ctlpoints - 1; i > closest_point; --i)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
396 memcpy(c->ctlpoint + i, c->ctlpoint + i - 1, sizeof(*c->ctlpoint));
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
397 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
398 c->grab_point = closest_point;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
399 c->ctlpoint[c->grab_point][0] = unproject(x, min_x, c->max_x, width);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
400 c->ctlpoint[c->grab_point][1] = unproject(height - y, c->min_y, c->max_y, height);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
401
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
402 xs_curve_interpolate(c, width, height);
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
403 break;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
404
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
405 case GTK_CURVE_TYPE_FREE:
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
406 c->point[x].x = RADIUS + x;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
407 c->point[x].y = RADIUS + y;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
408 c->grab_point = x;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
409 c->last = y;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
410 break;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
411 }
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
412 xs_curve_draw(c, width, height);
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
413 break;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
414
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
415 case GDK_BUTTON_RELEASE:
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
416 gtk_grab_remove(widget);
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
417
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
418 /* delete inactive points: */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
419 if (c->curve_type != GTK_CURVE_TYPE_FREE) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
420 for (src = dst = 0; src < c->num_ctlpoints; ++src) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
421 if (c->ctlpoint[src][0] >= min_x) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
422 memcpy(c->ctlpoint + dst, c->ctlpoint + src, sizeof(*c->ctlpoint));
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
423 ++dst;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
424 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
425 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
426 if (dst < src) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
427 c->num_ctlpoints -= (src - dst);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
428 if (c->num_ctlpoints <= 0) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
429 c->num_ctlpoints = 1;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
430 c->ctlpoint[0][0] = min_x;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
431 c->ctlpoint[0][1] = c->min_y;
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
432 xs_curve_interpolate(c, width, height);
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
433 xs_curve_draw(c, width, height);
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
434 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
435 c->ctlpoint = g_realloc(c->ctlpoint, c->num_ctlpoints * sizeof(*c->ctlpoint));
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
436 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
437 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
438 new_type = GDK_FLEUR;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
439 c->grab_point = -1;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
440 break;
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
441
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
442 case GDK_MOTION_NOTIFY:
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
443 mevent = (GdkEventMotion *) event;
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
444
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
445 switch (c->curve_type) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
446 case GTK_CURVE_TYPE_LINEAR:
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
447 case GTK_CURVE_TYPE_SPLINE:
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
448 if (c->grab_point == -1) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
449 /* if no point is grabbed... */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
450 if (distance <= MIN_DISTANCE)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
451 new_type = GDK_FLEUR;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
452 else
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
453 new_type = GDK_TCROSS;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
454 } else {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
455 /* drag the grabbed point */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
456 new_type = GDK_TCROSS;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
457
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
458 leftbound = -MIN_DISTANCE;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
459 if (c->grab_point > 0)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
460 leftbound = project(c->ctlpoint[c->grab_point - 1][0], min_x, c->max_x, width);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
461
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
462 rightbound = width + RADIUS * 2 + MIN_DISTANCE;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
463 if (c->grab_point + 1 < c->num_ctlpoints)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
464 rightbound = project(c->ctlpoint[c->grab_point + 1][0], min_x, c->max_x, width);
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
465
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
466 if (tx <= leftbound || tx >= rightbound
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
467 || ty > height + RADIUS * 2 + MIN_DISTANCE || ty < -MIN_DISTANCE)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
468 c->ctlpoint[c->grab_point][0] = min_x - 1.0;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
469 else {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
470 rx = unproject(x, min_x, c->max_x, width);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
471 ry = unproject(height - y, c->min_y, c->max_y, height);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
472 c->ctlpoint[c->grab_point][0] = rx;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
473 c->ctlpoint[c->grab_point][1] = ry;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
474 }
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
475 xs_curve_interpolate(c, width, height);
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
476 xs_curve_draw(c, width, height);
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
477 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
478 break;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
479
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
480 case GTK_CURVE_TYPE_FREE:
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
481 if (c->grab_point != -1) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
482 if (c->grab_point > x) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
483 x1 = x;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
484 x2 = c->grab_point;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
485 y1 = y;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
486 y2 = c->last;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
487 } else {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
488 x1 = c->grab_point;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
489 x2 = x;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
490 y1 = c->last;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
491 y2 = y;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
492 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
493
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
494 if (x2 != x1)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
495 for (i = x1; i <= x2; i++) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
496 c->point[i].x = RADIUS + i;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
497 c->point[i].y = RADIUS + (y1 + ((y2 - y1) * (i - x1)) / (x2 - x1));
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
498 } else {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
499 c->point[x].x = RADIUS + x;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
500 c->point[x].y = RADIUS + y;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
501 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
502 c->grab_point = x;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
503 c->last = y;
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
504 xs_curve_draw(c, width, height);
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
505 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
506 if (mevent->state & GDK_BUTTON1_MASK)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
507 new_type = GDK_TCROSS;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
508 else
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
509 new_type = GDK_PENCIL;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
510 break;
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
511 }
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
512 if (new_type != (GdkCursorType) c->cursor_type) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
513 GdkCursor *cursor;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
514
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
515 c->cursor_type = new_type;
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
516
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
517 cursor = gdk_cursor_new(c->cursor_type);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
518 gdk_window_set_cursor(w->window, cursor);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
519 gdk_cursor_destroy(cursor);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
520 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
521 break;
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
522
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
523 default:
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
524 break;
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
525 }
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
526 return FALSE;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
527 }
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
528
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
529 void xs_curve_set_curve_type(XSCurve * c, GtkCurveType new_type)
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
530 {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
531 gfloat rx, dx;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
532 gint x, i;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
533
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
534 if (new_type != c->curve_type) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
535 gint width, height;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
536
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
537 width = GTK_WIDGET(c)->allocation.width - RADIUS * 2;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
538 height = GTK_WIDGET(c)->allocation.height - RADIUS * 2;
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
539
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
540 if (new_type == GTK_CURVE_TYPE_FREE) {
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
541 xs_curve_interpolate(c, width, height);
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
542 c->curve_type = new_type;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
543 } else if (c->curve_type == GTK_CURVE_TYPE_FREE) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
544 if (c->ctlpoint)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
545 g_free(c->ctlpoint);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
546 c->num_ctlpoints = 9;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
547 c->ctlpoint = g_malloc(c->num_ctlpoints * sizeof(*c->ctlpoint));
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
548
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
549 rx = 0.0;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
550 dx = (width - 1) / (gfloat) (c->num_ctlpoints - 1);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
551
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
552 for (i = 0; i < c->num_ctlpoints; ++i, rx += dx) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
553 x = (int) (rx + 0.5);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
554 c->ctlpoint[i][0] = unproject(x, c->min_x, c->max_x, width);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
555 c->ctlpoint[i][1] =
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
556 unproject(RADIUS + height - c->point[x].y, c->min_y, c->max_y, height);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
557 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
558 c->curve_type = new_type;
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
559 xs_curve_interpolate(c, width, height);
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
560 } else {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
561 c->curve_type = new_type;
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
562 xs_curve_interpolate(c, width, height);
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
563 }
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
564 gtk_signal_emit(GTK_OBJECT(c), curve_type_changed_signal);
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
565 xs_curve_draw(c, width, height);
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
566 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
567 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
568
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
569 static void xs_curve_size_graph(XSCurve * curve)
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
570 {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
571 gint width, height;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
572 gfloat aspect;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
573
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
574 width = (curve->max_x - curve->min_x) + 1;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
575 height = (curve->max_y - curve->min_y) + 1;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
576 aspect = width / (gfloat) height;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
577 if (width > gdk_screen_width() / 4)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
578 width = gdk_screen_width() / 4;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
579 if (height > gdk_screen_height() / 4)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
580 height = gdk_screen_height() / 4;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
581
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
582 if (aspect < 1.0)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
583 width = height * aspect;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
584 else
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
585 height = width / aspect;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
586
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
587 gtk_drawing_area_size(GTK_DRAWING_AREA(curve), width + RADIUS * 2, height + RADIUS * 2);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
588 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
589
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
590 static void xs_curve_reset_vector(XSCurve * curve)
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
591 {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
592 if (curve->ctlpoint)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
593 g_free(curve->ctlpoint);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
594
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
595 curve->num_ctlpoints = 2;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
596 curve->ctlpoint = g_malloc(2 * sizeof(curve->ctlpoint[0]));
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
597 curve->ctlpoint[0][0] = curve->min_x;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
598 curve->ctlpoint[0][1] = curve->min_y;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
599 curve->ctlpoint[1][0] = curve->max_x;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
600 curve->ctlpoint[1][1] = curve->max_y;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
601
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
602 if (curve->pixmap) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
603 gint width, height;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
604
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
605 width = GTK_WIDGET(curve)->allocation.width - RADIUS * 2;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
606 height = GTK_WIDGET(curve)->allocation.height - RADIUS * 2;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
607
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
608 if (curve->curve_type == GTK_CURVE_TYPE_FREE) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
609 curve->curve_type = GTK_CURVE_TYPE_LINEAR;
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
610 xs_curve_interpolate(curve, width, height);
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
611 curve->curve_type = GTK_CURVE_TYPE_FREE;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
612 } else
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
613 xs_curve_interpolate(curve, width, height);
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
614 xs_curve_draw(curve, width, height);
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
615 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
616 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
617
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
618 void xs_curve_reset(XSCurve * c)
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
619 {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
620 GtkCurveType old_type;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
621
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
622 old_type = c->curve_type;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
623 c->curve_type = GTK_CURVE_TYPE_SPLINE;
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
624 xs_curve_reset_vector(c);
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
625
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
626 if (old_type != GTK_CURVE_TYPE_SPLINE)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
627 gtk_signal_emit(GTK_OBJECT(c), curve_type_changed_signal);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
628 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
629
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
630 void xs_curve_set_gamma(XSCurve * c, gfloat gamma)
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
631 {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
632 gfloat x, one_over_gamma, height, one_over_width;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
633 GtkCurveType old_type;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
634 gint i;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
635
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
636 if (c->num_points < 2)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
637 return;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
638
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
639 old_type = c->curve_type;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
640 c->curve_type = GTK_CURVE_TYPE_FREE;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
641
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
642 if (gamma <= 0)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
643 one_over_gamma = 1.0;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
644 else
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
645 one_over_gamma = 1.0 / gamma;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
646 one_over_width = 1.0 / (c->num_points - 1);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
647 height = c->height;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
648 for (i = 0; i < c->num_points; ++i) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
649 x = (gfloat) i / (c->num_points - 1);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
650 c->point[i].x = RADIUS + i;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
651 c->point[i].y = RADIUS + (height * (1.0 - pow(x, one_over_gamma)) + 0.5);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
652 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
653
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
654 if (old_type != GTK_CURVE_TYPE_FREE)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
655 gtk_signal_emit(GTK_OBJECT(c), curve_type_changed_signal);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
656
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
657 xs_curve_draw(c, c->num_points, c->height);
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
658 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
659
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
660 void xs_curve_set_range(XSCurve * curve, gfloat min_x, gfloat max_x, gfloat min_y, gfloat max_y)
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
661 {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
662 curve->min_x = min_x;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
663 curve->max_x = max_x;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
664 curve->min_y = min_y;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
665 curve->max_y = max_y;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
666
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
667 xs_curve_size_graph(curve);
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
668 xs_curve_reset_vector(curve);
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
669 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
670
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
671 void xs_curve_set_vector(XSCurve * c, int veclen, gfloat vector[])
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
672 {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
673 GtkCurveType old_type;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
674 gfloat rx, dx, ry;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
675 gint i, height;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
676
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
677 old_type = c->curve_type;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
678 c->curve_type = GTK_CURVE_TYPE_FREE;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
679
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
680 if (c->point)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
681 height = GTK_WIDGET(c)->allocation.height - RADIUS * 2;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
682 else {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
683 height = (c->max_y - c->min_y);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
684 if (height > gdk_screen_height() / 4)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
685 height = gdk_screen_height() / 4;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
686
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
687 c->height = height;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
688 c->num_points = veclen;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
689 c->point = g_malloc(c->num_points * sizeof(c->point[0]));
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
690 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
691 rx = 0;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
692 dx = (veclen - 1.0) / (c->num_points - 1.0);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
693
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
694 for (i = 0; i < c->num_points; ++i, rx += dx) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
695 ry = vector[(int) (rx + 0.5)];
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
696 if (ry > c->max_y)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
697 ry = c->max_y;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
698 if (ry < c->min_y)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
699 ry = c->min_y;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
700 c->point[i].x = RADIUS + i;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
701 c->point[i].y = RADIUS + height - project(ry, c->min_y, c->max_y, height);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
702 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
703 if (old_type != GTK_CURVE_TYPE_FREE)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
704 gtk_signal_emit(GTK_OBJECT(c), curve_type_changed_signal);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
705
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
706 xs_curve_draw(c, c->num_points, height);
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
707 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
708
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
709 void xs_curve_get_vector(XSCurve * c, int veclen, gfloat vector[])
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
710 {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
711 gfloat rx, ry, dx, dy, min_x, delta_x, *mem, *xv, *yv, *y2v, prev;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
712 gint dst, i, x, next, num_active_ctlpoints = 0, first_active = -1;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
713
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
714 min_x = c->min_x;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
715
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
716 if (c->curve_type != GTK_CURVE_TYPE_FREE) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
717 /* count active points: */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
718 prev = min_x - 1.0;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
719 for (i = num_active_ctlpoints = 0; i < c->num_ctlpoints; ++i)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
720 if (c->ctlpoint[i][0] > prev) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
721 if (first_active < 0)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
722 first_active = i;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
723 prev = c->ctlpoint[i][0];
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
724 ++num_active_ctlpoints;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
725 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
726
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
727 /* handle degenerate case: */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
728 if (num_active_ctlpoints < 2) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
729 if (num_active_ctlpoints > 0)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
730 ry = c->ctlpoint[first_active][1];
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
731 else
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
732 ry = c->min_y;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
733 if (ry < c->min_y)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
734 ry = c->min_y;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
735 if (ry > c->max_y)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
736 ry = c->max_y;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
737 for (x = 0; x < veclen; ++x)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
738 vector[x] = ry;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
739 return;
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
740 }
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
741 }
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
742
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
743 switch (c->curve_type) {
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
744 case GTK_CURVE_TYPE_SPLINE:
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
745 mem = g_malloc(3 * num_active_ctlpoints * sizeof(gfloat));
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
746 xv = mem;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
747 yv = mem + num_active_ctlpoints;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
748 y2v = mem + 2 * num_active_ctlpoints;
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
749
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
750 prev = min_x - 1.0;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
751 for (i = dst = 0; i < c->num_ctlpoints; ++i)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
752 if (c->ctlpoint[i][0] > prev) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
753 prev = c->ctlpoint[i][0];
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
754 xv[dst] = c->ctlpoint[i][0];
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
755 yv[dst] = c->ctlpoint[i][1];
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
756 ++dst;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
757 }
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
758
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
759 spline_solve(num_active_ctlpoints, xv, yv, y2v);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
760
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
761 rx = min_x;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
762 dx = (c->max_x - min_x) / (veclen - 1);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
763 for (x = 0; x < veclen; ++x, rx += dx) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
764 ry = spline_eval(num_active_ctlpoints, xv, yv, y2v, rx);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
765 if (ry < c->min_y)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
766 ry = c->min_y;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
767 if (ry > c->max_y)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
768 ry = c->max_y;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
769 vector[x] = ry;
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
770 }
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
771
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
772 g_free(mem);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
773 break;
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
774
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
775 case GTK_CURVE_TYPE_LINEAR:
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
776 dx = (c->max_x - min_x) / (veclen - 1);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
777 rx = min_x;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
778 ry = c->min_y;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
779 dy = 0.0;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
780 i = first_active;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
781 for (x = 0; x < veclen; ++x, rx += dx) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
782 if (rx >= c->ctlpoint[i][0]) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
783 if (rx > c->ctlpoint[i][0])
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
784 ry = c->min_y;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
785 dy = 0.0;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
786 next = i + 1;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
787 while (next < c->num_ctlpoints && c->ctlpoint[next][0] <= c->ctlpoint[i][0])
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
788 ++next;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
789 if (next < c->num_ctlpoints) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
790 delta_x = c->ctlpoint[next][0] - c->ctlpoint[i][0];
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
791 dy = ((c->ctlpoint[next][1] - c->ctlpoint[i][1])
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
792 / delta_x);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
793 dy *= dx;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
794 ry = c->ctlpoint[i][1];
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
795 i = next;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
796 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
797 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
798 vector[x] = ry;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
799 ry += dy;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
800 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
801 break;
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
802
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
803 case GTK_CURVE_TYPE_FREE:
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
804 if (c->point) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
805 rx = 0.0;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
806 dx = c->num_points / (double) veclen;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
807 for (x = 0; x < veclen; ++x, rx += dx)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
808 vector[x] = unproject(RADIUS + c->height - c->point[(int) rx].y,
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
809 c->min_y, c->max_y, c->height);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
810 } else
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
811 memset(vector, 0, veclen * sizeof(vector[0]));
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
812 break;
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
813 }
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
814 }
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
815
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
816 GtkWidget *xs_curve_new(void)
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
817 {
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
818 return gtk_type_new(xs_curve_get_type());
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
819 }
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
820
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
821 static void xs_curve_finalize(GtkObject * object)
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
822 {
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
823 XSCurve *curve;
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
824
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
825 g_return_if_fail(object != NULL);
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
826 g_return_if_fail(XS_IS_CURVE(object));
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
827
370
df6f12a00305 Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
828 curve = XS_CURVE(object);
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
829 if (curve->pixmap)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
830 gdk_pixmap_unref(curve->pixmap);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
831 if (curve->point)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
832 g_free(curve->point);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
833 if (curve->ctlpoint)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
834 g_free(curve->ctlpoint);
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
835
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
836 (*GTK_OBJECT_CLASS(parent_class)->finalize) (object);
358
4f247b19c9ea Add new files
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
837 }