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