Mercurial > audlegacy-plugins
annotate src/skins/ui_skinned_equalizer_slider.c @ 3103:b562bc52a93e
ported OSS
author | Michal Lipski <tallica@o2.pl> |
---|---|
date | Thu, 30 Apr 2009 18:06:46 +0200 |
parents | 6baa6eaf8290 |
children |
rev | line source |
---|---|
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); | |
2888
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
54 static void ui_skinned_equalizer_slider_unrealize (GtkWidget *widget); |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
55 static void ui_skinned_equalizer_slider_map (GtkWidget *widget); |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
56 static void ui_skinned_equalizer_slider_unmap (GtkWidget *widget); |
2605 | 57 static void ui_skinned_equalizer_slider_size_request (GtkWidget *widget, GtkRequisition *requisition); |
58 static void ui_skinned_equalizer_slider_size_allocate (GtkWidget *widget, GtkAllocation *allocation); | |
59 static gboolean ui_skinned_equalizer_slider_expose (GtkWidget *widget, GdkEventExpose *event); | |
60 static gboolean ui_skinned_equalizer_slider_button_press (GtkWidget *widget, GdkEventButton *event); | |
61 static gboolean ui_skinned_equalizer_slider_button_release (GtkWidget *widget, GdkEventButton *event); | |
62 static gboolean ui_skinned_equalizer_slider_motion_notify (GtkWidget *widget, GdkEventMotion *event); | |
63 static gboolean ui_skinned_equalizer_slider_scroll (GtkWidget *widget, GdkEventScroll *event); | |
64 static void ui_skinned_equalizer_slider_toggle_scaled (UiSkinnedEqualizerSlider *equalizer_slider); | |
65 void ui_skinned_equalizer_slider_set_mainwin_text (UiSkinnedEqualizerSlider * es); | |
66 | |
67 static GtkWidgetClass *parent_class = NULL; | |
68 static guint equalizer_slider_signals[LAST_SIGNAL] = { 0 }; | |
69 | |
70 GType ui_skinned_equalizer_slider_get_type() { | |
71 static GType equalizer_slider_type = 0; | |
72 if (!equalizer_slider_type) { | |
73 static const GTypeInfo equalizer_slider_info = { | |
74 sizeof (UiSkinnedEqualizerSliderClass), | |
75 NULL, | |
76 NULL, | |
77 (GClassInitFunc) ui_skinned_equalizer_slider_class_init, | |
78 NULL, | |
79 NULL, | |
80 sizeof (UiSkinnedEqualizerSlider), | |
81 0, | |
82 (GInstanceInitFunc) ui_skinned_equalizer_slider_init, | |
83 }; | |
84 equalizer_slider_type = g_type_register_static (GTK_TYPE_WIDGET, "UiSkinnedEqualizerSlider", &equalizer_slider_info, 0); | |
85 } | |
86 | |
87 return equalizer_slider_type; | |
88 } | |
89 | |
90 static void ui_skinned_equalizer_slider_class_init(UiSkinnedEqualizerSliderClass *klass) { | |
91 GObjectClass *gobject_class; | |
92 GtkObjectClass *object_class; | |
93 GtkWidgetClass *widget_class; | |
94 | |
95 gobject_class = G_OBJECT_CLASS(klass); | |
96 object_class = (GtkObjectClass*) klass; | |
97 widget_class = (GtkWidgetClass*) klass; | |
3032
6baa6eaf8290
Don't use deprecated gtk_type_class()
Tomasz Mon <desowin@gmail.com>
parents:
3017
diff
changeset
|
98 parent_class = g_type_class_peek_parent(klass); |
2605 | 99 |
100 object_class->destroy = ui_skinned_equalizer_slider_destroy; | |
101 | |
102 widget_class->realize = ui_skinned_equalizer_slider_realize; | |
2888
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
103 widget_class->unrealize = ui_skinned_equalizer_slider_unrealize; |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
104 widget_class->map = ui_skinned_equalizer_slider_map; |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
105 widget_class->unmap = ui_skinned_equalizer_slider_unmap; |
2605 | 106 widget_class->expose_event = ui_skinned_equalizer_slider_expose; |
107 widget_class->size_request = ui_skinned_equalizer_slider_size_request; | |
108 widget_class->size_allocate = ui_skinned_equalizer_slider_size_allocate; | |
109 widget_class->button_press_event = ui_skinned_equalizer_slider_button_press; | |
110 widget_class->button_release_event = ui_skinned_equalizer_slider_button_release; | |
111 widget_class->motion_notify_event = ui_skinned_equalizer_slider_motion_notify; | |
112 widget_class->scroll_event = ui_skinned_equalizer_slider_scroll; | |
113 | |
114 klass->scaled = ui_skinned_equalizer_slider_toggle_scaled; | |
115 | |
116 equalizer_slider_signals[DOUBLED] = | |
117 g_signal_new ("toggle-scaled", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, | |
118 G_STRUCT_OFFSET (UiSkinnedEqualizerSliderClass, scaled), NULL, NULL, | |
3017
963796db51ea
Don't use deprecated gtk macros and types
Tomasz Mon <desowin@gmail.com>
parents:
2888
diff
changeset
|
119 g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); |
2605 | 120 |
121 g_type_class_add_private (gobject_class, sizeof (UiSkinnedEqualizerSliderPrivate)); | |
122 } | |
123 | |
124 static void ui_skinned_equalizer_slider_init(UiSkinnedEqualizerSlider *equalizer_slider) { | |
125 UiSkinnedEqualizerSliderPrivate *priv = UI_SKINNED_EQUALIZER_SLIDER_GET_PRIVATE(equalizer_slider); | |
126 priv->pressed = FALSE; | |
2888
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
127 |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
128 equalizer_slider->event_window = NULL; |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
129 GTK_WIDGET_SET_FLAGS(equalizer_slider, GTK_NO_WINDOW); |
2605 | 130 } |
131 | |
132 GtkWidget* ui_skinned_equalizer_slider_new(GtkWidget *fixed, gint x, gint y) { | |
133 UiSkinnedEqualizerSlider *es = g_object_new (ui_skinned_equalizer_slider_get_type (), NULL); | |
134 UiSkinnedEqualizerSliderPrivate *priv = UI_SKINNED_EQUALIZER_SLIDER_GET_PRIVATE(es); | |
135 | |
136 es->x = x; | |
137 es->y = y; | |
138 priv->width = 14; | |
139 priv->height = 63; | |
140 priv->skin_index = SKIN_EQMAIN; | |
141 | |
142 gtk_fixed_put(GTK_FIXED(fixed), GTK_WIDGET(es), es->x, es->y); | |
143 | |
144 return GTK_WIDGET(es); | |
145 } | |
146 | |
147 static void ui_skinned_equalizer_slider_destroy(GtkObject *object) { | |
148 UiSkinnedEqualizerSlider *equalizer_slider; | |
149 | |
150 g_return_if_fail (object != NULL); | |
151 g_return_if_fail (UI_SKINNED_IS_EQUALIZER_SLIDER (object)); | |
152 | |
153 equalizer_slider = UI_SKINNED_EQUALIZER_SLIDER (object); | |
154 | |
155 if (GTK_OBJECT_CLASS (parent_class)->destroy) | |
156 (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); | |
157 } | |
158 | |
159 static void ui_skinned_equalizer_slider_realize(GtkWidget *widget) { | |
160 UiSkinnedEqualizerSlider *equalizer_slider; | |
161 GdkWindowAttr attributes; | |
162 gint attributes_mask; | |
163 | |
164 g_return_if_fail (widget != NULL); | |
165 g_return_if_fail (UI_SKINNED_IS_EQUALIZER_SLIDER(widget)); | |
166 | |
2888
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
167 if (GTK_WIDGET_CLASS (parent_class)->realize) |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
168 (* GTK_WIDGET_CLASS (parent_class)->realize) (widget); |
2605 | 169 equalizer_slider = UI_SKINNED_EQUALIZER_SLIDER(widget); |
170 | |
171 attributes.x = widget->allocation.x; | |
172 attributes.y = widget->allocation.y; | |
173 attributes.width = widget->allocation.width; | |
174 attributes.height = widget->allocation.height; | |
2888
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
175 attributes.wclass = GDK_INPUT_ONLY; |
2605 | 176 attributes.window_type = GDK_WINDOW_CHILD; |
177 attributes.event_mask = gtk_widget_get_events(widget); | |
2888
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
178 attributes.event_mask |= GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | |
2605 | 179 GDK_POINTER_MOTION_MASK | GDK_SCROLL_MASK; |
2888
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
180 |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
181 attributes_mask = GDK_WA_X | GDK_WA_Y; |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
182 equalizer_slider->event_window = gdk_window_new(widget->parent->window, &attributes, attributes_mask); |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
183 |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
184 gdk_window_set_user_data(equalizer_slider->event_window, widget); |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
185 } |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
186 |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
187 static void ui_skinned_equalizer_slider_unrealize(GtkWidget *widget) { |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
188 UiSkinnedEqualizerSlider *equalizer_slider = UI_SKINNED_EQUALIZER_SLIDER(widget); |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
189 |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
190 if ( equalizer_slider->event_window != NULL ) |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
191 { |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
192 gdk_window_set_user_data( equalizer_slider->event_window , NULL ); |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
193 gdk_window_destroy( equalizer_slider->event_window ); |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
194 equalizer_slider->event_window = NULL; |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
195 } |
2605 | 196 |
2888
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
197 if (GTK_WIDGET_CLASS (parent_class)->unrealize) |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
198 (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget); |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
199 } |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
200 |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
201 static void ui_skinned_equalizer_slider_map (GtkWidget *widget) |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
202 { |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
203 UiSkinnedEqualizerSlider *equalizer_slider = UI_SKINNED_EQUALIZER_SLIDER(widget); |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
204 |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
205 if (equalizer_slider->event_window != NULL) |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
206 gdk_window_show (equalizer_slider->event_window); |
2605 | 207 |
2888
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
208 if (GTK_WIDGET_CLASS (parent_class)->map) |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
209 (* GTK_WIDGET_CLASS (parent_class)->map) (widget); |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
210 } |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
211 |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
212 static void ui_skinned_equalizer_slider_unmap (GtkWidget *widget) |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
213 { |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
214 UiSkinnedEqualizerSlider *equalizer_slider = UI_SKINNED_EQUALIZER_SLIDER(widget); |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
215 |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
216 if (equalizer_slider->event_window != NULL) |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
217 gdk_window_hide (equalizer_slider->event_window); |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
218 |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
219 if (GTK_WIDGET_CLASS (parent_class)->unmap) |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
220 (* GTK_WIDGET_CLASS (parent_class)->unmap) (widget); |
2605 | 221 } |
222 | |
223 static void ui_skinned_equalizer_slider_size_request(GtkWidget *widget, GtkRequisition *requisition) { | |
224 UiSkinnedEqualizerSliderPrivate *priv = UI_SKINNED_EQUALIZER_SLIDER_GET_PRIVATE(widget); | |
225 | |
226 requisition->width = priv->width*(priv->scaled ? config.scale_factor : 1); | |
227 requisition->height = priv->height*(priv->scaled ? config.scale_factor : 1); | |
228 } | |
229 | |
230 static void ui_skinned_equalizer_slider_size_allocate(GtkWidget *widget, GtkAllocation *allocation) { | |
231 UiSkinnedEqualizerSlider *equalizer_slider = UI_SKINNED_EQUALIZER_SLIDER (widget); | |
232 UiSkinnedEqualizerSliderPrivate *priv = UI_SKINNED_EQUALIZER_SLIDER_GET_PRIVATE(equalizer_slider); | |
233 | |
234 widget->allocation = *allocation; | |
235 widget->allocation.x *= (priv->scaled ? config.scale_factor : 1); | |
236 widget->allocation.y *= (priv->scaled ? config.scale_factor : 1); | |
237 if (GTK_WIDGET_REALIZED (widget)) | |
2888
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
238 if (equalizer_slider->event_window) |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
239 gdk_window_move_resize(equalizer_slider->event_window, widget->allocation.x, widget->allocation.y, allocation->width, allocation->height); |
2605 | 240 |
241 equalizer_slider->x = widget->allocation.x/(priv->scaled ? config.scale_factor : 1); | |
242 equalizer_slider->y = widget->allocation.y/(priv->scaled ? config.scale_factor : 1); | |
243 } | |
244 | |
245 static gboolean ui_skinned_equalizer_slider_expose(GtkWidget *widget, GdkEventExpose *event) { | |
246 g_return_val_if_fail (widget != NULL, FALSE); | |
247 g_return_val_if_fail (UI_SKINNED_IS_EQUALIZER_SLIDER (widget), FALSE); | |
248 g_return_val_if_fail (event != NULL, FALSE); | |
249 | |
250 UiSkinnedEqualizerSlider *es = UI_SKINNED_EQUALIZER_SLIDER (widget); | |
251 UiSkinnedEqualizerSliderPrivate *priv = UI_SKINNED_EQUALIZER_SLIDER_GET_PRIVATE(es); | |
252 g_return_val_if_fail (priv->width > 0 && priv->height > 0, FALSE); | |
253 | |
254 GdkPixbuf *obj = NULL; | |
255 obj = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, priv->width, priv->height); | |
256 | |
257 gint frame; | |
258 frame = 27 - ((priv->position * 27) / 50); | |
259 if (frame < 14) | |
260 skin_draw_pixbuf(widget, aud_active_skin, obj, priv->skin_index, (frame * 15) + 13, 164, 0, 0, priv->width, priv->height); | |
261 else | |
262 skin_draw_pixbuf(widget, aud_active_skin, obj, priv->skin_index, ((frame - 14) * 15) + 13, 229, 0, 0, priv->width, priv->height); | |
263 | |
264 if (priv->pressed) | |
265 skin_draw_pixbuf(widget, aud_active_skin, obj, priv->skin_index, 0, 176, 1, priv->position, 11, 11); | |
266 else | |
267 skin_draw_pixbuf(widget, aud_active_skin, obj, priv->skin_index, 0, 164, 1, priv->position, 11, 11); | |
268 | |
2888
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
269 ui_skinned_widget_draw_with_coordinates(widget, obj, priv->width, priv->height, |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
270 widget->allocation.x, |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
271 widget->allocation.y, |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
272 priv->scaled); |
2605 | 273 |
274 g_object_unref(obj); | |
275 | |
276 return FALSE; | |
277 } | |
278 | |
279 static gboolean ui_skinned_equalizer_slider_button_press(GtkWidget *widget, GdkEventButton *event) { | |
280 g_return_val_if_fail (widget != NULL, FALSE); | |
281 g_return_val_if_fail (UI_SKINNED_IS_EQUALIZER_SLIDER (widget), FALSE); | |
282 g_return_val_if_fail (event != NULL, FALSE); | |
283 | |
284 UiSkinnedEqualizerSlider *es = UI_SKINNED_EQUALIZER_SLIDER (widget); | |
285 UiSkinnedEqualizerSliderPrivate *priv = UI_SKINNED_EQUALIZER_SLIDER_GET_PRIVATE(es); | |
286 | |
287 gint y; | |
288 | |
289 if (event->type == GDK_BUTTON_PRESS) { | |
290 if (event->button == 1) { | |
291 priv->pressed = TRUE; | |
292 y = event->y/(priv->scaled ? config.scale_factor : 1); | |
293 | |
294 if (y >= priv->position && y < priv->position + 11) | |
295 priv->drag_y = y - priv->position; | |
296 else { | |
297 priv->position = y - 5; | |
298 priv->drag_y = 5; | |
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 equalizerwin_eq_changed(); | |
308 } | |
309 | |
310 ui_skinned_equalizer_slider_set_mainwin_text(es); | |
311 gtk_widget_queue_draw(widget); | |
312 } | |
313 } | |
314 | |
315 return TRUE; | |
316 } | |
317 | |
318 static gboolean ui_skinned_equalizer_slider_button_release(GtkWidget *widget, GdkEventButton *event) { | |
319 UiSkinnedEqualizerSliderPrivate *priv = UI_SKINNED_EQUALIZER_SLIDER_GET_PRIVATE(widget); | |
320 | |
321 if (event->button == 1) { | |
322 priv->pressed = FALSE; | |
323 mainwin_release_info_text(); | |
324 gtk_widget_queue_draw(widget); | |
325 } | |
326 return TRUE; | |
327 } | |
328 | |
329 static gboolean ui_skinned_equalizer_slider_motion_notify(GtkWidget *widget, GdkEventMotion *event) { | |
330 g_return_val_if_fail (widget != NULL, FALSE); | |
331 g_return_val_if_fail (UI_SKINNED_IS_EQUALIZER_SLIDER (widget), FALSE); | |
332 g_return_val_if_fail (event != NULL, FALSE); | |
333 UiSkinnedEqualizerSlider *es = UI_SKINNED_EQUALIZER_SLIDER(widget); | |
334 UiSkinnedEqualizerSliderPrivate *priv = UI_SKINNED_EQUALIZER_SLIDER_GET_PRIVATE(widget); | |
335 | |
336 if (priv->pressed) { | |
337 gint y; | |
338 | |
339 y = event->y/(priv->scaled ? config.scale_factor : 1); | |
340 priv->position = y - priv->drag_y; | |
341 | |
342 if (priv->position < 0) | |
343 priv->position = 0; | |
344 if (priv->position > 50) | |
345 priv->position = 50; | |
346 if (priv->position >= 24 && priv->position <= 26) | |
347 priv->position = 25; | |
348 | |
349 priv->value = ((gfloat) (25 - priv->position) * EQUALIZER_MAX_GAIN / 25.0 ); | |
350 ui_skinned_equalizer_slider_set_mainwin_text(es); | |
351 equalizerwin_eq_changed(); | |
352 gtk_widget_queue_draw(widget); | |
353 } | |
354 | |
355 return TRUE; | |
356 } | |
357 | |
358 static gboolean ui_skinned_equalizer_slider_scroll(GtkWidget *widget, GdkEventScroll *event) { | |
359 g_return_val_if_fail (UI_SKINNED_IS_EQUALIZER_SLIDER (widget), FALSE); | |
360 g_return_val_if_fail (event != NULL, FALSE); | |
361 UiSkinnedEqualizerSliderPrivate *priv = UI_SKINNED_EQUALIZER_SLIDER_GET_PRIVATE(widget); | |
362 | |
363 if (event->direction == GDK_SCROLL_UP) { | |
364 priv->position -= 2; | |
365 | |
366 if (priv->position < 0) | |
367 priv->position = 0; | |
368 } | |
369 else { | |
370 priv->position += 2; | |
371 | |
372 if (priv->position > 50) | |
373 priv->position = 50; | |
374 } | |
375 | |
376 priv->value = ((gfloat) (25 - priv->position) * EQUALIZER_MAX_GAIN / 25.0 ); | |
377 equalizerwin_eq_changed(); | |
378 gtk_widget_queue_draw(widget); | |
379 return TRUE; | |
380 } | |
381 | |
382 static void ui_skinned_equalizer_slider_toggle_scaled(UiSkinnedEqualizerSlider *equalizer_slider) { | |
383 GtkWidget *widget = GTK_WIDGET (equalizer_slider); | |
384 UiSkinnedEqualizerSliderPrivate *priv = UI_SKINNED_EQUALIZER_SLIDER_GET_PRIVATE(equalizer_slider); | |
385 | |
386 priv->scaled = !priv->scaled; | |
387 | |
388 gtk_widget_set_size_request(widget, priv->width*(priv->scaled ? config.scale_factor : 1), | |
389 priv->height*(priv->scaled ? config.scale_factor : 1)); | |
390 | |
391 gtk_widget_queue_draw(GTK_WIDGET(equalizer_slider)); | |
392 } | |
393 | |
394 void ui_skinned_equalizer_slider_set_position(GtkWidget *widget, gfloat pos) { | |
395 g_return_if_fail (UI_SKINNED_IS_EQUALIZER_SLIDER (widget)); | |
396 UiSkinnedEqualizerSliderPrivate *priv = UI_SKINNED_EQUALIZER_SLIDER_GET_PRIVATE(widget); | |
397 | |
398 if (priv->pressed) | |
399 return; | |
400 | |
401 priv->value = (pos > EQUALIZER_MAX_GAIN) ? EQUALIZER_MAX_GAIN : ((pos < -EQUALIZER_MAX_GAIN) ? -EQUALIZER_MAX_GAIN : pos); | |
402 priv->position = 25 - (gint) ((pos * 25.0) / EQUALIZER_MAX_GAIN); | |
403 | |
404 if (priv->position < 0) | |
405 priv->position = 0; | |
406 | |
407 if (priv->position > 50) | |
408 priv->position = 50; | |
409 | |
410 if (priv->position >= 24 && priv->position <= 26) | |
411 priv->position = 25; | |
412 | |
413 gtk_widget_queue_draw(widget); | |
414 } | |
415 | |
416 gfloat ui_skinned_equalizer_slider_get_position(GtkWidget *widget) { | |
417 g_return_val_if_fail (UI_SKINNED_IS_EQUALIZER_SLIDER (widget), -1); | |
418 UiSkinnedEqualizerSliderPrivate *priv = UI_SKINNED_EQUALIZER_SLIDER_GET_PRIVATE(widget); | |
419 return priv->value; | |
420 } | |
421 | |
422 void ui_skinned_equalizer_slider_set_mainwin_text(UiSkinnedEqualizerSlider * es) { | |
423 gint band = 0; | |
424 const gchar *bandname[11] = { N_("PREAMP"), N_("60HZ"), N_("170HZ"), | |
425 N_("310HZ"), N_("600HZ"), N_("1KHZ"), | |
426 N_("3KHZ"), N_("6KHZ"), N_("12KHZ"), | |
427 N_("14KHZ"), N_("16KHZ") | |
428 }; | |
429 gchar *tmp; | |
430 | |
431 if (es->x > 21) | |
432 band = ((es->x - 78) / 18) + 1; | |
433 | |
434 tmp = | |
435 g_strdup_printf("EQ: %s: %+.1f DB", _(bandname[band]), | |
436 ui_skinned_equalizer_slider_get_position(GTK_WIDGET(es))); | |
437 mainwin_lock_info_text(tmp); | |
438 g_free(tmp); | |
439 } |