Mercurial > hg > xmms-sid
comparison src/xs_curve.c @ 370:df6f12a00305
Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 09 Nov 2005 05:52:01 +0000 |
parents | b1a858b8cb1a |
children | 58079c6180a0 |
comparison
equal
deleted
inserted
replaced
369:4611f1194941 | 370:df6f12a00305 |
---|---|
30 | 30 |
31 #include "xs_curve.h" | 31 #include "xs_curve.h" |
32 #include <gtk/gtkdrawingarea.h> | 32 #include <gtk/gtkdrawingarea.h> |
33 #include <gtk/gtkmain.h> | 33 #include <gtk/gtkmain.h> |
34 #include <gtk/gtksignal.h> | 34 #include <gtk/gtksignal.h> |
35 /* | 35 |
36 #include <gtk/gtktable.h> | |
37 #include <gtk/gtkradiobutton.h> | |
38 */ | |
39 | 36 |
40 #define RADIUS 3 /* radius of the control points */ | 37 #define RADIUS 3 /* radius of the control points */ |
41 #define MIN_DISTANCE 8 /* min distance between control points */ | 38 #define MIN_DISTANCE 8 /* min distance between control points */ |
42 | 39 |
43 #define GRAPH_MASK (GDK_EXPOSURE_MASK | \ | 40 #define GRAPH_MASK (GDK_EXPOSURE_MASK | \ |
61 static GtkDrawingAreaClass *parent_class = NULL; | 58 static GtkDrawingAreaClass *parent_class = NULL; |
62 static guint curve_type_changed_signal = 0; | 59 static guint curve_type_changed_signal = 0; |
63 | 60 |
64 | 61 |
65 /* forward declarations: */ | 62 /* forward declarations: */ |
66 static void gtk_curve_class_init(GtkCurveClass * class); | 63 static void xs_curve_class_init(XSCurveClass * class); |
67 static void gtk_curve_init(GtkCurve * curve); | 64 static void xs_curve_init(XSCurve * curve); |
68 static void gtk_curve_set_arg(GtkObject * object, GtkArg * arg, guint arg_id); | 65 static void xs_curve_set_arg(GtkObject * object, GtkArg * arg, guint arg_id); |
69 static void gtk_curve_get_arg(GtkObject * object, GtkArg * arg, guint arg_id); | 66 static void xs_curve_get_arg(GtkObject * object, GtkArg * arg, guint arg_id); |
70 static void gtk_curve_finalize(GtkObject * object); | 67 static void xs_curve_finalize(GtkObject * object); |
71 static gint gtk_curve_graph_events(GtkWidget * widget, GdkEvent * event, GtkCurve * c); | 68 static gint xs_curve_graph_events(GtkWidget * widget, GdkEvent * event, XSCurve * c); |
72 static void gtk_curve_size_graph(GtkCurve * curve); | 69 static void xs_curve_size_graph(XSCurve * curve); |
73 | 70 |
74 GtkType gtk_curve_get_type(void) | 71 GtkType xs_curve_get_type(void) |
75 { | 72 { |
76 static GtkType curve_type = 0; | 73 static GtkType curve_type = 0; |
77 | 74 |
78 if (!curve_type) { | 75 if (!curve_type) { |
79 static const GtkTypeInfo curve_info = { | 76 static const GtkTypeInfo curve_info = { |
80 "GtkCurve", | 77 "XSCurve", |
81 sizeof(GtkCurve), | 78 sizeof(XSCurve), |
82 sizeof(GtkCurveClass), | 79 sizeof(XSCurveClass), |
83 (GtkClassInitFunc) gtk_curve_class_init, | 80 (GtkClassInitFunc) xs_curve_class_init, |
84 (GtkObjectInitFunc) gtk_curve_init, | 81 (GtkObjectInitFunc) xs_curve_init, |
85 /* reserved_1 */ NULL, | 82 /* reserved_1 */ NULL, |
86 /* reserved_2 */ NULL, | 83 /* reserved_2 */ NULL, |
87 (GtkClassInitFunc) NULL, | 84 (GtkClassInitFunc) NULL, |
88 }; | 85 }; |
89 | 86 |
90 curve_type = gtk_type_unique(GTK_TYPE_DRAWING_AREA, &curve_info); | 87 curve_type = gtk_type_unique(GTK_TYPE_DRAWING_AREA, &curve_info); |
91 } | 88 } |
92 return curve_type; | 89 return curve_type; |
93 } | 90 } |
94 | 91 |
95 static void gtk_curve_class_init(GtkCurveClass * class) | 92 static void xs_curve_class_init(XSCurveClass * class) |
96 { | 93 { |
97 GtkObjectClass *object_class; | 94 GtkObjectClass *object_class; |
98 | 95 |
99 parent_class = gtk_type_class(GTK_TYPE_DRAWING_AREA); | 96 parent_class = gtk_type_class(GTK_TYPE_DRAWING_AREA); |
100 | 97 |
101 object_class = (GtkObjectClass *) class; | 98 object_class = (GtkObjectClass *) class; |
102 | 99 |
103 object_class->set_arg = gtk_curve_set_arg; | 100 object_class->set_arg = xs_curve_set_arg; |
104 object_class->get_arg = gtk_curve_get_arg; | 101 object_class->get_arg = xs_curve_get_arg; |
105 object_class->finalize = gtk_curve_finalize; | 102 object_class->finalize = xs_curve_finalize; |
106 | 103 |
107 curve_type_changed_signal = | 104 curve_type_changed_signal = |
108 gtk_signal_new("curve_type_changed", GTK_RUN_FIRST, object_class->type, | 105 gtk_signal_new("curve_type_changed", GTK_RUN_FIRST, object_class->type, |
109 GTK_SIGNAL_OFFSET(GtkCurveClass, curve_type_changed), | 106 GTK_SIGNAL_OFFSET(XSCurveClass, curve_type_changed), |
110 gtk_marshal_NONE__NONE, GTK_TYPE_NONE, 0); | 107 gtk_marshal_NONE__NONE, GTK_TYPE_NONE, 0); |
111 gtk_object_class_add_signals(object_class, &curve_type_changed_signal, 1); | 108 gtk_object_class_add_signals(object_class, &curve_type_changed_signal, 1); |
112 | 109 |
113 gtk_object_add_arg_type("GtkCurve::curve_type", GTK_TYPE_CURVE_TYPE, GTK_ARG_READWRITE, ARG_CURVE_TYPE); | 110 gtk_object_add_arg_type("XSCurve::curve_type", GTK_TYPE_CURVE_TYPE, GTK_ARG_READWRITE, ARG_CURVE_TYPE); |
114 gtk_object_add_arg_type("GtkCurve::min_x", GTK_TYPE_FLOAT, GTK_ARG_READWRITE, ARG_MIN_X); | 111 gtk_object_add_arg_type("XSCurve::min_x", GTK_TYPE_FLOAT, GTK_ARG_READWRITE, ARG_MIN_X); |
115 gtk_object_add_arg_type("GtkCurve::max_x", GTK_TYPE_FLOAT, GTK_ARG_READWRITE, ARG_MAX_X); | 112 gtk_object_add_arg_type("XSCurve::max_x", GTK_TYPE_FLOAT, GTK_ARG_READWRITE, ARG_MAX_X); |
116 gtk_object_add_arg_type("GtkCurve::min_y", GTK_TYPE_FLOAT, GTK_ARG_READWRITE, ARG_MIN_Y); | 113 gtk_object_add_arg_type("XSCurve::min_y", GTK_TYPE_FLOAT, GTK_ARG_READWRITE, ARG_MIN_Y); |
117 gtk_object_add_arg_type("GtkCurve::max_y", GTK_TYPE_FLOAT, GTK_ARG_READWRITE, ARG_MAX_Y); | 114 gtk_object_add_arg_type("XSCurve::max_y", GTK_TYPE_FLOAT, GTK_ARG_READWRITE, ARG_MAX_Y); |
118 } | 115 } |
119 | 116 |
120 static void gtk_curve_init(GtkCurve * curve) | 117 static void xs_curve_init(XSCurve * curve) |
121 { | 118 { |
122 gint old_mask; | 119 gint old_mask; |
123 | 120 |
124 curve->cursor_type = GDK_TOP_LEFT_ARROW; | 121 curve->cursor_type = GDK_TOP_LEFT_ARROW; |
125 curve->pixmap = NULL; | 122 curve->pixmap = NULL; |
138 curve->min_y = 0.0; | 135 curve->min_y = 0.0; |
139 curve->max_y = 1.0; | 136 curve->max_y = 1.0; |
140 | 137 |
141 old_mask = gtk_widget_get_events(GTK_WIDGET(curve)); | 138 old_mask = gtk_widget_get_events(GTK_WIDGET(curve)); |
142 gtk_widget_set_events(GTK_WIDGET(curve), old_mask | GRAPH_MASK); | 139 gtk_widget_set_events(GTK_WIDGET(curve), old_mask | GRAPH_MASK); |
143 gtk_signal_connect(GTK_OBJECT(curve), "event", (GtkSignalFunc) gtk_curve_graph_events, curve); | 140 gtk_signal_connect(GTK_OBJECT(curve), "event", (GtkSignalFunc) xs_curve_graph_events, curve); |
144 gtk_curve_size_graph(curve); | 141 xs_curve_size_graph(curve); |
145 } | 142 } |
146 | 143 |
147 static void gtk_curve_set_arg(GtkObject * object, GtkArg * arg, guint arg_id) | 144 static void xs_curve_set_arg(GtkObject * object, GtkArg * arg, guint arg_id) |
148 { | 145 { |
149 GtkCurve *curve = GTK_CURVE(object); | 146 XSCurve *curve = XS_CURVE(object); |
150 | 147 |
151 switch (arg_id) { | 148 switch (arg_id) { |
152 case ARG_CURVE_TYPE: | 149 case ARG_CURVE_TYPE: |
153 gtk_curve_set_curve_type(curve, GTK_VALUE_ENUM(*arg)); | 150 xs_curve_set_curve_type(curve, GTK_VALUE_ENUM(*arg)); |
154 break; | 151 break; |
155 case ARG_MIN_X: | 152 case ARG_MIN_X: |
156 gtk_curve_set_range(curve, GTK_VALUE_FLOAT(*arg), curve->max_x, curve->min_y, curve->max_y); | 153 xs_curve_set_range(curve, GTK_VALUE_FLOAT(*arg), curve->max_x, curve->min_y, curve->max_y); |
157 break; | 154 break; |
158 case ARG_MAX_X: | 155 case ARG_MAX_X: |
159 gtk_curve_set_range(curve, curve->min_x, GTK_VALUE_FLOAT(*arg), curve->min_y, curve->max_y); | 156 xs_curve_set_range(curve, curve->min_x, GTK_VALUE_FLOAT(*arg), curve->min_y, curve->max_y); |
160 break; | 157 break; |
161 case ARG_MIN_Y: | 158 case ARG_MIN_Y: |
162 gtk_curve_set_range(curve, curve->min_x, curve->max_x, GTK_VALUE_FLOAT(*arg), curve->max_y); | 159 xs_curve_set_range(curve, curve->min_x, curve->max_x, GTK_VALUE_FLOAT(*arg), curve->max_y); |
163 break; | 160 break; |
164 case ARG_MAX_Y: | 161 case ARG_MAX_Y: |
165 gtk_curve_set_range(curve, curve->min_x, curve->max_x, curve->min_y, GTK_VALUE_FLOAT(*arg)); | 162 xs_curve_set_range(curve, curve->min_x, curve->max_x, curve->min_y, GTK_VALUE_FLOAT(*arg)); |
166 break; | 163 break; |
167 } | 164 } |
168 } | 165 } |
169 | 166 |
170 static void gtk_curve_get_arg(GtkObject * object, GtkArg * arg, guint arg_id) | 167 static void xs_curve_get_arg(GtkObject * object, GtkArg * arg, guint arg_id) |
171 { | 168 { |
172 GtkCurve *curve = GTK_CURVE(object); | 169 XSCurve *curve = XS_CURVE(object); |
173 | 170 |
174 switch (arg_id) { | 171 switch (arg_id) { |
175 case ARG_CURVE_TYPE: | 172 case ARG_CURVE_TYPE: |
176 GTK_VALUE_ENUM(*arg) = curve->curve_type; | 173 GTK_VALUE_ENUM(*arg) = curve->curve_type; |
177 break; | 174 break; |
253 a = (x[k_hi] - val) / h; | 250 a = (x[k_hi] - val) / h; |
254 b = (val - x[k_lo]) / h; | 251 b = (val - x[k_lo]) / h; |
255 return a * y[k_lo] + b * y[k_hi] + ((a * a * a - a) * y2[k_lo] + (b * b * b - b) * y2[k_hi]) * (h * h) / 6.0; | 252 return a * y[k_lo] + b * y[k_hi] + ((a * a * a - a) * y2[k_lo] + (b * b * b - b) * y2[k_hi]) * (h * h) / 6.0; |
256 } | 253 } |
257 | 254 |
258 static void gtk_curve_interpolate(GtkCurve * c, gint width, gint height) | 255 static void xs_curve_interpolate(XSCurve * c, gint width, gint height) |
259 { | 256 { |
260 gfloat *vector; | 257 gfloat *vector; |
261 int i; | 258 int i; |
262 | 259 |
263 vector = g_malloc(width * sizeof(vector[0])); | 260 vector = g_malloc(width * sizeof(vector[0])); |
264 | 261 |
265 gtk_curve_get_vector(c, width, vector); | 262 xs_curve_get_vector(c, width, vector); |
266 | 263 |
267 c->height = height; | 264 c->height = height; |
268 if (c->num_points != width) { | 265 if (c->num_points != width) { |
269 c->num_points = width; | 266 c->num_points = width; |
270 if (c->point) | 267 if (c->point) |
278 } | 275 } |
279 | 276 |
280 g_free(vector); | 277 g_free(vector); |
281 } | 278 } |
282 | 279 |
283 static void gtk_curve_draw(GtkCurve * c, gint width, gint height) | 280 static void xs_curve_draw(XSCurve * c, gint width, gint height) |
284 { | 281 { |
285 GtkStateType state; | 282 GtkStateType state; |
286 GtkStyle *style; | 283 GtkStyle *style; |
287 gint i; | 284 gint i; |
288 | 285 |
289 if (!c->pixmap) | 286 if (!c->pixmap) |
290 return; | 287 return; |
291 | 288 |
292 if (c->height != height || c->num_points != width) | 289 if (c->height != height || c->num_points != width) |
293 gtk_curve_interpolate(c, width, height); | 290 xs_curve_interpolate(c, width, height); |
294 | 291 |
295 state = GTK_STATE_NORMAL; | 292 state = GTK_STATE_NORMAL; |
296 if (!GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(c))) | 293 if (!GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(c))) |
297 state = GTK_STATE_INSENSITIVE; | 294 state = GTK_STATE_INSENSITIVE; |
298 | 295 |
321 y = height - project(c->ctlpoint[i][1], c->min_y, c->max_y, height); | 318 y = height - project(c->ctlpoint[i][1], c->min_y, c->max_y, height); |
322 | 319 |
323 /* draw a bullet: */ | 320 /* draw a bullet: */ |
324 gdk_draw_arc(c->pixmap, style->fg_gc[state], TRUE, x, y, RADIUS * 2, RADIUS * 2, 0, 360 * 64); | 321 gdk_draw_arc(c->pixmap, style->fg_gc[state], TRUE, x, y, RADIUS * 2, RADIUS * 2, 0, 360 * 64); |
325 } | 322 } |
323 | |
326 gdk_draw_pixmap(GTK_WIDGET(c)->window, style->fg_gc[state], c->pixmap, | 324 gdk_draw_pixmap(GTK_WIDGET(c)->window, style->fg_gc[state], c->pixmap, |
327 0, 0, 0, 0, width + RADIUS * 2, height + RADIUS * 2); | 325 0, 0, 0, 0, width + RADIUS * 2, height + RADIUS * 2); |
328 } | 326 } |
329 | 327 |
330 static gint gtk_curve_graph_events(GtkWidget * widget, GdkEvent * event, GtkCurve * c) | 328 static gint xs_curve_graph_events(GtkWidget * widget, GdkEvent * event, XSCurve * c) |
331 { | 329 { |
332 GdkCursorType new_type = c->cursor_type; | 330 GdkCursorType new_type = c->cursor_type; |
333 gint i, src, dst, leftbound, rightbound; | 331 gint i, src, dst, leftbound, rightbound; |
334 GdkEventButton *bevent; | 332 GdkEventButton *bevent; |
335 GdkEventMotion *mevent; | 333 GdkEventMotion *mevent; |
371 c->pixmap = 0; | 369 c->pixmap = 0; |
372 /* fall through */ | 370 /* fall through */ |
373 case GDK_EXPOSE: | 371 case GDK_EXPOSE: |
374 if (!c->pixmap) | 372 if (!c->pixmap) |
375 c->pixmap = gdk_pixmap_new(w->window, w->allocation.width, w->allocation.height, -1); | 373 c->pixmap = gdk_pixmap_new(w->window, w->allocation.width, w->allocation.height, -1); |
376 gtk_curve_draw(c, width, height); | 374 xs_curve_draw(c, width, height); |
377 break; | 375 break; |
378 | 376 |
379 case GDK_BUTTON_PRESS: | 377 case GDK_BUTTON_PRESS: |
380 gtk_grab_add(widget); | 378 gtk_grab_add(widget); |
381 | 379 |
399 } | 397 } |
400 c->grab_point = closest_point; | 398 c->grab_point = closest_point; |
401 c->ctlpoint[c->grab_point][0] = unproject(x, min_x, c->max_x, width); | 399 c->ctlpoint[c->grab_point][0] = unproject(x, min_x, c->max_x, width); |
402 c->ctlpoint[c->grab_point][1] = unproject(height - y, c->min_y, c->max_y, height); | 400 c->ctlpoint[c->grab_point][1] = unproject(height - y, c->min_y, c->max_y, height); |
403 | 401 |
404 gtk_curve_interpolate(c, width, height); | 402 xs_curve_interpolate(c, width, height); |
405 break; | 403 break; |
406 | 404 |
407 case GTK_CURVE_TYPE_FREE: | 405 case GTK_CURVE_TYPE_FREE: |
408 c->point[x].x = RADIUS + x; | 406 c->point[x].x = RADIUS + x; |
409 c->point[x].y = RADIUS + y; | 407 c->point[x].y = RADIUS + y; |
410 c->grab_point = x; | 408 c->grab_point = x; |
411 c->last = y; | 409 c->last = y; |
412 break; | 410 break; |
413 } | 411 } |
414 gtk_curve_draw(c, width, height); | 412 xs_curve_draw(c, width, height); |
415 break; | 413 break; |
416 | 414 |
417 case GDK_BUTTON_RELEASE: | 415 case GDK_BUTTON_RELEASE: |
418 gtk_grab_remove(widget); | 416 gtk_grab_remove(widget); |
419 | 417 |
429 c->num_ctlpoints -= (src - dst); | 427 c->num_ctlpoints -= (src - dst); |
430 if (c->num_ctlpoints <= 0) { | 428 if (c->num_ctlpoints <= 0) { |
431 c->num_ctlpoints = 1; | 429 c->num_ctlpoints = 1; |
432 c->ctlpoint[0][0] = min_x; | 430 c->ctlpoint[0][0] = min_x; |
433 c->ctlpoint[0][1] = c->min_y; | 431 c->ctlpoint[0][1] = c->min_y; |
434 gtk_curve_interpolate(c, width, height); | 432 xs_curve_interpolate(c, width, height); |
435 gtk_curve_draw(c, width, height); | 433 xs_curve_draw(c, width, height); |
436 } | 434 } |
437 c->ctlpoint = g_realloc(c->ctlpoint, c->num_ctlpoints * sizeof(*c->ctlpoint)); | 435 c->ctlpoint = g_realloc(c->ctlpoint, c->num_ctlpoints * sizeof(*c->ctlpoint)); |
438 } | 436 } |
439 } | 437 } |
440 new_type = GDK_FLEUR; | 438 new_type = GDK_FLEUR; |
472 rx = unproject(x, min_x, c->max_x, width); | 470 rx = unproject(x, min_x, c->max_x, width); |
473 ry = unproject(height - y, c->min_y, c->max_y, height); | 471 ry = unproject(height - y, c->min_y, c->max_y, height); |
474 c->ctlpoint[c->grab_point][0] = rx; | 472 c->ctlpoint[c->grab_point][0] = rx; |
475 c->ctlpoint[c->grab_point][1] = ry; | 473 c->ctlpoint[c->grab_point][1] = ry; |
476 } | 474 } |
477 gtk_curve_interpolate(c, width, height); | 475 xs_curve_interpolate(c, width, height); |
478 gtk_curve_draw(c, width, height); | 476 xs_curve_draw(c, width, height); |
479 } | 477 } |
480 break; | 478 break; |
481 | 479 |
482 case GTK_CURVE_TYPE_FREE: | 480 case GTK_CURVE_TYPE_FREE: |
483 if (c->grab_point != -1) { | 481 if (c->grab_point != -1) { |
501 c->point[x].x = RADIUS + x; | 499 c->point[x].x = RADIUS + x; |
502 c->point[x].y = RADIUS + y; | 500 c->point[x].y = RADIUS + y; |
503 } | 501 } |
504 c->grab_point = x; | 502 c->grab_point = x; |
505 c->last = y; | 503 c->last = y; |
506 gtk_curve_draw(c, width, height); | 504 xs_curve_draw(c, width, height); |
507 } | 505 } |
508 if (mevent->state & GDK_BUTTON1_MASK) | 506 if (mevent->state & GDK_BUTTON1_MASK) |
509 new_type = GDK_TCROSS; | 507 new_type = GDK_TCROSS; |
510 else | 508 else |
511 new_type = GDK_PENCIL; | 509 new_type = GDK_PENCIL; |
526 break; | 524 break; |
527 } | 525 } |
528 return FALSE; | 526 return FALSE; |
529 } | 527 } |
530 | 528 |
531 void gtk_curve_set_curve_type(GtkCurve * c, GtkCurveType new_type) | 529 void xs_curve_set_curve_type(XSCurve * c, GtkCurveType new_type) |
532 { | 530 { |
533 gfloat rx, dx; | 531 gfloat rx, dx; |
534 gint x, i; | 532 gint x, i; |
535 | 533 |
536 if (new_type != c->curve_type) { | 534 if (new_type != c->curve_type) { |
538 | 536 |
539 width = GTK_WIDGET(c)->allocation.width - RADIUS * 2; | 537 width = GTK_WIDGET(c)->allocation.width - RADIUS * 2; |
540 height = GTK_WIDGET(c)->allocation.height - RADIUS * 2; | 538 height = GTK_WIDGET(c)->allocation.height - RADIUS * 2; |
541 | 539 |
542 if (new_type == GTK_CURVE_TYPE_FREE) { | 540 if (new_type == GTK_CURVE_TYPE_FREE) { |
543 gtk_curve_interpolate(c, width, height); | 541 xs_curve_interpolate(c, width, height); |
544 c->curve_type = new_type; | 542 c->curve_type = new_type; |
545 } else if (c->curve_type == GTK_CURVE_TYPE_FREE) { | 543 } else if (c->curve_type == GTK_CURVE_TYPE_FREE) { |
546 if (c->ctlpoint) | 544 if (c->ctlpoint) |
547 g_free(c->ctlpoint); | 545 g_free(c->ctlpoint); |
548 c->num_ctlpoints = 9; | 546 c->num_ctlpoints = 9; |
556 c->ctlpoint[i][0] = unproject(x, c->min_x, c->max_x, width); | 554 c->ctlpoint[i][0] = unproject(x, c->min_x, c->max_x, width); |
557 c->ctlpoint[i][1] = | 555 c->ctlpoint[i][1] = |
558 unproject(RADIUS + height - c->point[x].y, c->min_y, c->max_y, height); | 556 unproject(RADIUS + height - c->point[x].y, c->min_y, c->max_y, height); |
559 } | 557 } |
560 c->curve_type = new_type; | 558 c->curve_type = new_type; |
561 gtk_curve_interpolate(c, width, height); | 559 xs_curve_interpolate(c, width, height); |
562 } else { | 560 } else { |
563 c->curve_type = new_type; | 561 c->curve_type = new_type; |
564 gtk_curve_interpolate(c, width, height); | 562 xs_curve_interpolate(c, width, height); |
565 } | 563 } |
566 gtk_signal_emit(GTK_OBJECT(c), curve_type_changed_signal); | 564 gtk_signal_emit(GTK_OBJECT(c), curve_type_changed_signal); |
567 gtk_curve_draw(c, width, height); | 565 xs_curve_draw(c, width, height); |
568 } | 566 } |
569 } | 567 } |
570 | 568 |
571 static void gtk_curve_size_graph(GtkCurve * curve) | 569 static void xs_curve_size_graph(XSCurve * curve) |
572 { | 570 { |
573 gint width, height; | 571 gint width, height; |
574 gfloat aspect; | 572 gfloat aspect; |
575 | 573 |
576 width = (curve->max_x - curve->min_x) + 1; | 574 width = (curve->max_x - curve->min_x) + 1; |
587 height = width / aspect; | 585 height = width / aspect; |
588 | 586 |
589 gtk_drawing_area_size(GTK_DRAWING_AREA(curve), width + RADIUS * 2, height + RADIUS * 2); | 587 gtk_drawing_area_size(GTK_DRAWING_AREA(curve), width + RADIUS * 2, height + RADIUS * 2); |
590 } | 588 } |
591 | 589 |
592 static void gtk_curve_reset_vector(GtkCurve * curve) | 590 static void xs_curve_reset_vector(XSCurve * curve) |
593 { | 591 { |
594 if (curve->ctlpoint) | 592 if (curve->ctlpoint) |
595 g_free(curve->ctlpoint); | 593 g_free(curve->ctlpoint); |
596 | 594 |
597 curve->num_ctlpoints = 2; | 595 curve->num_ctlpoints = 2; |
607 width = GTK_WIDGET(curve)->allocation.width - RADIUS * 2; | 605 width = GTK_WIDGET(curve)->allocation.width - RADIUS * 2; |
608 height = GTK_WIDGET(curve)->allocation.height - RADIUS * 2; | 606 height = GTK_WIDGET(curve)->allocation.height - RADIUS * 2; |
609 | 607 |
610 if (curve->curve_type == GTK_CURVE_TYPE_FREE) { | 608 if (curve->curve_type == GTK_CURVE_TYPE_FREE) { |
611 curve->curve_type = GTK_CURVE_TYPE_LINEAR; | 609 curve->curve_type = GTK_CURVE_TYPE_LINEAR; |
612 gtk_curve_interpolate(curve, width, height); | 610 xs_curve_interpolate(curve, width, height); |
613 curve->curve_type = GTK_CURVE_TYPE_FREE; | 611 curve->curve_type = GTK_CURVE_TYPE_FREE; |
614 } else | 612 } else |
615 gtk_curve_interpolate(curve, width, height); | 613 xs_curve_interpolate(curve, width, height); |
616 gtk_curve_draw(curve, width, height); | 614 xs_curve_draw(curve, width, height); |
617 } | 615 } |
618 } | 616 } |
619 | 617 |
620 void gtk_curve_reset(GtkCurve * c) | 618 void xs_curve_reset(XSCurve * c) |
621 { | 619 { |
622 GtkCurveType old_type; | 620 GtkCurveType old_type; |
623 | 621 |
624 old_type = c->curve_type; | 622 old_type = c->curve_type; |
625 c->curve_type = GTK_CURVE_TYPE_SPLINE; | 623 c->curve_type = GTK_CURVE_TYPE_SPLINE; |
626 gtk_curve_reset_vector(c); | 624 xs_curve_reset_vector(c); |
627 | 625 |
628 if (old_type != GTK_CURVE_TYPE_SPLINE) | 626 if (old_type != GTK_CURVE_TYPE_SPLINE) |
629 gtk_signal_emit(GTK_OBJECT(c), curve_type_changed_signal); | 627 gtk_signal_emit(GTK_OBJECT(c), curve_type_changed_signal); |
630 } | 628 } |
631 | 629 |
632 void gtk_curve_set_gamma(GtkCurve * c, gfloat gamma) | 630 void xs_curve_set_gamma(XSCurve * c, gfloat gamma) |
633 { | 631 { |
634 gfloat x, one_over_gamma, height, one_over_width; | 632 gfloat x, one_over_gamma, height, one_over_width; |
635 GtkCurveType old_type; | 633 GtkCurveType old_type; |
636 gint i; | 634 gint i; |
637 | 635 |
654 } | 652 } |
655 | 653 |
656 if (old_type != GTK_CURVE_TYPE_FREE) | 654 if (old_type != GTK_CURVE_TYPE_FREE) |
657 gtk_signal_emit(GTK_OBJECT(c), curve_type_changed_signal); | 655 gtk_signal_emit(GTK_OBJECT(c), curve_type_changed_signal); |
658 | 656 |
659 gtk_curve_draw(c, c->num_points, c->height); | 657 xs_curve_draw(c, c->num_points, c->height); |
660 } | 658 } |
661 | 659 |
662 void gtk_curve_set_range(GtkCurve * curve, gfloat min_x, gfloat max_x, gfloat min_y, gfloat max_y) | 660 void xs_curve_set_range(XSCurve * curve, gfloat min_x, gfloat max_x, gfloat min_y, gfloat max_y) |
663 { | 661 { |
664 curve->min_x = min_x; | 662 curve->min_x = min_x; |
665 curve->max_x = max_x; | 663 curve->max_x = max_x; |
666 curve->min_y = min_y; | 664 curve->min_y = min_y; |
667 curve->max_y = max_y; | 665 curve->max_y = max_y; |
668 | 666 |
669 gtk_curve_size_graph(curve); | 667 xs_curve_size_graph(curve); |
670 gtk_curve_reset_vector(curve); | 668 xs_curve_reset_vector(curve); |
671 } | 669 } |
672 | 670 |
673 void gtk_curve_set_vector(GtkCurve * c, int veclen, gfloat vector[]) | 671 void xs_curve_set_vector(XSCurve * c, int veclen, gfloat vector[]) |
674 { | 672 { |
675 GtkCurveType old_type; | 673 GtkCurveType old_type; |
676 gfloat rx, dx, ry; | 674 gfloat rx, dx, ry; |
677 gint i, height; | 675 gint i, height; |
678 | 676 |
703 c->point[i].y = RADIUS + height - project(ry, c->min_y, c->max_y, height); | 701 c->point[i].y = RADIUS + height - project(ry, c->min_y, c->max_y, height); |
704 } | 702 } |
705 if (old_type != GTK_CURVE_TYPE_FREE) | 703 if (old_type != GTK_CURVE_TYPE_FREE) |
706 gtk_signal_emit(GTK_OBJECT(c), curve_type_changed_signal); | 704 gtk_signal_emit(GTK_OBJECT(c), curve_type_changed_signal); |
707 | 705 |
708 gtk_curve_draw(c, c->num_points, height); | 706 xs_curve_draw(c, c->num_points, height); |
709 } | 707 } |
710 | 708 |
711 void gtk_curve_get_vector(GtkCurve * c, int veclen, gfloat vector[]) | 709 void xs_curve_get_vector(XSCurve * c, int veclen, gfloat vector[]) |
712 { | 710 { |
713 gfloat rx, ry, dx, dy, min_x, delta_x, *mem, *xv, *yv, *y2v, prev; | 711 gfloat rx, ry, dx, dy, min_x, delta_x, *mem, *xv, *yv, *y2v, prev; |
714 gint dst, i, x, next, num_active_ctlpoints = 0, first_active = -1; | 712 gint dst, i, x, next, num_active_ctlpoints = 0, first_active = -1; |
715 | 713 |
716 min_x = c->min_x; | 714 min_x = c->min_x; |
813 memset(vector, 0, veclen * sizeof(vector[0])); | 811 memset(vector, 0, veclen * sizeof(vector[0])); |
814 break; | 812 break; |
815 } | 813 } |
816 } | 814 } |
817 | 815 |
818 GtkWidget *gtk_curve_new(void) | 816 GtkWidget *xs_curve_new(void) |
819 { | 817 { |
820 return gtk_type_new(gtk_curve_get_type()); | 818 return gtk_type_new(xs_curve_get_type()); |
821 } | 819 } |
822 | 820 |
823 static void gtk_curve_finalize(GtkObject * object) | 821 static void xs_curve_finalize(GtkObject * object) |
824 { | 822 { |
825 GtkCurve *curve; | 823 XSCurve *curve; |
826 | 824 |
827 g_return_if_fail(object != NULL); | 825 g_return_if_fail(object != NULL); |
828 g_return_if_fail(GTK_IS_CURVE(object)); | 826 g_return_if_fail(XS_IS_CURVE(object)); |
829 | 827 |
830 curve = GTK_CURVE(object); | 828 curve = XS_CURVE(object); |
831 if (curve->pixmap) | 829 if (curve->pixmap) |
832 gdk_pixmap_unref(curve->pixmap); | 830 gdk_pixmap_unref(curve->pixmap); |
833 if (curve->point) | 831 if (curve->point) |
834 g_free(curve->point); | 832 g_free(curve->point); |
835 if (curve->ctlpoint) | 833 if (curve->ctlpoint) |