annotate audacious/playlist_slider.c @ 1378:27d9eb18c7cf trunk

[svn] - some improvements to song_change, still sucky - jackd volume saving stuff (via galiyosha)
author nenolod
date Mon, 10 Jul 2006 01:18:38 -0700
parents 5c457dac866a
children f12d7e208b43
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1 /* BMP - Cross-platform multimedia player
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2 * Copyright (C) 2003-2004 BMP development team.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
3 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
4 * Based on XMMS:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
5 * Copyright (C) 1998-2003 XMMS development team.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
6 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
10 * (at your option) any later version.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
11 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
15 * GNU General Public License for more details.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
16 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
20 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
21
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
22 #include "playlist_slider.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
23
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
24 #include <glib.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
25
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
26 #include "playlist.h"
383
5c457dac866a [svn] - Rename playlistwin stuff to ui_playlist.*
nenolod
parents: 0
diff changeset
27 #include "ui_playlist.h"
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
28 #include "skin.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
29 #include "widget.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
30
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
31 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
32 playlistslider_draw(Widget * w)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
33 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
34 PlaylistSlider *ps = (PlaylistSlider *) w;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
35 GdkPixmap *obj;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
36 gint y, skinx;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
37
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
38 g_return_if_fail(ps != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
39 g_return_if_fail(ps->ps_list != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
40
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
41 if (playlist_get_length() > ps->ps_list->pl_num_visible)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
42 y = (ps->ps_list->pl_first * (ps->ps_widget.height - 19)) /
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
43 (playlist_get_length() - ps->ps_list->pl_num_visible);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
44 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
45 y = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
46
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
47 obj = ps->ps_widget.parent;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
48
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
49 if (ps->ps_back_image) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
50 if (skin_get_id() != ps->ps_skin_id)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
51 ps->ps_skin_id = skin_get_id();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
52 else if (ps->ps_widget.height == ps->ps_prev_height)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
53 gdk_draw_image(obj, ps->ps_widget.gc,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
54 ps->ps_back_image, 0, 0,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
55 ps->ps_widget.x,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
56 ps->ps_widget.y + ps->ps_prev_y, 8, 18);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
57 gdk_image_destroy(ps->ps_back_image);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
58 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
59
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
60 ps->ps_prev_y = y;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
61 ps->ps_prev_height = ps->ps_widget.height;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
62 ps->ps_back_image = gdk_drawable_get_image(obj, ps->ps_widget.x,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
63 ps->ps_widget.y + y, 8, 18);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
64 if (ps->ps_is_draging)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
65 skinx = 61;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
66 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
67 skinx = 52;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
68
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
69 skin_draw_pixmap(bmp_active_skin, obj, ps->ps_widget.gc, SKIN_PLEDIT,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
70 skinx, 53, ps->ps_widget.x, ps->ps_widget.y + y, 8, 18);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
71 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
72
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
73 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
74 playlistslider_set_pos(PlaylistSlider * ps, gint y)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
75 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
76 gint pos;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
77
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
78 y = CLAMP(y, 0, ps->ps_widget.height - 19);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
79
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
80 pos = (y * (playlist_get_length() - ps->ps_list->pl_num_visible)) /
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
81 (ps->ps_widget.height - 19);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
82 playlistwin_set_toprow(pos);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
83 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
84
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
85
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
86 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
87 playlistslider_button_press_cb(GtkWidget * widget,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
88 GdkEventButton * event, PlaylistSlider * ps)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
89 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
90 gint y = event->y - ps->ps_widget.y;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
91
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
92 if (!widget_contains(&ps->ps_widget, event->x, event->y))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
93 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
94
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
95 if (event->button != 1 && event->button != 2)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
96 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
97
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
98 if ((y >= ps->ps_prev_y && y < ps->ps_prev_y + 18)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
99 ps->ps_is_draging |= event->button;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
100 ps->ps_drag_y = y - ps->ps_prev_y;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
101 widget_draw(WIDGET(ps));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
102 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
103 else if (event->button == 2) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
104 playlistslider_set_pos(ps, y);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
105 ps->ps_is_draging |= event->button;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
106 ps->ps_drag_y = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
107 widget_draw(WIDGET(ps));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
108 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
109 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
110 gint n = ps->ps_list->pl_num_visible / 2;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
111 if (y < ps->ps_prev_y)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
112 n *= -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
113 playlistwin_scroll(n);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
114 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
115 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
116
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
117 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
118 playlistslider_button_release_cb(GtkWidget * widget,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
119 GdkEventButton * event,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
120 PlaylistSlider * ps)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
121 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
122 if (ps->ps_is_draging) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
123 ps->ps_is_draging &= ~event->button;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
124 widget_draw(WIDGET(ps));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
125 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
126 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
127
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
128 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
129 playlistslider_motion_cb(GtkWidget * widget, GdkEventMotion * event,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
130 PlaylistSlider * ps)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
131 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
132 gint y;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
133
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
134 if (!ps->ps_is_draging)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
135 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
136
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
137 y = event->y - ps->ps_widget.y - ps->ps_drag_y;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
138 playlistslider_set_pos(ps, y);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
139 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
140
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
141 PlaylistSlider *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
142 create_playlistslider(GList ** wlist, GdkPixmap * parent,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
143 GdkGC * gc, gint x, gint y, gint h,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
144 PlayList_List * list)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
145 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
146 PlaylistSlider *ps;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
147
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
148 ps = g_new0(PlaylistSlider, 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
149 widget_init(&ps->ps_widget, parent, gc, x, y, 8, h, 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
150
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
151 ps->ps_widget.button_press_cb =
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
152 (void (*)(GtkWidget *, GdkEventButton *, gpointer))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
153 playlistslider_button_press_cb;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
154
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
155 ps->ps_widget.button_release_cb =
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
156 (void (*)(GtkWidget *, GdkEventButton *, gpointer))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
157 playlistslider_button_release_cb;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
158
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
159 ps->ps_widget.motion_cb =
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
160 (void (*)(GtkWidget *, GdkEventMotion *, gpointer))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
161 playlistslider_motion_cb;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
162
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
163 ps->ps_widget.draw = playlistslider_draw;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
164 ps->ps_list = list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
165
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
166 widget_list_add(wlist, WIDGET(ps));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
167 return ps;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
168 }