Mercurial > hg > xmms-sid
annotate src/xs_curve.c @ 1002:ede5374e9294
Fix some warnings.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 21 Dec 2013 07:48:44 +0200 |
parents | 79f20427c99d |
children |
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 gfloat k1, k2, a, b, c, d, x; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
262 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
263 if (p1->x == p2->x) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
264 continue; |
514
982cec405ef0
Cleaned up the drawing function a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
265 |
908 | 266 if (p0->x == p1->x && p2->x == p3->x) |
267 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
268 k1 = k2 = (p2->y - p1->y) / (p2->x - p1->x); |
908 | 269 } |
270 else if (p0->x == p1->x) | |
271 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
272 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
|
273 k1 = (3 * (p2->y - p1->y) / (p2->x - p1->x) - k2) / 2; |
908 | 274 } |
275 else if (p2->x == p3->x) | |
276 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
277 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
|
278 k2 = (3 * (p2->y - p1->y) / (p2->x - p1->x) - k1) / 2; |
908 | 279 } |
280 else | |
281 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
282 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
|
283 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
|
284 } |
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
|
285 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
286 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
|
287 |
936 | 288 for (x = p1->x; x <= p2->x; x += res) |
908 | 289 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
290 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
|
291 gint qx, qy; |
908 | 292 qx = CP_RADIUS + xs_project(x, curve->min_x, curve->max_x, width); |
293 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
|
294 |
908 | 295 if (ox != -1) |
296 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
297 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
|
298 ox, oy, qx, qy); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
299 } |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
300 ox = qx; oy = qy; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
301 } |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
302 } |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
303 |
520 | 304 #endif |
305 | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
306 /* Draw control points */ |
908 | 307 for (i = 0; i < curve->nctlpoints; ++i) |
308 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
309 gint x, y; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
310 GtkStateType cstate; |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
311 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
312 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
|
313 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
|
314 continue; |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
315 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
316 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
|
317 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
|
318 |
908 | 319 if (i == curve->grab_point) |
320 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
321 cstate = GTK_STATE_SELECTED; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
322 gdk_draw_line(curve->pixmap, style->fg_gc[cstate], |
908 | 323 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
|
324 gdk_draw_line(curve->pixmap, style->fg_gc[cstate], |
908 | 325 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
|
326 } else |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
327 cstate = state; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
328 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
329 gdk_draw_arc(curve->pixmap, style->fg_gc[cstate], TRUE, |
908 | 330 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
|
331 } |
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 /* Draw pixmap in the widget */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
334 gdk_draw_pixmap(GTK_WIDGET(curve)->window, |
908 | 335 style->fg_gc[state], curve->pixmap, |
336 0, 0, 0, 0, | |
337 width + CP_RADIUS2, | |
338 height + CP_RADIUS2); | |
358 | 339 } |
340 | |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
341 |
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
342 static gint xs_curve_graph_events(GtkWidget *widget, GdkEvent *event, XSCurve *curve) |
358 | 343 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
344 GdkCursorType new_type = curve->cursor_type; |
1002 | 345 // GdkEventButton *bevent; |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
346 GtkWidget *w; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
347 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
|
348 guint distance; |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
349 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
350 w = GTK_WIDGET(curve); |
908 | 351 width = w->allocation.width - CP_RADIUS2; |
352 height = w->allocation.height - CP_RADIUS2; | |
358 | 353 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
354 if ((width < 0) || (height < 0)) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
355 return FALSE; |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
356 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
357 /* get the pointer position */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
358 gdk_window_get_pointer(w->window, &tx, &ty, NULL); |
908 | 359 x = CLAMP((tx - CP_RADIUS), 0, width - 1); |
360 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
|
361 min_x = curve->min_x; |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
362 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
363 distance = ~0U; |
908 | 364 for (i = 0; i < curve->nctlpoints; ++i) |
365 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
366 cx = xs_project(GET_X(i), min_x, curve->max_x, width); |
908 | 367 if ((guint) abs(x - cx) < distance) |
368 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
369 distance = abs(x - cx); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
370 closest_point = i; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
371 } |
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 /* Act based on event type */ |
908 | 375 switch (event->type) |
376 { | |
377 case GDK_CONFIGURE: | |
378 if (curve->pixmap) | |
379 gdk_pixmap_unref(curve->pixmap); | |
380 curve->pixmap = 0; | |
381 | |
382 /* fall through */ | |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
383 |
908 | 384 case GDK_EXPOSE: |
385 if (!curve->pixmap) | |
386 { | |
387 curve->pixmap = gdk_pixmap_new(w->window, | |
388 w->allocation.width, w->allocation.height, -1); | |
389 } | |
390 xs_curve_draw(curve, width, height); | |
391 break; | |
392 | |
393 case GDK_BUTTON_PRESS: | |
394 gtk_grab_add(widget); | |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
395 |
1002 | 396 // bevent = (GdkEventButton *) event; |
908 | 397 new_type = GDK_TCROSS; |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
398 |
908 | 399 if (distance > CP_MIN_DISTANCE) |
400 { | |
401 /* insert a new control point */ | |
402 if (curve->nctlpoints > 0) | |
403 { | |
404 cx = xs_project(GET_X(closest_point), min_x, curve->max_x, width); | |
405 if (x > cx) closest_point++; | |
406 } | |
407 | |
408 curve->nctlpoints++; | |
409 | |
410 curve->ctlpoints = g_realloc(curve->ctlpoints, | |
411 curve->nctlpoints * sizeof(*curve->ctlpoints)); | |
412 | |
413 for (i = curve->nctlpoints - 1; i > closest_point; --i) | |
414 { | |
415 memcpy(curve->ctlpoints + i, | |
416 curve->ctlpoints + i - 1, | |
417 sizeof(*curve->ctlpoints)); | |
418 } | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
419 } |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
420 |
908 | 421 curve->grab_point = closest_point; |
422 GET_X(curve->grab_point) = xs_unproject(x, min_x, curve->max_x, width); | |
423 GET_Y(curve->grab_point) = xs_unproject(y, curve->min_y, curve->max_y, height); | |
424 | |
425 xs_curve_draw(curve, width, height); | |
426 break; | |
427 | |
428 case GDK_BUTTON_RELEASE: | |
429 { | |
430 gint src, dst; | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
431 |
908 | 432 gtk_grab_remove(widget); |
433 | |
434 /* delete inactive points: */ | |
435 for (src = dst = 0; src < curve->nctlpoints; ++src) | |
436 { | |
437 if (GET_X(src) >= min_x) | |
438 { | |
439 memcpy(curve->ctlpoints + dst, | |
440 curve->ctlpoints + src, | |
441 sizeof(*curve->ctlpoints)); | |
442 dst++; | |
443 } | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
444 } |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
445 |
908 | 446 if (dst < src) |
447 { | |
448 curve->nctlpoints -= (src - dst); | |
449 if (curve->nctlpoints <= 0) | |
450 { | |
451 curve->nctlpoints = 1; | |
452 GET_X(0) = min_x; | |
453 GET_Y(0) = curve->min_y; | |
454 xs_curve_draw(curve, width, height); | |
455 } | |
456 curve->ctlpoints = g_realloc(curve->ctlpoints, | |
457 curve->nctlpoints * sizeof(*curve->ctlpoints)); | |
458 } | |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
459 |
908 | 460 new_type = GDK_FLEUR; |
461 curve->grab_point = -1; | |
462 } | |
463 xs_curve_draw(curve, width, height); | |
464 break; | |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
465 |
908 | 466 case GDK_MOTION_NOTIFY: |
467 if (curve->grab_point == -1) | |
468 { | |
469 /* if no point is grabbed... */ | |
470 if (distance <= CP_MIN_DISTANCE) | |
471 new_type = GDK_FLEUR; | |
472 else | |
473 new_type = GDK_TCROSS; | |
474 } else { | |
475 gint leftbound, rightbound; | |
476 | |
477 /* drag the grabbed point */ | |
478 new_type = GDK_TCROSS; | |
479 | |
480 leftbound = -CP_MIN_DISTANCE; | |
481 if (curve->grab_point > 0) | |
482 { | |
483 leftbound = xs_project( | |
484 GET_X(curve->grab_point-1), | |
485 min_x, curve->max_x, width); | |
486 } | |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
487 |
908 | 488 rightbound = width + CP_RADIUS2 + CP_MIN_DISTANCE; |
489 if (curve->grab_point + 1 < curve->nctlpoints) | |
490 { | |
491 rightbound = xs_project( | |
492 GET_X(curve->grab_point+1), | |
493 min_x, curve->max_x, width); | |
494 } | |
495 | |
496 if ((tx <= leftbound) || (tx >= rightbound) || | |
497 (ty > height + CP_RADIUS2 + CP_MIN_DISTANCE) || (ty < -CP_MIN_DISTANCE)) { | |
498 GET_X(curve->grab_point) = min_x - 1.0; | |
499 } | |
500 else | |
501 { | |
502 GET_X(curve->grab_point) = | |
503 xs_unproject(x, min_x, curve->max_x, width); | |
504 GET_Y(curve->grab_point) = | |
505 xs_unproject(y, curve->min_y, curve->max_y, height); | |
506 } | |
507 | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
508 xs_curve_draw(curve, width, height); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
509 } |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
510 |
908 | 511 /* See if cursor type was changed and update accordingly */ |
512 if (new_type != (GdkCursorType) curve->cursor_type) | |
513 { | |
514 GdkCursor *cursor; | |
515 curve->cursor_type = new_type; | |
516 cursor = gdk_cursor_new(curve->cursor_type); | |
517 gdk_window_set_cursor(w->window, cursor); | |
518 gdk_cursor_destroy(cursor); | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
519 } |
908 | 520 break; |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
521 |
908 | 522 default: |
523 break; | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
524 } |
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 return FALSE; |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
527 } |
358 | 528 |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
529 |
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
530 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
|
531 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
532 gint width, height; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
533 gfloat aspect; |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
534 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
535 width = (curve->max_x - curve->min_x) + 1; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
536 height = (curve->max_y - curve->min_y) + 1; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
537 aspect = width / (gfloat) height; |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
538 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
539 if (width > gdk_screen_width() / 4) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
540 width = gdk_screen_width() / 4; |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
541 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
542 if (height > gdk_screen_height() / 4) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
543 height = gdk_screen_height() / 4; |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
544 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
545 if (aspect < 1.0) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
546 width = height * aspect; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
547 else |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
548 height = width / aspect; |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
549 |
908 | 550 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
|
551 } |
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 |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
554 static void xs_curve_update(XSCurve *curve) |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
555 { |
908 | 556 if (curve->pixmap) |
557 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
558 gint width, height; |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
559 |
908 | 560 width = GTK_WIDGET(curve)->allocation.width - CP_RADIUS2; |
561 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
|
562 xs_curve_draw(curve, width, height); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
563 } |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
564 } |
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 |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
567 void xs_curve_reset(XSCurve *curve) |
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
568 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
569 if (curve->ctlpoints) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
570 g_free(curve->ctlpoints); |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
571 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
572 curve->nctlpoints = 4; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
573 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
|
574 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
575 GET_X(0) = curve->min_x; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
576 GET_Y(0) = curve->min_y; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
577 GET_X(1) = curve->min_x; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
578 GET_Y(1) = curve->min_y; |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
579 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
580 GET_X(2) = curve->max_x; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
581 GET_Y(2) = curve->max_y; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
582 GET_X(3) = curve->max_x; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
583 GET_Y(3) = curve->max_y; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
584 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
585 xs_curve_update(curve); |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
586 } |
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 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
|
590 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
591 curve->min_x = min_x; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
592 curve->max_x = max_x; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
593 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
594 curve->min_y = min_y; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
595 curve->max_y = max_y; |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
596 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
597 xs_curve_size_graph(curve); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
598 xs_curve_reset(curve); |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
599 } |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
600 |
358 | 601 |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
602 gboolean xs_curve_realloc_data(XSCurve *curve, gint npoints) |
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
603 { |
908 | 604 if (npoints != curve->nctlpoints) |
605 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
606 curve->nctlpoints = npoints; |
702 | 607 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
|
608 curve->nctlpoints * sizeof(*curve->ctlpoints)); |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
609 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
610 if (curve->ctlpoints == NULL) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
611 return FALSE; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
612 } |
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 return TRUE; |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
615 } |
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 |
702 | 618 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
|
619 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
620 *points = &(curve->ctlpoints); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
621 *npoints = &(curve->nctlpoints); |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
622 } |
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 |
702 | 625 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
|
626 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
627 gint i; |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
628 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
629 if (!xs_curve_realloc_data(curve, npoints + 4)) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
630 return FALSE; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
631 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
632 GET_X(0) = curve->min_x; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
633 GET_Y(0) = curve->min_y; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
634 GET_X(1) = curve->min_x; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
635 GET_Y(1) = curve->min_y; |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
636 |
908 | 637 for (i = 0; i < npoints; i++) |
638 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
639 GET_X(i+2) = points[i].x; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
640 GET_Y(i+2) = points[i].y; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
641 } |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
642 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
643 GET_X(npoints+2) = curve->max_x; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
644 GET_Y(npoints+2) = curve->max_y; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
645 GET_X(npoints+3) = curve->max_x; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
646 GET_Y(npoints+3) = curve->max_y; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
647 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
648 xs_curve_update(curve); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
649 return TRUE; |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
650 } |
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 |
702 | 653 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
|
654 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
655 gint i, n; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
656 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
657 n = curve->nctlpoints - 4; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
658 |
702 | 659 *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
|
660 if (*points == NULL) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
661 return FALSE; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
662 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
663 *npoints = n; |
908 | 664 for (i = 2; i < curve->nctlpoints - 2; i++) |
665 { | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
666 (*points)[i].x = GET_X(i); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
667 (*points)[i].y = GET_Y(i); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
668 } |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
669 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
670 return TRUE; |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
671 } |
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 |
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
|
674 GtkWidget *xs_curve_new(void) |
358 | 675 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
676 return gtk_type_new(xs_curve_get_type()); |
358 | 677 } |
678 | |
374
58079c6180a0
More removal of original curve code.
Matti Hamalainen <ccr@tnsp.org>
parents:
370
diff
changeset
|
679 |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
680 static void xs_curve_finalize(GtkObject *object) |
358 | 681 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
682 XSCurve *curve; |
358 | 683 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
684 g_return_if_fail(object != NULL); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
685 g_return_if_fail(XS_IS_CURVE(object)); |
358 | 686 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
687 curve = XS_CURVE(object); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
688 if (curve->pixmap) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
689 gdk_pixmap_unref(curve->pixmap); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
690 if (curve->ctlpoints) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
691 g_free(curve->ctlpoints); |
358 | 692 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
693 (*GTK_OBJECT_CLASS(parent_class)->finalize) (object); |
358 | 694 } |