Mercurial > audlegacy-plugins
comparison src/skins/ui_skinned_equalizer_slider.c @ 2605:ecd8b5653c30
add ui_skinned_equalizer_slider
author | Tomasz Mon <desowin@gmail.com> |
---|---|
date | Wed, 21 May 2008 14:23:38 +0200 |
parents | |
children | ba91ea50f214 |
comparison
equal
deleted
inserted
replaced
2604:e732655e8191 | 2605:ecd8b5653c30 |
---|---|
1 /* | |
2 * Audacious - a cross-platform multimedia player | |
3 * Copyright (c) 2007 Tomasz Moń | |
4 * | |
5 * Based on: | |
6 * BMP - Cross-platform multimedia player | |
7 * Copyright (C) 2003-2004 BMP development team. | |
8 * XMMS: | |
9 * Copyright (C) 1998-2003 XMMS development team. | |
10 * | |
11 * This program is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; under version 3 of the License. | |
14 * | |
15 * This program is distributed in the hope that it will be useful, | |
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 * GNU General Public License for more details. | |
19 * | |
20 * You should have received a copy of the GNU General Public License | |
21 * along with this program; If not, see <http://www.gnu.org/licenses>. | |
22 */ | |
23 | |
24 #include "ui_skin.h" | |
25 #if 0 | |
26 #include "ui_equalizer.h" | |
27 #endif | |
28 #include "ui_main.h" | |
29 #include "skins_cfg.h" | |
30 #include "ui_skinned_equalizer_slider.h" | |
31 #include <glib/gi18n.h> | |
32 | |
33 #define UI_TYPE_SKINNED_EQUALIZER_SLIDER (ui_skinned_equalizer_slider_get_type()) | |
34 #define UI_SKINNED_EQUALIZER_SLIDER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), UI_TYPE_SKINNED_EQUALIZER_SLIDER, UiSkinnedEqualizerSliderPrivate)) | |
35 typedef struct _UiSkinnedEqualizerSliderPrivate UiSkinnedEqualizerSliderPrivate; | |
36 | |
37 enum { | |
38 DOUBLED, | |
39 LAST_SIGNAL | |
40 }; | |
41 | |
42 struct _UiSkinnedEqualizerSliderPrivate { | |
43 SkinPixmapId skin_index; | |
44 gboolean scaled; | |
45 gint position; | |
46 gint width, height; | |
47 gboolean pressed; | |
48 gint drag_y; | |
49 gfloat value; /* store gain as is to prevent truncation --asphyx */ | |
50 }; | |
51 | |
52 static void ui_skinned_equalizer_slider_class_init (UiSkinnedEqualizerSliderClass *klass); | |
53 static void ui_skinned_equalizer_slider_init (UiSkinnedEqualizerSlider *equalizer_slider); | |
54 static void ui_skinned_equalizer_slider_destroy (GtkObject *object); | |
55 static void ui_skinned_equalizer_slider_realize (GtkWidget *widget); | |
56 static void ui_skinned_equalizer_slider_size_request (GtkWidget *widget, GtkRequisition *requisition); | |
57 static void ui_skinned_equalizer_slider_size_allocate (GtkWidget *widget, GtkAllocation *allocation); | |
58 static gboolean ui_skinned_equalizer_slider_expose (GtkWidget *widget, GdkEventExpose *event); | |
59 static gboolean ui_skinned_equalizer_slider_button_press (GtkWidget *widget, GdkEventButton *event); | |
60 static gboolean ui_skinned_equalizer_slider_button_release (GtkWidget *widget, GdkEventButton *event); | |
61 static gboolean ui_skinned_equalizer_slider_motion_notify (GtkWidget *widget, GdkEventMotion *event); | |
62 static gboolean ui_skinned_equalizer_slider_scroll (GtkWidget *widget, GdkEventScroll *event); | |
63 static void ui_skinned_equalizer_slider_toggle_scaled (UiSkinnedEqualizerSlider *equalizer_slider); | |
64 void ui_skinned_equalizer_slider_set_mainwin_text (UiSkinnedEqualizerSlider * es); | |
65 | |
66 static GtkWidgetClass *parent_class = NULL; | |
67 static guint equalizer_slider_signals[LAST_SIGNAL] = { 0 }; | |
68 | |
69 GType ui_skinned_equalizer_slider_get_type() { | |
70 static GType equalizer_slider_type = 0; | |
71 if (!equalizer_slider_type) { | |
72 static const GTypeInfo equalizer_slider_info = { | |
73 sizeof (UiSkinnedEqualizerSliderClass), | |
74 NULL, | |
75 NULL, | |
76 (GClassInitFunc) ui_skinned_equalizer_slider_class_init, | |
77 NULL, | |
78 NULL, | |
79 sizeof (UiSkinnedEqualizerSlider), | |
80 0, | |
81 (GInstanceInitFunc) ui_skinned_equalizer_slider_init, | |
82 }; | |
83 equalizer_slider_type = g_type_register_static (GTK_TYPE_WIDGET, "UiSkinnedEqualizerSlider", &equalizer_slider_info, 0); | |
84 } | |
85 | |
86 return equalizer_slider_type; | |
87 } | |
88 | |
89 static void ui_skinned_equalizer_slider_class_init(UiSkinnedEqualizerSliderClass *klass) { | |
90 GObjectClass *gobject_class; | |
91 GtkObjectClass *object_class; | |
92 GtkWidgetClass *widget_class; | |
93 | |
94 gobject_class = G_OBJECT_CLASS(klass); | |
95 object_class = (GtkObjectClass*) klass; | |
96 widget_class = (GtkWidgetClass*) klass; | |
97 parent_class = gtk_type_class (gtk_widget_get_type ()); | |
98 | |
99 object_class->destroy = ui_skinned_equalizer_slider_destroy; | |
100 | |
101 widget_class->realize = ui_skinned_equalizer_slider_realize; | |
102 widget_class->expose_event = ui_skinned_equalizer_slider_expose; | |
103 widget_class->size_request = ui_skinned_equalizer_slider_size_request; | |
104 widget_class->size_allocate = ui_skinned_equalizer_slider_size_allocate; | |
105 widget_class->button_press_event = ui_skinned_equalizer_slider_button_press; | |
106 widget_class->button_release_event = ui_skinned_equalizer_slider_button_release; | |
107 widget_class->motion_notify_event = ui_skinned_equalizer_slider_motion_notify; | |
108 widget_class->scroll_event = ui_skinned_equalizer_slider_scroll; | |
109 | |
110 klass->scaled = ui_skinned_equalizer_slider_toggle_scaled; | |
111 | |
112 equalizer_slider_signals[DOUBLED] = | |
113 g_signal_new ("toggle-scaled", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, | |
114 G_STRUCT_OFFSET (UiSkinnedEqualizerSliderClass, scaled), NULL, NULL, | |
115 gtk_marshal_VOID__VOID, G_TYPE_NONE, 0); | |
116 | |
117 g_type_class_add_private (gobject_class, sizeof (UiSkinnedEqualizerSliderPrivate)); | |
118 } | |
119 | |
120 static void ui_skinned_equalizer_slider_init(UiSkinnedEqualizerSlider *equalizer_slider) { | |
121 UiSkinnedEqualizerSliderPrivate *priv = UI_SKINNED_EQUALIZER_SLIDER_GET_PRIVATE(equalizer_slider); | |
122 priv->pressed = FALSE; | |
123 } | |
124 | |
125 GtkWidget* ui_skinned_equalizer_slider_new(GtkWidget *fixed, gint x, gint y) { | |
126 UiSkinnedEqualizerSlider *es = g_object_new (ui_skinned_equalizer_slider_get_type (), NULL); | |
127 UiSkinnedEqualizerSliderPrivate *priv = UI_SKINNED_EQUALIZER_SLIDER_GET_PRIVATE(es); | |
128 | |
129 es->x = x; | |
130 es->y = y; | |
131 priv->width = 14; | |
132 priv->height = 63; | |
133 priv->skin_index = SKIN_EQMAIN; | |
134 | |
135 gtk_fixed_put(GTK_FIXED(fixed), GTK_WIDGET(es), es->x, es->y); | |
136 | |
137 return GTK_WIDGET(es); | |
138 } | |
139 | |
140 static void ui_skinned_equalizer_slider_destroy(GtkObject *object) { | |
141 UiSkinnedEqualizerSlider *equalizer_slider; | |
142 | |
143 g_return_if_fail (object != NULL); | |
144 g_return_if_fail (UI_SKINNED_IS_EQUALIZER_SLIDER (object)); | |
145 | |
146 equalizer_slider = UI_SKINNED_EQUALIZER_SLIDER (object); | |
147 | |
148 if (GTK_OBJECT_CLASS (parent_class)->destroy) | |
149 (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); | |
150 } | |
151 | |
152 static void ui_skinned_equalizer_slider_realize(GtkWidget *widget) { | |
153 UiSkinnedEqualizerSlider *equalizer_slider; | |
154 GdkWindowAttr attributes; | |
155 gint attributes_mask; | |
156 | |
157 g_return_if_fail (widget != NULL); | |
158 g_return_if_fail (UI_SKINNED_IS_EQUALIZER_SLIDER(widget)); | |
159 | |
160 GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED); | |
161 equalizer_slider = UI_SKINNED_EQUALIZER_SLIDER(widget); | |
162 | |
163 attributes.x = widget->allocation.x; | |
164 attributes.y = widget->allocation.y; | |
165 attributes.width = widget->allocation.width; | |
166 attributes.height = widget->allocation.height; | |
167 attributes.wclass = GDK_INPUT_OUTPUT; | |
168 attributes.window_type = GDK_WINDOW_CHILD; | |
169 attributes.event_mask = gtk_widget_get_events(widget); | |
170 attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | | |
171 GDK_POINTER_MOTION_MASK | GDK_SCROLL_MASK; | |
172 attributes.visual = gtk_widget_get_visual(widget); | |
173 attributes.colormap = gtk_widget_get_colormap(widget); | |
174 | |
175 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; | |
176 widget->window = gdk_window_new(widget->parent->window, &attributes, attributes_mask); | |
177 | |
178 widget->style = gtk_style_attach(widget->style, widget->window); | |
179 gdk_window_set_user_data(widget->window, widget); | |
180 } | |
181 | |
182 static void ui_skinned_equalizer_slider_size_request(GtkWidget *widget, GtkRequisition *requisition) { | |
183 UiSkinnedEqualizerSliderPrivate *priv = UI_SKINNED_EQUALIZER_SLIDER_GET_PRIVATE(widget); | |
184 | |
185 requisition->width = priv->width*(priv->scaled ? config.scale_factor : 1); | |
186 requisition->height = priv->height*(priv->scaled ? config.scale_factor : 1); | |
187 } | |
188 | |
189 static void ui_skinned_equalizer_slider_size_allocate(GtkWidget *widget, GtkAllocation *allocation) { | |
190 UiSkinnedEqualizerSlider *equalizer_slider = UI_SKINNED_EQUALIZER_SLIDER (widget); | |
191 UiSkinnedEqualizerSliderPrivate *priv = UI_SKINNED_EQUALIZER_SLIDER_GET_PRIVATE(equalizer_slider); | |
192 | |
193 widget->allocation = *allocation; | |
194 widget->allocation.x *= (priv->scaled ? config.scale_factor : 1); | |
195 widget->allocation.y *= (priv->scaled ? config.scale_factor : 1); | |
196 if (GTK_WIDGET_REALIZED (widget)) | |
197 gdk_window_move_resize(widget->window, widget->allocation.x, widget->allocation.y, allocation->width, allocation->height); | |
198 | |
199 equalizer_slider->x = widget->allocation.x/(priv->scaled ? config.scale_factor : 1); | |
200 equalizer_slider->y = widget->allocation.y/(priv->scaled ? config.scale_factor : 1); | |
201 } | |
202 | |
203 static gboolean ui_skinned_equalizer_slider_expose(GtkWidget *widget, GdkEventExpose *event) { | |
204 g_return_val_if_fail (widget != NULL, FALSE); | |
205 g_return_val_if_fail (UI_SKINNED_IS_EQUALIZER_SLIDER (widget), FALSE); | |
206 g_return_val_if_fail (event != NULL, FALSE); | |
207 | |
208 UiSkinnedEqualizerSlider *es = UI_SKINNED_EQUALIZER_SLIDER (widget); | |
209 UiSkinnedEqualizerSliderPrivate *priv = UI_SKINNED_EQUALIZER_SLIDER_GET_PRIVATE(es); | |
210 g_return_val_if_fail (priv->width > 0 && priv->height > 0, FALSE); | |
211 | |
212 GdkPixbuf *obj = NULL; | |
213 obj = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, priv->width, priv->height); | |
214 | |
215 gint frame; | |
216 frame = 27 - ((priv->position * 27) / 50); | |
217 if (frame < 14) | |
218 skin_draw_pixbuf(widget, aud_active_skin, obj, priv->skin_index, (frame * 15) + 13, 164, 0, 0, priv->width, priv->height); | |
219 else | |
220 skin_draw_pixbuf(widget, aud_active_skin, obj, priv->skin_index, ((frame - 14) * 15) + 13, 229, 0, 0, priv->width, priv->height); | |
221 | |
222 if (priv->pressed) | |
223 skin_draw_pixbuf(widget, aud_active_skin, obj, priv->skin_index, 0, 176, 1, priv->position, 11, 11); | |
224 else | |
225 skin_draw_pixbuf(widget, aud_active_skin, obj, priv->skin_index, 0, 164, 1, priv->position, 11, 11); | |
226 | |
227 ui_skinned_widget_draw(widget, obj, priv->width, priv->height, priv->scaled); | |
228 | |
229 g_object_unref(obj); | |
230 | |
231 return FALSE; | |
232 } | |
233 | |
234 static gboolean ui_skinned_equalizer_slider_button_press(GtkWidget *widget, GdkEventButton *event) { | |
235 g_return_val_if_fail (widget != NULL, FALSE); | |
236 g_return_val_if_fail (UI_SKINNED_IS_EQUALIZER_SLIDER (widget), FALSE); | |
237 g_return_val_if_fail (event != NULL, FALSE); | |
238 | |
239 UiSkinnedEqualizerSlider *es = UI_SKINNED_EQUALIZER_SLIDER (widget); | |
240 UiSkinnedEqualizerSliderPrivate *priv = UI_SKINNED_EQUALIZER_SLIDER_GET_PRIVATE(es); | |
241 | |
242 gint y; | |
243 | |
244 if (event->type == GDK_BUTTON_PRESS) { | |
245 if (event->button == 1) { | |
246 priv->pressed = TRUE; | |
247 y = event->y/(priv->scaled ? config.scale_factor : 1); | |
248 | |
249 if (y >= priv->position && y < priv->position + 11) | |
250 priv->drag_y = y - priv->position; | |
251 else { | |
252 priv->position = y - 5; | |
253 priv->drag_y = 5; | |
254 if (priv->position < 0) | |
255 priv->position = 0; | |
256 if (priv->position > 50) | |
257 priv->position = 50; | |
258 if (priv->position >= 24 && priv->position <= 26) | |
259 priv->position = 25; | |
260 | |
261 priv->value = ((gfloat) (25 - priv->position) * EQUALIZER_MAX_GAIN / 25.0 ); | |
262 #if 0 | |
263 equalizerwin_eq_changed(); | |
264 #endif | |
265 } | |
266 | |
267 ui_skinned_equalizer_slider_set_mainwin_text(es); | |
268 gtk_widget_queue_draw(widget); | |
269 } | |
270 } | |
271 | |
272 return TRUE; | |
273 } | |
274 | |
275 static gboolean ui_skinned_equalizer_slider_button_release(GtkWidget *widget, GdkEventButton *event) { | |
276 UiSkinnedEqualizerSliderPrivate *priv = UI_SKINNED_EQUALIZER_SLIDER_GET_PRIVATE(widget); | |
277 | |
278 if (event->button == 1) { | |
279 priv->pressed = FALSE; | |
280 mainwin_release_info_text(); | |
281 gtk_widget_queue_draw(widget); | |
282 } | |
283 return TRUE; | |
284 } | |
285 | |
286 static gboolean ui_skinned_equalizer_slider_motion_notify(GtkWidget *widget, GdkEventMotion *event) { | |
287 g_return_val_if_fail (widget != NULL, FALSE); | |
288 g_return_val_if_fail (UI_SKINNED_IS_EQUALIZER_SLIDER (widget), FALSE); | |
289 g_return_val_if_fail (event != NULL, FALSE); | |
290 UiSkinnedEqualizerSlider *es = UI_SKINNED_EQUALIZER_SLIDER(widget); | |
291 UiSkinnedEqualizerSliderPrivate *priv = UI_SKINNED_EQUALIZER_SLIDER_GET_PRIVATE(widget); | |
292 | |
293 if (priv->pressed) { | |
294 gint y; | |
295 | |
296 y = event->y/(priv->scaled ? config.scale_factor : 1); | |
297 priv->position = y - priv->drag_y; | |
298 | |
299 if (priv->position < 0) | |
300 priv->position = 0; | |
301 if (priv->position > 50) | |
302 priv->position = 50; | |
303 if (priv->position >= 24 && priv->position <= 26) | |
304 priv->position = 25; | |
305 | |
306 priv->value = ((gfloat) (25 - priv->position) * EQUALIZER_MAX_GAIN / 25.0 ); | |
307 ui_skinned_equalizer_slider_set_mainwin_text(es); | |
308 #if 0 | |
309 equalizerwin_eq_changed(); | |
310 #endif | |
311 gtk_widget_queue_draw(widget); | |
312 } | |
313 | |
314 return TRUE; | |
315 } | |
316 | |
317 static gboolean ui_skinned_equalizer_slider_scroll(GtkWidget *widget, GdkEventScroll *event) { | |
318 g_return_val_if_fail (UI_SKINNED_IS_EQUALIZER_SLIDER (widget), FALSE); | |
319 g_return_val_if_fail (event != NULL, FALSE); | |
320 UiSkinnedEqualizerSliderPrivate *priv = UI_SKINNED_EQUALIZER_SLIDER_GET_PRIVATE(widget); | |
321 | |
322 if (event->direction == GDK_SCROLL_UP) { | |
323 priv->position -= 2; | |
324 | |
325 if (priv->position < 0) | |
326 priv->position = 0; | |
327 } | |
328 else { | |
329 priv->position += 2; | |
330 | |
331 if (priv->position > 50) | |
332 priv->position = 50; | |
333 } | |
334 | |
335 priv->value = ((gfloat) (25 - priv->position) * EQUALIZER_MAX_GAIN / 25.0 ); | |
336 #if 0 | |
337 equalizerwin_eq_changed(); | |
338 #endif | |
339 gtk_widget_queue_draw(widget); | |
340 return TRUE; | |
341 } | |
342 | |
343 static void ui_skinned_equalizer_slider_toggle_scaled(UiSkinnedEqualizerSlider *equalizer_slider) { | |
344 GtkWidget *widget = GTK_WIDGET (equalizer_slider); | |
345 UiSkinnedEqualizerSliderPrivate *priv = UI_SKINNED_EQUALIZER_SLIDER_GET_PRIVATE(equalizer_slider); | |
346 | |
347 priv->scaled = !priv->scaled; | |
348 | |
349 gtk_widget_set_size_request(widget, priv->width*(priv->scaled ? config.scale_factor : 1), | |
350 priv->height*(priv->scaled ? config.scale_factor : 1)); | |
351 | |
352 gtk_widget_queue_draw(GTK_WIDGET(equalizer_slider)); | |
353 } | |
354 | |
355 void ui_skinned_equalizer_slider_set_position(GtkWidget *widget, gfloat pos) { | |
356 g_return_if_fail (UI_SKINNED_IS_EQUALIZER_SLIDER (widget)); | |
357 UiSkinnedEqualizerSliderPrivate *priv = UI_SKINNED_EQUALIZER_SLIDER_GET_PRIVATE(widget); | |
358 | |
359 if (priv->pressed) | |
360 return; | |
361 | |
362 priv->value = (pos > EQUALIZER_MAX_GAIN) ? EQUALIZER_MAX_GAIN : ((pos < -EQUALIZER_MAX_GAIN) ? -EQUALIZER_MAX_GAIN : pos); | |
363 priv->position = 25 - (gint) ((pos * 25.0) / EQUALIZER_MAX_GAIN); | |
364 | |
365 if (priv->position < 0) | |
366 priv->position = 0; | |
367 | |
368 if (priv->position > 50) | |
369 priv->position = 50; | |
370 | |
371 if (priv->position >= 24 && priv->position <= 26) | |
372 priv->position = 25; | |
373 | |
374 gtk_widget_queue_draw(widget); | |
375 } | |
376 | |
377 gfloat ui_skinned_equalizer_slider_get_position(GtkWidget *widget) { | |
378 g_return_val_if_fail (UI_SKINNED_IS_EQUALIZER_SLIDER (widget), -1); | |
379 UiSkinnedEqualizerSliderPrivate *priv = UI_SKINNED_EQUALIZER_SLIDER_GET_PRIVATE(widget); | |
380 return priv->value; | |
381 } | |
382 | |
383 void ui_skinned_equalizer_slider_set_mainwin_text(UiSkinnedEqualizerSlider * es) { | |
384 gint band = 0; | |
385 const gchar *bandname[11] = { N_("PREAMP"), N_("60HZ"), N_("170HZ"), | |
386 N_("310HZ"), N_("600HZ"), N_("1KHZ"), | |
387 N_("3KHZ"), N_("6KHZ"), N_("12KHZ"), | |
388 N_("14KHZ"), N_("16KHZ") | |
389 }; | |
390 gchar *tmp; | |
391 | |
392 if (es->x > 21) | |
393 band = ((es->x - 78) / 18) + 1; | |
394 | |
395 tmp = | |
396 g_strdup_printf("EQ: %s: %+.1f DB", _(bandname[band]), | |
397 ui_skinned_equalizer_slider_get_position(GTK_WIDGET(es))); | |
398 mainwin_lock_info_text(tmp); | |
399 g_free(tmp); | |
400 } |