Mercurial > hg > xmms-sid
annotate src/xs_curve.c @ 897:cfc20df88401
Cosmetics.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 09 Nov 2012 08:24:46 +0200 |
parents | 9321ffa2ea7e |
children | 8b4c016802ea |
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 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
36 #define RADIUS 3 /* radius of the control points */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
37 #define RADIUS2 (RADIUS * 2) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
38 #define 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 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
41 #define GRAPH_MASK (GDK_EXPOSURE_MASK | \ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
42 GDK_POINTER_MOTION_MASK | \ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
43 GDK_POINTER_MOTION_HINT_MASK | \ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
44 GDK_ENTER_NOTIFY_MASK | \ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
45 GDK_BUTTON_PRESS_MASK | \ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
46 GDK_BUTTON_RELEASE_MASK | \ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
47 GDK_BUTTON1_MOTION_MASK) |
358 | 48 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
49 #define GET_X(i) curve->ctlpoints[i].x |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
50 #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
|
51 |
982cec405ef0
Cleaned up the drawing function a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
52 |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
53 enum { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
54 ARG_0, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
55 ARG_MIN_X, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
56 ARG_MAX_X, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
57 ARG_MIN_Y, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
58 ARG_MAX_Y |
358 | 59 }; |
60 | |
61 static GtkDrawingAreaClass *parent_class = NULL; | |
62 | |
370
df6f12a00305
Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents:
359
diff
changeset
|
63 static void xs_curve_class_init(XSCurveClass * class); |
df6f12a00305
Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents:
359
diff
changeset
|
64 static void xs_curve_init(XSCurve * curve); |
df6f12a00305
Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents:
359
diff
changeset
|
65 static void xs_curve_set_arg(GtkObject * object, GtkArg * arg, guint arg_id); |
df6f12a00305
Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents:
359
diff
changeset
|
66 static void xs_curve_get_arg(GtkObject * object, GtkArg * arg, guint arg_id); |
df6f12a00305
Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents:
359
diff
changeset
|
67 static void xs_curve_finalize(GtkObject * object); |
df6f12a00305
Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents:
359
diff
changeset
|
68 static gint xs_curve_graph_events(GtkWidget * widget, GdkEvent * event, XSCurve * c); |
df6f12a00305
Work on filter curve widget begins, based on GtkCurve widget from Gtk+ 1.2.10.
Matti Hamalainen <ccr@tnsp.org>
parents:
359
diff
changeset
|
69 static void xs_curve_size_graph(XSCurve * curve); |
358 | 70 |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
71 |
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
|
72 GtkType xs_curve_get_type(void) |
358 | 73 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
74 static GtkType curve_type = 0; |
358 | 75 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
76 if (!curve_type) { |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
77 static const GtkTypeInfo curve_info = { |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
78 "XSCurve", |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
79 sizeof(XSCurve), |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
80 sizeof(XSCurveClass), |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
81 (GtkClassInitFunc) xs_curve_class_init, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
82 (GtkObjectInitFunc) xs_curve_init, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
83 /* reserved_1 */ NULL, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
84 /* reserved_2 */ NULL, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
85 (GtkClassInitFunc) NULL, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
86 }; |
358 | 87 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
88 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
|
89 } |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
90 return curve_type; |
358 | 91 } |
92 | |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
93 |
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
94 static void xs_curve_class_init(XSCurveClass *class) |
358 | 95 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
96 GtkObjectClass *object_class; |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
97 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
98 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
|
99 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
100 object_class = (GtkObjectClass *) class; |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
101 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
102 object_class->set_arg = xs_curve_set_arg; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
103 object_class->get_arg = xs_curve_get_arg; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
104 object_class->finalize = xs_curve_finalize; |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
105 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
106 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
|
107 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
|
108 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
|
109 gtk_object_add_arg_type("XSCurve::max_y", GTK_TYPE_FLOAT, GTK_ARG_READWRITE, ARG_MAX_Y); |
358 | 110 } |
111 | |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
112 |
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
113 static void xs_curve_init(XSCurve *curve) |
358 | 114 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
115 gint old_mask; |
358 | 116 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
117 curve->pixmap = NULL; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
118 curve->grab_point = -1; |
358 | 119 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
120 curve->nctlpoints = 0; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
121 curve->ctlpoints = NULL; |
358 | 122 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
123 curve->min_x = 0.0; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
124 curve->max_x = 2047.0; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
125 curve->min_y = 0.0; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
126 curve->max_y = 24000.0; |
358 | 127 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
128 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
|
129 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
|
130 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
|
131 xs_curve_size_graph(curve); |
358 | 132 } |
133 | |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
134 |
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
135 static void xs_curve_set_arg(GtkObject *object, GtkArg *arg, guint arg_id) |
358 | 136 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
137 XSCurve *curve = XS_CURVE(object); |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
138 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
139 switch (arg_id) { |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
140 case ARG_MIN_X: |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
141 xs_curve_set_range(curve, GTK_VALUE_FLOAT(*arg), curve->max_x, curve->min_y, curve->max_y); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
142 break; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
143 case ARG_MAX_X: |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
144 xs_curve_set_range(curve, curve->min_x, GTK_VALUE_FLOAT(*arg), curve->min_y, curve->max_y); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
145 break; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
146 case ARG_MIN_Y: |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
147 xs_curve_set_range(curve, curve->min_x, curve->max_x, GTK_VALUE_FLOAT(*arg), curve->max_y); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
148 break; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
149 case ARG_MAX_Y: |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
150 xs_curve_set_range(curve, curve->min_x, curve->max_x, curve->min_y, GTK_VALUE_FLOAT(*arg)); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
151 break; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
152 } |
358 | 153 } |
154 | |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
155 |
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
156 static void xs_curve_get_arg(GtkObject *object, GtkArg *arg, guint arg_id) |
358 | 157 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
158 XSCurve *curve = XS_CURVE(object); |
358 | 159 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
160 switch (arg_id) { |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
161 case ARG_MIN_X: |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
162 GTK_VALUE_FLOAT(*arg) = curve->min_x; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
163 break; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
164 case ARG_MAX_X: |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
165 GTK_VALUE_FLOAT(*arg) = curve->max_x; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
166 break; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
167 case ARG_MIN_Y: |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
168 GTK_VALUE_FLOAT(*arg) = curve->min_y; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
169 break; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
170 case ARG_MAX_Y: |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
171 GTK_VALUE_FLOAT(*arg) = curve->max_y; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
172 break; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
173 default: |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
174 arg->type = GTK_TYPE_INVALID; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
175 break; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
176 } |
358 | 177 } |
178 | |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
179 |
374
58079c6180a0
More removal of original curve code.
Matti Hamalainen <ccr@tnsp.org>
parents:
370
diff
changeset
|
180 static int xs_project(gfloat value, gfloat min, gfloat max, int norm) |
358 | 181 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
182 return (norm - 1) * ((value - min) / (max - min)) + 0.5; |
358 | 183 } |
184 | |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
185 |
374
58079c6180a0
More removal of original curve code.
Matti Hamalainen <ccr@tnsp.org>
parents:
370
diff
changeset
|
186 static gfloat xs_unproject(gint value, gfloat min, gfloat max, int norm) |
358 | 187 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
188 return value / (gfloat) (norm - 1) * (max - min) + min; |
358 | 189 } |
190 | |
191 | |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
192 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
|
193 gfloat x2, gfloat y2, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
194 gfloat k1, gfloat k2, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
195 gfloat *a, gfloat *b, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
196 gfloat *c, gfloat *d) |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
197 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
198 gfloat dx = x2 - x1, dy = y2 - y1; |
358 | 199 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
200 *a = ((k1 + k2) - 2 * dy / dx) / (dx * dx); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
201 *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
|
202 *c = k1 - (3 * x1 * (*a) + 2 * (*b)) * x1; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
203 *d = y1 - ((x1 * (*a) + (*b)) * x1 + (*c)) * x1; |
358 | 204 } |
205 | |
206 | |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
207 static void xs_curve_draw(XSCurve *curve, gint width, gint height) |
358 | 208 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
209 gfloat res = 5.0f; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
210 GtkStateType state; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
211 GtkStyle *style; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
212 gint i, ox = -1, oy = -1; |
702 | 213 xs_point_t *p0, *p1, *p2, *p3; |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
214 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
215 if (!curve->pixmap) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
216 return; |
358 | 217 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
218 state = GTK_STATE_NORMAL; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
219 if (!GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(curve))) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
220 state = GTK_STATE_INSENSITIVE; |
358 | 221 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
222 style = GTK_WIDGET(curve)->style; |
358 | 223 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
224 /* Clear the pixmap */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
225 gtk_paint_flat_box(style, curve->pixmap, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
226 GTK_STATE_NORMAL, GTK_SHADOW_NONE, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
227 NULL, GTK_WIDGET(curve), "curve_bg", |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
228 0, 0, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
229 width + RADIUS2, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
230 height + RADIUS2); |
374
58079c6180a0
More removal of original curve code.
Matti Hamalainen <ccr@tnsp.org>
parents:
370
diff
changeset
|
231 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
232 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
233 /* Draw the grid */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
234 for (i = 0; i < 5; i++) { |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
235 gdk_draw_line(curve->pixmap, style->dark_gc[state], |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
236 RADIUS, i * (height / 4.0) + RADIUS, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
237 width + RADIUS, i * (height / 4.0) + RADIUS); |
374
58079c6180a0
More removal of original curve code.
Matti Hamalainen <ccr@tnsp.org>
parents:
370
diff
changeset
|
238 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
239 gdk_draw_line(curve->pixmap, style->dark_gc[state], |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
240 i * (width / 4.0) + RADIUS, RADIUS, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
241 i * (width / 4.0) + RADIUS, height + RADIUS); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
242 } |
358 | 243 |
520 | 244 #if 1 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
245 /* Draw the spline/curve itself */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
246 p0 = curve->ctlpoints; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
247 p1 = p0; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
248 p2 = p1; p2++; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
249 p3 = p2; p3++; |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
250 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
251 /* Draw each curve segment */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
252 if (curve->nctlpoints > 5) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
253 for (i = 0; i < curve->nctlpoints; i++, ++p0, ++p1, ++p2, ++p3) { |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
254 gint n; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
255 gfloat k1, k2, a, b, c, d, x; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
256 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
257 if (p1->x == p2->x) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
258 continue; |
514
982cec405ef0
Cleaned up the drawing function a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
259 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
260 if (p0->x == p1->x && p2->x == p3->x) { |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
261 k1 = k2 = (p2->y - p1->y) / (p2->x - p1->x); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
262 } else if (p0->x == p1->x) { |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
263 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
|
264 k1 = (3 * (p2->y - p1->y) / (p2->x - p1->x) - k2) / 2; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
265 } else if (p2->x == p3->x) { |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
266 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
|
267 k2 = (3 * (p2->y - p1->y) / (p2->x - p1->x) - k1) / 2; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
268 } else { |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
269 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
|
270 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
|
271 } |
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
|
272 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
273 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
|
274 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
275 for (x = p1->x; x <= p2->x; x += res, n++) { |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
276 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
|
277 gint qx, qy; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
278 qx = RADIUS + xs_project(x, curve->min_x, curve->max_x, width); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
279 qy = RADIUS + xs_project(y, curve->min_y, curve->max_y, height); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
280 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
281 if (ox != -1) { |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
282 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
|
283 ox, oy, qx, qy); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
284 } |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
285 ox = qx; oy = qy; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
286 } |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
287 } |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
288 |
520 | 289 #endif |
290 | |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
291 /* Draw control points */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
292 for (i = 0; i < curve->nctlpoints; ++i) { |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
293 gint x, y; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
294 GtkStateType cstate; |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
295 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
296 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
|
297 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
|
298 continue; |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
299 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
300 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
|
301 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
|
302 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
303 if (i == curve->grab_point) { |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
304 cstate = GTK_STATE_SELECTED; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
305 gdk_draw_line(curve->pixmap, style->fg_gc[cstate], |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
306 x + RADIUS, RADIUS, x + RADIUS, height + RADIUS); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
307 gdk_draw_line(curve->pixmap, style->fg_gc[cstate], |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
308 RADIUS, y + RADIUS, width + RADIUS, y + RADIUS); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
309 } else |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
310 cstate = state; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
311 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
312 gdk_draw_arc(curve->pixmap, style->fg_gc[cstate], TRUE, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
313 x, y, RADIUS2, RADIUS2, 0, 360 * 64); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
314 } |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
315 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
316 /* Draw pixmap in the widget */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
317 gdk_draw_pixmap(GTK_WIDGET(curve)->window, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
318 style->fg_gc[state], curve->pixmap, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
319 0, 0, 0, 0, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
320 width + RADIUS2, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
321 height + RADIUS2); |
358 | 322 } |
323 | |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
324 |
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
325 static gint xs_curve_graph_events(GtkWidget *widget, GdkEvent *event, XSCurve *curve) |
358 | 326 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
327 GdkCursorType new_type = curve->cursor_type; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
328 GdkEventButton *bevent; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
329 GtkWidget *w; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
330 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
|
331 guint distance; |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
332 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
333 w = GTK_WIDGET(curve); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
334 width = w->allocation.width - RADIUS2; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
335 height = w->allocation.height - RADIUS2; |
358 | 336 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
337 if ((width < 0) || (height < 0)) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
338 return FALSE; |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
339 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
340 /* get the pointer position */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
341 gdk_window_get_pointer(w->window, &tx, &ty, NULL); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
342 x = CLAMP((tx - RADIUS), 0, width - 1); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
343 y = CLAMP((ty - RADIUS), 0, height - 1); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
344 min_x = curve->min_x; |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
345 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
346 distance = ~0U; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
347 for (i = 0; i < curve->nctlpoints; ++i) { |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
348 cx = xs_project(GET_X(i), min_x, curve->max_x, width); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
349 if ((guint) abs(x - cx) < distance) { |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
350 distance = abs(x - cx); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
351 closest_point = i; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
352 } |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
353 } |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
354 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
355 /* Act based on event type */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
356 switch (event->type) { |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
357 case GDK_CONFIGURE: |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
358 if (curve->pixmap) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
359 gdk_pixmap_unref(curve->pixmap); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
360 curve->pixmap = 0; |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
361 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
362 /* fall through */ |
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 case GDK_EXPOSE: |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
365 if (!curve->pixmap) { |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
366 curve->pixmap = gdk_pixmap_new(w->window, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
367 w->allocation.width, w->allocation.height, -1); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
368 } |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
369 xs_curve_draw(curve, width, height); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
370 break; |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
371 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
372 case GDK_BUTTON_PRESS: |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
373 gtk_grab_add(widget); |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
374 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
375 bevent = (GdkEventButton *) event; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
376 new_type = GDK_TCROSS; |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
377 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
378 if (distance > MIN_DISTANCE) { |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
379 /* insert a new control point */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
380 if (curve->nctlpoints > 0) { |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
381 cx = xs_project(GET_X(closest_point), min_x, curve->max_x, width); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
382 if (x > cx) closest_point++; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
383 } |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
384 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
385 curve->nctlpoints++; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
386 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
387 curve->ctlpoints = g_realloc(curve->ctlpoints, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
388 curve->nctlpoints * sizeof(*curve->ctlpoints)); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
389 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
390 for (i = curve->nctlpoints - 1; i > closest_point; --i) { |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
391 memcpy(curve->ctlpoints + i, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
392 curve->ctlpoints + i - 1, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
393 sizeof(*curve->ctlpoints)); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
394 } |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
395 } |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
396 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
397 curve->grab_point = closest_point; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
398 GET_X(curve->grab_point) = xs_unproject(x, min_x, curve->max_x, width); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
399 GET_Y(curve->grab_point) = xs_unproject(y, curve->min_y, curve->max_y, height); |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
400 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
401 xs_curve_draw(curve, width, height); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
402 break; |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
403 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
404 case GDK_BUTTON_RELEASE: |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
405 { |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
406 gint src, dst; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
407 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
408 gtk_grab_remove(widget); |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
409 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
410 /* delete inactive points: */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
411 for (src = dst = 0; src < curve->nctlpoints; ++src) { |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
412 if (GET_X(src) >= min_x) { |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
413 memcpy(curve->ctlpoints + dst, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
414 curve->ctlpoints + src, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
415 sizeof(*curve->ctlpoints)); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
416 dst++; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
417 } |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
418 } |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
419 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
420 if (dst < src) { |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
421 curve->nctlpoints -= (src - dst); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
422 if (curve->nctlpoints <= 0) { |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
423 curve->nctlpoints = 1; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
424 GET_X(0) = min_x; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
425 GET_Y(0) = curve->min_y; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
426 xs_curve_draw(curve, width, height); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
427 } |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
428 curve->ctlpoints = g_realloc(curve->ctlpoints, |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
429 curve->nctlpoints * sizeof(*curve->ctlpoints)); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
430 } |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
431 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
432 new_type = GDK_FLEUR; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
433 curve->grab_point = -1; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
434 } |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
435 xs_curve_draw(curve, width, height); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
436 break; |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
437 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
438 case GDK_MOTION_NOTIFY: |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
439 if (curve->grab_point == -1) { |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
440 /* if no point is grabbed... */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
441 if (distance <= MIN_DISTANCE) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
442 new_type = GDK_FLEUR; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
443 else |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
444 new_type = GDK_TCROSS; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
445 } else { |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
446 gint leftbound, rightbound; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
447 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
448 /* drag the grabbed point */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
449 new_type = GDK_TCROSS; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
450 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
451 leftbound = -MIN_DISTANCE; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
452 if (curve->grab_point > 0) { |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
453 leftbound = xs_project( |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
454 GET_X(curve->grab_point-1), |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
455 min_x, curve->max_x, width); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
456 } |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
457 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
458 rightbound = width + RADIUS2 + MIN_DISTANCE; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
459 if (curve->grab_point + 1 < curve->nctlpoints) { |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
460 rightbound = xs_project( |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
461 GET_X(curve->grab_point+1), |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
462 min_x, curve->max_x, width); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
463 } |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
464 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
465 if ((tx <= leftbound) || (tx >= rightbound) || |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
466 (ty > height + RADIUS2 + MIN_DISTANCE) || (ty < -MIN_DISTANCE)) { |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
467 GET_X(curve->grab_point) = min_x - 1.0; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
468 } else { |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
469 GET_X(curve->grab_point) = |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
470 xs_unproject(x, min_x, curve->max_x, width); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
471 GET_Y(curve->grab_point) = |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
472 xs_unproject(y, curve->min_y, curve->max_y, height); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
473 } |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
474 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
475 xs_curve_draw(curve, width, height); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
476 } |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
477 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
478 /* See if cursor type was changed and update accordingly */ |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
479 if (new_type != (GdkCursorType) curve->cursor_type) { |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
480 GdkCursor *cursor; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
481 curve->cursor_type = new_type; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
482 cursor = gdk_cursor_new(curve->cursor_type); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
483 gdk_window_set_cursor(w->window, cursor); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
484 gdk_cursor_destroy(cursor); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
485 } |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
486 break; |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
487 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
488 default: |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
489 break; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
490 } |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
491 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
492 return FALSE; |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
493 } |
358 | 494 |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
495 |
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
496 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
|
497 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
498 gint width, height; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
499 gfloat aspect; |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
500 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
501 width = (curve->max_x - curve->min_x) + 1; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
502 height = (curve->max_y - curve->min_y) + 1; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
503 aspect = width / (gfloat) height; |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
504 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
505 if (width > gdk_screen_width() / 4) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
506 width = gdk_screen_width() / 4; |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
507 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
508 if (height > gdk_screen_height() / 4) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
509 height = gdk_screen_height() / 4; |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
510 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
511 if (aspect < 1.0) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
512 width = height * aspect; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
513 else |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
514 height = width / aspect; |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
515 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
516 gtk_drawing_area_size(GTK_DRAWING_AREA(curve), width + RADIUS2, height + RADIUS2); |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
517 } |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
518 |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
519 |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
520 static void xs_curve_update(XSCurve *curve) |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
521 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
522 if (curve->pixmap) { |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
523 gint width, height; |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
524 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
525 width = GTK_WIDGET(curve)->allocation.width - RADIUS2; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
526 height = GTK_WIDGET(curve)->allocation.height - RADIUS2; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
527 xs_curve_draw(curve, width, height); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
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 |
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
531 |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
532 void xs_curve_reset(XSCurve *curve) |
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
533 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
534 if (curve->ctlpoints) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
535 g_free(curve->ctlpoints); |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
536 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
537 curve->nctlpoints = 4; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
538 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
|
539 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
540 GET_X(0) = curve->min_x; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
541 GET_Y(0) = curve->min_y; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
542 GET_X(1) = curve->min_x; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
543 GET_Y(1) = curve->min_y; |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
544 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
545 GET_X(2) = curve->max_x; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
546 GET_Y(2) = curve->max_y; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
547 GET_X(3) = curve->max_x; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
548 GET_Y(3) = curve->max_y; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
549 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
550 xs_curve_update(curve); |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
551 } |
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
552 |
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
553 |
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
554 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
|
555 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
556 curve->min_x = min_x; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
557 curve->max_x = max_x; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
558 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
559 curve->min_y = min_y; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
560 curve->max_y = max_y; |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
561 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
562 xs_curve_size_graph(curve); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
563 xs_curve_reset(curve); |
359
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
564 } |
b1a858b8cb1a
Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
565 |
358 | 566 |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
567 gboolean xs_curve_realloc_data(XSCurve *curve, gint npoints) |
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 (npoints != curve->nctlpoints) { |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
570 curve->nctlpoints = npoints; |
702 | 571 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
|
572 curve->nctlpoints * sizeof(*curve->ctlpoints)); |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
573 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
574 if (curve->ctlpoints == NULL) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
575 return FALSE; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
576 } |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
577 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
578 return TRUE; |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
579 } |
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
580 |
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
581 |
702 | 582 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
|
583 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
584 *points = &(curve->ctlpoints); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
585 *npoints = &(curve->nctlpoints); |
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 |
702 | 589 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
|
590 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
591 gint i; |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
592 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
593 if (!xs_curve_realloc_data(curve, npoints + 4)) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
594 return FALSE; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
595 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
596 GET_X(0) = curve->min_x; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
597 GET_Y(0) = curve->min_y; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
598 GET_X(1) = curve->min_x; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
599 GET_Y(1) = curve->min_y; |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
600 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
601 for (i = 0; i < npoints; i++) { |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
602 GET_X(i+2) = points[i].x; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
603 GET_Y(i+2) = points[i].y; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
604 } |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
605 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
606 GET_X(npoints+2) = curve->max_x; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
607 GET_Y(npoints+2) = curve->max_y; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
608 GET_X(npoints+3) = curve->max_x; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
609 GET_Y(npoints+3) = curve->max_y; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
610 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
611 xs_curve_update(curve); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
612 return TRUE; |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
613 } |
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
614 |
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
615 |
702 | 616 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
|
617 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
618 gint i, n; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
619 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
620 n = curve->nctlpoints - 4; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
621 |
702 | 622 *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
|
623 if (*points == NULL) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
624 return FALSE; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
625 |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
626 *npoints = n; |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
627 for (i = 2; i < curve->nctlpoints - 2; i++) { |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
628 (*points)[i].x = GET_X(i); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
629 (*points)[i].y = GET_Y(i); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
630 } |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
631 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
632 return TRUE; |
545
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
633 } |
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
634 |
425da926d310
Working on XSCurve widget implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
520
diff
changeset
|
635 |
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
|
636 GtkWidget *xs_curve_new(void) |
358 | 637 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
638 return gtk_type_new(xs_curve_get_type()); |
358 | 639 } |
640 | |
374
58079c6180a0
More removal of original curve code.
Matti Hamalainen <ccr@tnsp.org>
parents:
370
diff
changeset
|
641 |
502
54d86ee98b98
Alpha/preliminary curve widget code merged.
Matti Hamalainen <ccr@tnsp.org>
parents:
378
diff
changeset
|
642 static void xs_curve_finalize(GtkObject *object) |
358 | 643 { |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
644 XSCurve *curve; |
358 | 645 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
646 g_return_if_fail(object != NULL); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
647 g_return_if_fail(XS_IS_CURVE(object)); |
358 | 648 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
649 curve = XS_CURVE(object); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
650 if (curve->pixmap) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
651 gdk_pixmap_unref(curve->pixmap); |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
652 if (curve->ctlpoints) |
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
653 g_free(curve->ctlpoints); |
358 | 654 |
660
b0743dc9165d
Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
629
diff
changeset
|
655 (*GTK_OBJECT_CLASS(parent_class)->finalize) (object); |
358 | 656 } |