Mercurial > hg > xmms-sid
annotate src/xs_curve.c @ 912:4c6c5247de7d
Improve ROM loading functions, make ROM list a public variable.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 10 Nov 2012 13:29:42 +0200 |
parents | 8b4c016802ea |
children | 79f20427c99d |
rev | line source |
---|---|
554 | 1 /* |
2 XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS) | |
3 | |
4 XSCurve, a custom Gtk+ spline widget for representing SIDPlay2/reSID | |
5 filter curves in the configuration GUI. Implementation based heavily | |
602 | 6 on GtkCurve from Gtk+ 1.2.10 (C) 1997 David Mosberger & Gtk-team. |
554 | 7 Spline formula from reSID 0.16 (C) 2004 Dag Lem. |
8 | |
9 Programmed by Matti 'ccr' Hamalainen <ccr@tnsp.org> | |
723 | 10 (C) Copyright 2006-2009 Tecnic Software productions (TNSP) |
554 | 11 |
12 This program is free software; you can redistribute it and/or modify | |
13 it under the terms of the GNU General Public License as published by | |
14 the Free Software Foundation; either version 2 of the License, or | |
15 (at your option) any later version. | |
16 | |
17 This program is distributed in the hope that it will be useful, | |
18 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 GNU General Public License for more details. | |
21 | |
22 You should have received a copy of the GNU General Public License along | |
23 with this program; if not, write to the Free Software Foundation, Inc., | |
24 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
25 */ | |
358 | 26 #include <stdlib.h> |
27 #include <string.h> | |
28 #include <math.h> | |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
29 #include <stdio.h> |
358 | 30 #include "xs_curve.h" |
31 #include <gtk/gtkdrawingarea.h> | |
32 #include <gtk/gtkmain.h> | |
33 #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
|
34 |
358 | 35 |
908 | 36 #define CP_RADIUS 3 /* radius of the control points */ |
37 #define CP_RADIUS2 (CP_RADIUS * 2) | |
38 #define CP_MIN_DISTANCE 7 /* min distance between control points */ | |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
39 |
358 | 40 |
908 | 41 #define GRAPH_MASK ( \ |
42 GDK_EXPOSURE_MASK | \ | |
43 GDK_POINTER_MOTION_MASK | \ | |
44 GDK_POINTER_MOTION_HINT_MASK | \ | |
45 GDK_ENTER_NOTIFY_MASK | \ | |
46 GDK_BUTTON_PRESS_MASK | \ | |
47 GDK_BUTTON_RELEASE_MASK | \ | |
48 GDK_BUTTON1_MOTION_MASK) | |
358 | 49 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
50 #define GET_X(i) curve->ctlpoints[i].x |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
51 #define GET_Y(i) curve->ctlpoints[i].y |
514
982cec405ef0
Cleaned up the drawing function a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
52 |
982cec405ef0
Cleaned up the drawing function a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
53 |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
54 enum { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
55 ARG_0, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
56 ARG_MIN_X, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
57 ARG_MAX_X, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
58 ARG_MIN_Y, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
59 ARG_MAX_Y |
358 | 60 }; |
61 | |
62 static GtkDrawingAreaClass *parent_class = NULL; | |
63 | |
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
|
64 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
|
65 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
|
66 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
|
67 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
|
68 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
|
69 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
|
70 static void xs_curve_size_graph(XSCurve * curve); |
358 | 71 |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
72 |
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
|
73 GtkType xs_curve_get_type(void) |
358 | 74 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
75 static GtkType curve_type = 0; |
358 | 76 |
908 | 77 if (!curve_type) |
78 { | |
79 static const GtkTypeInfo curve_info = | |
80 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
81 "XSCurve", |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
82 sizeof(XSCurve), |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
83 sizeof(XSCurveClass), |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
84 (GtkClassInitFunc) xs_curve_class_init, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
85 (GtkObjectInitFunc) xs_curve_init, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
86 /* reserved_1 */ NULL, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
87 /* reserved_2 */ NULL, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
88 (GtkClassInitFunc) NULL, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
89 }; |
358 | 90 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
91 curve_type = gtk_type_unique(GTK_TYPE_DRAWING_AREA, &curve_info); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
92 } |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
93 return curve_type; |
358 | 94 } |
95 | |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
96 |
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
97 static void xs_curve_class_init(XSCurveClass *class) |
358 | 98 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
99 GtkObjectClass *object_class; |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
100 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
101 parent_class = gtk_type_class(GTK_TYPE_DRAWING_AREA); |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
102 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
103 object_class = (GtkObjectClass *) class; |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
104 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
105 object_class->set_arg = xs_curve_set_arg; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
106 object_class->get_arg = xs_curve_get_arg; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
107 object_class->finalize = xs_curve_finalize; |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
108 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
109 gtk_object_add_arg_type("XSCurve::min_x", GTK_TYPE_FLOAT, GTK_ARG_READWRITE, ARG_MIN_X); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
110 gtk_object_add_arg_type("XSCurve::max_x", GTK_TYPE_FLOAT, GTK_ARG_READWRITE, ARG_MAX_X); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
111 gtk_object_add_arg_type("XSCurve::min_y", GTK_TYPE_FLOAT, GTK_ARG_READWRITE, ARG_MIN_Y); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
112 gtk_object_add_arg_type("XSCurve::max_y", GTK_TYPE_FLOAT, GTK_ARG_READWRITE, ARG_MAX_Y); |
358 | 113 } |
114 | |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
115 |
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
116 static void xs_curve_init(XSCurve *curve) |
358 | 117 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
118 gint old_mask; |
358 | 119 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
120 curve->pixmap = NULL; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
121 curve->grab_point = -1; |
358 | 122 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
123 curve->nctlpoints = 0; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
124 curve->ctlpoints = NULL; |
358 | 125 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
126 curve->min_x = 0.0; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
127 curve->max_x = 2047.0; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
128 curve->min_y = 0.0; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
129 curve->max_y = 24000.0; |
358 | 130 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
131 old_mask = gtk_widget_get_events(GTK_WIDGET(curve)); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
132 gtk_widget_set_events(GTK_WIDGET(curve), old_mask | GRAPH_MASK); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
133 gtk_signal_connect(GTK_OBJECT(curve), "event", (GtkSignalFunc) xs_curve_graph_events, curve); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
134 xs_curve_size_graph(curve); |
358 | 135 } |
136 | |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
137 |
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
138 static void xs_curve_set_arg(GtkObject *object, GtkArg *arg, guint arg_id) |
358 | 139 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
140 XSCurve *curve = XS_CURVE(object); |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
141 |
908 | 142 switch (arg_id) |
143 { | |
144 case ARG_MIN_X: | |
145 xs_curve_set_range(curve, GTK_VALUE_FLOAT(*arg), curve->max_x, curve->min_y, curve->max_y); | |
146 break; | |
147 case ARG_MAX_X: | |
148 xs_curve_set_range(curve, curve->min_x, GTK_VALUE_FLOAT(*arg), curve->min_y, curve->max_y); | |
149 break; | |
150 case ARG_MIN_Y: | |
151 xs_curve_set_range(curve, curve->min_x, curve->max_x, GTK_VALUE_FLOAT(*arg), curve->max_y); | |
152 break; | |
153 case ARG_MAX_Y: | |
154 xs_curve_set_range(curve, curve->min_x, curve->max_x, curve->min_y, GTK_VALUE_FLOAT(*arg)); | |
155 break; | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
156 } |
358 | 157 } |
158 | |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
159 |
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
160 static void xs_curve_get_arg(GtkObject *object, GtkArg *arg, guint arg_id) |
358 | 161 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
162 XSCurve *curve = XS_CURVE(object); |
358 | 163 |
908 | 164 switch (arg_id) |
165 { | |
166 case ARG_MIN_X: | |
167 GTK_VALUE_FLOAT(*arg) = curve->min_x; | |
168 break; | |
169 case ARG_MAX_X: | |
170 GTK_VALUE_FLOAT(*arg) = curve->max_x; | |
171 break; | |
172 case ARG_MIN_Y: | |
173 GTK_VALUE_FLOAT(*arg) = curve->min_y; | |
174 break; | |
175 case ARG_MAX_Y: | |
176 GTK_VALUE_FLOAT(*arg) = curve->max_y; | |
177 break; | |
178 default: | |
179 arg->type = GTK_TYPE_INVALID; | |
180 break; | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
181 } |
358 | 182 } |
183 | |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
184 |
374
58079c6180a0
More removal of original curve code.
Matti Hamalainen <ccr@tnsp.org>
parents:
370
diff
changeset
|
185 static int xs_project(gfloat value, gfloat min, gfloat max, int norm) |
358 | 186 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
187 return (norm - 1) * ((value - min) / (max - min)) + 0.5; |
358 | 188 } |
189 | |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
190 |
374
58079c6180a0
More removal of original curve code.
Matti Hamalainen <ccr@tnsp.org>
parents:
370
diff
changeset
|
191 static gfloat xs_unproject(gint value, gfloat min, gfloat max, int norm) |
358 | 192 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
193 return value / (gfloat) (norm - 1) * (max - min) + min; |
358 | 194 } |
195 | |
196 | |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
197 static inline void xs_cubic_coeff(gfloat x1, gfloat y1, |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
198 gfloat x2, gfloat y2, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
199 gfloat k1, gfloat k2, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
200 gfloat *a, gfloat *b, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
201 gfloat *c, gfloat *d) |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
202 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
203 gfloat dx = x2 - x1, dy = y2 - y1; |
358 | 204 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
205 *a = ((k1 + k2) - 2 * dy / dx) / (dx * dx); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
206 *b = ((k2 - k1) / dx - 3 * (x1 + x2) * (*a)) / 2; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
207 *c = k1 - (3 * x1 * (*a) + 2 * (*b)) * x1; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
208 *d = y1 - ((x1 * (*a) + (*b)) * x1 + (*c)) * x1; |
358 | 209 } |
210 | |
211 | |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
212 static void xs_curve_draw(XSCurve *curve, gint width, gint height) |
358 | 213 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
214 gfloat res = 5.0f; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
215 GtkStateType state; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
216 GtkStyle *style; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
217 gint i, ox = -1, oy = -1; |
702 | 218 xs_point_t *p0, *p1, *p2, *p3; |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
219 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
220 if (!curve->pixmap) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
221 return; |
358 | 222 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
223 state = GTK_STATE_NORMAL; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
224 if (!GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(curve))) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
225 state = GTK_STATE_INSENSITIVE; |
358 | 226 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
227 style = GTK_WIDGET(curve)->style; |
358 | 228 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
229 /* Clear the pixmap */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
230 gtk_paint_flat_box(style, curve->pixmap, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
231 GTK_STATE_NORMAL, GTK_SHADOW_NONE, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
232 NULL, GTK_WIDGET(curve), "curve_bg", |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
233 0, 0, |
908 | 234 width + CP_RADIUS2, |
235 height + CP_RADIUS2); | |
374
58079c6180a0
More removal of original curve code.
Matti Hamalainen <ccr@tnsp.org>
parents:
370
diff
changeset
|
236 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
237 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
238 /* Draw the grid */ |
908 | 239 for (i = 0; i < 5; i++) |
240 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
241 gdk_draw_line(curve->pixmap, style->dark_gc[state], |
908 | 242 CP_RADIUS, i * (height / 4.0) + CP_RADIUS, |
243 width + CP_RADIUS, i * (height / 4.0) + CP_RADIUS); | |
374
58079c6180a0
More removal of original curve code.
Matti Hamalainen <ccr@tnsp.org>
parents:
370
diff
changeset
|
244 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
245 gdk_draw_line(curve->pixmap, style->dark_gc[state], |
908 | 246 i * (width / 4.0) + CP_RADIUS, CP_RADIUS, |
247 i * (width / 4.0) + CP_RADIUS, height + CP_RADIUS); | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
248 } |
358 | 249 |
520 | 250 #if 1 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
251 /* Draw the spline/curve itself */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
252 p0 = curve->ctlpoints; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
253 p1 = p0; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
254 p2 = p1; p2++; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
255 p3 = p2; p3++; |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
256 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
257 /* Draw each curve segment */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
258 if (curve->nctlpoints > 5) |
908 | 259 for (i = 0; i < curve->nctlpoints; i++, ++p0, ++p1, ++p2, ++p3) |
260 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
261 gint n; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
262 gfloat k1, k2, a, b, c, d, x; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
263 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
264 if (p1->x == p2->x) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
265 continue; |
514
982cec405ef0
Cleaned up the drawing function a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
266 |
908 | 267 if (p0->x == p1->x && p2->x == p3->x) |
268 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
269 k1 = k2 = (p2->y - p1->y) / (p2->x - p1->x); |
908 | 270 } |
271 else if (p0->x == p1->x) | |
272 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
273 k2 = (p3->y - p1->y) / (p3->x - p1->x); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
274 k1 = (3 * (p2->y - p1->y) / (p2->x - p1->x) - k2) / 2; |
908 | 275 } |
276 else if (p2->x == p3->x) | |
277 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
278 k1 = (p2->y - p0->y) / (p2->x - p0->x); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
279 k2 = (3 * (p2->y - p1->y) / (p2->x - p1->x) - k1) / 2; |
908 | 280 } |
281 else | |
282 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
283 k1 = (p2->y - p0->y) / (p2->x - p0->x); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
284 k2 = (p3->y - p1->y) / (p3->x - p1->x); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
285 } |
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
|
286 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
287 xs_cubic_coeff(p1->x, p1->y, p2->x, p2->y, k1, k2, &a, &b, &c, &d); |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
288 |
908 | 289 for (x = p1->x; x <= p2->x; x += res, n++) |
290 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
291 gfloat y = ((a * x + b) * x + c) * x + d; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
292 gint qx, qy; |
908 | 293 qx = CP_RADIUS + xs_project(x, curve->min_x, curve->max_x, width); |
294 qy = CP_RADIUS + xs_project(y, curve->min_y, curve->max_y, height); | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
295 |
908 | 296 if (ox != -1) |
297 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
298 gdk_draw_line(curve->pixmap, style->fg_gc[state], |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
299 ox, oy, qx, qy); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
300 } |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
301 ox = qx; oy = qy; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
302 } |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
303 } |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
304 |
520 | 305 #endif |
306 | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
307 /* Draw control points */ |
908 | 308 for (i = 0; i < curve->nctlpoints; ++i) |
309 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
310 gint x, y; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
311 GtkStateType cstate; |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
312 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
313 if (GET_X(i) < curve->min_x || GET_Y(i) < curve->min_y || |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
314 GET_X(i) >= curve->max_x || GET_Y(i) >= curve->max_y) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
315 continue; |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
316 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
317 x = xs_project(GET_X(i), curve->min_x, curve->max_x, width); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
318 y = xs_project(GET_Y(i), curve->min_y, curve->max_y, height); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
319 |
908 | 320 if (i == curve->grab_point) |
321 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
322 cstate = GTK_STATE_SELECTED; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
323 gdk_draw_line(curve->pixmap, style->fg_gc[cstate], |
908 | 324 x + CP_RADIUS, CP_RADIUS, x + CP_RADIUS, height + CP_RADIUS); |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
325 gdk_draw_line(curve->pixmap, style->fg_gc[cstate], |
908 | 326 CP_RADIUS, y + CP_RADIUS, width + CP_RADIUS, y + CP_RADIUS); |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
327 } else |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
328 cstate = state; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
329 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
330 gdk_draw_arc(curve->pixmap, style->fg_gc[cstate], TRUE, |
908 | 331 x, y, CP_RADIUS2, CP_RADIUS2, 0, 360 * 64); |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
332 } |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
333 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
334 /* Draw pixmap in the widget */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
335 gdk_draw_pixmap(GTK_WIDGET(curve)->window, |
908 | 336 style->fg_gc[state], curve->pixmap, |
337 0, 0, 0, 0, | |
338 width + CP_RADIUS2, | |
339 height + CP_RADIUS2); | |
358 | 340 } |
341 | |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
342 |
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
343 static gint xs_curve_graph_events(GtkWidget *widget, GdkEvent *event, XSCurve *curve) |
358 | 344 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
345 GdkCursorType new_type = curve->cursor_type; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
346 GdkEventButton *bevent; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
347 GtkWidget *w; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
348 gint i, width, height, x, y, tx, ty, cx, closest_point = 0, min_x; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
349 guint distance; |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
350 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
351 w = GTK_WIDGET(curve); |
908 | 352 width = w->allocation.width - CP_RADIUS2; |
353 height = w->allocation.height - CP_RADIUS2; | |
358 | 354 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
355 if ((width < 0) || (height < 0)) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
356 return FALSE; |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
357 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
358 /* get the pointer position */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
359 gdk_window_get_pointer(w->window, &tx, &ty, NULL); |
908 | 360 x = CLAMP((tx - CP_RADIUS), 0, width - 1); |
361 y = CLAMP((ty - CP_RADIUS), 0, height - 1); | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
362 min_x = curve->min_x; |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
363 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
364 distance = ~0U; |
908 | 365 for (i = 0; i < curve->nctlpoints; ++i) |
366 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
367 cx = xs_project(GET_X(i), min_x, curve->max_x, width); |
908 | 368 if ((guint) abs(x - cx) < distance) |
369 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
370 distance = abs(x - cx); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
371 closest_point = i; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
372 } |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
373 } |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
374 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
375 /* Act based on event type */ |
908 | 376 switch (event->type) |
377 { | |
378 case GDK_CONFIGURE: | |
379 if (curve->pixmap) | |
380 gdk_pixmap_unref(curve->pixmap); | |
381 curve->pixmap = 0; | |
382 | |
383 /* fall through */ | |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
384 |
908 | 385 case GDK_EXPOSE: |
386 if (!curve->pixmap) | |
387 { | |
388 curve->pixmap = gdk_pixmap_new(w->window, | |
389 w->allocation.width, w->allocation.height, -1); | |
390 } | |
391 xs_curve_draw(curve, width, height); | |
392 break; | |
393 | |
394 case GDK_BUTTON_PRESS: | |
395 gtk_grab_add(widget); | |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
396 |
908 | 397 bevent = (GdkEventButton *) event; |
398 new_type = GDK_TCROSS; | |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
399 |
908 | 400 if (distance > CP_MIN_DISTANCE) |
401 { | |
402 /* insert a new control point */ | |
403 if (curve->nctlpoints > 0) | |
404 { | |
405 cx = xs_project(GET_X(closest_point), min_x, curve->max_x, width); | |
406 if (x > cx) closest_point++; | |
407 } | |
408 | |
409 curve->nctlpoints++; | |
410 | |
411 curve->ctlpoints = g_realloc(curve->ctlpoints, | |
412 curve->nctlpoints * sizeof(*curve->ctlpoints)); | |
413 | |
414 for (i = curve->nctlpoints - 1; i > closest_point; --i) | |
415 { | |
416 memcpy(curve->ctlpoints + i, | |
417 curve->ctlpoints + i - 1, | |
418 sizeof(*curve->ctlpoints)); | |
419 } | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
420 } |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
421 |
908 | 422 curve->grab_point = closest_point; |
423 GET_X(curve->grab_point) = xs_unproject(x, min_x, curve->max_x, width); | |
424 GET_Y(curve->grab_point) = xs_unproject(y, curve->min_y, curve->max_y, height); | |
425 | |
426 xs_curve_draw(curve, width, height); | |
427 break; | |
428 | |
429 case GDK_BUTTON_RELEASE: | |
430 { | |
431 gint src, dst; | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
432 |
908 | 433 gtk_grab_remove(widget); |
434 | |
435 /* delete inactive points: */ | |
436 for (src = dst = 0; src < curve->nctlpoints; ++src) | |
437 { | |
438 if (GET_X(src) >= min_x) | |
439 { | |
440 memcpy(curve->ctlpoints + dst, | |
441 curve->ctlpoints + src, | |
442 sizeof(*curve->ctlpoints)); | |
443 dst++; | |
444 } | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
445 } |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
446 |
908 | 447 if (dst < src) |
448 { | |
449 curve->nctlpoints -= (src - dst); | |
450 if (curve->nctlpoints <= 0) | |
451 { | |
452 curve->nctlpoints = 1; | |
453 GET_X(0) = min_x; | |
454 GET_Y(0) = curve->min_y; | |
455 xs_curve_draw(curve, width, height); | |
456 } | |
457 curve->ctlpoints = g_realloc(curve->ctlpoints, | |
458 curve->nctlpoints * sizeof(*curve->ctlpoints)); | |
459 } | |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
460 |
908 | 461 new_type = GDK_FLEUR; |
462 curve->grab_point = -1; | |
463 } | |
464 xs_curve_draw(curve, width, height); | |
465 break; | |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
466 |
908 | 467 case GDK_MOTION_NOTIFY: |
468 if (curve->grab_point == -1) | |
469 { | |
470 /* if no point is grabbed... */ | |
471 if (distance <= CP_MIN_DISTANCE) | |
472 new_type = GDK_FLEUR; | |
473 else | |
474 new_type = GDK_TCROSS; | |
475 } else { | |
476 gint leftbound, rightbound; | |
477 | |
478 /* drag the grabbed point */ | |
479 new_type = GDK_TCROSS; | |
480 | |
481 leftbound = -CP_MIN_DISTANCE; | |
482 if (curve->grab_point > 0) | |
483 { | |
484 leftbound = xs_project( | |
485 GET_X(curve->grab_point-1), | |
486 min_x, curve->max_x, width); | |
487 } | |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
488 |
908 | 489 rightbound = width + CP_RADIUS2 + CP_MIN_DISTANCE; |
490 if (curve->grab_point + 1 < curve->nctlpoints) | |
491 { | |
492 rightbound = xs_project( | |
493 GET_X(curve->grab_point+1), | |
494 min_x, curve->max_x, width); | |
495 } | |
496 | |
497 if ((tx <= leftbound) || (tx >= rightbound) || | |
498 (ty > height + CP_RADIUS2 + CP_MIN_DISTANCE) || (ty < -CP_MIN_DISTANCE)) { | |
499 GET_X(curve->grab_point) = min_x - 1.0; | |
500 } | |
501 else | |
502 { | |
503 GET_X(curve->grab_point) = | |
504 xs_unproject(x, min_x, curve->max_x, width); | |
505 GET_Y(curve->grab_point) = | |
506 xs_unproject(y, curve->min_y, curve->max_y, height); | |
507 } | |
508 | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
509 xs_curve_draw(curve, width, height); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
510 } |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
511 |
908 | 512 /* See if cursor type was changed and update accordingly */ |
513 if (new_type != (GdkCursorType) curve->cursor_type) | |
514 { | |
515 GdkCursor *cursor; | |
516 curve->cursor_type = new_type; | |
517 cursor = gdk_cursor_new(curve->cursor_type); | |
518 gdk_window_set_cursor(w->window, cursor); | |
519 gdk_cursor_destroy(cursor); | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
520 } |
908 | 521 break; |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
522 |
908 | 523 default: |
524 break; | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
525 } |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
526 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
527 return FALSE; |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
528 } |
358 | 529 |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
530 |
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
531 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
|
532 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
533 gint width, height; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
534 gfloat aspect; |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
535 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
536 width = (curve->max_x - curve->min_x) + 1; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
537 height = (curve->max_y - curve->min_y) + 1; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
538 aspect = width / (gfloat) height; |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
539 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
540 if (width > gdk_screen_width() / 4) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
541 width = gdk_screen_width() / 4; |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
542 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
543 if (height > gdk_screen_height() / 4) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
544 height = gdk_screen_height() / 4; |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
545 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
546 if (aspect < 1.0) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
547 width = height * aspect; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
548 else |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
549 height = width / aspect; |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
550 |
908 | 551 gtk_drawing_area_size(GTK_DRAWING_AREA(curve), width + CP_RADIUS2, height + CP_RADIUS2); |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
552 } |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
553 |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
554 |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
555 static void xs_curve_update(XSCurve *curve) |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
556 { |
908 | 557 if (curve->pixmap) |
558 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
559 gint width, height; |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
560 |
908 | 561 width = GTK_WIDGET(curve)->allocation.width - CP_RADIUS2; |
562 height = GTK_WIDGET(curve)->allocation.height - CP_RADIUS2; | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
563 xs_curve_draw(curve, width, height); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
564 } |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
565 } |
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
566 |
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
567 |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
568 void xs_curve_reset(XSCurve *curve) |
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
569 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
570 if (curve->ctlpoints) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
571 g_free(curve->ctlpoints); |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
572 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
573 curve->nctlpoints = 4; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
574 curve->ctlpoints = g_malloc(curve->nctlpoints * sizeof(curve->ctlpoints[0])); |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
575 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
576 GET_X(0) = curve->min_x; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
577 GET_Y(0) = curve->min_y; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
578 GET_X(1) = curve->min_x; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
579 GET_Y(1) = curve->min_y; |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
580 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
581 GET_X(2) = curve->max_x; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
582 GET_Y(2) = curve->max_y; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
583 GET_X(3) = curve->max_x; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
584 GET_Y(3) = curve->max_y; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
585 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
586 xs_curve_update(curve); |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
587 } |
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
588 |
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
589 |
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
590 void xs_curve_set_range(XSCurve *curve, gfloat min_x, gfloat min_y, gfloat max_x, gfloat max_y) |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
591 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
592 curve->min_x = min_x; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
593 curve->max_x = max_x; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
594 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
595 curve->min_y = min_y; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
596 curve->max_y = max_y; |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
597 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
598 xs_curve_size_graph(curve); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
599 xs_curve_reset(curve); |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
600 } |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
601 |
358 | 602 |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
603 gboolean xs_curve_realloc_data(XSCurve *curve, gint npoints) |
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
604 { |
908 | 605 if (npoints != curve->nctlpoints) |
606 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
607 curve->nctlpoints = npoints; |
702 | 608 curve->ctlpoints = (xs_point_t *) g_realloc(curve->ctlpoints, |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
609 curve->nctlpoints * sizeof(*curve->ctlpoints)); |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
610 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
611 if (curve->ctlpoints == NULL) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
612 return FALSE; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
613 } |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
614 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
615 return TRUE; |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
616 } |
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
617 |
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
618 |
702 | 619 void xs_curve_get_data(XSCurve *curve, xs_point_t ***points, gint **npoints) |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
620 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
621 *points = &(curve->ctlpoints); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
622 *npoints = &(curve->nctlpoints); |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
623 } |
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
624 |
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
625 |
702 | 626 gboolean xs_curve_set_points(XSCurve *curve, xs_int_point_t *points, gint npoints) |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
627 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
628 gint i; |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
629 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
630 if (!xs_curve_realloc_data(curve, npoints + 4)) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
631 return FALSE; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
632 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
633 GET_X(0) = curve->min_x; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
634 GET_Y(0) = curve->min_y; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
635 GET_X(1) = curve->min_x; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
636 GET_Y(1) = curve->min_y; |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
637 |
908 | 638 for (i = 0; i < npoints; i++) |
639 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
640 GET_X(i+2) = points[i].x; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
641 GET_Y(i+2) = points[i].y; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
642 } |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
643 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
644 GET_X(npoints+2) = curve->max_x; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
645 GET_Y(npoints+2) = curve->max_y; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
646 GET_X(npoints+3) = curve->max_x; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
647 GET_Y(npoints+3) = curve->max_y; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
648 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
649 xs_curve_update(curve); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
650 return TRUE; |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
651 } |
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
652 |
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
653 |
702 | 654 gboolean xs_curve_get_points(XSCurve *curve, xs_int_point_t **points, gint *npoints) |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
655 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
656 gint i, n; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
657 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
658 n = curve->nctlpoints - 4; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
659 |
702 | 660 *points = g_malloc(n * sizeof(xs_int_point_t)); |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
661 if (*points == NULL) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
662 return FALSE; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
663 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
664 *npoints = n; |
908 | 665 for (i = 2; i < curve->nctlpoints - 2; i++) |
666 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
667 (*points)[i].x = GET_X(i); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
668 (*points)[i].y = GET_Y(i); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
669 } |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
670 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
671 return TRUE; |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
672 } |
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
673 |
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
674 |
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
|
675 GtkWidget *xs_curve_new(void) |
358 | 676 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
677 return gtk_type_new(xs_curve_get_type()); |
358 | 678 } |
679 | |
374
58079c6180a0
More removal of original curve code.
Matti Hamalainen <ccr@tnsp.org>
parents:
370
diff
changeset
|
680 |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
681 static void xs_curve_finalize(GtkObject *object) |
358 | 682 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
683 XSCurve *curve; |
358 | 684 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
685 g_return_if_fail(object != NULL); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
686 g_return_if_fail(XS_IS_CURVE(object)); |
358 | 687 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
688 curve = XS_CURVE(object); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
689 if (curve->pixmap) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
690 gdk_pixmap_unref(curve->pixmap); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
691 if (curve->ctlpoints) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
692 g_free(curve->ctlpoints); |
358 | 693 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
694 (*GTK_OBJECT_CLASS(parent_class)->finalize) (object); |
358 | 695 } |