0
|
1 /* BMP - Cross-platform multimedia player
|
|
2 * Copyright (C) 2003-2004 BMP development team.
|
|
3 *
|
|
4 * Based on XMMS:
|
|
5 * Copyright (C) 1998-2003 XMMS development team.
|
|
6 *
|
|
7 * This program is free software; you can redistribute it and/or modify
|
|
8 * it under the terms of the GNU General Public License as published by
|
|
9 * the Free Software Foundation; either version 2 of the License, or
|
|
10 * (at your option) any later version.
|
|
11 *
|
|
12 * This program is distributed in the hope that it will be useful,
|
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 * GNU General Public License for more details.
|
|
16 *
|
|
17 * You should have received a copy of the GNU General Public License
|
|
18 * along with this program; if not, write to the Free Software
|
|
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
20 */
|
|
21
|
|
22 #include "eq_slider.h"
|
|
23
|
|
24 #include <glib.h>
|
|
25 #include <glib/gi18n.h>
|
|
26 #include <gtk/gtk.h>
|
|
27 #include <gdk/gdk.h>
|
|
28
|
|
29 #include "equalizer.h"
|
|
30 #include "mainwin.h"
|
|
31 #include "skin.h"
|
|
32
|
|
33 void
|
|
34 eqslider_set_position(EqSlider * es,
|
|
35 gfloat pos)
|
|
36 {
|
|
37 es->es_position = 25 - (gint) ((pos * 25.0) / 20.0);
|
|
38
|
|
39 if (es->es_position < 0)
|
|
40 es->es_position = 0;
|
|
41
|
|
42 if (es->es_position > 50)
|
|
43 es->es_position = 50;
|
|
44
|
|
45 if (es->es_position >= 24 && es->es_position <= 26)
|
|
46 es->es_position = 25;
|
|
47
|
|
48 widget_draw(WIDGET(es));
|
|
49 }
|
|
50
|
|
51 gfloat
|
|
52 eqslider_get_position(EqSlider * es)
|
|
53 {
|
|
54 return 20.0 - (((gfloat) es->es_position * 20.0) / 25.0);
|
|
55 }
|
|
56
|
|
57 void
|
|
58 eqslider_draw(Widget * w)
|
|
59 {
|
|
60 EqSlider *es = (EqSlider *) w;
|
|
61 GdkPixmap *obj;
|
|
62 SkinPixmapId src;
|
|
63 gint frame;
|
|
64
|
|
65 src = SKIN_EQMAIN;
|
|
66 obj = es->es_widget.parent;
|
|
67
|
|
68 frame = 27 - ((es->es_position * 27) / 50);
|
|
69 if (frame < 14)
|
|
70 skin_draw_pixmap(bmp_active_skin, obj, es->es_widget.gc, src,
|
|
71 (frame * 15) + 13, 164, es->es_widget.x,
|
|
72 es->es_widget.y, es->es_widget.width,
|
|
73 es->es_widget.height);
|
|
74 else
|
|
75 skin_draw_pixmap(bmp_active_skin, obj, es->es_widget.gc, src,
|
|
76 ((frame - 14) * 15) + 13, 229, es->es_widget.x,
|
|
77 es->es_widget.y, es->es_widget.width,
|
|
78 es->es_widget.height);
|
|
79 if (es->es_isdragging)
|
|
80 skin_draw_pixmap(bmp_active_skin, obj, es->es_widget.gc, src, 0,
|
|
81 176, es->es_widget.x + 1,
|
|
82 es->es_widget.y + es->es_position, 11, 11);
|
|
83 else
|
|
84 skin_draw_pixmap(bmp_active_skin, obj, es->es_widget.gc, src, 0,
|
|
85 164, es->es_widget.x + 1,
|
|
86 es->es_widget.y + es->es_position, 11, 11);
|
|
87 }
|
|
88
|
|
89 void
|
|
90 eqslider_set_mainwin_text(EqSlider * es)
|
|
91 {
|
|
92 gint band = 0;
|
|
93 const gchar *bandname[11] = { N_("PREAMP"), N_("60HZ"), N_("170HZ"),
|
|
94 N_("310HZ"), N_("600HZ"), N_("1KHZ"),
|
|
95 N_("3KHZ"), N_("6KHZ"), N_("12KHZ"),
|
|
96 N_("14KHZ"), N_("16KHZ")
|
|
97 };
|
|
98 gchar *tmp;
|
|
99
|
|
100 if (es->es_widget.x > 21)
|
|
101 band = ((es->es_widget.x - 78) / 18) + 1;
|
|
102
|
|
103 tmp =
|
|
104 g_strdup_printf("EQ: %s: %+.1f DB", _(bandname[band]),
|
|
105 eqslider_get_position(es));
|
|
106 mainwin_lock_info_text(tmp);
|
|
107 g_free(tmp);
|
|
108 }
|
|
109
|
|
110 void
|
|
111 eqslider_button_press_cb(GtkWidget * w,
|
|
112 GdkEventButton * event,
|
|
113 gpointer data)
|
|
114 {
|
|
115 EqSlider *es = EQ_SLIDER(data);
|
|
116 gint y;
|
|
117
|
|
118 if (widget_contains(&es->es_widget, event->x, event->y)) {
|
|
119 if (event->button == 1) {
|
|
120 y = event->y - es->es_widget.y;
|
|
121 es->es_isdragging = TRUE;
|
|
122 if (y >= es->es_position && y < es->es_position + 11)
|
|
123 es->es_drag_y = y - es->es_position;
|
|
124 else {
|
|
125 es->es_position = y - 5;
|
|
126 es->es_drag_y = 5;
|
|
127 if (es->es_position < 0)
|
|
128 es->es_position = 0;
|
|
129 if (es->es_position > 50)
|
|
130 es->es_position = 50;
|
|
131 if (es->es_position >= 24 && es->es_position <= 26)
|
|
132 es->es_position = 25;
|
|
133 equalizerwin_eq_changed();
|
|
134 }
|
|
135
|
|
136 eqslider_set_mainwin_text(es);
|
|
137 widget_draw(WIDGET(es));
|
|
138 }
|
|
139 if (event->button == 4) {
|
|
140 es->es_position -= 2;
|
|
141 if (es->es_position < 0)
|
|
142 es->es_position = 0;
|
|
143 equalizerwin_eq_changed();
|
|
144 widget_draw(WIDGET(es));
|
|
145 }
|
|
146 }
|
|
147 }
|
|
148
|
|
149 void
|
|
150 eqslider_mouse_scroll_cb(GtkWidget * w,
|
|
151 GdkEventScroll * event,
|
|
152 gpointer data)
|
|
153 {
|
|
154 EqSlider *es = EQ_SLIDER(data);
|
|
155
|
|
156 if (!widget_contains(&es->es_widget, event->x, event->y))
|
|
157 return;
|
|
158
|
|
159 if (event->direction == GDK_SCROLL_UP) {
|
|
160 es->es_position -= 2;
|
|
161
|
|
162 if (es->es_position < 0)
|
|
163 es->es_position = 0;
|
|
164
|
|
165 equalizerwin_eq_changed();
|
|
166 widget_draw(WIDGET(es));
|
|
167 }
|
|
168 else {
|
|
169 es->es_position += 2;
|
|
170
|
|
171 if (es->es_position > 50)
|
|
172 es->es_position = 50;
|
|
173
|
|
174 equalizerwin_eq_changed();
|
|
175 widget_draw(WIDGET(es));
|
|
176 }
|
|
177 }
|
|
178
|
|
179 void
|
|
180 eqslider_motion_cb(GtkWidget * w,
|
|
181 GdkEventMotion * event,
|
|
182 gpointer data)
|
|
183 {
|
|
184 EqSlider *es = EQ_SLIDER(data);
|
|
185 gint y;
|
|
186
|
|
187 y = event->y - es->es_widget.y;
|
|
188 if (es->es_isdragging) {
|
|
189 es->es_position = y - es->es_drag_y;
|
|
190 if (es->es_position < 0)
|
|
191 es->es_position = 0;
|
|
192 if (es->es_position > 50)
|
|
193 es->es_position = 50;
|
|
194 if (es->es_position >= 24 && es->es_position <= 26)
|
|
195 es->es_position = 25;
|
|
196 equalizerwin_eq_changed();
|
|
197 eqslider_set_mainwin_text(es);
|
|
198 widget_draw(WIDGET(es));
|
|
199 }
|
|
200 }
|
|
201
|
|
202 void
|
|
203 eqslider_button_release_cb(GtkWidget * w,
|
|
204 GdkEventButton * event,
|
|
205 gpointer data)
|
|
206 {
|
|
207 EqSlider *es = EQ_SLIDER(data);
|
|
208
|
|
209 if (es->es_isdragging) {
|
|
210 es->es_isdragging = FALSE;
|
|
211 mainwin_release_info_text();
|
|
212 widget_draw(WIDGET(es));
|
|
213 }
|
|
214 }
|
|
215
|
|
216 EqSlider *
|
|
217 create_eqslider(GList ** wlist,
|
|
218 GdkPixmap * parent,
|
|
219 GdkGC * gc,
|
|
220 gint x, gint y)
|
|
221 {
|
|
222 EqSlider *es;
|
|
223
|
|
224 es = g_new0(EqSlider, 1);
|
|
225 widget_init(&es->es_widget, parent, gc, x, y, 14, 63, TRUE);
|
|
226 es->es_widget.button_press_cb = eqslider_button_press_cb;
|
|
227 es->es_widget.button_release_cb = eqslider_button_release_cb;
|
|
228 es->es_widget.motion_cb = eqslider_motion_cb;
|
|
229 es->es_widget.draw = eqslider_draw;
|
|
230 es->es_widget.mouse_scroll_cb = eqslider_mouse_scroll_cb;
|
|
231
|
|
232 widget_list_add(wlist, WIDGET(es));
|
|
233
|
|
234 return es;
|
|
235 }
|