Mercurial > audlegacy
annotate Plugins/Visualization/paranormal/pn/pnfloatoption.c @ 1717:837983bac90f trunk
[svn] Fixed a lot of warnings that only showed up on *BSD.
author | js |
---|---|
date | Sat, 16 Sep 2006 16:26:54 -0700 |
parents | 6647d5cc717c |
children |
rev | line source |
---|---|
1507 | 1 /* Paranormal - A highly customizable audio visualization library |
2 * Copyright (C) 2001 Jamie Gennis <jgennis@mindspring.com> | |
3 * | |
4 * This library is free software; you can redistribute it and/or | |
5 * modify it under the terms of the GNU Library General Public | |
6 * License as published by the Free Software Foundation; either | |
7 * version 2 of the License, or (at your option) any later version. | |
8 * | |
9 * This library is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 * Library General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU Library General Public | |
15 * License along with this library; if not, write to the Free | |
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
17 */ | |
18 | |
19 #include <config.h> | |
20 | |
21 #include <stdlib.h> | |
22 #include <limits.h> | |
23 #include <glib.h> | |
24 #include "pnfloatoption.h" | |
25 #include "pnxml.h" | |
26 #include "pnerror.h" | |
27 | |
28 static void pn_float_option_class_init (PnFloatOptionClass *class); | |
29 static void pn_float_option_init (PnFloatOption *float_option, | |
30 PnFloatOptionClass *class); | |
31 | |
32 /* PnUserObject methods */ | |
33 static void pn_float_option_save_thyself (PnUserObject *user_object, | |
34 xmlNodePtr node); | |
35 static void pn_float_option_load_thyself (PnUserObject *user_object, | |
36 xmlNodePtr node); | |
37 | |
38 static PnUserObjectClass *parent_class = NULL; | |
39 | |
40 GType | |
41 pn_float_option_get_type (void) | |
42 { | |
43 static GType float_option_type = 0; | |
44 | |
45 if (! float_option_type) | |
46 { | |
47 static const GTypeInfo float_option_info = | |
48 { | |
49 sizeof (PnFloatOptionClass), | |
50 NULL, /* base_init */ | |
51 NULL, /* base_finalize */ | |
52 (GClassInitFunc) pn_float_option_class_init, | |
53 NULL, /* class_finalize */ | |
54 NULL, /* class_data */ | |
55 sizeof (PnFloatOption), | |
56 0, /* n_preallocs */ | |
57 (GInstanceInitFunc) pn_float_option_init | |
58 }; | |
59 | |
60 /* FIXME: should this be dynamic? */ | |
61 float_option_type = g_type_register_static (PN_TYPE_OPTION, | |
62 "PnFloatOption", | |
63 &float_option_info, | |
64 0); | |
65 } | |
66 return float_option_type; | |
67 } | |
68 | |
69 static void | |
70 pn_float_option_class_init (PnFloatOptionClass *class) | |
71 { | |
72 PnObjectClass *object_class; | |
73 PnUserObjectClass *user_object_class; | |
74 PnOptionClass *option_class; | |
75 | |
76 parent_class = g_type_class_peek_parent (class); | |
77 | |
78 object_class = (PnObjectClass *) class; | |
79 user_object_class = (PnUserObjectClass *) class; | |
80 option_class = (PnOptionClass *) class; | |
81 | |
82 /* PnUserObject methods */ | |
83 user_object_class->save_thyself = pn_float_option_save_thyself; | |
84 user_object_class->load_thyself = pn_float_option_load_thyself; | |
85 | |
86 /* PnOption methods */ | |
87 /* FIXME: this needs to be uncommented when the widget is done */ | |
88 /* option_class->widget_type = PN_TYPE_FLOAT_OPTION_WIDGET; */ | |
89 } | |
90 | |
91 static void | |
92 pn_float_option_init (PnFloatOption *float_option, | |
93 PnFloatOptionClass *class) | |
94 { | |
95 float_option->min = INT_MIN; | |
96 float_option->max = INT_MAX; | |
97 } | |
98 | |
99 static void | |
100 pn_float_option_save_thyself (PnUserObject *user_object, xmlNodePtr node) | |
101 { | |
102 PnFloatOption *float_option; | |
103 xmlNodePtr value_node; | |
104 gchar str[16]; | |
105 | |
106 g_return_if_fail (user_object != NULL); | |
107 g_return_if_fail (PN_IS_FLOAT_OPTION (user_object)); | |
108 g_return_if_fail (node != NULL); | |
109 | |
110 float_option = (PnFloatOption *) user_object; | |
111 | |
1591
02841f72b897
[svn] Cast variable to proper type before passing it into libxml2. Include necessary header to make this possible. Resolves 35 pointer signedness warnings on PPC.
chainsaw
parents:
1507
diff
changeset
|
112 value_node = xmlNewChild (node, NULL, (xmlChar *) "Value", NULL); |
1507 | 113 sprintf (str, "%f", float_option->value); |
1591
02841f72b897
[svn] Cast variable to proper type before passing it into libxml2. Include necessary header to make this possible. Resolves 35 pointer signedness warnings on PPC.
chainsaw
parents:
1507
diff
changeset
|
114 xmlNodeSetContent (value_node, (xmlChar *) str); |
1507 | 115 |
116 if (parent_class->save_thyself) | |
117 parent_class->save_thyself (user_object, node); | |
118 } | |
119 | |
120 static void | |
121 pn_float_option_load_thyself (PnUserObject *user_object, const xmlNodePtr node) | |
122 { | |
123 PnFloatOption *float_option; | |
124 xmlNodePtr float_option_node; | |
125 gchar *val_str; | |
126 | |
127 g_return_if_fail (user_object != NULL); | |
128 g_return_if_fail (PN_IS_FLOAT_OPTION (user_object)); | |
129 g_return_if_fail (node != NULL); | |
130 | |
131 float_option = (PnFloatOption *) user_object; | |
132 | |
133 /* find the node for this class */ | |
134 for (float_option_node = node->xmlChildrenNode; | |
135 float_option_node; | |
136 float_option_node = float_option_node->next) | |
1592
752949e9aec4
[svn] Actually cast variables to glib types before feeding them into glib compare functions. Resolves another 16 signedness warnings on PPC.
chainsaw
parents:
1591
diff
changeset
|
137 if (g_strcasecmp ((gchar *) float_option_node->name, "Value") == 0) |
1507 | 138 break; |
139 if (! float_option_node) | |
140 { | |
141 pn_error ("unable to load a PnFloatOption from xml node \"%s\"", node->name); | |
142 return; | |
143 } | |
144 | |
1593
6647d5cc717c
[svn] Additional (PPC?) warning squashing by Joseph Jezak from Gentoo.
chainsaw
parents:
1592
diff
changeset
|
145 val_str = (gchar *)xmlNodeGetContent (float_option_node); |
1507 | 146 |
147 if (val_str) | |
148 pn_float_option_set_value (float_option, strtod (val_str, NULL)); | |
149 else | |
150 { | |
151 pn_error ("invalid float option value encountered at xml node \"%s\"", node->name); | |
152 return; | |
153 } | |
154 | |
155 if (parent_class->load_thyself) | |
156 parent_class->load_thyself (user_object, node); | |
157 } | |
158 | |
159 PnFloatOption* | |
160 pn_float_option_new (const gchar *name, const gchar *desc) | |
161 { | |
162 PnFloatOption *float_option; | |
163 | |
164 g_return_val_if_fail (name != NULL, NULL); | |
165 g_return_val_if_fail (desc != NULL, NULL); | |
166 | |
167 float_option = (PnFloatOption *) g_object_new (PN_TYPE_FLOAT_OPTION, NULL); | |
168 | |
169 pn_user_object_set_name (PN_USER_OBJECT (float_option), name); | |
170 pn_user_object_set_description (PN_USER_OBJECT (float_option), desc); | |
171 | |
172 return float_option; | |
173 } | |
174 | |
175 void | |
176 pn_float_option_set_value (PnFloatOption *float_option, gfloat value) | |
177 { | |
178 g_return_if_fail (float_option != NULL); | |
179 g_return_if_fail (PN_IS_FLOAT_OPTION (float_option)); | |
180 | |
181 float_option->value = CLAMP (value, float_option->min, float_option->max); | |
182 } | |
183 | |
184 gfloat | |
185 pn_float_option_get_value (PnFloatOption *float_option) | |
186 { | |
187 g_return_val_if_fail (float_option != NULL, FALSE); | |
188 g_return_val_if_fail (PN_IS_FLOAT_OPTION (float_option), FALSE); | |
189 | |
190 return float_option->value; | |
191 } | |
192 | |
193 void | |
194 pn_float_option_set_min (PnFloatOption *float_option, gfloat min) | |
195 { | |
196 g_return_if_fail (float_option != NULL); | |
197 g_return_if_fail (PN_IS_FLOAT_OPTION (float_option)); | |
198 | |
199 if (min > float_option->max) | |
200 { | |
201 float_option->min = float_option->max; | |
202 float_option->max = min; | |
203 } | |
204 else | |
205 float_option->min = min; | |
206 | |
207 pn_float_option_set_value (float_option, float_option->value); | |
208 } | |
209 | |
210 gfloat | |
211 pn_float_option_get_min (PnFloatOption *float_option) | |
212 { | |
213 g_return_val_if_fail (float_option != NULL, FALSE); | |
214 g_return_val_if_fail (PN_IS_FLOAT_OPTION (float_option), FALSE); | |
215 | |
216 return float_option->min; | |
217 } | |
218 | |
219 void | |
220 pn_float_option_set_max (PnFloatOption *float_option, gfloat max) | |
221 { | |
222 g_return_if_fail (float_option != NULL); | |
223 g_return_if_fail (PN_IS_FLOAT_OPTION (float_option)); | |
224 | |
225 if (max < float_option->min) | |
226 { | |
227 float_option->max = float_option->min; | |
228 float_option->min = max; | |
229 } | |
230 else | |
231 float_option->max = max; | |
232 | |
233 pn_float_option_set_value (float_option, float_option->value); | |
234 } | |
235 | |
236 gfloat | |
237 pn_float_option_get_max (PnFloatOption *float_option) | |
238 { | |
239 g_return_val_if_fail (float_option != NULL, FALSE); | |
240 g_return_val_if_fail (PN_IS_FLOAT_OPTION (float_option), FALSE); | |
241 | |
242 return float_option->max; | |
243 } |