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