2313
|
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
20 */
|
|
21
|
|
22 #include "widgetcore.h"
|
|
23
|
|
24 #include <glib.h>
|
|
25
|
|
26 #include "playlist.h"
|
|
27 #include "ui_playlist.h"
|
|
28 #include "skin.h"
|
|
29 #include "widget.h"
|
|
30
|
|
31 extern GCond *cond_scan;
|
|
32
|
|
33 void
|
|
34 playlistslider_draw(Widget * w)
|
|
35 {
|
|
36 PlaylistSlider *ps = (PlaylistSlider *) w;
|
|
37 GdkPixmap *obj;
|
|
38 gint y, skinx;
|
|
39 Playlist *playlist = playlist_get_active();
|
|
40
|
|
41 g_return_if_fail(ps != NULL);
|
|
42 g_return_if_fail(ps->ps_list != NULL);
|
|
43
|
|
44 if (playlist_get_length(playlist) > ps->ps_list->pl_num_visible)
|
|
45 y = (ps->ps_list->pl_first * (ps->ps_widget.height - 19)) /
|
|
46 (playlist_get_length(playlist) - ps->ps_list->pl_num_visible);
|
|
47 else
|
|
48 y = 0;
|
|
49
|
|
50 obj = ps->ps_widget.parent;
|
|
51
|
|
52 if (ps->ps_back_image) {
|
|
53 if (skin_get_id() != ps->ps_skin_id)
|
|
54 ps->ps_skin_id = skin_get_id();
|
|
55 else if (ps->ps_widget.height == ps->ps_prev_height)
|
|
56 gdk_draw_image(obj, ps->ps_widget.gc,
|
|
57 ps->ps_back_image, 0, 0,
|
|
58 ps->ps_widget.x,
|
|
59 ps->ps_widget.y + ps->ps_prev_y, 8, 18);
|
|
60 g_object_unref(ps->ps_back_image);
|
|
61 }
|
|
62
|
|
63 ps->ps_prev_y = y;
|
|
64 ps->ps_prev_height = ps->ps_widget.height;
|
|
65 ps->ps_back_image = gdk_drawable_get_image(obj, ps->ps_widget.x,
|
|
66 ps->ps_widget.y + y, 8, 18);
|
|
67 if (ps->ps_is_draging)
|
|
68 skinx = 61;
|
|
69 else
|
|
70 skinx = 52;
|
|
71
|
|
72 skin_draw_pixmap(bmp_active_skin, obj, ps->ps_widget.gc, SKIN_PLEDIT,
|
|
73 skinx, 53, ps->ps_widget.x, ps->ps_widget.y + y, 8, 18);
|
|
74 }
|
|
75
|
|
76 static void
|
|
77 playlistslider_set_pos(PlaylistSlider * ps, gint y)
|
|
78 {
|
|
79 gint pos;
|
|
80 Playlist *playlist = playlist_get_active();
|
|
81
|
|
82 y = CLAMP(y, 0, ps->ps_widget.height - 19);
|
|
83
|
|
84 pos = (y * (playlist_get_length(playlist) - ps->ps_list->pl_num_visible)) /
|
|
85 (ps->ps_widget.height - 19);
|
|
86 playlistwin_set_toprow(pos);
|
|
87 }
|
|
88
|
|
89 void
|
|
90 playlistslider_button_press_cb(GtkWidget * widget,
|
|
91 GdkEventButton * event, PlaylistSlider * ps)
|
|
92 {
|
|
93 gint y = event->y - ps->ps_widget.y;
|
|
94
|
|
95 if (!widget_contains(&ps->ps_widget, event->x, event->y))
|
|
96 return;
|
|
97
|
|
98 if (event->button != 1 && event->button != 2)
|
|
99 return;
|
|
100
|
|
101 if ((y >= ps->ps_prev_y && y < ps->ps_prev_y + 18)) {
|
|
102 ps->ps_is_draging |= event->button;
|
|
103 ps->ps_drag_y = y - ps->ps_prev_y;
|
|
104 widget_draw(WIDGET(ps));
|
|
105 }
|
|
106 else if (event->button == 2) {
|
|
107 playlistslider_set_pos(ps, y);
|
|
108 ps->ps_is_draging |= event->button;
|
|
109 ps->ps_drag_y = 0;
|
|
110 widget_draw(WIDGET(ps));
|
|
111 }
|
|
112 else {
|
|
113 gint n = ps->ps_list->pl_num_visible / 2;
|
|
114 if (y < ps->ps_prev_y)
|
|
115 n *= -1;
|
|
116 playlistwin_scroll(n);
|
|
117 }
|
|
118 g_cond_signal(cond_scan);
|
|
119 }
|
|
120
|
|
121 void
|
|
122 playlistslider_button_release_cb(GtkWidget * widget,
|
|
123 GdkEventButton * event,
|
|
124 PlaylistSlider * ps)
|
|
125 {
|
|
126 if (ps->ps_is_draging) {
|
|
127 ps->ps_is_draging &= ~event->button;
|
|
128 widget_draw(WIDGET(ps));
|
|
129 }
|
|
130 }
|
|
131
|
|
132 void
|
|
133 playlistslider_motion_cb(GtkWidget * widget, GdkEventMotion * event,
|
|
134 PlaylistSlider * ps)
|
|
135 {
|
|
136 gint y;
|
|
137
|
|
138 if (!ps->ps_is_draging)
|
|
139 return;
|
|
140
|
|
141 y = event->y - ps->ps_widget.y - ps->ps_drag_y;
|
|
142 playlistslider_set_pos(ps, y);
|
|
143 g_cond_signal(cond_scan);
|
|
144 }
|
|
145
|
|
146 PlaylistSlider *
|
|
147 create_playlistslider(GList ** wlist, GdkPixmap * parent,
|
|
148 GdkGC * gc, gint x, gint y, gint h,
|
|
149 PlayList_List * list)
|
|
150 {
|
|
151 PlaylistSlider *ps;
|
|
152
|
|
153 ps = g_new0(PlaylistSlider, 1);
|
|
154 widget_init(&ps->ps_widget, parent, gc, x, y, 8, h, 1);
|
|
155
|
|
156 ps->ps_widget.button_press_cb =
|
|
157 (void (*)(GtkWidget *, GdkEventButton *, gpointer))
|
|
158 playlistslider_button_press_cb;
|
|
159
|
|
160 ps->ps_widget.button_release_cb =
|
|
161 (void (*)(GtkWidget *, GdkEventButton *, gpointer))
|
|
162 playlistslider_button_release_cb;
|
|
163
|
|
164 ps->ps_widget.motion_cb =
|
|
165 (void (*)(GtkWidget *, GdkEventMotion *, gpointer))
|
|
166 playlistslider_motion_cb;
|
|
167
|
|
168 ps->ps_widget.draw = playlistslider_draw;
|
|
169 ps->ps_list = list;
|
|
170
|
|
171 widget_list_add(wlist, WIDGET(ps));
|
|
172 return ps;
|
|
173 }
|