Mercurial > audlegacy
diff src/audacious/widgets/playlist_slider.c @ 2313:3149d4b1a9a9 trunk
[svn] - objective-make autodepend fixes
- move all sourcecode into src/ and adjust Makefiles accordingly
author | nenolod |
---|---|
date | Fri, 12 Jan 2007 11:43:40 -0800 |
parents | |
children | 41d3854f3625 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/audacious/widgets/playlist_slider.c Fri Jan 12 11:43:40 2007 -0800 @@ -0,0 +1,173 @@ +/* BMP - Cross-platform multimedia player + * Copyright (C) 2003-2004 BMP development team. + * + * Based on XMMS: + * Copyright (C) 1998-2003 XMMS development team. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "widgetcore.h" + +#include <glib.h> + +#include "playlist.h" +#include "ui_playlist.h" +#include "skin.h" +#include "widget.h" + +extern GCond *cond_scan; + +void +playlistslider_draw(Widget * w) +{ + PlaylistSlider *ps = (PlaylistSlider *) w; + GdkPixmap *obj; + gint y, skinx; + Playlist *playlist = playlist_get_active(); + + g_return_if_fail(ps != NULL); + g_return_if_fail(ps->ps_list != NULL); + + if (playlist_get_length(playlist) > ps->ps_list->pl_num_visible) + y = (ps->ps_list->pl_first * (ps->ps_widget.height - 19)) / + (playlist_get_length(playlist) - ps->ps_list->pl_num_visible); + else + y = 0; + + obj = ps->ps_widget.parent; + + if (ps->ps_back_image) { + if (skin_get_id() != ps->ps_skin_id) + ps->ps_skin_id = skin_get_id(); + else if (ps->ps_widget.height == ps->ps_prev_height) + gdk_draw_image(obj, ps->ps_widget.gc, + ps->ps_back_image, 0, 0, + ps->ps_widget.x, + ps->ps_widget.y + ps->ps_prev_y, 8, 18); + g_object_unref(ps->ps_back_image); + } + + ps->ps_prev_y = y; + ps->ps_prev_height = ps->ps_widget.height; + ps->ps_back_image = gdk_drawable_get_image(obj, ps->ps_widget.x, + ps->ps_widget.y + y, 8, 18); + if (ps->ps_is_draging) + skinx = 61; + else + skinx = 52; + + skin_draw_pixmap(bmp_active_skin, obj, ps->ps_widget.gc, SKIN_PLEDIT, + skinx, 53, ps->ps_widget.x, ps->ps_widget.y + y, 8, 18); +} + +static void +playlistslider_set_pos(PlaylistSlider * ps, gint y) +{ + gint pos; + Playlist *playlist = playlist_get_active(); + + y = CLAMP(y, 0, ps->ps_widget.height - 19); + + pos = (y * (playlist_get_length(playlist) - ps->ps_list->pl_num_visible)) / + (ps->ps_widget.height - 19); + playlistwin_set_toprow(pos); +} + +void +playlistslider_button_press_cb(GtkWidget * widget, + GdkEventButton * event, PlaylistSlider * ps) +{ + gint y = event->y - ps->ps_widget.y; + + if (!widget_contains(&ps->ps_widget, event->x, event->y)) + return; + + if (event->button != 1 && event->button != 2) + return; + + if ((y >= ps->ps_prev_y && y < ps->ps_prev_y + 18)) { + ps->ps_is_draging |= event->button; + ps->ps_drag_y = y - ps->ps_prev_y; + widget_draw(WIDGET(ps)); + } + else if (event->button == 2) { + playlistslider_set_pos(ps, y); + ps->ps_is_draging |= event->button; + ps->ps_drag_y = 0; + widget_draw(WIDGET(ps)); + } + else { + gint n = ps->ps_list->pl_num_visible / 2; + if (y < ps->ps_prev_y) + n *= -1; + playlistwin_scroll(n); + } + g_cond_signal(cond_scan); +} + +void +playlistslider_button_release_cb(GtkWidget * widget, + GdkEventButton * event, + PlaylistSlider * ps) +{ + if (ps->ps_is_draging) { + ps->ps_is_draging &= ~event->button; + widget_draw(WIDGET(ps)); + } +} + +void +playlistslider_motion_cb(GtkWidget * widget, GdkEventMotion * event, + PlaylistSlider * ps) +{ + gint y; + + if (!ps->ps_is_draging) + return; + + y = event->y - ps->ps_widget.y - ps->ps_drag_y; + playlistslider_set_pos(ps, y); + g_cond_signal(cond_scan); +} + +PlaylistSlider * +create_playlistslider(GList ** wlist, GdkPixmap * parent, + GdkGC * gc, gint x, gint y, gint h, + PlayList_List * list) +{ + PlaylistSlider *ps; + + ps = g_new0(PlaylistSlider, 1); + widget_init(&ps->ps_widget, parent, gc, x, y, 8, h, 1); + + ps->ps_widget.button_press_cb = + (void (*)(GtkWidget *, GdkEventButton *, gpointer)) + playlistslider_button_press_cb; + + ps->ps_widget.button_release_cb = + (void (*)(GtkWidget *, GdkEventButton *, gpointer)) + playlistslider_button_release_cb; + + ps->ps_widget.motion_cb = + (void (*)(GtkWidget *, GdkEventMotion *, gpointer)) + playlistslider_motion_cb; + + ps->ps_widget.draw = playlistslider_draw; + ps->ps_list = list; + + widget_list_add(wlist, WIDGET(ps)); + return ps; +}