3136
|
1 /*
|
|
2 * Audacious - a cross-platform multimedia player
|
|
3 * Copyright (c) 2007 Audacious development team.
|
|
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 * The Audacious team does not consider modular code linking to
|
|
24 * Audacious or using our public API to be a derived work.
|
|
25 */
|
|
26
|
|
27 #include "widgets/widgetcore.h"
|
|
28 #include "ui_skinned_playlist_slider.h"
|
|
29 #include "main.h"
|
|
30 #include "util.h"
|
|
31 #include "ui_playlist.h"
|
|
32
|
|
33 static GMutex *mutex = NULL;
|
|
34
|
|
35 #define UI_SKINNED_PLAYLIST_SLIDER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), ui_skinned_playlist_slider_get_type(), UiSkinnedPlaylistSliderPrivate))
|
|
36 typedef struct _UiSkinnedPlaylistSliderPrivate UiSkinnedPlaylistSliderPrivate;
|
|
37
|
|
38 enum {
|
|
39 REDRAW,
|
|
40 LAST_SIGNAL
|
|
41 };
|
|
42
|
|
43 struct _UiSkinnedPlaylistSliderPrivate {
|
|
44 GtkWidget *fixed;
|
|
45 SkinPixmapId skin_index;
|
|
46 gint width, height;
|
|
47
|
|
48 gint resize_height;
|
|
49 gint move_x;
|
|
50 };
|
|
51
|
|
52 static void ui_skinned_playlist_slider_class_init (UiSkinnedPlaylistSliderClass *klass);
|
|
53 static void ui_skinned_playlist_slider_init (UiSkinnedPlaylistSlider *playlist_slider);
|
|
54 static void ui_skinned_playlist_slider_destroy (GtkObject *object);
|
|
55 static void ui_skinned_playlist_slider_realize (GtkWidget *widget);
|
|
56 static void ui_skinned_playlist_slider_size_request (GtkWidget *widget, GtkRequisition *requisition);
|
|
57 static void ui_skinned_playlist_slider_size_allocate (GtkWidget *widget, GtkAllocation *allocation);
|
|
58 static gboolean ui_skinned_playlist_slider_expose (GtkWidget *widget, GdkEventExpose *event);
|
|
59 static void ui_skinned_playlist_slider_set_position (GtkWidget *widget, gint y);
|
|
60 static gboolean ui_skinned_playlist_slider_button_press (GtkWidget *widget, GdkEventButton *event);
|
|
61 static gboolean ui_skinned_playlist_slider_button_release (GtkWidget *widget, GdkEventButton *event);
|
|
62 static gboolean ui_skinned_playlist_slider_motion_notify (GtkWidget *widget, GdkEventMotion *event);
|
|
63 static void ui_skinned_playlist_slider_redraw (UiSkinnedPlaylistSlider *playlist_slider);
|
|
64
|
|
65 static GtkWidgetClass *parent_class = NULL;
|
|
66 static guint playlist_slider_signals[LAST_SIGNAL] = { 0 };
|
|
67
|
|
68 GType ui_skinned_playlist_slider_get_type() {
|
|
69 static GType playlist_slider_type = 0;
|
|
70 if (!playlist_slider_type) {
|
|
71 static const GTypeInfo playlist_slider_info = {
|
|
72 sizeof (UiSkinnedPlaylistSliderClass),
|
|
73 NULL,
|
|
74 NULL,
|
|
75 (GClassInitFunc) ui_skinned_playlist_slider_class_init,
|
|
76 NULL,
|
|
77 NULL,
|
|
78 sizeof (UiSkinnedPlaylistSlider),
|
|
79 0,
|
|
80 (GInstanceInitFunc) ui_skinned_playlist_slider_init,
|
|
81 };
|
|
82 playlist_slider_type = g_type_register_static (GTK_TYPE_WIDGET, "UiSkinnedPlaylistSlider", &playlist_slider_info, 0);
|
|
83 }
|
|
84
|
|
85 return playlist_slider_type;
|
|
86 }
|
|
87
|
|
88 static void ui_skinned_playlist_slider_class_init(UiSkinnedPlaylistSliderClass *klass) {
|
|
89 GObjectClass *gobject_class;
|
|
90 GtkObjectClass *object_class;
|
|
91 GtkWidgetClass *widget_class;
|
|
92
|
|
93 gobject_class = G_OBJECT_CLASS(klass);
|
|
94 object_class = (GtkObjectClass*) klass;
|
|
95 widget_class = (GtkWidgetClass*) klass;
|
|
96 parent_class = gtk_type_class (gtk_widget_get_type ());
|
|
97
|
|
98 object_class->destroy = ui_skinned_playlist_slider_destroy;
|
|
99
|
|
100 widget_class->realize = ui_skinned_playlist_slider_realize;
|
|
101 widget_class->expose_event = ui_skinned_playlist_slider_expose;
|
|
102 widget_class->size_request = ui_skinned_playlist_slider_size_request;
|
|
103 widget_class->size_allocate = ui_skinned_playlist_slider_size_allocate;
|
|
104 widget_class->button_press_event = ui_skinned_playlist_slider_button_press;
|
|
105 widget_class->button_release_event = ui_skinned_playlist_slider_button_release;
|
|
106 widget_class->motion_notify_event = ui_skinned_playlist_slider_motion_notify;
|
|
107
|
|
108 klass->redraw = ui_skinned_playlist_slider_redraw;
|
|
109
|
|
110 playlist_slider_signals[REDRAW] =
|
|
111 g_signal_new ("redraw", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
|
|
112 G_STRUCT_OFFSET (UiSkinnedPlaylistSliderClass, redraw), NULL, NULL,
|
|
113 gtk_marshal_VOID__VOID, G_TYPE_NONE, 0);
|
|
114
|
|
115 g_type_class_add_private (gobject_class, sizeof (UiSkinnedPlaylistSliderPrivate));
|
|
116 }
|
|
117
|
|
118 static void ui_skinned_playlist_slider_init(UiSkinnedPlaylistSlider *playlist_slider) {
|
|
119 UiSkinnedPlaylistSliderPrivate *priv = UI_SKINNED_PLAYLIST_SLIDER_GET_PRIVATE(playlist_slider);
|
|
120 mutex = g_mutex_new();
|
|
121 playlist_slider->pressed = FALSE;
|
|
122 priv->resize_height = 0;
|
|
123 priv->move_x = 0;
|
|
124 }
|
|
125
|
|
126 GtkWidget* ui_skinned_playlist_slider_new(GtkWidget *fixed, gint x, gint y, gint h) {
|
|
127
|
|
128 UiSkinnedPlaylistSlider *hs = g_object_new (ui_skinned_playlist_slider_get_type (), NULL);
|
|
129 UiSkinnedPlaylistSliderPrivate *priv = UI_SKINNED_PLAYLIST_SLIDER_GET_PRIVATE(hs);
|
|
130
|
|
131 hs->x = x;
|
|
132 hs->y = y;
|
|
133 priv->width = 8;
|
|
134 priv->height = h;
|
|
135 priv->fixed = fixed;
|
|
136 priv->skin_index = SKIN_PLEDIT;
|
|
137
|
|
138 gtk_fixed_put(GTK_FIXED(priv->fixed), GTK_WIDGET(hs), hs->x, hs->y);
|
|
139
|
|
140 return GTK_WIDGET(hs);
|
|
141 }
|
|
142
|
|
143 static void ui_skinned_playlist_slider_destroy(GtkObject *object) {
|
|
144 UiSkinnedPlaylistSlider *playlist_slider;
|
|
145
|
|
146 g_return_if_fail (object != NULL);
|
|
147 g_return_if_fail (UI_SKINNED_IS_PLAYLIST_SLIDER (object));
|
|
148
|
|
149 playlist_slider = UI_SKINNED_PLAYLIST_SLIDER (object);
|
|
150
|
|
151 if (GTK_OBJECT_CLASS (parent_class)->destroy)
|
|
152 (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
|
|
153 }
|
|
154
|
|
155 static void ui_skinned_playlist_slider_realize(GtkWidget *widget) {
|
|
156 UiSkinnedPlaylistSlider *playlist_slider;
|
|
157 GdkWindowAttr attributes;
|
|
158 gint attributes_mask;
|
|
159
|
|
160 g_return_if_fail (widget != NULL);
|
|
161 g_return_if_fail (UI_SKINNED_IS_PLAYLIST_SLIDER(widget));
|
|
162
|
|
163 GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED);
|
|
164 playlist_slider = UI_SKINNED_PLAYLIST_SLIDER(widget);
|
|
165
|
|
166 attributes.x = widget->allocation.x;
|
|
167 attributes.y = widget->allocation.y;
|
|
168 attributes.width = widget->allocation.width;
|
|
169 attributes.height = widget->allocation.height;
|
|
170 attributes.wclass = GDK_INPUT_OUTPUT;
|
|
171 attributes.window_type = GDK_WINDOW_CHILD;
|
|
172 attributes.event_mask = gtk_widget_get_events(widget);
|
|
173 attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK |
|
|
174 GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK;
|
|
175 attributes.visual = gtk_widget_get_visual(widget);
|
|
176 attributes.colormap = gtk_widget_get_colormap(widget);
|
|
177
|
|
178 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
|
|
179 widget->window = gdk_window_new(widget->parent->window, &attributes, attributes_mask);
|
|
180
|
|
181 widget->style = gtk_style_attach(widget->style, widget->window);
|
|
182 gdk_window_set_user_data(widget->window, widget);
|
|
183 }
|
|
184
|
|
185 static void ui_skinned_playlist_slider_size_request(GtkWidget *widget, GtkRequisition *requisition) {
|
|
186 UiSkinnedPlaylistSliderPrivate *priv = UI_SKINNED_PLAYLIST_SLIDER_GET_PRIVATE(widget);
|
|
187
|
|
188 requisition->width = priv->width;
|
|
189 requisition->height = priv->height;
|
|
190 }
|
|
191
|
|
192 static void ui_skinned_playlist_slider_size_allocate(GtkWidget *widget, GtkAllocation *allocation) {
|
|
193 g_mutex_lock(mutex);
|
|
194 UiSkinnedPlaylistSlider *playlist_slider = UI_SKINNED_PLAYLIST_SLIDER (widget);
|
|
195 UiSkinnedPlaylistSliderPrivate *priv = UI_SKINNED_PLAYLIST_SLIDER_GET_PRIVATE(playlist_slider);
|
|
196
|
|
197 widget->allocation = *allocation;
|
|
198 if (GTK_WIDGET_REALIZED (widget))
|
|
199 gdk_window_move_resize(widget->window, widget->allocation.x, widget->allocation.y, allocation->width, allocation->height);
|
|
200
|
|
201 playlist_slider->x = widget->allocation.x;
|
|
202 playlist_slider->y = widget->allocation.y;
|
|
203
|
|
204 priv->move_x = 0;
|
|
205
|
|
206 if (priv->height != widget->allocation.height) {
|
|
207 priv->height = priv->height + priv->resize_height;
|
|
208 priv->resize_height = 0;
|
|
209 gtk_widget_queue_draw(widget);
|
|
210 }
|
|
211 g_mutex_unlock(mutex);
|
|
212 }
|
|
213
|
|
214 static gboolean ui_skinned_playlist_slider_expose(GtkWidget *widget, GdkEventExpose *event) {
|
|
215 g_return_val_if_fail (widget != NULL, FALSE);
|
|
216 g_return_val_if_fail (UI_SKINNED_IS_PLAYLIST_SLIDER (widget), FALSE);
|
|
217 g_return_val_if_fail (event != NULL, FALSE);
|
|
218
|
|
219 UiSkinnedPlaylistSlider *ps = UI_SKINNED_PLAYLIST_SLIDER (widget);
|
|
220 UiSkinnedPlaylistSliderPrivate *priv = UI_SKINNED_PLAYLIST_SLIDER_GET_PRIVATE(ps);
|
|
221
|
|
222 GdkPixmap *obj = NULL;
|
|
223 GdkGC *gc;
|
|
224
|
|
225 obj = gdk_pixmap_new(NULL, priv->width, priv->height, gdk_rgb_get_visual()->depth);
|
|
226 gc = gdk_gc_new(obj);
|
|
227
|
|
228 gint num_visible;
|
|
229 num_visible = playlistwin_list_get_visible_count();
|
|
230
|
|
231
|
|
232 Playlist *playlist = playlist_get_active();
|
|
233
|
|
234 gint y;
|
|
235 if (playlist_get_length(playlist) > num_visible)
|
|
236 y = (playlistwin_list_get_first() * (priv->height - 19)) /
|
|
237 (playlist_get_length(playlist) - num_visible);
|
|
238 else
|
|
239 y = 0;
|
|
240
|
|
241 if (y < 0) y=0;
|
|
242 if (y > priv->height - 19) y = priv->height - 19;
|
|
243
|
|
244 /* FIXME: uses bmp_active_skin->pixmaps directly and may need calibration */
|
|
245 /* drawing background */
|
|
246 gint c;
|
|
247 for (c = 0; c <= priv->height / 29; c++) {
|
|
248 gdk_draw_drawable(obj, gc, bmp_active_skin->pixmaps[SKIN_PLEDIT].pixmap,
|
|
249 36, 42, 0, c*29, priv->width, 29);
|
|
250 }
|
|
251
|
|
252 /* drawing knob */
|
|
253 skin_draw_pixmap(bmp_active_skin, obj, gc, priv->skin_index, ps->pressed ? 61 : 52, 53, 0, y, priv->width, 18);
|
|
254
|
|
255 gdk_draw_drawable(widget->window, gc, obj, 0, 0, 0, 0, priv->width, priv->height);
|
|
256 g_object_unref(obj);
|
|
257 g_object_unref(gc);
|
|
258
|
|
259 return FALSE;
|
|
260 }
|
|
261
|
|
262 static void ui_skinned_playlist_slider_set_position(GtkWidget *widget, gint y) {
|
|
263 gint pos;
|
|
264 Playlist *playlist = playlist_get_active();
|
|
265 UiSkinnedPlaylistSliderPrivate *priv = UI_SKINNED_PLAYLIST_SLIDER_GET_PRIVATE(widget);
|
|
266
|
|
267 y = CLAMP(y, 0, priv->height - 19);
|
|
268
|
|
269 pos = (y * (playlist_get_length(playlist) - playlistwin_list_get_visible_count())) / (priv->height - 19);
|
|
270 playlistwin_set_toprow(pos);
|
|
271
|
|
272 gtk_widget_queue_draw(widget);
|
|
273 }
|
|
274
|
|
275 static gboolean ui_skinned_playlist_slider_button_press(GtkWidget *widget, GdkEventButton *event) {
|
|
276 UiSkinnedPlaylistSlider *ps = UI_SKINNED_PLAYLIST_SLIDER (widget);
|
|
277
|
|
278 if (event->type == GDK_BUTTON_PRESS) {
|
|
279 if (event->button == 1) {
|
|
280 ps->pressed = TRUE;
|
|
281 gint y = event->y;
|
|
282 ui_skinned_playlist_slider_set_position(widget, y);
|
|
283 }
|
|
284 }
|
|
285
|
|
286 return TRUE;
|
|
287 }
|
|
288
|
|
289 static gboolean ui_skinned_playlist_slider_button_release(GtkWidget *widget, GdkEventButton *event) {
|
|
290 UiSkinnedPlaylistSlider *ps = UI_SKINNED_PLAYLIST_SLIDER(widget);
|
|
291
|
|
292 if (event->button == 1) {
|
|
293 ps->pressed = FALSE;
|
|
294 gtk_widget_queue_draw(widget);
|
|
295 }
|
|
296 return TRUE;
|
|
297 }
|
|
298
|
|
299 static gboolean ui_skinned_playlist_slider_motion_notify(GtkWidget *widget, GdkEventMotion *event) {
|
|
300 UiSkinnedPlaylistSlider *ps = UI_SKINNED_PLAYLIST_SLIDER(widget);
|
|
301
|
|
302 if (ps->pressed) {
|
|
303 gint y = event->y;
|
|
304 ui_skinned_playlist_slider_set_position(widget, y);
|
|
305 }
|
|
306 return TRUE;
|
|
307 }
|
|
308
|
|
309 static void ui_skinned_playlist_slider_redraw(UiSkinnedPlaylistSlider *playlist_slider) {
|
|
310 g_mutex_lock(mutex);
|
|
311 UiSkinnedPlaylistSliderPrivate *priv = UI_SKINNED_PLAYLIST_SLIDER_GET_PRIVATE(playlist_slider);
|
|
312
|
|
313 if (priv->resize_height)
|
|
314 gtk_widget_set_size_request(GTK_WIDGET(playlist_slider), priv->width, priv->height+priv->resize_height);
|
|
315 if (priv->move_x)
|
|
316 gtk_fixed_move(GTK_FIXED(priv->fixed), GTK_WIDGET(playlist_slider), playlist_slider->x+priv->move_x, playlist_slider->y);
|
|
317
|
|
318 gtk_widget_queue_draw(GTK_WIDGET(playlist_slider));
|
|
319 g_mutex_unlock(mutex);
|
|
320 }
|
|
321
|
|
322 void ui_skinned_playlist_slider_move_relative(GtkWidget *widget, gint x) {
|
|
323 g_mutex_lock(mutex);
|
|
324 UiSkinnedPlaylistSliderPrivate *priv = UI_SKINNED_PLAYLIST_SLIDER_GET_PRIVATE(widget);
|
|
325 priv->move_x += x;
|
|
326 g_mutex_unlock(mutex);
|
|
327 }
|
|
328
|
|
329 void ui_skinned_playlist_slider_resize_relative(GtkWidget *widget, gint h) {
|
|
330 g_mutex_lock(mutex);
|
|
331 UiSkinnedPlaylistSliderPrivate *priv = UI_SKINNED_PLAYLIST_SLIDER_GET_PRIVATE(widget);
|
|
332 priv->resize_height += h;
|
|
333 g_mutex_unlock(mutex);
|
|
334 }
|